Mercurial > mplayer.hg
annotate vidix/sysdep/libdha_win32.c @ 36388:542cf5882264
Remove pointless casts.
author | reimar |
---|---|
date | Fri, 25 Oct 2013 19:59:56 +0000 |
parents | d9cf7500b0d8 |
children |
rev | line source |
---|---|
4164 | 1 /* |
30419 | 2 * MAPDEV.h - include file for VxD MAPDEV |
3 * Copyright (c) 1996 Vireo Software, Inc. | |
4 * Modified for libdha by Nick Kurshev. | |
5 * | |
6 * This file is part of MPlayer. | |
7 * | |
8 * MPlayer is free software; you can redistribute it and/or modify | |
9 * it under the terms of the GNU General Public License as published by | |
10 * the Free Software Foundation; either version 2 of the License, or | |
11 * (at your option) any later version. | |
12 * | |
13 * MPlayer is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License along | |
19 * with MPlayer; if not, write to the Free Software Foundation, Inc., | |
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
21 */ | |
4164 | 22 |
23 #include <windows.h> | |
12056 | 24 #include <ddk/ntddk.h> |
26994 | 25 #include "vidix/dhahelperwin/dhahelper.h" |
33627
d9cf7500b0d8
vidix: Replace IsWinNT() forward declaration by a proper header.
diego
parents:
33623
diff
changeset
|
26 #include "libdha_win32.h" |
12056 | 27 |
4164 | 28 /* |
29 This is the request structure that applications use | |
30 to request services from the MAPDEV VxD. | |
31 */ | |
32 | |
25607
9d0b189ce1b2
Fix illegal identifiers: Names starting with __ or _ and uppercase are reserved
diego
parents:
22900
diff
changeset
|
33 typedef struct MapDevRequest |
4164 | 34 { |
35 DWORD mdr_ServiceID; /* supplied by caller */ | |
36 LPVOID mdr_PhysicalAddress; /* supplied by caller */ | |
37 DWORD mdr_SizeInBytes; /* supplied by caller */ | |
38 LPVOID mdr_LinearAddress; /* returned by VxD */ | |
39 WORD mdr_Selector; /* returned if 16-bit caller */ | |
40 WORD mdr_Status; /* MDR_xxxx code below */ | |
41 } MAPDEVREQUEST, *PMAPDEVREQUEST; | |
42 | |
43 #define MDR_SERVICE_MAP CTL_CODE(FILE_DEVICE_UNKNOWN, 1, METHOD_NEITHER, FILE_ANY_ACCESS) | |
44 #define MDR_SERVICE_UNMAP CTL_CODE(FILE_DEVICE_UNKNOWN, 2, METHOD_NEITHER, FILE_ANY_ACCESS) | |
45 | |
46 #define MDR_STATUS_SUCCESS 1 | |
47 #define MDR_STATUS_ERROR 0 | |
48 /*#include "winioctl.h"*/ | |
49 #define FILE_DEVICE_UNKNOWN 0x00000022 | |
50 #define METHOD_NEITHER 3 | |
51 | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28232
diff
changeset
|
52 |
28232
8df85ad26746
Add missing 'void' keyword to parameterless function declarations.
diego
parents:
27721
diff
changeset
|
53 int IsWinNT(void) { |
12056 | 54 OSVERSIONINFO OSVersionInfo; |
55 OSVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); | |
56 GetVersionEx(&OSVersionInfo); | |
57 return OSVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28232
diff
changeset
|
58 } |
12056 | 59 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28232
diff
changeset
|
60 static HANDLE hDriver = INVALID_HANDLE_VALUE; |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28232
diff
changeset
|
61 |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28232
diff
changeset
|
62 |
4164 | 63 /* Memory Map a piece of Real Memory */ |
10980 | 64 void *map_phys_mem(unsigned long base, unsigned long size) { |
12056 | 65 if(!IsWinNT()){ |
4164 | 66 HANDLE hDevice ; |
67 PVOID inBuf[1] ; /* buffer for struct pointer to VxD */ | |
68 DWORD cbBytesReturned ; /* count of bytes returned from VxD */ | |
69 MAPDEVREQUEST req ; /* map device request structure */ | |
70 const PCHAR VxDName = "\\\\.\\MAPDEV.VXD" ; | |
71 const PCHAR VxDNameAlreadyLoaded = "\\\\.\\MAPDEV" ; | |
72 | |
73 hDevice = CreateFile(VxDName, 0,0,0, | |
74 CREATE_NEW, FILE_FLAG_DELETE_ON_CLOSE, 0) ; | |
75 if (hDevice == INVALID_HANDLE_VALUE) | |
76 hDevice = CreateFile(VxDNameAlreadyLoaded, 0,0,0, | |
77 CREATE_NEW, FILE_FLAG_DELETE_ON_CLOSE, 0) ; | |
78 if (hDevice == INVALID_HANDLE_VALUE) { | |
79 fprintf(stderr, "Cannot open driver, error=%08lx\n", GetLastError()) ; | |
80 exit(1) ; } | |
81 | |
82 req.mdr_ServiceID = MDR_SERVICE_MAP ; | |
83 req.mdr_PhysicalAddress = (PVOID)base ; | |
84 req.mdr_SizeInBytes = size ; | |
85 inBuf[0] = &req ; | |
86 | |
87 if ( ! DeviceIoControl(hDevice, MDR_SERVICE_MAP, inBuf, sizeof(PVOID), | |
88 NULL, 0, &cbBytesReturned, NULL) ) { | |
89 fprintf(stderr, "Failed to map device\n") ; exit(1) ; } | |
90 | |
91 return (void*)req.mdr_LinearAddress ; | |
12056 | 92 } |
93 else{ | |
94 dhahelper_t dhahelper_priv; | |
95 DWORD dwBytesReturned; | |
96 dhahelper_priv.size = size; | |
97 dhahelper_priv.base = base; | |
98 if(hDriver==INVALID_HANDLE_VALUE)hDriver = CreateFile("\\\\.\\DHAHELPER",GENERIC_READ | GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); | |
99 if (!DeviceIoControl(hDriver, IOCTL_DHAHELPER_MAPPHYSTOLIN, &dhahelper_priv,sizeof(dhahelper_t), &dhahelper_priv, sizeof(dhahelper_t),&dwBytesReturned, NULL)){ | |
17971 | 100 fprintf(stderr,"Unable to map the requested memory region.\n"); |
12056 | 101 return NULL; |
102 } | |
103 else return dhahelper_priv.ptr; | |
104 } | |
4164 | 105 } |
106 | |
12056 | 107 void unmap_phys_mem(void *ptr, unsigned long size) { |
108 if(IsWinNT()){ | |
109 dhahelper_t dhahelper_priv; | |
110 DWORD dwBytesReturned; | |
111 dhahelper_priv.ptr = ptr; | |
112 DeviceIoControl(hDriver, IOCTL_DHAHELPER_UNMAPPHYSADDR, &dhahelper_priv,sizeof(dhahelper_t), NULL, 0, &dwBytesReturned, NULL); | |
113 } | |
114 } |