Name all sections of type sect1.
[wine.git] / win32 / device.c
blob45245d48169c5605483b73c5dc133b08cd44a2ff
1 /*
2 * Win32 device functions
4 * Copyright 1998 Marcus Meissner
5 * Copyright 1998 Ulrich Weigand
6 * Copyright 1998 Patrik Stridvall
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "config.h"
24 #include "wine/port.h"
26 #include <stdlib.h>
27 #ifdef HAVE_UNISTD_H
28 # include <unistd.h>
29 #endif
30 #include <sys/types.h>
31 #include <string.h>
32 #include <stdarg.h>
33 #include <time.h>
35 #include "windef.h"
36 #include "winbase.h"
37 #include "winreg.h"
38 #include "winerror.h"
39 #include "file.h"
40 #include "winioctl.h"
41 #include "winnt.h"
42 #include "msdos.h"
43 #include "miscemu.h"
44 #include "stackframe.h"
45 #include "wine/server.h"
46 #include "wine/debug.h"
47 #include "callback.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(file);
52 static BOOL DeviceIo_VTDAPI(DWORD dwIoControlCode,
53 LPVOID lpvInBuffer, DWORD cbInBuffer,
54 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
55 LPDWORD lpcbBytesReturned,
56 LPOVERLAPPED lpOverlapped);
57 static BOOL DeviceIo_MONODEBG(DWORD dwIoControlCode,
58 LPVOID lpvInBuffer, DWORD cbInBuffer,
59 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
60 LPDWORD lpcbBytesReturned,
61 LPOVERLAPPED lpOverlapped);
62 static BOOL DeviceIo_MMDEVLDR(DWORD dwIoControlCode,
63 LPVOID lpvInBuffer, DWORD cbInBuffer,
64 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
65 LPDWORD lpcbBytesReturned,
66 LPOVERLAPPED lpOverlapped);
68 static DWORD VxDCall_VMM( DWORD service, CONTEXT86 *context );
70 static BOOL DeviceIo_IFSMgr(DWORD dwIoControlCode,
71 LPVOID lpvInBuffer, DWORD cbInBuffer,
72 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
73 LPDWORD lpcbBytesReturned,
74 LPOVERLAPPED lpOverlapped);
76 static BOOL DeviceIo_VCD(DWORD dwIoControlCode,
77 LPVOID lpvInBuffer, DWORD cbInBuffer,
78 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
79 LPDWORD lpcbBytesReturned,
80 LPOVERLAPPED lpOverlapped);
82 static DWORD VxDCall_VWin32( DWORD service, CONTEXT86 *context );
84 static BOOL DeviceIo_VWin32(DWORD dwIoControlCode,
85 LPVOID lpvInBuffer, DWORD cbInBuffer,
86 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
87 LPDWORD lpcbBytesReturned,
88 LPOVERLAPPED lpOverlapped);
90 static BOOL DeviceIo_PCCARD (DWORD dwIoControlCode,
91 LPVOID lpvInBuffer, DWORD cbInBuffer,
92 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
93 LPDWORD lpcbBytesReturned,
94 LPOVERLAPPED lpOverlapped);
96 static BOOL DeviceIo_HASP (DWORD dwIoControlCode,
97 LPVOID lpvInBuffer, DWORD cbInBuffer,
98 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
99 LPDWORD lpcbBytesReturned,
100 LPOVERLAPPED lpOverlapped);
102 * VxD names are taken from the Win95 DDK
105 struct VxDInfo
107 LPCSTR name;
108 WORD id;
109 DWORD (*vxdcall)(DWORD, CONTEXT86 *);
110 BOOL (*deviceio)(DWORD, LPVOID, DWORD,
111 LPVOID, DWORD, LPDWORD, LPOVERLAPPED);
114 static const struct VxDInfo VxDList[] =
116 /* Standard VxD IDs */
117 { "VMM", 0x0001, VxDCall_VMM, NULL },
118 { "DEBUG", 0x0002, NULL, NULL },
119 { "VPICD", 0x0003, NULL, NULL },
120 { "VDMAD", 0x0004, NULL, NULL },
121 { "VTD", 0x0005, NULL, NULL },
122 { "V86MMGR", 0x0006, NULL, NULL },
123 { "PAGESWAP", 0x0007, NULL, NULL },
124 { "PARITY", 0x0008, NULL, NULL },
125 { "REBOOT", 0x0009, NULL, NULL },
126 { "VDD", 0x000A, NULL, NULL },
127 { "VSD", 0x000B, NULL, NULL },
128 { "VMD", 0x000C, NULL, NULL },
129 { "VKD", 0x000D, NULL, NULL },
130 { "VCD", 0x000E, NULL, DeviceIo_VCD },
131 { "VPD", 0x000F, NULL, NULL },
132 { "BLOCKDEV", 0x0010, NULL, NULL },
133 { "VMCPD", 0x0011, NULL, NULL },
134 { "EBIOS", 0x0012, NULL, NULL },
135 { "BIOSXLAT", 0x0013, NULL, NULL },
136 { "VNETBIOS", 0x0014, NULL, NULL },
137 { "DOSMGR", 0x0015, NULL, NULL },
138 { "WINLOAD", 0x0016, NULL, NULL },
139 { "SHELL", 0x0017, NULL, NULL },
140 { "VMPOLL", 0x0018, NULL, NULL },
141 { "VPROD", 0x0019, NULL, NULL },
142 { "DOSNET", 0x001A, NULL, NULL },
143 { "VFD", 0x001B, NULL, NULL },
144 { "VDD2", 0x001C, NULL, NULL },
145 { "WINDEBUG", 0x001D, NULL, NULL },
146 { "TSRLOAD", 0x001E, NULL, NULL },
147 { "BIOSHOOK", 0x001F, NULL, NULL },
148 { "INT13", 0x0020, NULL, NULL },
149 { "PAGEFILE", 0x0021, NULL, NULL },
150 { "SCSI", 0x0022, NULL, NULL },
151 { "MCA_POS", 0x0023, NULL, NULL },
152 { "SCSIFD", 0x0024, NULL, NULL },
153 { "VPEND", 0x0025, NULL, NULL },
154 { "VPOWERD", 0x0026, NULL, NULL },
155 { "VXDLDR", 0x0027, NULL, NULL },
156 { "NDIS", 0x0028, NULL, NULL },
157 { "BIOS_EXT", 0x0029, NULL, NULL },
158 { "VWIN32", 0x002A, VxDCall_VWin32, DeviceIo_VWin32 },
159 { "VCOMM", 0x002B, NULL, NULL },
160 { "SPOOLER", 0x002C, NULL, NULL },
161 { "WIN32S", 0x002D, NULL, NULL },
162 { "DEBUGCMD", 0x002E, NULL, NULL },
164 { "VNB", 0x0031, NULL, NULL },
165 { "SERVER", 0x0032, NULL, NULL },
166 { "CONFIGMG", 0x0033, NULL, NULL },
167 { "DWCFGMG", 0x0034, NULL, NULL },
168 { "SCSIPORT", 0x0035, NULL, NULL },
169 { "VFBACKUP", 0x0036, NULL, NULL },
170 { "ENABLE", 0x0037, NULL, NULL },
171 { "VCOND", 0x0038, NULL, NULL },
173 { "EFAX", 0x003A, NULL, NULL },
174 { "DSVXD", 0x003B, NULL, NULL },
175 { "ISAPNP", 0x003C, NULL, NULL },
176 { "BIOS", 0x003D, NULL, NULL },
177 { "WINSOCK", 0x003E, NULL, NULL },
178 { "WSOCK", 0x003E, NULL, NULL },
179 { "WSIPX", 0x003F, NULL, NULL },
180 { "IFSMgr", 0x0040, NULL, DeviceIo_IFSMgr },
181 { "VCDFSD", 0x0041, NULL, NULL },
182 { "MRCI2", 0x0042, NULL, NULL },
183 { "PCI", 0x0043, NULL, NULL },
184 { "PELOADER", 0x0044, NULL, NULL },
185 { "EISA", 0x0045, NULL, NULL },
186 { "DRAGCLI", 0x0046, NULL, NULL },
187 { "DRAGSRV", 0x0047, NULL, NULL },
188 { "PERF", 0x0048, NULL, NULL },
189 { "AWREDIR", 0x0049, NULL, NULL },
191 /* Far East support */
192 { "ETEN", 0x0060, NULL, NULL },
193 { "CHBIOS", 0x0061, NULL, NULL },
194 { "VMSGD", 0x0062, NULL, NULL },
195 { "VPPID", 0x0063, NULL, NULL },
196 { "VIME", 0x0064, NULL, NULL },
197 { "VHBIOSD", 0x0065, NULL, NULL },
199 /* Multimedia OEM IDs */
200 { "VTDAPI", 0x0442, NULL, DeviceIo_VTDAPI },
201 { "MMDEVLDR", 0x044A, NULL, DeviceIo_MMDEVLDR },
203 /* Network Device IDs */
204 { "VNetSup", 0x0480, NULL, NULL },
205 { "VRedir", 0x0481, NULL, NULL },
206 { "VBrowse", 0x0482, NULL, NULL },
207 { "VSHARE", 0x0483, NULL, NULL },
208 { "IFSMgr", 0x0484, NULL, NULL },
209 { "MEMPROBE", 0x0485, NULL, NULL },
210 { "VFAT", 0x0486, NULL, NULL },
211 { "NWLINK", 0x0487, NULL, NULL },
212 { "VNWLINK", 0x0487, NULL, NULL },
213 { "NWSUP", 0x0487, NULL, NULL },
214 { "VTDI", 0x0488, NULL, NULL },
215 { "VIP", 0x0489, NULL, NULL },
216 { "VTCP", 0x048A, NULL, NULL },
217 { "VCache", 0x048B, NULL, NULL },
218 { "VUDP", 0x048C, NULL, NULL },
219 { "VAsync", 0x048D, NULL, NULL },
220 { "NWREDIR", 0x048E, NULL, NULL },
221 { "STAT80", 0x048F, NULL, NULL },
222 { "SCSIPORT", 0x0490, NULL, NULL },
223 { "FILESEC", 0x0491, NULL, NULL },
224 { "NWSERVER", 0x0492, NULL, NULL },
225 { "SECPROV", 0x0493, NULL, NULL },
226 { "NSCL", 0x0494, NULL, NULL },
227 { "WSTCP", 0x0495, NULL, NULL },
228 { "NDIS2SUP", 0x0496, NULL, NULL },
229 { "MSODISUP", 0x0497, NULL, NULL },
230 { "Splitter", 0x0498, NULL, NULL },
231 { "PPP", 0x0499, NULL, NULL },
232 { "VDHCP", 0x049A, NULL, NULL },
233 { "VNBT", 0x049B, NULL, NULL },
234 { "LOGGER", 0x049D, NULL, NULL },
235 { "EFILTER", 0x049E, NULL, NULL },
236 { "FFILTER", 0x049F, NULL, NULL },
237 { "TFILTER", 0x04A0, NULL, NULL },
238 { "AFILTER", 0x04A1, NULL, NULL },
239 { "IRLAMP", 0x04A2, NULL, NULL },
241 { "PCCARD", 0x097C, NULL, DeviceIo_PCCARD },
242 { "HASP95", 0x3721, NULL, DeviceIo_HASP },
244 /* WINE additions, ids unknown */
245 { "MONODEBG.VXD", 0x4242, NULL, DeviceIo_MONODEBG },
247 { NULL, 0, NULL, NULL }
251 * VMM VxDCall service names are (mostly) taken from Stan Mitchell's
252 * "Inside the Windows 95 File System"
255 #define N_VMM_SERVICE 41
257 LPCSTR VMM_Service_Name[N_VMM_SERVICE] =
259 "PageReserve", /* 0x0000 */
260 "PageCommit", /* 0x0001 */
261 "PageDecommit", /* 0x0002 */
262 "PagerRegister", /* 0x0003 */
263 "PagerQuery", /* 0x0004 */
264 "HeapAllocate", /* 0x0005 */
265 "ContextCreate", /* 0x0006 */
266 "ContextDestroy", /* 0x0007 */
267 "PageAttach", /* 0x0008 */
268 "PageFlush", /* 0x0009 */
269 "PageFree", /* 0x000A */
270 "ContextSwitch", /* 0x000B */
271 "HeapReAllocate", /* 0x000C */
272 "PageModifyPermissions", /* 0x000D */
273 "PageQuery", /* 0x000E */
274 "GetCurrentContext", /* 0x000F */
275 "HeapFree", /* 0x0010 */
276 "RegOpenKey", /* 0x0011 */
277 "RegCreateKey", /* 0x0012 */
278 "RegCloseKey", /* 0x0013 */
279 "RegDeleteKey", /* 0x0014 */
280 "RegSetValue", /* 0x0015 */
281 "RegDeleteValue", /* 0x0016 */
282 "RegQueryValue", /* 0x0017 */
283 "RegEnumKey", /* 0x0018 */
284 "RegEnumValue", /* 0x0019 */
285 "RegQueryValueEx", /* 0x001A */
286 "RegSetValueEx", /* 0x001B */
287 "RegFlushKey", /* 0x001C */
288 "RegQueryInfoKey", /* 0x001D */
289 "GetDemandPageInfo", /* 0x001E */
290 "BlockOnID", /* 0x001F */
291 "SignalID", /* 0x0020 */
292 "RegLoadKey", /* 0x0021 */
293 "RegUnLoadKey", /* 0x0022 */
294 "RegSaveKey", /* 0x0023 */
295 "RegRemapPreDefKey", /* 0x0024 */
296 "PageChangePager", /* 0x0025 */
297 "RegQueryMultipleValues", /* 0x0026 */
298 "RegReplaceKey", /* 0x0027 */
299 "<KERNEL32.101>" /* 0x0028 -- What does this do??? */
302 /* PageReserve arena values */
303 #define PR_PRIVATE 0x80000400 /* anywhere in private arena */
304 #define PR_SHARED 0x80060000 /* anywhere in shared arena */
305 #define PR_SYSTEM 0x80080000 /* anywhere in system arena */
307 /* PageReserve flags */
308 #define PR_FIXED 0x00000008 /* don't move during PageReAllocate */
309 #define PR_4MEG 0x00000001 /* allocate on 4mb boundary */
310 #define PR_STATIC 0x00000010 /* see PageReserve documentation */
312 /* PageCommit default pager handle values */
313 #define PD_ZEROINIT 0x00000001 /* swappable zero-initialized pages */
314 #define PD_NOINIT 0x00000002 /* swappable uninitialized pages */
315 #define PD_FIXEDZERO 0x00000003 /* fixed zero-initialized pages */
316 #define PD_FIXED 0x00000004 /* fixed uninitialized pages */
318 /* PageCommit flags */
319 #define PC_FIXED 0x00000008 /* pages are permanently locked */
320 #define PC_LOCKED 0x00000080 /* pages are made present and locked */
321 #define PC_LOCKEDIFDP 0x00000100 /* pages are locked if swap via DOS */
322 #define PC_WRITEABLE 0x00020000 /* make the pages writeable */
323 #define PC_USER 0x00040000 /* make the pages ring 3 accessible */
324 #define PC_INCR 0x40000000 /* increment "pagerdata" each page */
325 #define PC_PRESENT 0x80000000 /* make pages initially present */
326 #define PC_STATIC 0x20000000 /* allow commit in PR_STATIC object */
327 #define PC_DIRTY 0x08000000 /* make pages initially dirty */
328 #define PC_CACHEDIS 0x00100000 /* Allocate uncached pages - new for WDM */
329 #define PC_CACHEWT 0x00080000 /* Allocate write through cache pages - new for WDM */
330 #define PC_PAGEFLUSH 0x00008000 /* Touch device mapped pages on alloc - new for WDM */
332 /* PageCommitContig additional flags */
333 #define PCC_ZEROINIT 0x00000001 /* zero-initialize new pages */
334 #define PCC_NOLIN 0x10000000 /* don't map to any linear address */
338 HANDLE DEVICE_Open( LPCWSTR filenameW, DWORD access, LPSECURITY_ATTRIBUTES sa )
340 const struct VxDInfo *info;
341 char filename[MAX_PATH];
343 if (!WideCharToMultiByte(CP_ACP, 0, filenameW, -1, filename, MAX_PATH, NULL, NULL))
345 SetLastError( ERROR_FILE_NOT_FOUND );
346 return 0;
349 for (info = VxDList; info->name; info++)
350 if (!strncasecmp( info->name, filename, strlen(info->name) ))
351 return FILE_CreateDevice( info->id | 0x10000, access, sa );
353 FIXME( "Unknown/unsupported VxD %s. Try setting Windows version to 'nt40' or 'win31'.\n",
354 filename);
355 SetLastError( ERROR_FILE_NOT_FOUND );
356 return 0;
359 static DWORD DEVICE_GetClientID( HANDLE handle )
361 DWORD ret = 0;
362 SERVER_START_REQ( get_device_id )
364 req->handle = handle;
365 if (!wine_server_call( req )) ret = reply->id;
367 SERVER_END_REQ;
368 return ret;
371 static const struct VxDInfo *DEVICE_GetInfo( DWORD clientID )
373 const struct VxDInfo *info = NULL;
375 if (clientID & 0x10000)
377 for (info = VxDList; info->name; info++)
378 if (info->id == LOWORD(clientID)) break;
380 return info;
383 /****************************************************************************
384 * DeviceIoControl (KERNEL32.@)
385 * This is one of those big ugly nasty procedure which can do
386 * a million and one things when it comes to devices. It can also be
387 * used for VxD communication.
389 * A return value of FALSE indicates that something has gone wrong which
390 * GetLastError can decipher.
392 BOOL WINAPI DeviceIoControl(HANDLE hDevice, DWORD dwIoControlCode,
393 LPVOID lpvInBuffer, DWORD cbInBuffer,
394 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
395 LPDWORD lpcbBytesReturned,
396 LPOVERLAPPED lpOverlapped)
398 DWORD clientID;
400 TRACE( "(%p,%ld,%p,%ld,%p,%ld,%p,%p)\n",
401 hDevice,dwIoControlCode,lpvInBuffer,cbInBuffer,
402 lpvOutBuffer,cbOutBuffer,lpcbBytesReturned,lpOverlapped );
404 if (!(clientID = DEVICE_GetClientID( hDevice )))
406 SetLastError( ERROR_INVALID_PARAMETER );
407 return FALSE;
410 /* Check if this is a user defined control code for a VxD */
411 if( HIWORD( dwIoControlCode ) == 0 )
413 const struct VxDInfo *info;
414 if (!(info = DEVICE_GetInfo( clientID )))
416 FIXME( "No device found for id %lx\n", clientID);
418 else if ( info->deviceio )
420 return info->deviceio( dwIoControlCode,
421 lpvInBuffer, cbInBuffer,
422 lpvOutBuffer, cbOutBuffer,
423 lpcbBytesReturned, lpOverlapped );
425 else
427 FIXME( "Unimplemented control %ld for VxD device %s\n",
428 dwIoControlCode, info->name ? info->name : "???" );
429 /* FIXME: this is for invalid calls on W98SE,
430 * but maybe we should use ERROR_CALL_NOT_IMPLEMENTED
431 * instead ? */
432 SetLastError( ERROR_INVALID_FUNCTION );
435 else
437 NTSTATUS status;
439 if (lpOverlapped)
441 status = NtDeviceIoControlFile(hDevice, lpOverlapped->hEvent,
442 NULL, NULL,
443 (PIO_STATUS_BLOCK)lpOverlapped,
444 dwIoControlCode,
445 lpvInBuffer, cbInBuffer,
446 lpvOutBuffer, cbOutBuffer);
447 if (status) SetLastError(RtlNtStatusToDosError(status));
448 if (lpcbBytesReturned) *lpcbBytesReturned = lpOverlapped->InternalHigh;
449 return !status;
451 else
453 IO_STATUS_BLOCK iosb;
455 status = NtDeviceIoControlFile(hDevice, NULL, NULL, NULL, &iosb,
456 dwIoControlCode,
457 lpvInBuffer, cbInBuffer,
458 lpvOutBuffer, cbOutBuffer);
459 if (status) SetLastError(RtlNtStatusToDosError(status));
460 if (lpcbBytesReturned) *lpcbBytesReturned = iosb.Information;
461 return !status;
464 return FALSE;
467 /***********************************************************************
468 * DeviceIo_VTDAPI
470 static BOOL DeviceIo_VTDAPI(DWORD dwIoControlCode, LPVOID lpvInBuffer, DWORD cbInBuffer,
471 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
472 LPDWORD lpcbBytesReturned,
473 LPOVERLAPPED lpOverlapped)
475 BOOL retv = TRUE;
477 switch (dwIoControlCode)
479 case 5:
480 if (lpvOutBuffer && (cbOutBuffer>=4))
481 *(DWORD*)lpvOutBuffer = GetTickCount();
483 if (lpcbBytesReturned)
484 *lpcbBytesReturned = 4;
486 break;
488 default:
489 FIXME( "Control %ld not implemented\n", dwIoControlCode);
490 retv = FALSE;
491 break;
494 return retv;
497 /***********************************************************************
498 * VxDCall0 (KERNEL32.1)
499 * VxDCall1 (KERNEL32.2)
500 * VxDCall2 (KERNEL32.3)
501 * VxDCall3 (KERNEL32.4)
502 * VxDCall4 (KERNEL32.5)
503 * VxDCall5 (KERNEL32.6)
504 * VxDCall6 (KERNEL32.7)
505 * VxDCall7 (KERNEL32.8)
506 * VxDCall8 (KERNEL32.9)
508 void VxDCall( DWORD service, CONTEXT86 *context )
510 DWORD ret = 0xffffffff; /* FIXME */
511 int i;
513 TRACE( "(%08lx, ...)\n", service);
515 for (i = 0; VxDList[i].name; i++)
516 if (VxDList[i].id == HIWORD(service))
517 break;
519 if (!VxDList[i].name)
520 FIXME( "Unknown VxD (%08lx)\n", service);
521 else if (!VxDList[i].vxdcall)
522 FIXME( "Unimplemented VxD (%08lx)\n", service);
523 else
524 ret = VxDList[i].vxdcall( service, context );
526 context->Eax = ret;
530 /******************************************************************************
531 * The following is a massive duplication of the advapi32 code.
532 * Unfortunately sharing the code is not possible since the native
533 * Win95 advapi32 depends on it. Someday we should probably stop
534 * supporting native Win95 advapi32 altogether...
538 #define HKEY_SPECIAL_ROOT_FIRST HKEY_CLASSES_ROOT
539 #define HKEY_SPECIAL_ROOT_LAST HKEY_DYN_DATA
540 #define NB_SPECIAL_ROOT_KEYS ((UINT)HKEY_SPECIAL_ROOT_LAST - (UINT)HKEY_SPECIAL_ROOT_FIRST + 1)
542 static HKEY special_root_keys[NB_SPECIAL_ROOT_KEYS];
544 static const WCHAR name_CLASSES_ROOT[] =
545 {'M','a','c','h','i','n','e','\\',
546 'S','o','f','t','w','a','r','e','\\',
547 'C','l','a','s','s','e','s',0};
548 static const WCHAR name_LOCAL_MACHINE[] =
549 {'M','a','c','h','i','n','e',0};
550 static const WCHAR name_USERS[] =
551 {'U','s','e','r',0};
552 static const WCHAR name_PERFORMANCE_DATA[] =
553 {'P','e','r','f','D','a','t','a',0};
554 static const WCHAR name_CURRENT_CONFIG[] =
555 {'M','a','c','h','i','n','e','\\',
556 'S','y','s','t','e','m','\\',
557 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
558 'H','a','r','d','w','a','r','e','P','r','o','f','i','l','e','s','\\',
559 'C','u','r','r','e','n','t',0};
560 static const WCHAR name_DYN_DATA[] =
561 {'D','y','n','D','a','t','a',0};
563 #define DECL_STR(key) { sizeof(name_##key)-sizeof(WCHAR), sizeof(name_##key), (LPWSTR)name_##key }
564 static UNICODE_STRING root_key_names[NB_SPECIAL_ROOT_KEYS] =
566 DECL_STR(CLASSES_ROOT),
567 { 0, 0, NULL }, /* HKEY_CURRENT_USER is determined dynamically */
568 DECL_STR(LOCAL_MACHINE),
569 DECL_STR(USERS),
570 DECL_STR(PERFORMANCE_DATA),
571 DECL_STR(CURRENT_CONFIG),
572 DECL_STR(DYN_DATA)
574 #undef DECL_STR
577 /* check if value type needs string conversion (Ansi<->Unicode) */
578 inline static int is_string( DWORD type )
580 return (type == REG_SZ) || (type == REG_EXPAND_SZ) || (type == REG_MULTI_SZ);
583 /* create one of the HKEY_* special root keys */
584 static HKEY create_special_root_hkey( HKEY hkey, DWORD access )
586 HKEY ret = 0;
587 int idx = (UINT)hkey - (UINT)HKEY_SPECIAL_ROOT_FIRST;
589 if (hkey == HKEY_CURRENT_USER)
591 if (RtlOpenCurrentUser( access, &hkey )) return 0;
593 else
595 OBJECT_ATTRIBUTES attr;
597 attr.Length = sizeof(attr);
598 attr.RootDirectory = 0;
599 attr.ObjectName = &root_key_names[idx];
600 attr.Attributes = 0;
601 attr.SecurityDescriptor = NULL;
602 attr.SecurityQualityOfService = NULL;
603 if (NtCreateKey( &hkey, access, &attr, 0, NULL, 0, NULL )) return 0;
606 if (!(ret = InterlockedCompareExchangePointer( (PVOID) &special_root_keys[idx], hkey, 0 )))
607 ret = hkey;
608 else
609 NtClose( hkey ); /* somebody beat us to it */
610 return ret;
613 /* map the hkey from special root to normal key if necessary */
614 inline static HKEY get_special_root_hkey( HKEY hkey )
616 HKEY ret = hkey;
618 if ((hkey >= HKEY_SPECIAL_ROOT_FIRST) && (hkey <= HKEY_SPECIAL_ROOT_LAST))
620 if (!(ret = special_root_keys[(UINT)hkey - (UINT)HKEY_SPECIAL_ROOT_FIRST]))
621 ret = create_special_root_hkey( hkey, KEY_ALL_ACCESS );
623 return ret;
627 /******************************************************************************
628 * VMM_RegCreateKeyA
630 static DWORD VMM_RegCreateKeyA( HKEY hkey, LPCSTR name, PHKEY retkey )
632 OBJECT_ATTRIBUTES attr;
633 UNICODE_STRING nameW;
634 ANSI_STRING nameA;
635 NTSTATUS status;
637 if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
639 attr.Length = sizeof(attr);
640 attr.RootDirectory = hkey;
641 attr.ObjectName = &nameW;
642 attr.Attributes = 0;
643 attr.SecurityDescriptor = NULL;
644 attr.SecurityQualityOfService = NULL;
645 RtlInitAnsiString( &nameA, name );
647 if (!(status = RtlAnsiStringToUnicodeString( &nameW, &nameA, TRUE )))
649 status = NtCreateKey( retkey, KEY_ALL_ACCESS, &attr, 0, NULL,
650 REG_OPTION_NON_VOLATILE, NULL );
651 RtlFreeUnicodeString( &nameW );
653 return RtlNtStatusToDosError( status );
657 /******************************************************************************
658 * VMM_RegOpenKeyExA
660 DWORD WINAPI VMM_RegOpenKeyExA(HKEY hkey, LPCSTR name, DWORD reserved, REGSAM access, PHKEY retkey)
662 OBJECT_ATTRIBUTES attr;
663 UNICODE_STRING nameW;
664 STRING nameA;
665 NTSTATUS status;
667 if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
669 attr.Length = sizeof(attr);
670 attr.RootDirectory = hkey;
671 attr.ObjectName = &nameW;
672 attr.Attributes = 0;
673 attr.SecurityDescriptor = NULL;
674 attr.SecurityQualityOfService = NULL;
676 RtlInitAnsiString( &nameA, name );
677 if (!(status = RtlAnsiStringToUnicodeString( &nameW, &nameA, TRUE )))
679 status = NtOpenKey( retkey, access, &attr );
680 RtlFreeUnicodeString( &nameW );
682 return RtlNtStatusToDosError( status );
686 /******************************************************************************
687 * VMM_RegCloseKey
689 static DWORD VMM_RegCloseKey( HKEY hkey )
691 if (!hkey || hkey >= (HKEY)0x80000000) return ERROR_SUCCESS;
692 return RtlNtStatusToDosError( NtClose( hkey ) );
696 /******************************************************************************
697 * VMM_RegDeleteKeyA
699 static DWORD VMM_RegDeleteKeyA( HKEY hkey, LPCSTR name )
701 DWORD ret;
702 HKEY tmp;
704 if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
706 if (!name || !*name) return RtlNtStatusToDosError( NtDeleteKey( hkey ) );
707 if (!(ret = VMM_RegOpenKeyExA( hkey, name, 0, 0, &tmp )))
709 ret = RtlNtStatusToDosError( NtDeleteKey( tmp ) );
710 NtClose( tmp );
712 return ret;
716 /******************************************************************************
717 * VMM_RegSetValueExA
719 static DWORD VMM_RegSetValueExA( HKEY hkey, LPCSTR name, DWORD reserved, DWORD type,
720 CONST BYTE *data, DWORD count )
722 UNICODE_STRING nameW;
723 ANSI_STRING nameA;
724 WCHAR *dataW = NULL;
725 NTSTATUS status;
727 if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
729 if (is_string(type))
731 DWORD lenW;
733 if (count)
735 /* if user forgot to count terminating null, add it (yes NT does this) */
736 if (data[count-1] && !data[count]) count++;
738 RtlMultiByteToUnicodeSize( &lenW, data, count );
739 if (!(dataW = HeapAlloc( GetProcessHeap(), 0, lenW ))) return ERROR_OUTOFMEMORY;
740 RtlMultiByteToUnicodeN( dataW, lenW, NULL, data, count );
741 count = lenW;
742 data = (BYTE *)dataW;
745 RtlInitAnsiString( &nameA, name );
746 if (!(status = RtlAnsiStringToUnicodeString( &nameW, &nameA, TRUE )))
748 status = NtSetValueKey( hkey, &nameW, 0, type, data, count );
749 RtlFreeUnicodeString( &nameW );
751 if (dataW) HeapFree( GetProcessHeap(), 0, dataW );
752 return RtlNtStatusToDosError( status );
756 /******************************************************************************
757 * VMM_RegSetValueA
759 static DWORD VMM_RegSetValueA( HKEY hkey, LPCSTR name, DWORD type, LPCSTR data, DWORD count )
761 HKEY subkey = hkey;
762 DWORD ret;
764 if (type != REG_SZ) return ERROR_INVALID_PARAMETER;
766 if (name && name[0]) /* need to create the subkey */
768 if ((ret = VMM_RegCreateKeyA( hkey, name, &subkey )) != ERROR_SUCCESS) return ret;
770 ret = VMM_RegSetValueExA( subkey, NULL, 0, REG_SZ, (LPBYTE)data, strlen(data)+1 );
771 if (subkey != hkey) NtClose( subkey );
772 return ret;
776 /******************************************************************************
777 * VMM_RegDeleteValueA
779 static DWORD VMM_RegDeleteValueA( HKEY hkey, LPCSTR name )
781 UNICODE_STRING nameW;
782 STRING nameA;
783 NTSTATUS status;
785 if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
787 RtlInitAnsiString( &nameA, name );
788 if (!(status = RtlAnsiStringToUnicodeString( &nameW, &nameA, TRUE )))
790 status = NtDeleteValueKey( hkey, &nameW );
791 RtlFreeUnicodeString( &nameW );
793 return RtlNtStatusToDosError( status );
797 /******************************************************************************
798 * VMM_RegQueryValueExA
800 static DWORD VMM_RegQueryValueExA( HKEY hkey, LPCSTR name, LPDWORD reserved, LPDWORD type,
801 LPBYTE data, LPDWORD count )
803 NTSTATUS status;
804 ANSI_STRING nameA;
805 UNICODE_STRING nameW;
806 DWORD total_size;
807 char buffer[256], *buf_ptr = buffer;
808 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)buffer;
809 static const int info_size = offsetof( KEY_VALUE_PARTIAL_INFORMATION, Data );
811 if ((data && !count) || reserved) return ERROR_INVALID_PARAMETER;
812 if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
814 RtlInitAnsiString( &nameA, name );
815 if ((status = RtlAnsiStringToUnicodeString( &nameW, &nameA, TRUE )))
816 return RtlNtStatusToDosError(status);
818 status = NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation,
819 buffer, sizeof(buffer), &total_size );
820 if (status && status != STATUS_BUFFER_OVERFLOW) goto done;
822 /* we need to fetch the contents for a string type even if not requested,
823 * because we need to compute the length of the ASCII string. */
824 if (data || is_string(info->Type))
826 /* retry with a dynamically allocated buffer */
827 while (status == STATUS_BUFFER_OVERFLOW)
829 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
830 if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
832 status = STATUS_NO_MEMORY;
833 goto done;
835 info = (KEY_VALUE_PARTIAL_INFORMATION *)buf_ptr;
836 status = NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation,
837 buf_ptr, total_size, &total_size );
840 if (!status)
842 if (is_string(info->Type))
844 DWORD len = WideCharToMultiByte( CP_ACP, 0, (WCHAR *)(buf_ptr + info_size),
845 (total_size - info_size) /sizeof(WCHAR),
846 NULL, 0, NULL, NULL );
847 if (data && len)
849 if (len > *count) status = STATUS_BUFFER_OVERFLOW;
850 else
852 WideCharToMultiByte( CP_ACP, 0, (WCHAR *)(buf_ptr + info_size),
853 (total_size - info_size) /sizeof(WCHAR),
854 data, len, NULL, NULL );
855 /* if the type is REG_SZ and data is not 0-terminated
856 * and there is enough space in the buffer NT appends a \0 */
857 if (len < *count && data[len-1]) data[len] = 0;
860 total_size = len + info_size;
862 else if (data)
864 if (total_size - info_size > *count) status = STATUS_BUFFER_OVERFLOW;
865 else memcpy( data, buf_ptr + info_size, total_size - info_size );
868 else if (status != STATUS_BUFFER_OVERFLOW) goto done;
871 if (type) *type = info->Type;
872 if (count) *count = total_size - info_size;
874 done:
875 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
876 RtlFreeUnicodeString( &nameW );
877 return RtlNtStatusToDosError(status);
881 /******************************************************************************
882 * VMM_RegQueryValueA
884 static DWORD VMM_RegQueryValueA( HKEY hkey, LPCSTR name, LPSTR data, LPLONG count )
886 DWORD ret;
887 HKEY subkey = hkey;
889 if (name && name[0])
891 if ((ret = VMM_RegOpenKeyExA( hkey, name, 0, KEY_ALL_ACCESS, &subkey )) != ERROR_SUCCESS)
892 return ret;
894 ret = VMM_RegQueryValueExA( subkey, NULL, NULL, NULL, (LPBYTE)data, count );
895 if (subkey != hkey) NtClose( subkey );
896 if (ret == ERROR_FILE_NOT_FOUND)
898 /* return empty string if default value not found */
899 if (data) *data = 0;
900 if (count) *count = 1;
901 ret = ERROR_SUCCESS;
903 return ret;
907 /******************************************************************************
908 * VMM_RegEnumValueA
910 static DWORD VMM_RegEnumValueA( HKEY hkey, DWORD index, LPSTR value, LPDWORD val_count,
911 LPDWORD reserved, LPDWORD type, LPBYTE data, LPDWORD count )
913 NTSTATUS status;
914 DWORD total_size;
915 char buffer[256], *buf_ptr = buffer;
916 KEY_VALUE_FULL_INFORMATION *info = (KEY_VALUE_FULL_INFORMATION *)buffer;
917 static const int info_size = offsetof( KEY_VALUE_FULL_INFORMATION, Name );
919 TRACE("(%p,%ld,%p,%p,%p,%p,%p,%p)\n",
920 hkey, index, value, val_count, reserved, type, data, count );
922 /* NT only checks count, not val_count */
923 if ((data && !count) || reserved) return ERROR_INVALID_PARAMETER;
924 if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
926 total_size = info_size + (MAX_PATH + 1) * sizeof(WCHAR);
927 if (data) total_size += *count;
928 total_size = min( sizeof(buffer), total_size );
930 status = NtEnumerateValueKey( hkey, index, KeyValueFullInformation,
931 buffer, total_size, &total_size );
932 if (status && status != STATUS_BUFFER_OVERFLOW) goto done;
934 /* we need to fetch the contents for a string type even if not requested,
935 * because we need to compute the length of the ASCII string. */
936 if (value || data || is_string(info->Type))
938 /* retry with a dynamically allocated buffer */
939 while (status == STATUS_BUFFER_OVERFLOW)
941 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
942 if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
943 return ERROR_NOT_ENOUGH_MEMORY;
944 info = (KEY_VALUE_FULL_INFORMATION *)buf_ptr;
945 status = NtEnumerateValueKey( hkey, index, KeyValueFullInformation,
946 buf_ptr, total_size, &total_size );
949 if (status) goto done;
951 if (is_string(info->Type))
953 DWORD len;
954 RtlUnicodeToMultiByteSize( &len, (WCHAR *)(buf_ptr + info->DataOffset),
955 total_size - info->DataOffset );
956 if (data && len)
958 if (len > *count) status = STATUS_BUFFER_OVERFLOW;
959 else
961 RtlUnicodeToMultiByteN( data, len, NULL, (WCHAR *)(buf_ptr + info->DataOffset),
962 total_size - info->DataOffset );
963 /* if the type is REG_SZ and data is not 0-terminated
964 * and there is enough space in the buffer NT appends a \0 */
965 if (len < *count && data[len-1]) data[len] = 0;
968 info->DataLength = len;
970 else if (data)
972 if (total_size - info->DataOffset > *count) status = STATUS_BUFFER_OVERFLOW;
973 else memcpy( data, buf_ptr + info->DataOffset, total_size - info->DataOffset );
976 if (value && !status)
978 DWORD len;
980 RtlUnicodeToMultiByteSize( &len, info->Name, info->NameLength );
981 if (len >= *val_count)
983 status = STATUS_BUFFER_OVERFLOW;
984 if (*val_count)
986 len = *val_count - 1;
987 RtlUnicodeToMultiByteN( value, len, NULL, info->Name, info->NameLength );
988 value[len] = 0;
991 else
993 RtlUnicodeToMultiByteN( value, len, NULL, info->Name, info->NameLength );
994 value[len] = 0;
995 *val_count = len;
999 else status = STATUS_SUCCESS;
1001 if (type) *type = info->Type;
1002 if (count) *count = info->DataLength;
1004 done:
1005 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
1006 return RtlNtStatusToDosError(status);
1010 /******************************************************************************
1011 * VMM_RegEnumKeyA
1013 static DWORD VMM_RegEnumKeyA( HKEY hkey, DWORD index, LPSTR name, DWORD name_len )
1015 NTSTATUS status;
1016 char buffer[256], *buf_ptr = buffer;
1017 KEY_NODE_INFORMATION *info = (KEY_NODE_INFORMATION *)buffer;
1018 DWORD total_size;
1020 if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
1022 status = NtEnumerateKey( hkey, index, KeyNodeInformation,
1023 buffer, sizeof(buffer), &total_size );
1025 while (status == STATUS_BUFFER_OVERFLOW)
1027 /* retry with a dynamically allocated buffer */
1028 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
1029 if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
1030 return ERROR_NOT_ENOUGH_MEMORY;
1031 info = (KEY_NODE_INFORMATION *)buf_ptr;
1032 status = NtEnumerateKey( hkey, index, KeyNodeInformation,
1033 buf_ptr, total_size, &total_size );
1036 if (!status)
1038 DWORD len;
1040 RtlUnicodeToMultiByteSize( &len, info->Name, info->NameLength );
1041 if (len >= name_len) status = STATUS_BUFFER_OVERFLOW;
1042 else
1044 RtlUnicodeToMultiByteN( name, len, NULL, info->Name, info->NameLength );
1045 name[len] = 0;
1049 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
1050 return RtlNtStatusToDosError( status );
1054 /******************************************************************************
1055 * VMM_RegQueryInfoKeyA
1057 * NOTE: This VxDCall takes only a subset of the parameters that the
1058 * corresponding Win32 API call does. The implementation in Win95
1059 * ADVAPI32 sets all output parameters not mentioned here to zero.
1061 static DWORD VMM_RegQueryInfoKeyA( HKEY hkey, LPDWORD subkeys, LPDWORD max_subkey,
1062 LPDWORD values, LPDWORD max_value, LPDWORD max_data )
1064 NTSTATUS status;
1065 KEY_FULL_INFORMATION info;
1066 DWORD total_size;
1068 if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
1070 status = NtQueryKey( hkey, KeyFullInformation, &info, sizeof(info), &total_size );
1071 if (status && status != STATUS_BUFFER_OVERFLOW) return RtlNtStatusToDosError( status );
1073 if (subkeys) *subkeys = info.SubKeys;
1074 if (max_subkey) *max_subkey = info.MaxNameLen;
1075 if (values) *values = info.Values;
1076 if (max_value) *max_value = info.MaxValueNameLen;
1077 if (max_data) *max_data = info.MaxValueDataLen;
1078 return ERROR_SUCCESS;
1082 /***********************************************************************
1083 * VxDCall_VMM
1085 static DWORD VxDCall_VMM( DWORD service, CONTEXT86 *context )
1087 switch ( LOWORD(service) )
1089 case 0x0011: /* RegOpenKey */
1091 HKEY hkey = (HKEY) stack32_pop( context );
1092 LPCSTR lpszSubKey = (LPCSTR)stack32_pop( context );
1093 PHKEY retkey = (PHKEY)stack32_pop( context );
1094 return VMM_RegOpenKeyExA( hkey, lpszSubKey, 0, KEY_ALL_ACCESS, retkey );
1097 case 0x0012: /* RegCreateKey */
1099 HKEY hkey = (HKEY) stack32_pop( context );
1100 LPCSTR lpszSubKey = (LPCSTR)stack32_pop( context );
1101 PHKEY retkey = (PHKEY)stack32_pop( context );
1102 return VMM_RegCreateKeyA( hkey, lpszSubKey, retkey );
1105 case 0x0013: /* RegCloseKey */
1107 HKEY hkey = (HKEY)stack32_pop( context );
1108 return VMM_RegCloseKey( hkey );
1111 case 0x0014: /* RegDeleteKey */
1113 HKEY hkey = (HKEY) stack32_pop( context );
1114 LPCSTR lpszSubKey = (LPCSTR)stack32_pop( context );
1115 return VMM_RegDeleteKeyA( hkey, lpszSubKey );
1118 case 0x0015: /* RegSetValue */
1120 HKEY hkey = (HKEY) stack32_pop( context );
1121 LPCSTR lpszSubKey = (LPCSTR)stack32_pop( context );
1122 DWORD dwType = (DWORD) stack32_pop( context );
1123 LPCSTR lpszData = (LPCSTR)stack32_pop( context );
1124 DWORD cbData = (DWORD) stack32_pop( context );
1125 return VMM_RegSetValueA( hkey, lpszSubKey, dwType, lpszData, cbData );
1128 case 0x0016: /* RegDeleteValue */
1130 HKEY hkey = (HKEY) stack32_pop( context );
1131 LPSTR lpszValue = (LPSTR)stack32_pop( context );
1132 return VMM_RegDeleteValueA( hkey, lpszValue );
1135 case 0x0017: /* RegQueryValue */
1137 HKEY hkey = (HKEY) stack32_pop( context );
1138 LPSTR lpszSubKey = (LPSTR) stack32_pop( context );
1139 LPSTR lpszData = (LPSTR) stack32_pop( context );
1140 LPDWORD lpcbData = (LPDWORD)stack32_pop( context );
1141 return VMM_RegQueryValueA( hkey, lpszSubKey, lpszData, lpcbData );
1144 case 0x0018: /* RegEnumKey */
1146 HKEY hkey = (HKEY) stack32_pop( context );
1147 DWORD iSubkey = (DWORD)stack32_pop( context );
1148 LPSTR lpszName = (LPSTR)stack32_pop( context );
1149 DWORD lpcchName = (DWORD)stack32_pop( context );
1150 return VMM_RegEnumKeyA( hkey, iSubkey, lpszName, lpcchName );
1153 case 0x0019: /* RegEnumValue */
1155 HKEY hkey = (HKEY) stack32_pop( context );
1156 DWORD iValue = (DWORD) stack32_pop( context );
1157 LPSTR lpszValue = (LPSTR) stack32_pop( context );
1158 LPDWORD lpcchValue = (LPDWORD)stack32_pop( context );
1159 LPDWORD lpReserved = (LPDWORD)stack32_pop( context );
1160 LPDWORD lpdwType = (LPDWORD)stack32_pop( context );
1161 LPBYTE lpbData = (LPBYTE) stack32_pop( context );
1162 LPDWORD lpcbData = (LPDWORD)stack32_pop( context );
1163 return VMM_RegEnumValueA( hkey, iValue, lpszValue, lpcchValue,
1164 lpReserved, lpdwType, lpbData, lpcbData );
1167 case 0x001A: /* RegQueryValueEx */
1169 HKEY hkey = (HKEY) stack32_pop( context );
1170 LPSTR lpszValue = (LPSTR) stack32_pop( context );
1171 LPDWORD lpReserved = (LPDWORD)stack32_pop( context );
1172 LPDWORD lpdwType = (LPDWORD)stack32_pop( context );
1173 LPBYTE lpbData = (LPBYTE) stack32_pop( context );
1174 LPDWORD lpcbData = (LPDWORD)stack32_pop( context );
1175 return VMM_RegQueryValueExA( hkey, lpszValue, lpReserved,
1176 lpdwType, lpbData, lpcbData );
1179 case 0x001B: /* RegSetValueEx */
1181 HKEY hkey = (HKEY) stack32_pop( context );
1182 LPSTR lpszValue = (LPSTR) stack32_pop( context );
1183 DWORD dwReserved = (DWORD) stack32_pop( context );
1184 DWORD dwType = (DWORD) stack32_pop( context );
1185 LPBYTE lpbData = (LPBYTE)stack32_pop( context );
1186 DWORD cbData = (DWORD) stack32_pop( context );
1187 return VMM_RegSetValueExA( hkey, lpszValue, dwReserved,
1188 dwType, lpbData, cbData );
1191 case 0x001C: /* RegFlushKey */
1193 HKEY hkey = (HKEY)stack32_pop( context );
1194 FIXME( "RegFlushKey(%p): stub\n", hkey );
1195 return ERROR_SUCCESS;
1198 case 0x001D: /* RegQueryInfoKey */
1200 /* NOTE: This VxDCall takes only a subset of the parameters that the
1201 corresponding Win32 API call does. The implementation in Win95
1202 ADVAPI32 sets all output parameters not mentioned here to zero. */
1204 HKEY hkey = (HKEY) stack32_pop( context );
1205 LPDWORD lpcSubKeys = (LPDWORD)stack32_pop( context );
1206 LPDWORD lpcchMaxSubKey = (LPDWORD)stack32_pop( context );
1207 LPDWORD lpcValues = (LPDWORD)stack32_pop( context );
1208 LPDWORD lpcchMaxValueName = (LPDWORD)stack32_pop( context );
1209 LPDWORD lpcchMaxValueData = (LPDWORD)stack32_pop( context );
1210 return VMM_RegQueryInfoKeyA( hkey, lpcSubKeys, lpcchMaxSubKey,
1211 lpcValues, lpcchMaxValueName, lpcchMaxValueData );
1214 case 0x0021: /* RegLoadKey */
1216 HKEY hkey = (HKEY) stack32_pop( context );
1217 LPCSTR lpszSubKey = (LPCSTR)stack32_pop( context );
1218 LPCSTR lpszFile = (LPCSTR)stack32_pop( context );
1219 FIXME("RegLoadKey(%p,%s,%s): stub\n",hkey, debugstr_a(lpszSubKey), debugstr_a(lpszFile));
1220 return ERROR_SUCCESS;
1223 case 0x0022: /* RegUnLoadKey */
1225 HKEY hkey = (HKEY) stack32_pop( context );
1226 LPCSTR lpszSubKey = (LPCSTR)stack32_pop( context );
1227 FIXME("RegUnLoadKey(%p,%s): stub\n",hkey, debugstr_a(lpszSubKey));
1228 return ERROR_SUCCESS;
1231 case 0x0023: /* RegSaveKey */
1233 HKEY hkey = (HKEY) stack32_pop( context );
1234 LPCSTR lpszFile = (LPCSTR)stack32_pop( context );
1235 LPSECURITY_ATTRIBUTES sa = (LPSECURITY_ATTRIBUTES)stack32_pop( context );
1236 FIXME("RegSaveKey(%p,%s,%p): stub\n",hkey, debugstr_a(lpszFile),sa);
1237 return ERROR_SUCCESS;
1240 #if 0 /* Functions are not yet implemented in misc/registry.c */
1241 case 0x0024: /* RegRemapPreDefKey */
1242 case 0x0026: /* RegQueryMultipleValues */
1243 #endif
1245 case 0x0027: /* RegReplaceKey */
1247 HKEY hkey = (HKEY) stack32_pop( context );
1248 LPCSTR lpszSubKey = (LPCSTR)stack32_pop( context );
1249 LPCSTR lpszNewFile= (LPCSTR)stack32_pop( context );
1250 LPCSTR lpszOldFile= (LPCSTR)stack32_pop( context );
1251 FIXME("RegReplaceKey(%p,%s,%s,%s): stub\n", hkey, debugstr_a(lpszSubKey),
1252 debugstr_a(lpszNewFile),debugstr_a(lpszOldFile));
1253 return ERROR_SUCCESS;
1256 case 0x0000: /* PageReserve */
1258 LPVOID address;
1259 LPVOID ret;
1260 DWORD psize = getpagesize();
1261 ULONG page = (ULONG) stack32_pop( context );
1262 ULONG npages = (ULONG) stack32_pop( context );
1263 ULONG flags = (ULONG) stack32_pop( context );
1265 TRACE("PageReserve: page: %08lx, npages: %08lx, flags: %08lx partial stub!\n",
1266 page, npages, flags );
1268 if ( page == PR_SYSTEM ) {
1269 ERR("Can't reserve ring 1 memory\n");
1270 return -1;
1272 /* FIXME: This has to be handled separately for the separate
1273 address-spaces we now have */
1274 if ( page == PR_PRIVATE || page == PR_SHARED ) page = 0;
1275 /* FIXME: Handle flags in some way */
1276 address = (LPVOID )(page * psize);
1277 ret = VirtualAlloc ( address, ( npages * psize ), MEM_RESERVE, 0 );
1278 TRACE("PageReserve: returning: %08lx\n", (DWORD )ret );
1279 if ( ret == NULL )
1280 return -1;
1281 else
1282 return (DWORD )ret;
1285 case 0x0001: /* PageCommit */
1287 LPVOID address;
1288 LPVOID ret;
1289 DWORD virt_perm;
1290 DWORD psize = getpagesize();
1291 ULONG page = (ULONG) stack32_pop( context );
1292 ULONG npages = (ULONG) stack32_pop( context );
1293 ULONG hpd = (ULONG) stack32_pop( context );
1294 ULONG pagerdata = (ULONG) stack32_pop( context );
1295 ULONG flags = (ULONG) stack32_pop( context );
1297 TRACE("PageCommit: page: %08lx, npages: %08lx, hpd: %08lx pagerdata: "
1298 "%08lx, flags: %08lx partial stub\n",
1299 page, npages, hpd, pagerdata, flags );
1301 if ( flags & PC_USER )
1302 if ( flags & PC_WRITEABLE )
1303 virt_perm = PAGE_EXECUTE_READWRITE;
1304 else
1305 virt_perm = PAGE_EXECUTE_READ;
1306 else
1307 virt_perm = PAGE_NOACCESS;
1309 address = (LPVOID )(page * psize);
1310 ret = VirtualAlloc ( address, ( npages * psize ), MEM_COMMIT, virt_perm );
1311 TRACE("PageCommit: Returning: %08lx\n", (DWORD )ret );
1312 return (DWORD )ret;
1315 case 0x0002: /* PageDecommit */
1317 LPVOID address;
1318 BOOL ret;
1319 DWORD psize = getpagesize();
1320 ULONG page = (ULONG) stack32_pop( context );
1321 ULONG npages = (ULONG) stack32_pop( context );
1322 ULONG flags = (ULONG) stack32_pop( context );
1324 TRACE("PageDecommit: page: %08lx, npages: %08lx, flags: %08lx partial stub\n",
1325 page, npages, flags );
1326 address = (LPVOID )( page * psize );
1327 ret = VirtualFree ( address, ( npages * psize ), MEM_DECOMMIT );
1328 TRACE("PageDecommit: Returning: %s\n", ret ? "TRUE" : "FALSE" );
1329 return ret;
1331 case 0x000d: /* PageModifyPermissions */
1333 DWORD pg_old_perm;
1334 DWORD pg_new_perm;
1335 DWORD virt_old_perm;
1336 DWORD virt_new_perm;
1337 MEMORY_BASIC_INFORMATION mbi;
1338 LPVOID address;
1339 DWORD psize = getpagesize();
1340 ULONG page = stack32_pop ( context );
1341 ULONG npages = stack32_pop ( context );
1342 ULONG permand = stack32_pop ( context );
1343 ULONG permor = stack32_pop ( context );
1345 TRACE("PageModifyPermissions %08lx %08lx %08lx %08lx partial stub\n",
1346 page, npages, permand, permor );
1347 address = (LPVOID )( page * psize );
1349 VirtualQuery ( address, &mbi, sizeof ( MEMORY_BASIC_INFORMATION ));
1350 virt_old_perm = mbi.Protect;
1352 switch ( virt_old_perm & mbi.Protect ) {
1353 case PAGE_READONLY:
1354 case PAGE_EXECUTE:
1355 case PAGE_EXECUTE_READ:
1356 pg_old_perm = PC_USER;
1357 break;
1358 case PAGE_READWRITE:
1359 case PAGE_WRITECOPY:
1360 case PAGE_EXECUTE_READWRITE:
1361 case PAGE_EXECUTE_WRITECOPY:
1362 pg_old_perm = PC_USER | PC_WRITEABLE;
1363 break;
1364 case PAGE_NOACCESS:
1365 default:
1366 pg_old_perm = 0;
1367 break;
1369 pg_new_perm = pg_old_perm;
1370 pg_new_perm &= permand & ~PC_STATIC;
1371 pg_new_perm |= permor & ~PC_STATIC;
1373 virt_new_perm = ( virt_old_perm ) & ~0xff;
1374 if ( pg_new_perm & PC_USER )
1376 if ( pg_new_perm & PC_WRITEABLE )
1377 virt_new_perm |= PAGE_EXECUTE_READWRITE;
1378 else
1379 virt_new_perm |= PAGE_EXECUTE_READ;
1382 if ( ! VirtualProtect ( address, ( npages * psize ), virt_new_perm, &virt_old_perm ) ) {
1383 ERR("Can't change page permissions for %08lx\n", (DWORD )address );
1384 return 0xffffffff;
1386 TRACE("Returning: %08lx\n", pg_old_perm );
1387 return pg_old_perm;
1389 case 0x000a: /* PageFree */
1391 BOOL ret;
1392 LPVOID hmem = (LPVOID) stack32_pop( context );
1393 DWORD flags = (DWORD ) stack32_pop( context );
1395 TRACE("PageFree: hmem: %08lx, flags: %08lx partial stub\n",
1396 (DWORD )hmem, flags );
1398 ret = VirtualFree ( hmem, 0, MEM_RELEASE );
1399 context->Eax = ret;
1400 TRACE("Returning: %d\n", ret );
1402 return 0;
1404 case 0x001e: /* GetDemandPageInfo */
1406 DWORD dinfo = (DWORD)stack32_pop( context );
1407 DWORD flags = (DWORD)stack32_pop( context );
1409 /* GetDemandPageInfo is supposed to fill out the struct at
1410 * "dinfo" with various low-level memory management information.
1411 * Apps are certainly not supposed to call this, although it's
1412 * demoed and documented by Pietrek on pages 441-443 of "Windows
1413 * 95 System Programming Secrets" if any program needs a real
1414 * implementation of this.
1417 FIXME("GetDemandPageInfo(%08lx %08lx): stub!\n", dinfo, flags);
1419 return 0;
1421 default:
1422 if (LOWORD(service) < N_VMM_SERVICE)
1423 FIXME( "Unimplemented service %s (%08lx)\n",
1424 VMM_Service_Name[LOWORD(service)], service);
1425 else
1426 FIXME( "Unknown service %08lx\n", service);
1427 break;
1430 return 0xffffffff; /* FIXME */
1433 /***********************************************************************
1434 * DeviceIo_IFSMgr
1435 * NOTES
1436 * These ioctls are used by 'MSNET32.DLL'.
1438 * I have been unable to uncover any documentation about the ioctls so
1439 * the implementation of the cases IFS_IOCTL_21 and IFS_IOCTL_2F are
1440 * based on reasonable guesses on information found in the Windows 95 DDK.
1445 * IFSMgr DeviceIO service
1448 #define IFS_IOCTL_21 100
1449 #define IFS_IOCTL_2F 101
1450 #define IFS_IOCTL_GET_RES 102
1451 #define IFS_IOCTL_GET_NETPRO_NAME_A 103
1453 struct win32apireq {
1454 unsigned long ar_proid;
1455 unsigned long ar_eax;
1456 unsigned long ar_ebx;
1457 unsigned long ar_ecx;
1458 unsigned long ar_edx;
1459 unsigned long ar_esi;
1460 unsigned long ar_edi;
1461 unsigned long ar_ebp;
1462 unsigned short ar_error;
1463 unsigned short ar_pad;
1466 static void win32apieq_2_CONTEXT(struct win32apireq *pIn,CONTEXT86 *pCxt)
1468 memset(pCxt,0,sizeof(*pCxt));
1470 pCxt->ContextFlags=CONTEXT86_INTEGER|CONTEXT86_CONTROL;
1471 pCxt->Eax = pIn->ar_eax;
1472 pCxt->Ebx = pIn->ar_ebx;
1473 pCxt->Ecx = pIn->ar_ecx;
1474 pCxt->Edx = pIn->ar_edx;
1475 pCxt->Esi = pIn->ar_esi;
1476 pCxt->Edi = pIn->ar_edi;
1478 /* FIXME: Only partial CONTEXT86_CONTROL */
1479 pCxt->Ebp = pIn->ar_ebp;
1481 /* FIXME: pIn->ar_proid ignored */
1482 /* FIXME: pIn->ar_error ignored */
1483 /* FIXME: pIn->ar_pad ignored */
1486 static void CONTEXT_2_win32apieq(CONTEXT86 *pCxt,struct win32apireq *pOut)
1488 memset(pOut,0,sizeof(struct win32apireq));
1490 pOut->ar_eax = pCxt->Eax;
1491 pOut->ar_ebx = pCxt->Ebx;
1492 pOut->ar_ecx = pCxt->Ecx;
1493 pOut->ar_edx = pCxt->Edx;
1494 pOut->ar_esi = pCxt->Esi;
1495 pOut->ar_edi = pCxt->Edi;
1497 /* FIXME: Only partial CONTEXT86_CONTROL */
1498 pOut->ar_ebp = pCxt->Ebp;
1500 /* FIXME: pOut->ar_proid ignored */
1501 /* FIXME: pOut->ar_error ignored */
1502 /* FIXME: pOut->ar_pad ignored */
1505 static BOOL DeviceIo_IFSMgr(DWORD dwIoControlCode, LPVOID lpvInBuffer, DWORD cbInBuffer,
1506 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
1507 LPDWORD lpcbBytesReturned,
1508 LPOVERLAPPED lpOverlapped)
1510 BOOL retv = TRUE;
1511 TRACE("(%ld,%p,%ld,%p,%ld,%p,%p): stub\n",
1512 dwIoControlCode,
1513 lpvInBuffer,cbInBuffer,
1514 lpvOutBuffer,cbOutBuffer,
1515 lpcbBytesReturned,
1516 lpOverlapped);
1518 switch (dwIoControlCode)
1520 case IFS_IOCTL_21:
1521 case IFS_IOCTL_2F:{
1522 CONTEXT86 cxt;
1523 struct win32apireq *pIn=(struct win32apireq *) lpvInBuffer;
1524 struct win32apireq *pOut=(struct win32apireq *) lpvOutBuffer;
1526 TRACE(
1527 "Control '%s': "
1528 "proid=0x%08lx, eax=0x%08lx, ebx=0x%08lx, ecx=0x%08lx, "
1529 "edx=0x%08lx, esi=0x%08lx, edi=0x%08lx, ebp=0x%08lx, "
1530 "error=0x%04x, pad=0x%04x\n",
1531 (dwIoControlCode==IFS_IOCTL_21)?"IFS_IOCTL_21":"IFS_IOCTL_2F",
1532 pIn->ar_proid, pIn->ar_eax, pIn->ar_ebx, pIn->ar_ecx,
1533 pIn->ar_edx, pIn->ar_esi, pIn->ar_edi, pIn->ar_ebp,
1534 pIn->ar_error, pIn->ar_pad
1537 win32apieq_2_CONTEXT(pIn,&cxt);
1539 if(dwIoControlCode==IFS_IOCTL_21)
1541 if(Dosvm.CallBuiltinHandler || DPMI_LoadDosSystem())
1542 Dosvm.CallBuiltinHandler( &cxt, 0x21 );
1544 else
1546 if(Dosvm.CallBuiltinHandler || DPMI_LoadDosSystem())
1547 Dosvm.CallBuiltinHandler( &cxt, 0x2f );
1550 CONTEXT_2_win32apieq(&cxt,pOut);
1552 retv = TRUE;
1553 } break;
1554 case IFS_IOCTL_GET_RES:{
1555 FIXME( "Control 'IFS_IOCTL_GET_RES' not implemented\n");
1556 retv = FALSE;
1557 } break;
1558 case IFS_IOCTL_GET_NETPRO_NAME_A:{
1559 FIXME( "Control 'IFS_IOCTL_GET_NETPRO_NAME_A' not implemented\n");
1560 retv = FALSE;
1561 } break;
1562 default:
1563 FIXME( "Control %ld not implemented\n", dwIoControlCode);
1564 retv = FALSE;
1567 return retv;
1570 /********************************************************************************
1571 * VxDCall_VWin32
1573 * Service numbers taken from page 448 of Pietrek's "Windows 95 System
1574 * Programming Secrets". Parameters from experimentation on real Win98.
1578 static DWORD VxDCall_VWin32( DWORD service, CONTEXT86 *context )
1580 switch ( LOWORD(service) )
1582 case 0x0000: /* GetVersion */
1584 DWORD vers = GetVersion();
1585 return (LOBYTE(vers) << 8) | HIBYTE(vers);
1587 break;
1589 case 0x0020: /* Get VMCPD Version */
1591 DWORD parm = (DWORD) stack32_pop(context);
1593 FIXME("Get VMCPD Version(%08lx): partial stub!\n", parm);
1595 /* FIXME: This is what Win98 returns, it may
1596 * not be correct in all situations.
1597 * It makes Bleem! happy though.
1600 return 0x0405;
1603 case 0x0029: /* Int31/DPMI dispatch */
1605 DWORD callnum = (DWORD) stack32_pop(context);
1606 DWORD parm = (DWORD) stack32_pop(context);
1608 TRACE("Int31/DPMI dispatch(%08lx)\n", callnum);
1610 SET_AX( context, callnum );
1611 SET_CX( context, parm );
1612 if(Dosvm.CallBuiltinHandler || DPMI_LoadDosSystem())
1613 Dosvm.CallBuiltinHandler( context, 0x31 );
1615 return LOWORD(context->Eax);
1617 break;
1619 case 0x002a: /* Int41 dispatch - parm = int41 service number */
1621 DWORD callnum = (DWORD) stack32_pop(context);
1623 return callnum; /* FIXME: should really call INT_Int41Handler() */
1625 break;
1627 default:
1628 FIXME("Unknown VWin32 service %08lx\n", service);
1629 break;
1632 return 0xffffffff;
1636 /***********************************************************************
1637 * DeviceIo_VCD
1639 static BOOL DeviceIo_VCD(DWORD dwIoControlCode,
1640 LPVOID lpvInBuffer, DWORD cbInBuffer,
1641 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
1642 LPDWORD lpcbBytesReturned,
1643 LPOVERLAPPED lpOverlapped)
1645 BOOL retv = TRUE;
1647 switch (dwIoControlCode)
1649 case IOCTL_SERIAL_LSRMST_INSERT:
1651 FIXME( "IOCTL_SERIAL_LSRMST_INSERT NIY !\n");
1652 retv = FALSE;
1654 break;
1656 default:
1657 FIXME( "Unknown Control %ld\n", dwIoControlCode);
1658 retv = FALSE;
1659 break;
1662 return retv;
1666 /***********************************************************************
1667 * DeviceIo_VWin32
1670 static void DIOCRegs_2_CONTEXT( DIOC_REGISTERS *pIn, CONTEXT86 *pCxt )
1672 memset( pCxt, 0, sizeof(*pCxt) );
1673 /* Note: segment registers == 0 means that CTX_SEG_OFF_TO_LIN
1674 will interpret 32-bit register contents as linear pointers */
1676 pCxt->ContextFlags=CONTEXT86_INTEGER|CONTEXT86_CONTROL;
1677 pCxt->Eax = pIn->reg_EAX;
1678 pCxt->Ebx = pIn->reg_EBX;
1679 pCxt->Ecx = pIn->reg_ECX;
1680 pCxt->Edx = pIn->reg_EDX;
1681 pCxt->Esi = pIn->reg_ESI;
1682 pCxt->Edi = pIn->reg_EDI;
1684 /* FIXME: Only partial CONTEXT86_CONTROL */
1685 pCxt->EFlags = pIn->reg_Flags;
1688 static void CONTEXT_2_DIOCRegs( CONTEXT86 *pCxt, DIOC_REGISTERS *pOut )
1690 memset( pOut, 0, sizeof(DIOC_REGISTERS) );
1692 pOut->reg_EAX = pCxt->Eax;
1693 pOut->reg_EBX = pCxt->Ebx;
1694 pOut->reg_ECX = pCxt->Ecx;
1695 pOut->reg_EDX = pCxt->Edx;
1696 pOut->reg_ESI = pCxt->Esi;
1697 pOut->reg_EDI = pCxt->Edi;
1699 /* FIXME: Only partial CONTEXT86_CONTROL */
1700 pOut->reg_Flags = pCxt->EFlags;
1703 #define DIOC_AH(regs) (((unsigned char*)&((regs)->reg_EAX))[1])
1704 #define DIOC_AL(regs) (((unsigned char*)&((regs)->reg_EAX))[0])
1705 #define DIOC_BH(regs) (((unsigned char*)&((regs)->reg_EBX))[1])
1706 #define DIOC_BL(regs) (((unsigned char*)&((regs)->reg_EBX))[0])
1707 #define DIOC_DH(regs) (((unsigned char*)&((regs)->reg_EDX))[1])
1708 #define DIOC_DL(regs) (((unsigned char*)&((regs)->reg_EDX))[0])
1710 #define DIOC_AX(regs) (((unsigned short*)&((regs)->reg_EAX))[0])
1711 #define DIOC_BX(regs) (((unsigned short*)&((regs)->reg_EBX))[0])
1712 #define DIOC_CX(regs) (((unsigned short*)&((regs)->reg_ECX))[0])
1713 #define DIOC_DX(regs) (((unsigned short*)&((regs)->reg_EDX))[0])
1715 #define DIOC_SET_CARRY(regs) (((regs)->reg_Flags)|=0x00000001)
1717 static BOOL DeviceIo_VWin32(DWORD dwIoControlCode,
1718 LPVOID lpvInBuffer, DWORD cbInBuffer,
1719 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
1720 LPDWORD lpcbBytesReturned,
1721 LPOVERLAPPED lpOverlapped)
1723 BOOL retv = TRUE;
1725 switch (dwIoControlCode)
1727 case VWIN32_DIOC_DOS_IOCTL:
1728 case 0x10: /* Int 0x21 call, call it VWIN_DIOC_INT21 ? */
1729 case VWIN32_DIOC_DOS_INT13:
1730 case VWIN32_DIOC_DOS_INT25:
1731 case VWIN32_DIOC_DOS_INT26:
1732 case 0x29: /* Int 0x31 call, call it VWIN_DIOC_INT31 ? */
1733 case VWIN32_DIOC_DOS_DRIVEINFO:
1735 CONTEXT86 cxt;
1736 DIOC_REGISTERS *pIn = (DIOC_REGISTERS *)lpvInBuffer;
1737 DIOC_REGISTERS *pOut = (DIOC_REGISTERS *)lpvOutBuffer;
1738 BYTE intnum = 0;
1740 TRACE( "Control '%s': "
1741 "eax=0x%08lx, ebx=0x%08lx, ecx=0x%08lx, "
1742 "edx=0x%08lx, esi=0x%08lx, edi=0x%08lx \n",
1743 (dwIoControlCode == VWIN32_DIOC_DOS_IOCTL)? "VWIN32_DIOC_DOS_IOCTL" :
1744 (dwIoControlCode == VWIN32_DIOC_DOS_INT25)? "VWIN32_DIOC_DOS_INT25" :
1745 (dwIoControlCode == VWIN32_DIOC_DOS_INT26)? "VWIN32_DIOC_DOS_INT26" :
1746 (dwIoControlCode == VWIN32_DIOC_DOS_DRIVEINFO)? "VWIN32_DIOC_DOS_DRIVEINFO" : "???",
1747 pIn->reg_EAX, pIn->reg_EBX, pIn->reg_ECX,
1748 pIn->reg_EDX, pIn->reg_ESI, pIn->reg_EDI );
1750 DIOCRegs_2_CONTEXT( pIn, &cxt );
1752 switch (dwIoControlCode)
1754 case VWIN32_DIOC_DOS_IOCTL: /* Call int 21h */
1755 case 0x10: /* Int 0x21 call, call it VWIN_DIOC_INT21 ? */
1756 case VWIN32_DIOC_DOS_DRIVEINFO: /* Call int 21h 730x */
1757 intnum = 0x21;
1758 break;
1759 case VWIN32_DIOC_DOS_INT13:
1760 intnum = 0x13;
1761 break;
1762 case VWIN32_DIOC_DOS_INT25:
1763 intnum = 0x25;
1764 break;
1765 case VWIN32_DIOC_DOS_INT26:
1766 intnum = 0x26;
1767 break;
1768 case 0x29: /* Int 0x31 call, call it VWIN_DIOC_INT31 ? */
1769 intnum = 0x31;
1770 break;
1773 if(Dosvm.CallBuiltinHandler || DPMI_LoadDosSystem())
1774 Dosvm.CallBuiltinHandler( &cxt, intnum );
1776 CONTEXT_2_DIOCRegs( &cxt, pOut );
1778 break;
1780 case VWIN32_DIOC_SIMCTRLC:
1781 FIXME( "Control VWIN32_DIOC_SIMCTRLC not implemented\n");
1782 retv = FALSE;
1783 break;
1785 default:
1786 FIXME( "Unknown Control %ld\n", dwIoControlCode);
1787 retv = FALSE;
1788 break;
1791 return retv;
1794 /* this is the main multimedia device loader */
1795 static BOOL DeviceIo_MMDEVLDR(DWORD dwIoControlCode,
1796 LPVOID lpvInBuffer, DWORD cbInBuffer,
1797 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
1798 LPDWORD lpcbBytesReturned,
1799 LPOVERLAPPED lpOverlapped)
1801 FIXME("(%ld,%p,%ld,%p,%ld,%p,%p): stub\n",
1802 dwIoControlCode,
1803 lpvInBuffer,cbInBuffer,
1804 lpvOutBuffer,cbOutBuffer,
1805 lpcbBytesReturned,
1806 lpOverlapped
1808 switch (dwIoControlCode) {
1809 case 5:
1810 /* Hmm. */
1811 *(DWORD*)lpvOutBuffer=0;
1812 *lpcbBytesReturned=4;
1813 return TRUE;
1815 return FALSE;
1817 /* this is used by some Origin games */
1818 static BOOL DeviceIo_MONODEBG(DWORD dwIoControlCode,
1819 LPVOID lpvInBuffer, DWORD cbInBuffer,
1820 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
1821 LPDWORD lpcbBytesReturned,
1822 LPOVERLAPPED lpOverlapped)
1824 switch (dwIoControlCode) {
1825 case 1: /* version */
1826 *(LPDWORD)lpvOutBuffer = 0x20004; /* WC SecretOps */
1827 break;
1828 case 9: /* debug output */
1829 ERR("MONODEBG: %s\n",debugstr_a(lpvInBuffer));
1830 break;
1831 default:
1832 FIXME("(%ld,%p,%ld,%p,%ld,%p,%p): stub\n",
1833 dwIoControlCode,
1834 lpvInBuffer,cbInBuffer,
1835 lpvOutBuffer,cbOutBuffer,
1836 lpcbBytesReturned,
1837 lpOverlapped
1839 break;
1841 return TRUE;
1843 /* pccard */
1844 static BOOL DeviceIo_PCCARD (DWORD dwIoControlCode,
1845 LPVOID lpvInBuffer, DWORD cbInBuffer,
1846 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
1847 LPDWORD lpcbBytesReturned,
1848 LPOVERLAPPED lpOverlapped)
1850 switch (dwIoControlCode) {
1851 case 0x0000: /* PCCARD_Get_Version */
1852 case 0x0001: /* PCCARD_Card_Services */
1853 default:
1854 FIXME( "(%ld,%p,%ld,%p,%ld,%p,%p): stub\n",
1855 dwIoControlCode,
1856 lpvInBuffer,cbInBuffer,
1857 lpvOutBuffer,cbOutBuffer,
1858 lpcbBytesReturned,
1859 lpOverlapped
1861 break;
1863 return FALSE;
1866 /***********************************************************************
1867 * OpenVxDHandle (KERNEL32.@)
1869 * This function is supposed to return the corresponding Ring 0
1870 * ("kernel") handle for a Ring 3 handle in Win9x.
1871 * Evidently, Wine will have problems with this. But we try anyway,
1872 * maybe it helps...
1874 HANDLE WINAPI OpenVxDHandle(HANDLE hHandleRing3)
1876 FIXME( "(%p), stub! (returning Ring 3 handle instead of Ring 0)\n", hHandleRing3);
1877 return hHandleRing3;
1880 static BOOL DeviceIo_HASP(DWORD dwIoControlCode, LPVOID lpvInBuffer, DWORD cbInBuffer,
1881 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
1882 LPDWORD lpcbBytesReturned,
1883 LPOVERLAPPED lpOverlapped)
1885 BOOL retv = TRUE;
1886 FIXME("(%ld,%p,%ld,%p,%ld,%p,%p): stub\n",
1887 dwIoControlCode,
1888 lpvInBuffer,cbInBuffer,
1889 lpvOutBuffer,cbOutBuffer,
1890 lpcbBytesReturned,
1891 lpOverlapped);
1893 return retv;