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>
|
|
8 /*
|
|
9 This is the request structure that applications use
|
|
10 to request services from the MAPDEV VxD.
|
|
11 */
|
|
12
|
|
13 typedef struct _MapDevRequest
|
|
14 {
|
|
15 DWORD mdr_ServiceID; /* supplied by caller */
|
|
16 LPVOID mdr_PhysicalAddress; /* supplied by caller */
|
|
17 DWORD mdr_SizeInBytes; /* supplied by caller */
|
|
18 LPVOID mdr_LinearAddress; /* returned by VxD */
|
|
19 WORD mdr_Selector; /* returned if 16-bit caller */
|
|
20 WORD mdr_Status; /* MDR_xxxx code below */
|
|
21 } MAPDEVREQUEST, *PMAPDEVREQUEST;
|
|
22
|
|
23 #define MDR_SERVICE_MAP CTL_CODE(FILE_DEVICE_UNKNOWN, 1, METHOD_NEITHER, FILE_ANY_ACCESS)
|
|
24 #define MDR_SERVICE_UNMAP CTL_CODE(FILE_DEVICE_UNKNOWN, 2, METHOD_NEITHER, FILE_ANY_ACCESS)
|
|
25
|
|
26 #define MDR_STATUS_SUCCESS 1
|
|
27 #define MDR_STATUS_ERROR 0
|
|
28 /*#include "winioctl.h"*/
|
|
29 #define FILE_DEVICE_UNKNOWN 0x00000022
|
|
30 #define METHOD_NEITHER 3
|
|
31 #define FILE_ANY_ACCESS 0
|
|
32 #define CTL_CODE( DeviceType, Function, Method, Access ) ( \
|
|
33 ((DeviceType)<<16) | ((Access)<<14) | ((Function)<<2) | (Method) )
|
|
34
|
|
35 /* Memory Map a piece of Real Memory */
|
10980
|
36 void *map_phys_mem(unsigned long base, unsigned long size) {
|
4164
|
37
|
|
38 HANDLE hDevice ;
|
|
39 PVOID inBuf[1] ; /* buffer for struct pointer to VxD */
|
|
40 DWORD RetInfo[2] ; /* buffer to receive data from VxD */
|
|
41 DWORD cbBytesReturned ; /* count of bytes returned from VxD */
|
|
42 MAPDEVREQUEST req ; /* map device request structure */
|
|
43 DWORD *pNicstar, Status, Time ; int i ; char *endptr ;
|
|
44 const PCHAR VxDName = "\\\\.\\MAPDEV.VXD" ;
|
|
45 const PCHAR VxDNameAlreadyLoaded = "\\\\.\\MAPDEV" ;
|
|
46
|
|
47 hDevice = CreateFile(VxDName, 0,0,0,
|
|
48 CREATE_NEW, FILE_FLAG_DELETE_ON_CLOSE, 0) ;
|
|
49 if (hDevice == INVALID_HANDLE_VALUE)
|
|
50 hDevice = CreateFile(VxDNameAlreadyLoaded, 0,0,0,
|
|
51 CREATE_NEW, FILE_FLAG_DELETE_ON_CLOSE, 0) ;
|
|
52 if (hDevice == INVALID_HANDLE_VALUE) {
|
|
53 fprintf(stderr, "Cannot open driver, error=%08lx\n", GetLastError()) ;
|
|
54 exit(1) ; }
|
|
55
|
|
56 req.mdr_ServiceID = MDR_SERVICE_MAP ;
|
|
57 req.mdr_PhysicalAddress = (PVOID)base ;
|
|
58 req.mdr_SizeInBytes = size ;
|
|
59 inBuf[0] = &req ;
|
|
60
|
|
61 if ( ! DeviceIoControl(hDevice, MDR_SERVICE_MAP, inBuf, sizeof(PVOID),
|
|
62 NULL, 0, &cbBytesReturned, NULL) ) {
|
|
63 fprintf(stderr, "Failed to map device\n") ; exit(1) ; }
|
|
64
|
|
65 return (void*)req.mdr_LinearAddress ;
|
|
66 }
|
|
67
|
10980
|
68 void unmap_phys_mem(void *ptr, unsigned long size) { }
|