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