annotate vidix/sysdep/libdha_win32.c @ 24012:94d4930701b4

Remove useless #include and silence warnings when compiling find_sub.c.
author cehoyos
date Wed, 08 Aug 2007 10:40:17 +0000
parents a9e111b88c4a
children 9d0b189ce1b2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4164
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
1 /*
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
2 MAPDEV.h - include file for VxD MAPDEV
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
3 Copyright (c) 1996 Vireo Software, Inc.
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
4 Modified for libdha by Nick Kurshev.
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
5 */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
6
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
7 #include <windows.h>
12056
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
8 #include <ddk/ntddk.h>
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
9 #include "../dhahelperwin/dhahelper.h"
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
10
4164
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
11 /*
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
12 This is the request structure that applications use
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
13 to request services from the MAPDEV VxD.
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
14 */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
15
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
16 typedef struct _MapDevRequest
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
17 {
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
18 DWORD mdr_ServiceID; /* supplied by caller */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
19 LPVOID mdr_PhysicalAddress; /* supplied by caller */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
20 DWORD mdr_SizeInBytes; /* supplied by caller */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
21 LPVOID mdr_LinearAddress; /* returned by VxD */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
22 WORD mdr_Selector; /* returned if 16-bit caller */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
23 WORD mdr_Status; /* MDR_xxxx code below */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
24 } MAPDEVREQUEST, *PMAPDEVREQUEST;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
25
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
26 #define MDR_SERVICE_MAP CTL_CODE(FILE_DEVICE_UNKNOWN, 1, METHOD_NEITHER, FILE_ANY_ACCESS)
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
27 #define MDR_SERVICE_UNMAP CTL_CODE(FILE_DEVICE_UNKNOWN, 2, METHOD_NEITHER, FILE_ANY_ACCESS)
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
28
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
29 #define MDR_STATUS_SUCCESS 1
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
30 #define MDR_STATUS_ERROR 0
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
31 /*#include "winioctl.h"*/
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
32 #define FILE_DEVICE_UNKNOWN 0x00000022
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
33 #define METHOD_NEITHER 3
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
34 #define FILE_ANY_ACCESS 0
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
35 #define CTL_CODE( DeviceType, Function, Method, Access ) ( \
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
36 ((DeviceType)<<16) | ((Access)<<14) | ((Function)<<2) | (Method) )
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
37
12056
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
38
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
39 int IsWinNT(){
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
40 OSVERSIONINFO OSVersionInfo;
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
41 OSVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
42 GetVersionEx(&OSVersionInfo);
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
43 return OSVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT;
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
44 }
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
45
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
46 static HANDLE hDriver = INVALID_HANDLE_VALUE;
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
47
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
48
4164
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
49 /* Memory Map a piece of Real Memory */
10980
e687fa1d55c6 port libdha to mingw
faust3
parents: 4164
diff changeset
50 void *map_phys_mem(unsigned long base, unsigned long size) {
12056
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
51 if(!IsWinNT()){
4164
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
52 HANDLE hDevice ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
53 PVOID inBuf[1] ; /* buffer for struct pointer to VxD */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
54 DWORD RetInfo[2] ; /* buffer to receive data from VxD */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
55 DWORD cbBytesReturned ; /* count of bytes returned from VxD */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
56 MAPDEVREQUEST req ; /* map device request structure */
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
57 DWORD *pNicstar, Status, Time ; int i ; char *endptr ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
58 const PCHAR VxDName = "\\\\.\\MAPDEV.VXD" ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
59 const PCHAR VxDNameAlreadyLoaded = "\\\\.\\MAPDEV" ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
60
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
61 hDevice = CreateFile(VxDName, 0,0,0,
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
62 CREATE_NEW, FILE_FLAG_DELETE_ON_CLOSE, 0) ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
63 if (hDevice == INVALID_HANDLE_VALUE)
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
64 hDevice = CreateFile(VxDNameAlreadyLoaded, 0,0,0,
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
65 CREATE_NEW, FILE_FLAG_DELETE_ON_CLOSE, 0) ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
66 if (hDevice == INVALID_HANDLE_VALUE) {
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
67 fprintf(stderr, "Cannot open driver, error=%08lx\n", GetLastError()) ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
68 exit(1) ; }
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
69
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
70 req.mdr_ServiceID = MDR_SERVICE_MAP ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
71 req.mdr_PhysicalAddress = (PVOID)base ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
72 req.mdr_SizeInBytes = size ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
73 inBuf[0] = &req ;
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
74
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
75 if ( ! DeviceIoControl(hDevice, MDR_SERVICE_MAP, inBuf, sizeof(PVOID),
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
76 NULL, 0, &cbBytesReturned, NULL) ) {
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
77 fprintf(stderr, "Failed to map device\n") ; exit(1) ; }
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
78
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
79 return (void*)req.mdr_LinearAddress ;
12056
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
80 }
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
81 else{
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
82 dhahelper_t dhahelper_priv;
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
83 DWORD dwBytesReturned;
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
84 dhahelper_priv.size = size;
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
85 dhahelper_priv.base = base;
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
86 if(hDriver==INVALID_HANDLE_VALUE)hDriver = CreateFile("\\\\.\\DHAHELPER",GENERIC_READ | GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
87 if (!DeviceIoControl(hDriver, IOCTL_DHAHELPER_MAPPHYSTOLIN, &dhahelper_priv,sizeof(dhahelper_t), &dhahelper_priv, sizeof(dhahelper_t),&dwBytesReturned, NULL)){
17971
fd0d4b94b5ec Change some printf calls to fprintf.
diego
parents: 12056
diff changeset
88 fprintf(stderr,"Unable to map the requested memory region.\n");
12056
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
89 return NULL;
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
90 }
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
91 else return dhahelper_priv.ptr;
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
92 }
4164
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
93 }
2e3262002acb Improved readability and new stuffs
nick
parents:
diff changeset
94
12056
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
95 void unmap_phys_mem(void *ptr, unsigned long size) {
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
96 if(IsWinNT()){
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
97 dhahelper_t dhahelper_priv;
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
98 DWORD dwBytesReturned;
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
99 dhahelper_priv.ptr = ptr;
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
100 DeviceIoControl(hDriver, IOCTL_DHAHELPER_UNMAPPHYSADDR, &dhahelper_priv,sizeof(dhahelper_t), NULL, 0, &dwBytesReturned, NULL);
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
101 }
3a727f52c4a2 windows xp support
faust3
parents: 10980
diff changeset
102 }