Mercurial > mplayer.hg
annotate vidix/sysdep/libdha_win32.c @ 27795:51c2de6369b6
cosmetics: alphabetical order
author | diego |
---|---|
date | Sun, 26 Oct 2008 07:33:15 +0000 |
parents | ed6ee2ef3b53 |
children | 8df85ad26746 |
rev | line source |
---|---|
4164 | 1 /* |
2 MAPDEV.h - include file for VxD MAPDEV | |
3 Copyright (c) 1996 Vireo Software, Inc. | |
4 Modified for libdha by Nick Kurshev. | |
5 */ | |
6 | |
7 #include <windows.h> | |
12056 | 8 #include <ddk/ntddk.h> |
26994 | 9 #include "vidix/dhahelperwin/dhahelper.h" |
12056 | 10 |
4164 | 11 /* |
12 This is the request structure that applications use | |
13 to request services from the MAPDEV VxD. | |
14 */ | |
15 | |
25607
9d0b189ce1b2
Fix illegal identifiers: Names starting with __ or _ and uppercase are reserved
diego
parents:
22900
diff
changeset
|
16 typedef struct MapDevRequest |
4164 | 17 { |
18 DWORD mdr_ServiceID; /* supplied by caller */ | |
19 LPVOID mdr_PhysicalAddress; /* supplied by caller */ | |
20 DWORD mdr_SizeInBytes; /* supplied by caller */ | |
21 LPVOID mdr_LinearAddress; /* returned by VxD */ | |
22 WORD mdr_Selector; /* returned if 16-bit caller */ | |
23 WORD mdr_Status; /* MDR_xxxx code below */ | |
24 } MAPDEVREQUEST, *PMAPDEVREQUEST; | |
25 | |
26 #define MDR_SERVICE_MAP CTL_CODE(FILE_DEVICE_UNKNOWN, 1, METHOD_NEITHER, FILE_ANY_ACCESS) | |
27 #define MDR_SERVICE_UNMAP CTL_CODE(FILE_DEVICE_UNKNOWN, 2, METHOD_NEITHER, FILE_ANY_ACCESS) | |
28 | |
29 #define MDR_STATUS_SUCCESS 1 | |
30 #define MDR_STATUS_ERROR 0 | |
31 /*#include "winioctl.h"*/ | |
32 #define FILE_DEVICE_UNKNOWN 0x00000022 | |
33 #define METHOD_NEITHER 3 | |
34 | |
12056 | 35 |
36 int IsWinNT(){ | |
37 OSVERSIONINFO OSVersionInfo; | |
38 OSVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); | |
39 GetVersionEx(&OSVersionInfo); | |
40 return OSVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT; | |
41 } | |
42 | |
43 static HANDLE hDriver = INVALID_HANDLE_VALUE; | |
44 | |
45 | |
4164 | 46 /* Memory Map a piece of Real Memory */ |
10980 | 47 void *map_phys_mem(unsigned long base, unsigned long size) { |
12056 | 48 if(!IsWinNT()){ |
4164 | 49 HANDLE hDevice ; |
50 PVOID inBuf[1] ; /* buffer for struct pointer to VxD */ | |
51 DWORD cbBytesReturned ; /* count of bytes returned from VxD */ | |
52 MAPDEVREQUEST req ; /* map device request structure */ | |
53 const PCHAR VxDName = "\\\\.\\MAPDEV.VXD" ; | |
54 const PCHAR VxDNameAlreadyLoaded = "\\\\.\\MAPDEV" ; | |
55 | |
56 hDevice = CreateFile(VxDName, 0,0,0, | |
57 CREATE_NEW, FILE_FLAG_DELETE_ON_CLOSE, 0) ; | |
58 if (hDevice == INVALID_HANDLE_VALUE) | |
59 hDevice = CreateFile(VxDNameAlreadyLoaded, 0,0,0, | |
60 CREATE_NEW, FILE_FLAG_DELETE_ON_CLOSE, 0) ; | |
61 if (hDevice == INVALID_HANDLE_VALUE) { | |
62 fprintf(stderr, "Cannot open driver, error=%08lx\n", GetLastError()) ; | |
63 exit(1) ; } | |
64 | |
65 req.mdr_ServiceID = MDR_SERVICE_MAP ; | |
66 req.mdr_PhysicalAddress = (PVOID)base ; | |
67 req.mdr_SizeInBytes = size ; | |
68 inBuf[0] = &req ; | |
69 | |
70 if ( ! DeviceIoControl(hDevice, MDR_SERVICE_MAP, inBuf, sizeof(PVOID), | |
71 NULL, 0, &cbBytesReturned, NULL) ) { | |
72 fprintf(stderr, "Failed to map device\n") ; exit(1) ; } | |
73 | |
74 return (void*)req.mdr_LinearAddress ; | |
12056 | 75 } |
76 else{ | |
77 dhahelper_t dhahelper_priv; | |
78 DWORD dwBytesReturned; | |
79 dhahelper_priv.size = size; | |
80 dhahelper_priv.base = base; | |
81 if(hDriver==INVALID_HANDLE_VALUE)hDriver = CreateFile("\\\\.\\DHAHELPER",GENERIC_READ | GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); | |
82 if (!DeviceIoControl(hDriver, IOCTL_DHAHELPER_MAPPHYSTOLIN, &dhahelper_priv,sizeof(dhahelper_t), &dhahelper_priv, sizeof(dhahelper_t),&dwBytesReturned, NULL)){ | |
17971 | 83 fprintf(stderr,"Unable to map the requested memory region.\n"); |
12056 | 84 return NULL; |
85 } | |
86 else return dhahelper_priv.ptr; | |
87 } | |
4164 | 88 } |
89 | |
12056 | 90 void unmap_phys_mem(void *ptr, unsigned long size) { |
91 if(IsWinNT()){ | |
92 dhahelper_t dhahelper_priv; | |
93 DWORD dwBytesReturned; | |
94 dhahelper_priv.ptr = ptr; | |
95 DeviceIoControl(hDriver, IOCTL_DHAHELPER_UNMAPPHYSADDR, &dhahelper_priv,sizeof(dhahelper_t), NULL, 0, &dwBytesReturned, NULL); | |
96 } | |
97 } |