|
|
1.1 root 1: /*++
2:
3: Copyright (c) 1993 Microsoft Corporation
4:
5: Module Name:
6:
7: maptest.h
8:
9: Abstract:
10:
11: Win32 test app for the MAPMEM driver
12:
13: Environment:
14:
15: User mode
16:
17: Notes:
18:
19:
20: Revision History:
21:
22: --*/
23:
24:
25: #include "windows.h"
26: #include "winioctl.h"
27: #include "stdio.h"
28: #include "stdlib.h"
29:
30:
31: //
32: // A couple of typedefs mapmem.h depends on from MINIPORT.H & NTDDK.H.
33: //
34:
35: typedef enum _INTERFACE_TYPE
36: {
37: Internal,
38: Isa,
39: Eisa,
40: MicroChannel,
41: TurboChannel,
42: MaximumInterfaceType
43: } INTERFACE_TYPE, *PINTERFACE_TYPE;
44:
45: typedef LARGE_INTEGER PHYSICAL_ADDRESS;
46:
47: #include "mapmem.h"
48:
49:
50:
51: int
52: main(
53: IN int argc,
54: IN char *argv[])
55: /*++
56:
57: Routine Description:
58:
59: Tries to open the MAPMEM driver & send it a couple of IOCTLs.
60:
61: Arguments:
62:
63: argc - count of command line arguments
64:
65: argv - command line arguments
66:
67: Return Value:
68:
69:
70: --*/
71: {
72: HANDLE hDriver;
73: PHYSICAL_MEMORY_INFO pmi;
74: PVOID pPartyMem;
75: DWORD cbReturned;
76: ULONG length;
77: char *aInterfaceType[] = {"Internal",
78: "Isa",
79: "Eisa",
80: "MicroChannel",
81: "TurboChannel" };
82: if (argc < 4)
83: {
84: //
85: // Display usage message
86: //
87:
88: printf ("\nUsage: maptest <InterfaceType> <BusNumber> <BusAddress> <AddressSpace> <length>\n\n");
89: printf ("\t<InterfaceType>: 1 = Isa, 2 = Eisa, 3 = Microchannel, 4 = TurboChannel\n");
90: printf ("\t<BusNumber> : bus number, i.e. 0 for standard x86 ISA systems\n");
91: printf ("\t<BusAddress> : physical address to map (hex)\n");
92: printf ("\t<AddressSpace> : 0 = memory, 1 = I/O\n");
93: printf ("\t<length> : length of section to map (hex)\n\n");
94:
95: printf ("\tExample: 'maptest 1 0 0xa0000 0 0x2000'\n");
96: return 0;
97: }
98:
99:
100:
101: //
102: // Parse the args
103: //
104:
105: pmi.InterfaceType = (INTERFACE_TYPE) atoi (argv[1]);
106: pmi.BusNumber = (ULONG) atoi (argv[2]);
107: pmi.BusAddress.HighPart = (LONG) 0x00000000;
108: pmi.AddressSpace = (LONG) atoi (argv[4]);
109:
110: sscanf (argv[3], "%x", &pmi.BusAddress.LowPart);
111: sscanf (argv[5], "%x", &pmi.Length);
112:
113: printf ("\tInterfaceType = %s\n", aInterfaceType[pmi.InterfaceType]);
114: printf ("\tBusNumber = %d\n", pmi.BusNumber);
115: printf ("\tBusAddress = 0x%x\n", pmi.BusAddress.LowPart, pmi.BusAddress.LowPart);
116: printf ("\tAddressSpac = %d\n", pmi.AddressSpace);
117: printf ("\tLength = 0x%x\n", pmi.Length, pmi.Length);
118:
119: length = pmi.Length;
120:
121:
122:
123: //
124: // Try to open the device
125: //
126:
127: if ((hDriver = CreateFile("\\\\.\\MAPMEM",
128: GENERIC_READ | GENERIC_WRITE,
129: 0,
130: NULL,
131: OPEN_EXISTING,
132: FILE_ATTRIBUTE_NORMAL,
133: NULL
134: )) != ((HANDLE)-1))
135:
136: printf ("\nRetrieved valid handle for MAPMEM driver\n");
137:
138:
139: else
140: {
141: printf ("Can't get a handle to MAPMEM driver\n");
142:
143: return 0;
144: }
145:
146:
147:
148: //
149: // Try to map the memory
150: //
151:
152: if (DeviceIoControl (hDriver,
153: (DWORD) IOCTL_MAPMEM_MAP_USER_PHYSICAL_MEMORY,
154: &pmi,
155: sizeof(PHYSICAL_MEMORY_INFO),
156: &pPartyMem,
157: sizeof(PVOID),
158: &cbReturned,
159: 0
160: ) )
161: {
162: ULONG j;
163:
164: //
165: // party on memory...
166: //
167:
168: if (pPartyMem)
169: {
170: UCHAR uc;
171:
172: for (j = 0; j < length; j++)
173: {
174: uc = *(((PUCHAR) pPartyMem) + j);
175:
176: *(((PUCHAR) pPartyMem) + j) = 0x47;
177: }
178:
179:
180: //
181: // Unmap the memory
182: //
183:
184: DeviceIoControl (hDriver,
185: (DWORD) IOCTL_MAPMEM_UNMAP_USER_PHYSICAL_MEMORY,
186: &pPartyMem,
187: sizeof(PVOID),
188: NULL,
189: 0,
190: &cbReturned,
191: 0
192: );
193: }
194:
195: else
196:
197: printf ("pPartyMem = NULL\n");
198: }
199:
200: else
201:
202: //
203: // We failed to map, possibly due to resource conflicts (i.e
204: // some other driver/device already grabbed the section we
205: // wanted).
206: //
207:
208: printf ("DeviceIoControl failed\n");
209:
210:
211: CloseHandle(hDriver);
212:
213: return 1;
214: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.