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
24 #include "wine/port.h"
30 #include <sys/types.h>
44 #include "stackframe.h"
45 #include "wine/server.h"
46 #include "wine/debug.h"
49 #ifdef HAVE_SYS_IOCTL_H
50 # include <sys/ioctl.h>
54 # include <linux/fd.h>
58 WINE_DEFAULT_DEBUG_CHANNEL(file);
61 static BOOL DeviceIo_VTDAPI(DWORD dwIoControlCode,
62 LPVOID lpvInBuffer, DWORD cbInBuffer,
63 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
64 LPDWORD lpcbBytesReturned,
65 LPOVERLAPPED lpOverlapped);
66 static BOOL DeviceIo_MONODEBG(DWORD dwIoControlCode,
67 LPVOID lpvInBuffer, DWORD cbInBuffer,
68 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
69 LPDWORD lpcbBytesReturned,
70 LPOVERLAPPED lpOverlapped);
71 static BOOL DeviceIo_MMDEVLDR(DWORD dwIoControlCode,
72 LPVOID lpvInBuffer, DWORD cbInBuffer,
73 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
74 LPDWORD lpcbBytesReturned,
75 LPOVERLAPPED lpOverlapped);
77 static DWORD VxDCall_VMM( DWORD service, CONTEXT86 *context );
79 static BOOL DeviceIo_IFSMgr(DWORD dwIoControlCode,
80 LPVOID lpvInBuffer, DWORD cbInBuffer,
81 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
82 LPDWORD lpcbBytesReturned,
83 LPOVERLAPPED lpOverlapped);
85 static BOOL DeviceIo_VCD(DWORD dwIoControlCode,
86 LPVOID lpvInBuffer, DWORD cbInBuffer,
87 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
88 LPDWORD lpcbBytesReturned,
89 LPOVERLAPPED lpOverlapped);
91 static DWORD VxDCall_VWin32( DWORD service, CONTEXT86 *context );
93 static BOOL DeviceIo_VWin32(DWORD dwIoControlCode,
94 LPVOID lpvInBuffer, DWORD cbInBuffer,
95 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
96 LPDWORD lpcbBytesReturned,
97 LPOVERLAPPED lpOverlapped);
99 static BOOL DeviceIo_PCCARD (DWORD dwIoControlCode,
100 LPVOID lpvInBuffer, DWORD cbInBuffer,
101 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
102 LPDWORD lpcbBytesReturned,
103 LPOVERLAPPED lpOverlapped);
105 static BOOL DeviceIo_HASP (DWORD dwIoControlCode,
106 LPVOID lpvInBuffer, DWORD cbInBuffer,
107 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
108 LPDWORD lpcbBytesReturned,
109 LPOVERLAPPED lpOverlapped);
111 * VxD names are taken from the Win95 DDK
118 DWORD (*vxdcall)(DWORD, CONTEXT86 *);
119 BOOL (*deviceio)(DWORD, LPVOID, DWORD,
120 LPVOID, DWORD, LPDWORD, LPOVERLAPPED);
123 static const struct VxDInfo VxDList[] =
125 /* Standard VxD IDs */
126 { "VMM", 0x0001, VxDCall_VMM, NULL },
127 { "DEBUG", 0x0002, NULL, NULL },
128 { "VPICD", 0x0003, NULL, NULL },
129 { "VDMAD", 0x0004, NULL, NULL },
130 { "VTD", 0x0005, NULL, NULL },
131 { "V86MMGR", 0x0006, NULL, NULL },
132 { "PAGESWAP", 0x0007, NULL, NULL },
133 { "PARITY", 0x0008, NULL, NULL },
134 { "REBOOT", 0x0009, NULL, NULL },
135 { "VDD", 0x000A, NULL, NULL },
136 { "VSD", 0x000B, NULL, NULL },
137 { "VMD", 0x000C, NULL, NULL },
138 { "VKD", 0x000D, NULL, NULL },
139 { "VCD", 0x000E, NULL, DeviceIo_VCD },
140 { "VPD", 0x000F, NULL, NULL },
141 { "BLOCKDEV", 0x0010, NULL, NULL },
142 { "VMCPD", 0x0011, NULL, NULL },
143 { "EBIOS", 0x0012, NULL, NULL },
144 { "BIOSXLAT", 0x0013, NULL, NULL },
145 { "VNETBIOS", 0x0014, NULL, NULL },
146 { "DOSMGR", 0x0015, NULL, NULL },
147 { "WINLOAD", 0x0016, NULL, NULL },
148 { "SHELL", 0x0017, NULL, NULL },
149 { "VMPOLL", 0x0018, NULL, NULL },
150 { "VPROD", 0x0019, NULL, NULL },
151 { "DOSNET", 0x001A, NULL, NULL },
152 { "VFD", 0x001B, NULL, NULL },
153 { "VDD2", 0x001C, NULL, NULL },
154 { "WINDEBUG", 0x001D, NULL, NULL },
155 { "TSRLOAD", 0x001E, NULL, NULL },
156 { "BIOSHOOK", 0x001F, NULL, NULL },
157 { "INT13", 0x0020, NULL, NULL },
158 { "PAGEFILE", 0x0021, NULL, NULL },
159 { "SCSI", 0x0022, NULL, NULL },
160 { "MCA_POS", 0x0023, NULL, NULL },
161 { "SCSIFD", 0x0024, NULL, NULL },
162 { "VPEND", 0x0025, NULL, NULL },
163 { "VPOWERD", 0x0026, NULL, NULL },
164 { "VXDLDR", 0x0027, NULL, NULL },
165 { "NDIS", 0x0028, NULL, NULL },
166 { "BIOS_EXT", 0x0029, NULL, NULL },
167 { "VWIN32", 0x002A, VxDCall_VWin32, DeviceIo_VWin32 },
168 { "VCOMM", 0x002B, NULL, NULL },
169 { "SPOOLER", 0x002C, NULL, NULL },
170 { "WIN32S", 0x002D, NULL, NULL },
171 { "DEBUGCMD", 0x002E, NULL, NULL },
173 { "VNB", 0x0031, NULL, NULL },
174 { "SERVER", 0x0032, NULL, NULL },
175 { "CONFIGMG", 0x0033, NULL, NULL },
176 { "DWCFGMG", 0x0034, NULL, NULL },
177 { "SCSIPORT", 0x0035, NULL, NULL },
178 { "VFBACKUP", 0x0036, NULL, NULL },
179 { "ENABLE", 0x0037, NULL, NULL },
180 { "VCOND", 0x0038, NULL, NULL },
182 { "EFAX", 0x003A, NULL, NULL },
183 { "DSVXD", 0x003B, NULL, NULL },
184 { "ISAPNP", 0x003C, NULL, NULL },
185 { "BIOS", 0x003D, NULL, NULL },
186 { "WINSOCK", 0x003E, NULL, NULL },
187 { "WSOCK", 0x003E, NULL, NULL },
188 { "WSIPX", 0x003F, NULL, NULL },
189 { "IFSMgr", 0x0040, NULL, DeviceIo_IFSMgr },
190 { "VCDFSD", 0x0041, NULL, NULL },
191 { "MRCI2", 0x0042, NULL, NULL },
192 { "PCI", 0x0043, NULL, NULL },
193 { "PELOADER", 0x0044, NULL, NULL },
194 { "EISA", 0x0045, NULL, NULL },
195 { "DRAGCLI", 0x0046, NULL, NULL },
196 { "DRAGSRV", 0x0047, NULL, NULL },
197 { "PERF", 0x0048, NULL, NULL },
198 { "AWREDIR", 0x0049, NULL, NULL },
200 /* Far East support */
201 { "ETEN", 0x0060, NULL, NULL },
202 { "CHBIOS", 0x0061, NULL, NULL },
203 { "VMSGD", 0x0062, NULL, NULL },
204 { "VPPID", 0x0063, NULL, NULL },
205 { "VIME", 0x0064, NULL, NULL },
206 { "VHBIOSD", 0x0065, NULL, NULL },
208 /* Multimedia OEM IDs */
209 { "VTDAPI", 0x0442, NULL, DeviceIo_VTDAPI },
210 { "MMDEVLDR", 0x044A, NULL, DeviceIo_MMDEVLDR },
212 /* Network Device IDs */
213 { "VNetSup", 0x0480, NULL, NULL },
214 { "VRedir", 0x0481, NULL, NULL },
215 { "VBrowse", 0x0482, NULL, NULL },
216 { "VSHARE", 0x0483, NULL, NULL },
217 { "IFSMgr", 0x0484, NULL, NULL },
218 { "MEMPROBE", 0x0485, NULL, NULL },
219 { "VFAT", 0x0486, NULL, NULL },
220 { "NWLINK", 0x0487, NULL, NULL },
221 { "VNWLINK", 0x0487, NULL, NULL },
222 { "NWSUP", 0x0487, NULL, NULL },
223 { "VTDI", 0x0488, NULL, NULL },
224 { "VIP", 0x0489, NULL, NULL },
225 { "VTCP", 0x048A, NULL, NULL },
226 { "VCache", 0x048B, NULL, NULL },
227 { "VUDP", 0x048C, NULL, NULL },
228 { "VAsync", 0x048D, NULL, NULL },
229 { "NWREDIR", 0x048E, NULL, NULL },
230 { "STAT80", 0x048F, NULL, NULL },
231 { "SCSIPORT", 0x0490, NULL, NULL },
232 { "FILESEC", 0x0491, NULL, NULL },
233 { "NWSERVER", 0x0492, NULL, NULL },
234 { "SECPROV", 0x0493, NULL, NULL },
235 { "NSCL", 0x0494, NULL, NULL },
236 { "WSTCP", 0x0495, NULL, NULL },
237 { "NDIS2SUP", 0x0496, NULL, NULL },
238 { "MSODISUP", 0x0497, NULL, NULL },
239 { "Splitter", 0x0498, NULL, NULL },
240 { "PPP", 0x0499, NULL, NULL },
241 { "VDHCP", 0x049A, NULL, NULL },
242 { "VNBT", 0x049B, NULL, NULL },
243 { "LOGGER", 0x049D, NULL, NULL },
244 { "EFILTER", 0x049E, NULL, NULL },
245 { "FFILTER", 0x049F, NULL, NULL },
246 { "TFILTER", 0x04A0, NULL, NULL },
247 { "AFILTER", 0x04A1, NULL, NULL },
248 { "IRLAMP", 0x04A2, NULL, NULL },
250 { "PCCARD", 0x097C, NULL, DeviceIo_PCCARD },
251 { "HASP95", 0x3721, NULL, DeviceIo_HASP },
253 /* WINE additions, ids unknown */
254 { "MONODEBG.VXD", 0x4242, NULL, DeviceIo_MONODEBG },
256 { NULL, 0, NULL, NULL }
260 * VMM VxDCall service names are (mostly) taken from Stan Mitchell's
261 * "Inside the Windows 95 File System"
264 #define N_VMM_SERVICE 41
266 LPCSTR VMM_Service_Name[N_VMM_SERVICE] =
268 "PageReserve", /* 0x0000 */
269 "PageCommit", /* 0x0001 */
270 "PageDecommit", /* 0x0002 */
271 "PagerRegister", /* 0x0003 */
272 "PagerQuery", /* 0x0004 */
273 "HeapAllocate", /* 0x0005 */
274 "ContextCreate", /* 0x0006 */
275 "ContextDestroy", /* 0x0007 */
276 "PageAttach", /* 0x0008 */
277 "PageFlush", /* 0x0009 */
278 "PageFree", /* 0x000A */
279 "ContextSwitch", /* 0x000B */
280 "HeapReAllocate", /* 0x000C */
281 "PageModifyPermissions", /* 0x000D */
282 "PageQuery", /* 0x000E */
283 "GetCurrentContext", /* 0x000F */
284 "HeapFree", /* 0x0010 */
285 "RegOpenKey", /* 0x0011 */
286 "RegCreateKey", /* 0x0012 */
287 "RegCloseKey", /* 0x0013 */
288 "RegDeleteKey", /* 0x0014 */
289 "RegSetValue", /* 0x0015 */
290 "RegDeleteValue", /* 0x0016 */
291 "RegQueryValue", /* 0x0017 */
292 "RegEnumKey", /* 0x0018 */
293 "RegEnumValue", /* 0x0019 */
294 "RegQueryValueEx", /* 0x001A */
295 "RegSetValueEx", /* 0x001B */
296 "RegFlushKey", /* 0x001C */
297 "RegQueryInfoKey", /* 0x001D */
298 "GetDemandPageInfo", /* 0x001E */
299 "BlockOnID", /* 0x001F */
300 "SignalID", /* 0x0020 */
301 "RegLoadKey", /* 0x0021 */
302 "RegUnLoadKey", /* 0x0022 */
303 "RegSaveKey", /* 0x0023 */
304 "RegRemapPreDefKey", /* 0x0024 */
305 "PageChangePager", /* 0x0025 */
306 "RegQueryMultipleValues", /* 0x0026 */
307 "RegReplaceKey", /* 0x0027 */
308 "<KERNEL32.101>" /* 0x0028 -- What does this do??? */
311 /* PageReserve arena values */
312 #define PR_PRIVATE 0x80000400 /* anywhere in private arena */
313 #define PR_SHARED 0x80060000 /* anywhere in shared arena */
314 #define PR_SYSTEM 0x80080000 /* anywhere in system arena */
316 /* PageReserve flags */
317 #define PR_FIXED 0x00000008 /* don't move during PageReAllocate */
318 #define PR_4MEG 0x00000001 /* allocate on 4mb boundary */
319 #define PR_STATIC 0x00000010 /* see PageReserve documentation */
321 /* PageCommit default pager handle values */
322 #define PD_ZEROINIT 0x00000001 /* swappable zero-initialized pages */
323 #define PD_NOINIT 0x00000002 /* swappable uninitialized pages */
324 #define PD_FIXEDZERO 0x00000003 /* fixed zero-initialized pages */
325 #define PD_FIXED 0x00000004 /* fixed uninitialized pages */
327 /* PageCommit flags */
328 #define PC_FIXED 0x00000008 /* pages are permanently locked */
329 #define PC_LOCKED 0x00000080 /* pages are made present and locked */
330 #define PC_LOCKEDIFDP 0x00000100 /* pages are locked if swap via DOS */
331 #define PC_WRITEABLE 0x00020000 /* make the pages writeable */
332 #define PC_USER 0x00040000 /* make the pages ring 3 accessible */
333 #define PC_INCR 0x40000000 /* increment "pagerdata" each page */
334 #define PC_PRESENT 0x80000000 /* make pages initially present */
335 #define PC_STATIC 0x20000000 /* allow commit in PR_STATIC object */
336 #define PC_DIRTY 0x08000000 /* make pages initially dirty */
337 #define PC_CACHEDIS 0x00100000 /* Allocate uncached pages - new for WDM */
338 #define PC_CACHEWT 0x00080000 /* Allocate write through cache pages - new for WDM */
339 #define PC_PAGEFLUSH 0x00008000 /* Touch device mapped pages on alloc - new for WDM */
341 /* PageCommitContig additional flags */
342 #define PCC_ZEROINIT 0x00000001 /* zero-initialize new pages */
343 #define PCC_NOLIN 0x10000000 /* don't map to any linear address */
347 HANDLE DEVICE_Open( LPCWSTR filenameW, DWORD access, LPSECURITY_ATTRIBUTES sa )
349 const struct VxDInfo *info;
350 char filename[MAX_PATH];
352 if (!WideCharToMultiByte(CP_ACP, 0, filenameW, -1, filename, MAX_PATH, NULL, NULL))
354 SetLastError( ERROR_FILE_NOT_FOUND );
358 for (info = VxDList; info->name; info++)
359 if (!strncasecmp( info->name, filename, strlen(info->name) ))
360 return FILE_CreateDevice( info->id | 0x10000, access, sa );
362 FIXME( "Unknown/unsupported VxD %s. Try setting Windows version to 'nt40' or 'win31'.\n",
364 SetLastError( ERROR_FILE_NOT_FOUND );
368 static DWORD DEVICE_GetClientID( HANDLE handle )
371 SERVER_START_REQ( get_file_info )
373 req->handle = handle;
374 if (!wine_server_call( req ) && (reply->type == FILE_TYPE_UNKNOWN))
381 static const struct VxDInfo *DEVICE_GetInfo( DWORD clientID )
383 const struct VxDInfo *info = NULL;
385 if (clientID & 0x10000)
387 for (info = VxDList; info->name; info++)
388 if (info->id == LOWORD(clientID)) break;
393 /****************************************************************************
394 * DeviceIoControl (KERNEL32.@)
395 * This is one of those big ugly nasty procedure which can do
396 * a million and one things when it comes to devices. It can also be
397 * used for VxD communication.
399 * A return value of FALSE indicates that something has gone wrong which
400 * GetLastError can decipher.
402 BOOL WINAPI DeviceIoControl(HANDLE hDevice, DWORD dwIoControlCode,
403 LPVOID lpvInBuffer, DWORD cbInBuffer,
404 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
405 LPDWORD lpcbBytesReturned,
406 LPOVERLAPPED lpOverlapped)
410 TRACE( "(%d,%ld,%p,%ld,%p,%ld,%p,%p)\n",
411 hDevice,dwIoControlCode,lpvInBuffer,cbInBuffer,
412 lpvOutBuffer,cbOutBuffer,lpcbBytesReturned,lpOverlapped );
414 if (!(clientID = DEVICE_GetClientID( hDevice )))
416 SetLastError( ERROR_INVALID_PARAMETER );
420 /* Check if this is a user defined control code for a VxD */
421 if( HIWORD( dwIoControlCode ) == 0 )
423 const struct VxDInfo *info;
424 if (!(info = DEVICE_GetInfo( clientID )))
426 FIXME( "No device found for id %lx\n", clientID);
428 else if ( info->deviceio )
430 return info->deviceio( dwIoControlCode,
431 lpvInBuffer, cbInBuffer,
432 lpvOutBuffer, cbOutBuffer,
433 lpcbBytesReturned, lpOverlapped );
437 FIXME( "Unimplemented control %ld for VxD device %s\n",
438 dwIoControlCode, info->name ? info->name : "???" );
439 /* FIXME: this is for invalid calls on W98SE,
440 * but maybe we should use ERROR_CALL_NOT_IMPLEMENTED
442 SetLastError( ERROR_INVALID_FUNCTION );
450 str[0] += LOBYTE(clientID);
451 if (GetDriveTypeA(str) == DRIVE_CDROM)
452 return CDROM_DeviceIoControl(clientID, hDevice, dwIoControlCode, lpvInBuffer, cbInBuffer,
453 lpvOutBuffer, cbOutBuffer, lpcbBytesReturned,
455 else switch( dwIoControlCode )
457 case FSCTL_DELETE_REPARSE_POINT:
458 case FSCTL_DISMOUNT_VOLUME:
459 case FSCTL_GET_COMPRESSION:
460 case FSCTL_GET_REPARSE_POINT:
461 case FSCTL_LOCK_VOLUME:
462 case FSCTL_QUERY_ALLOCATED_RANGES:
463 case FSCTL_SET_COMPRESSION:
464 case FSCTL_SET_REPARSE_POINT:
465 case FSCTL_SET_SPARSE:
466 case FSCTL_SET_ZERO_DATA:
467 case FSCTL_UNLOCK_VOLUME:
468 case IOCTL_DISK_CHECK_VERIFY:
469 case IOCTL_DISK_EJECT_MEDIA:
470 case IOCTL_DISK_FORMAT_TRACKS:
471 case IOCTL_DISK_GET_DRIVE_GEOMETRY:
472 case IOCTL_DISK_GET_DRIVE_LAYOUT:
473 case IOCTL_DISK_GET_MEDIA_TYPES:
474 case IOCTL_DISK_GET_PARTITION_INFO:
475 case IOCTL_DISK_LOAD_MEDIA:
476 case IOCTL_DISK_MEDIA_REMOVAL:
477 case IOCTL_DISK_PERFORMANCE:
478 case IOCTL_DISK_REASSIGN_BLOCKS:
479 case IOCTL_DISK_SET_DRIVE_LAYOUT:
480 case IOCTL_DISK_SET_PARTITION_INFO:
481 case IOCTL_DISK_VERIFY:
482 case IOCTL_SERIAL_LSRMST_INSERT:
483 case IOCTL_STORAGE_CHECK_VERIFY:
484 case IOCTL_STORAGE_EJECT_MEDIA:
485 case IOCTL_STORAGE_GET_MEDIA_TYPES:
486 case IOCTL_STORAGE_LOAD_MEDIA:
487 case IOCTL_STORAGE_MEDIA_REMOVAL:
488 FIXME( "unimplemented dwIoControlCode=%08lx\n", dwIoControlCode);
489 SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
493 FIXME( "ignored dwIoControlCode=%08lx\n",dwIoControlCode);
494 SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
502 /***********************************************************************
505 static BOOL DeviceIo_VTDAPI(DWORD dwIoControlCode, LPVOID lpvInBuffer, DWORD cbInBuffer,
506 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
507 LPDWORD lpcbBytesReturned,
508 LPOVERLAPPED lpOverlapped)
512 switch (dwIoControlCode)
515 if (lpvOutBuffer && (cbOutBuffer>=4))
516 *(DWORD*)lpvOutBuffer = GetTickCount();
518 if (lpcbBytesReturned)
519 *lpcbBytesReturned = 4;
524 FIXME( "Control %ld not implemented\n", dwIoControlCode);
532 /***********************************************************************
533 * VxDCall0 (KERNEL32.1)
534 * VxDCall1 (KERNEL32.2)
535 * VxDCall2 (KERNEL32.3)
536 * VxDCall3 (KERNEL32.4)
537 * VxDCall4 (KERNEL32.5)
538 * VxDCall5 (KERNEL32.6)
539 * VxDCall6 (KERNEL32.7)
540 * VxDCall7 (KERNEL32.8)
541 * VxDCall8 (KERNEL32.9)
543 void VxDCall( DWORD service, CONTEXT86 *context )
545 DWORD ret = 0xffffffff; /* FIXME */
548 TRACE( "(%08lx, ...)\n", service);
550 for (i = 0; VxDList[i].name; i++)
551 if (VxDList[i].id == HIWORD(service))
554 if (!VxDList[i].name)
555 FIXME( "Unknown VxD (%08lx)\n", service);
556 else if (!VxDList[i].vxdcall)
557 FIXME( "Unimplemented VxD (%08lx)\n", service);
559 ret = VxDList[i].vxdcall( service, context );
565 /******************************************************************************
566 * The following is a massive duplication of the advapi32 code.
567 * Unfortunately sharing the code is not possible since the native
568 * Win95 advapi32 depends on it. Someday we should probably stop
569 * supporting native Win95 advapi32 altogether...
573 #define HKEY_SPECIAL_ROOT_FIRST HKEY_CLASSES_ROOT
574 #define HKEY_SPECIAL_ROOT_LAST HKEY_DYN_DATA
575 #define NB_SPECIAL_ROOT_KEYS ((UINT)HKEY_SPECIAL_ROOT_LAST - (UINT)HKEY_SPECIAL_ROOT_FIRST + 1)
577 static HKEY special_root_keys[NB_SPECIAL_ROOT_KEYS];
579 static const WCHAR name_CLASSES_ROOT[] =
580 {'M','a','c','h','i','n','e','\\',
581 'S','o','f','t','w','a','r','e','\\',
582 'C','l','a','s','s','e','s',0};
583 static const WCHAR name_LOCAL_MACHINE[] =
584 {'M','a','c','h','i','n','e',0};
585 static const WCHAR name_USERS[] =
587 static const WCHAR name_PERFORMANCE_DATA[] =
588 {'P','e','r','f','D','a','t','a',0};
589 static const WCHAR name_CURRENT_CONFIG[] =
590 {'M','a','c','h','i','n','e','\\',
591 'S','y','s','t','e','m','\\',
592 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
593 'H','a','r','d','w','a','r','e','P','r','o','f','i','l','e','s','\\',
594 'C','u','r','r','e','n','t',0};
595 static const WCHAR name_DYN_DATA[] =
596 {'D','y','n','D','a','t','a',0};
598 #define DECL_STR(key) { sizeof(name_##key)-sizeof(WCHAR), sizeof(name_##key), (LPWSTR)name_##key }
599 static UNICODE_STRING root_key_names[NB_SPECIAL_ROOT_KEYS] =
601 DECL_STR(CLASSES_ROOT),
602 { 0, 0, NULL }, /* HKEY_CURRENT_USER is determined dynamically */
603 DECL_STR(LOCAL_MACHINE),
605 DECL_STR(PERFORMANCE_DATA),
606 DECL_STR(CURRENT_CONFIG),
612 /* check if value type needs string conversion (Ansi<->Unicode) */
613 inline static int is_string( DWORD type )
615 return (type == REG_SZ) || (type == REG_EXPAND_SZ) || (type == REG_MULTI_SZ);
618 /* create one of the HKEY_* special root keys */
619 static HKEY create_special_root_hkey( HKEY hkey, DWORD access )
622 int idx = (UINT)hkey - (UINT)HKEY_SPECIAL_ROOT_FIRST;
624 if (hkey == HKEY_CURRENT_USER)
626 if (RtlOpenCurrentUser( access, &hkey )) return 0;
630 OBJECT_ATTRIBUTES attr;
632 attr.Length = sizeof(attr);
633 attr.RootDirectory = 0;
634 attr.ObjectName = &root_key_names[idx];
636 attr.SecurityDescriptor = NULL;
637 attr.SecurityQualityOfService = NULL;
638 if (NtCreateKey( &hkey, access, &attr, 0, NULL, 0, NULL )) return 0;
641 if (!(ret = InterlockedCompareExchange( (PLONG)&special_root_keys[idx], hkey, 0 )))
644 NtClose( hkey ); /* somebody beat us to it */
648 /* map the hkey from special root to normal key if necessary */
649 inline static HKEY get_special_root_hkey( HKEY hkey )
653 if ((hkey >= HKEY_SPECIAL_ROOT_FIRST) && (hkey <= HKEY_SPECIAL_ROOT_LAST))
655 if (!(ret = special_root_keys[(UINT)hkey - (UINT)HKEY_SPECIAL_ROOT_FIRST]))
656 ret = create_special_root_hkey( hkey, KEY_ALL_ACCESS );
662 /******************************************************************************
665 static DWORD VMM_RegCreateKeyA( HKEY hkey, LPCSTR name, LPHKEY retkey )
667 OBJECT_ATTRIBUTES attr;
668 UNICODE_STRING nameW;
672 if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
674 attr.Length = sizeof(attr);
675 attr.RootDirectory = hkey;
676 attr.ObjectName = &nameW;
678 attr.SecurityDescriptor = NULL;
679 attr.SecurityQualityOfService = NULL;
680 RtlInitAnsiString( &nameA, name );
682 if (!(status = RtlAnsiStringToUnicodeString( &nameW, &nameA, TRUE )))
684 status = NtCreateKey( retkey, KEY_ALL_ACCESS, &attr, 0, NULL,
685 REG_OPTION_NON_VOLATILE, NULL );
686 RtlFreeUnicodeString( &nameW );
688 return RtlNtStatusToDosError( status );
692 /******************************************************************************
695 DWORD WINAPI VMM_RegOpenKeyExA(HKEY hkey, LPCSTR name, DWORD reserved, REGSAM access, LPHKEY retkey)
697 OBJECT_ATTRIBUTES attr;
698 UNICODE_STRING nameW;
702 if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
704 attr.Length = sizeof(attr);
705 attr.RootDirectory = hkey;
706 attr.ObjectName = &nameW;
708 attr.SecurityDescriptor = NULL;
709 attr.SecurityQualityOfService = NULL;
711 RtlInitAnsiString( &nameA, name );
712 if (!(status = RtlAnsiStringToUnicodeString( &nameW, &nameA, TRUE )))
714 status = NtOpenKey( retkey, access, &attr );
715 RtlFreeUnicodeString( &nameW );
717 return RtlNtStatusToDosError( status );
721 /******************************************************************************
724 static DWORD VMM_RegCloseKey( HKEY hkey )
726 if (!hkey || hkey >= (HKEY)0x80000000) return ERROR_SUCCESS;
727 return RtlNtStatusToDosError( NtClose( hkey ) );
731 /******************************************************************************
734 static DWORD VMM_RegDeleteKeyA( HKEY hkey, LPCSTR name )
739 if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
741 if (!name || !*name) return RtlNtStatusToDosError( NtDeleteKey( hkey ) );
742 if (!(ret = VMM_RegOpenKeyExA( hkey, name, 0, 0, &tmp )))
744 ret = RtlNtStatusToDosError( NtDeleteKey( tmp ) );
751 /******************************************************************************
754 static DWORD VMM_RegSetValueExA( HKEY hkey, LPCSTR name, DWORD reserved, DWORD type,
755 CONST BYTE *data, DWORD count )
757 UNICODE_STRING nameW;
762 if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
770 /* if user forgot to count terminating null, add it (yes NT does this) */
771 if (data[count-1] && !data[count]) count++;
773 RtlMultiByteToUnicodeSize( &lenW, data, count );
774 if (!(dataW = HeapAlloc( GetProcessHeap(), 0, lenW ))) return ERROR_OUTOFMEMORY;
775 RtlMultiByteToUnicodeN( dataW, lenW, NULL, data, count );
777 data = (BYTE *)dataW;
780 RtlInitAnsiString( &nameA, name );
781 if (!(status = RtlAnsiStringToUnicodeString( &nameW, &nameA, TRUE )))
783 status = NtSetValueKey( hkey, &nameW, 0, type, data, count );
784 RtlFreeUnicodeString( &nameW );
786 if (dataW) HeapFree( GetProcessHeap(), 0, dataW );
787 return RtlNtStatusToDosError( status );
791 /******************************************************************************
794 static DWORD VMM_RegSetValueA( HKEY hkey, LPCSTR name, DWORD type, LPCSTR data, DWORD count )
799 if (type != REG_SZ) return ERROR_INVALID_PARAMETER;
801 if (name && name[0]) /* need to create the subkey */
803 if ((ret = VMM_RegCreateKeyA( hkey, name, &subkey )) != ERROR_SUCCESS) return ret;
805 ret = VMM_RegSetValueExA( subkey, NULL, 0, REG_SZ, (LPBYTE)data, strlen(data)+1 );
806 if (subkey != hkey) NtClose( subkey );
811 /******************************************************************************
812 * VMM_RegDeleteValueA
814 static DWORD VMM_RegDeleteValueA( HKEY hkey, LPCSTR name )
816 UNICODE_STRING nameW;
820 if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
822 RtlInitAnsiString( &nameA, name );
823 if (!(status = RtlAnsiStringToUnicodeString( &nameW, &nameA, TRUE )))
825 status = NtDeleteValueKey( hkey, &nameW );
826 RtlFreeUnicodeString( &nameW );
828 return RtlNtStatusToDosError( status );
832 /******************************************************************************
833 * VMM_RegQueryValueExA
835 static DWORD VMM_RegQueryValueExA( HKEY hkey, LPCSTR name, LPDWORD reserved, LPDWORD type,
836 LPBYTE data, LPDWORD count )
840 UNICODE_STRING nameW;
842 char buffer[256], *buf_ptr = buffer;
843 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)buffer;
844 static const int info_size = offsetof( KEY_VALUE_PARTIAL_INFORMATION, Data );
846 if ((data && !count) || reserved) return ERROR_INVALID_PARAMETER;
847 if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
849 RtlInitAnsiString( &nameA, name );
850 if ((status = RtlAnsiStringToUnicodeString( &nameW, &nameA, TRUE )))
851 return RtlNtStatusToDosError(status);
853 status = NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation,
854 buffer, sizeof(buffer), &total_size );
855 if (status && status != STATUS_BUFFER_OVERFLOW) goto done;
857 /* we need to fetch the contents for a string type even if not requested,
858 * because we need to compute the length of the ASCII string. */
859 if (data || is_string(info->Type))
861 /* retry with a dynamically allocated buffer */
862 while (status == STATUS_BUFFER_OVERFLOW)
864 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
865 if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
867 status = STATUS_NO_MEMORY;
870 info = (KEY_VALUE_PARTIAL_INFORMATION *)buf_ptr;
871 status = NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation,
872 buf_ptr, total_size, &total_size );
877 if (is_string(info->Type))
879 DWORD len = WideCharToMultiByte( CP_ACP, 0, (WCHAR *)(buf_ptr + info_size),
880 (total_size - info_size) /sizeof(WCHAR),
881 NULL, 0, NULL, NULL );
884 if (len > *count) status = STATUS_BUFFER_OVERFLOW;
887 WideCharToMultiByte( CP_ACP, 0, (WCHAR *)(buf_ptr + info_size),
888 (total_size - info_size) /sizeof(WCHAR),
889 data, len, NULL, NULL );
890 /* if the type is REG_SZ and data is not 0-terminated
891 * and there is enough space in the buffer NT appends a \0 */
892 if (len < *count && data[len-1]) data[len] = 0;
895 total_size = len + info_size;
899 if (total_size - info_size > *count) status = STATUS_BUFFER_OVERFLOW;
900 else memcpy( data, buf_ptr + info_size, total_size - info_size );
903 else if (status != STATUS_BUFFER_OVERFLOW) goto done;
906 if (type) *type = info->Type;
907 if (count) *count = total_size - info_size;
910 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
911 RtlFreeUnicodeString( &nameW );
912 return RtlNtStatusToDosError(status);
916 /******************************************************************************
919 static DWORD VMM_RegQueryValueA( HKEY hkey, LPCSTR name, LPSTR data, LPLONG count )
926 if ((ret = VMM_RegOpenKeyExA( hkey, name, 0, KEY_ALL_ACCESS, &subkey )) != ERROR_SUCCESS)
929 ret = VMM_RegQueryValueExA( subkey, NULL, NULL, NULL, (LPBYTE)data, count );
930 if (subkey != hkey) NtClose( subkey );
931 if (ret == ERROR_FILE_NOT_FOUND)
933 /* return empty string if default value not found */
935 if (count) *count = 1;
942 /******************************************************************************
945 static DWORD VMM_RegEnumValueA( HKEY hkey, DWORD index, LPSTR value, LPDWORD val_count,
946 LPDWORD reserved, LPDWORD type, LPBYTE data, LPDWORD count )
950 char buffer[256], *buf_ptr = buffer;
951 KEY_VALUE_FULL_INFORMATION *info = (KEY_VALUE_FULL_INFORMATION *)buffer;
952 static const int info_size = offsetof( KEY_VALUE_FULL_INFORMATION, Name );
954 TRACE("(%x,%ld,%p,%p,%p,%p,%p,%p)\n",
955 hkey, index, value, val_count, reserved, type, data, count );
957 /* NT only checks count, not val_count */
958 if ((data && !count) || reserved) return ERROR_INVALID_PARAMETER;
959 if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
961 total_size = info_size + (MAX_PATH + 1) * sizeof(WCHAR);
962 if (data) total_size += *count;
963 total_size = min( sizeof(buffer), total_size );
965 status = NtEnumerateValueKey( hkey, index, KeyValueFullInformation,
966 buffer, total_size, &total_size );
967 if (status && status != STATUS_BUFFER_OVERFLOW) goto done;
969 /* we need to fetch the contents for a string type even if not requested,
970 * because we need to compute the length of the ASCII string. */
971 if (value || data || is_string(info->Type))
973 /* retry with a dynamically allocated buffer */
974 while (status == STATUS_BUFFER_OVERFLOW)
976 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
977 if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
978 return ERROR_NOT_ENOUGH_MEMORY;
979 info = (KEY_VALUE_FULL_INFORMATION *)buf_ptr;
980 status = NtEnumerateValueKey( hkey, index, KeyValueFullInformation,
981 buf_ptr, total_size, &total_size );
984 if (status) goto done;
986 if (is_string(info->Type))
989 RtlUnicodeToMultiByteSize( &len, (WCHAR *)(buf_ptr + info->DataOffset),
990 total_size - info->DataOffset );
993 if (len > *count) status = STATUS_BUFFER_OVERFLOW;
996 RtlUnicodeToMultiByteN( data, len, NULL, (WCHAR *)(buf_ptr + info->DataOffset),
997 total_size - info->DataOffset );
998 /* if the type is REG_SZ and data is not 0-terminated
999 * and there is enough space in the buffer NT appends a \0 */
1000 if (len < *count && data[len-1]) data[len] = 0;
1003 info->DataLength = len;
1007 if (total_size - info->DataOffset > *count) status = STATUS_BUFFER_OVERFLOW;
1008 else memcpy( data, buf_ptr + info->DataOffset, total_size - info->DataOffset );
1011 if (value && !status)
1015 RtlUnicodeToMultiByteSize( &len, info->Name, info->NameLength );
1016 if (len >= *val_count)
1018 status = STATUS_BUFFER_OVERFLOW;
1021 len = *val_count - 1;
1022 RtlUnicodeToMultiByteN( value, len, NULL, info->Name, info->NameLength );
1028 RtlUnicodeToMultiByteN( value, len, NULL, info->Name, info->NameLength );
1034 else status = STATUS_SUCCESS;
1036 if (type) *type = info->Type;
1037 if (count) *count = info->DataLength;
1040 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
1041 return RtlNtStatusToDosError(status);
1045 /******************************************************************************
1048 static DWORD VMM_RegEnumKeyA( HKEY hkey, DWORD index, LPSTR name, DWORD name_len )
1051 char buffer[256], *buf_ptr = buffer;
1052 KEY_NODE_INFORMATION *info = (KEY_NODE_INFORMATION *)buffer;
1055 if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
1057 status = NtEnumerateKey( hkey, index, KeyNodeInformation,
1058 buffer, sizeof(buffer), &total_size );
1060 while (status == STATUS_BUFFER_OVERFLOW)
1062 /* retry with a dynamically allocated buffer */
1063 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
1064 if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
1065 return ERROR_NOT_ENOUGH_MEMORY;
1066 info = (KEY_NODE_INFORMATION *)buf_ptr;
1067 status = NtEnumerateKey( hkey, index, KeyNodeInformation,
1068 buf_ptr, total_size, &total_size );
1075 RtlUnicodeToMultiByteSize( &len, info->Name, info->NameLength );
1076 if (len >= name_len) status = STATUS_BUFFER_OVERFLOW;
1079 RtlUnicodeToMultiByteN( name, len, NULL, info->Name, info->NameLength );
1084 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
1085 return RtlNtStatusToDosError( status );
1089 /******************************************************************************
1090 * VMM_RegQueryInfoKeyA
1092 * NOTE: This VxDCall takes only a subset of the parameters that the
1093 * corresponding Win32 API call does. The implementation in Win95
1094 * ADVAPI32 sets all output parameters not mentioned here to zero.
1096 static DWORD VMM_RegQueryInfoKeyA( HKEY hkey, LPDWORD subkeys, LPDWORD max_subkey,
1097 LPDWORD values, LPDWORD max_value, LPDWORD max_data )
1100 KEY_FULL_INFORMATION info;
1103 if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
1105 status = NtQueryKey( hkey, KeyFullInformation, &info, sizeof(info), &total_size );
1106 if (status && status != STATUS_BUFFER_OVERFLOW) return RtlNtStatusToDosError( status );
1108 if (subkeys) *subkeys = info.SubKeys;
1109 if (max_subkey) *max_subkey = info.MaxNameLen;
1110 if (values) *values = info.Values;
1111 if (max_value) *max_value = info.MaxValueNameLen;
1112 if (max_data) *max_data = info.MaxValueDataLen;
1113 return ERROR_SUCCESS;
1117 /***********************************************************************
1120 static DWORD VxDCall_VMM( DWORD service, CONTEXT86 *context )
1122 switch ( LOWORD(service) )
1124 case 0x0011: /* RegOpenKey */
1126 HKEY hkey = (HKEY) stack32_pop( context );
1127 LPCSTR lpszSubKey = (LPCSTR)stack32_pop( context );
1128 LPHKEY retkey = (LPHKEY)stack32_pop( context );
1129 return VMM_RegOpenKeyExA( hkey, lpszSubKey, 0, KEY_ALL_ACCESS, retkey );
1132 case 0x0012: /* RegCreateKey */
1134 HKEY hkey = (HKEY) stack32_pop( context );
1135 LPCSTR lpszSubKey = (LPCSTR)stack32_pop( context );
1136 LPHKEY retkey = (LPHKEY)stack32_pop( context );
1137 return VMM_RegCreateKeyA( hkey, lpszSubKey, retkey );
1140 case 0x0013: /* RegCloseKey */
1142 HKEY hkey = (HKEY)stack32_pop( context );
1143 return VMM_RegCloseKey( hkey );
1146 case 0x0014: /* RegDeleteKey */
1148 HKEY hkey = (HKEY) stack32_pop( context );
1149 LPCSTR lpszSubKey = (LPCSTR)stack32_pop( context );
1150 return VMM_RegDeleteKeyA( hkey, lpszSubKey );
1153 case 0x0015: /* RegSetValue */
1155 HKEY hkey = (HKEY) stack32_pop( context );
1156 LPCSTR lpszSubKey = (LPCSTR)stack32_pop( context );
1157 DWORD dwType = (DWORD) stack32_pop( context );
1158 LPCSTR lpszData = (LPCSTR)stack32_pop( context );
1159 DWORD cbData = (DWORD) stack32_pop( context );
1160 return VMM_RegSetValueA( hkey, lpszSubKey, dwType, lpszData, cbData );
1163 case 0x0016: /* RegDeleteValue */
1165 HKEY hkey = (HKEY) stack32_pop( context );
1166 LPSTR lpszValue = (LPSTR)stack32_pop( context );
1167 return VMM_RegDeleteValueA( hkey, lpszValue );
1170 case 0x0017: /* RegQueryValue */
1172 HKEY hkey = (HKEY) stack32_pop( context );
1173 LPSTR lpszSubKey = (LPSTR) stack32_pop( context );
1174 LPSTR lpszData = (LPSTR) stack32_pop( context );
1175 LPDWORD lpcbData = (LPDWORD)stack32_pop( context );
1176 return VMM_RegQueryValueA( hkey, lpszSubKey, lpszData, lpcbData );
1179 case 0x0018: /* RegEnumKey */
1181 HKEY hkey = (HKEY) stack32_pop( context );
1182 DWORD iSubkey = (DWORD)stack32_pop( context );
1183 LPSTR lpszName = (LPSTR)stack32_pop( context );
1184 DWORD lpcchName = (DWORD)stack32_pop( context );
1185 return VMM_RegEnumKeyA( hkey, iSubkey, lpszName, lpcchName );
1188 case 0x0019: /* RegEnumValue */
1190 HKEY hkey = (HKEY) stack32_pop( context );
1191 DWORD iValue = (DWORD) stack32_pop( context );
1192 LPSTR lpszValue = (LPSTR) stack32_pop( context );
1193 LPDWORD lpcchValue = (LPDWORD)stack32_pop( context );
1194 LPDWORD lpReserved = (LPDWORD)stack32_pop( context );
1195 LPDWORD lpdwType = (LPDWORD)stack32_pop( context );
1196 LPBYTE lpbData = (LPBYTE) stack32_pop( context );
1197 LPDWORD lpcbData = (LPDWORD)stack32_pop( context );
1198 return VMM_RegEnumValueA( hkey, iValue, lpszValue, lpcchValue,
1199 lpReserved, lpdwType, lpbData, lpcbData );
1202 case 0x001A: /* RegQueryValueEx */
1204 HKEY hkey = (HKEY) stack32_pop( context );
1205 LPSTR lpszValue = (LPSTR) stack32_pop( context );
1206 LPDWORD lpReserved = (LPDWORD)stack32_pop( context );
1207 LPDWORD lpdwType = (LPDWORD)stack32_pop( context );
1208 LPBYTE lpbData = (LPBYTE) stack32_pop( context );
1209 LPDWORD lpcbData = (LPDWORD)stack32_pop( context );
1210 return VMM_RegQueryValueExA( hkey, lpszValue, lpReserved,
1211 lpdwType, lpbData, lpcbData );
1214 case 0x001B: /* RegSetValueEx */
1216 HKEY hkey = (HKEY) stack32_pop( context );
1217 LPSTR lpszValue = (LPSTR) stack32_pop( context );
1218 DWORD dwReserved = (DWORD) stack32_pop( context );
1219 DWORD dwType = (DWORD) stack32_pop( context );
1220 LPBYTE lpbData = (LPBYTE)stack32_pop( context );
1221 DWORD cbData = (DWORD) stack32_pop( context );
1222 return VMM_RegSetValueExA( hkey, lpszValue, dwReserved,
1223 dwType, lpbData, cbData );
1226 case 0x001C: /* RegFlushKey */
1228 HKEY hkey = (HKEY)stack32_pop( context );
1229 FIXME( "RegFlushKey(%x): stub\n", hkey );
1230 return ERROR_SUCCESS;
1233 case 0x001D: /* RegQueryInfoKey */
1235 /* NOTE: This VxDCall takes only a subset of the parameters that the
1236 corresponding Win32 API call does. The implementation in Win95
1237 ADVAPI32 sets all output parameters not mentioned here to zero. */
1239 HKEY hkey = (HKEY) stack32_pop( context );
1240 LPDWORD lpcSubKeys = (LPDWORD)stack32_pop( context );
1241 LPDWORD lpcchMaxSubKey = (LPDWORD)stack32_pop( context );
1242 LPDWORD lpcValues = (LPDWORD)stack32_pop( context );
1243 LPDWORD lpcchMaxValueName = (LPDWORD)stack32_pop( context );
1244 LPDWORD lpcchMaxValueData = (LPDWORD)stack32_pop( context );
1245 return VMM_RegQueryInfoKeyA( hkey, lpcSubKeys, lpcchMaxSubKey,
1246 lpcValues, lpcchMaxValueName, lpcchMaxValueData );
1249 case 0x0021: /* RegLoadKey */
1251 HKEY hkey = (HKEY) stack32_pop( context );
1252 LPCSTR lpszSubKey = (LPCSTR)stack32_pop( context );
1253 LPCSTR lpszFile = (LPCSTR)stack32_pop( context );
1254 FIXME("RegLoadKey(%x,%s,%s): stub\n",hkey, debugstr_a(lpszSubKey), debugstr_a(lpszFile));
1255 return ERROR_SUCCESS;
1258 case 0x0022: /* RegUnLoadKey */
1260 HKEY hkey = (HKEY) stack32_pop( context );
1261 LPCSTR lpszSubKey = (LPCSTR)stack32_pop( context );
1262 FIXME("RegUnLoadKey(%x,%s): stub\n",hkey, debugstr_a(lpszSubKey));
1263 return ERROR_SUCCESS;
1266 case 0x0023: /* RegSaveKey */
1268 HKEY hkey = (HKEY) stack32_pop( context );
1269 LPCSTR lpszFile = (LPCSTR)stack32_pop( context );
1270 LPSECURITY_ATTRIBUTES sa = (LPSECURITY_ATTRIBUTES)stack32_pop( context );
1271 FIXME("RegSaveKey(%x,%s,%p): stub\n",hkey, debugstr_a(lpszFile),sa);
1272 return ERROR_SUCCESS;
1275 #if 0 /* Functions are not yet implemented in misc/registry.c */
1276 case 0x0024: /* RegRemapPreDefKey */
1277 case 0x0026: /* RegQueryMultipleValues */
1280 case 0x0027: /* RegReplaceKey */
1282 HKEY hkey = (HKEY) stack32_pop( context );
1283 LPCSTR lpszSubKey = (LPCSTR)stack32_pop( context );
1284 LPCSTR lpszNewFile= (LPCSTR)stack32_pop( context );
1285 LPCSTR lpszOldFile= (LPCSTR)stack32_pop( context );
1286 FIXME("RegReplaceKey(%x,%s,%s,%s): stub\n", hkey, debugstr_a(lpszSubKey),
1287 debugstr_a(lpszNewFile),debugstr_a(lpszOldFile));
1288 return ERROR_SUCCESS;
1291 case 0x0000: /* PageReserve */
1295 DWORD psize = getpagesize();
1296 ULONG page = (ULONG) stack32_pop( context );
1297 ULONG npages = (ULONG) stack32_pop( context );
1298 ULONG flags = (ULONG) stack32_pop( context );
1300 TRACE("PageReserve: page: %08lx, npages: %08lx, flags: %08lx partial stub!\n",
1301 page, npages, flags );
1303 if ( page == PR_SYSTEM ) {
1304 ERR("Can't reserve ring 1 memory\n");
1307 /* FIXME: This has to be handled separately for the separate
1308 address-spaces we now have */
1309 if ( page == PR_PRIVATE || page == PR_SHARED ) page = 0;
1310 /* FIXME: Handle flags in some way */
1311 address = (LPVOID )(page * psize);
1312 ret = VirtualAlloc ( address, ( npages * psize ), MEM_RESERVE, 0 );
1313 TRACE("PageReserve: returning: %08lx\n", (DWORD )ret );
1320 case 0x0001: /* PageCommit */
1325 DWORD psize = getpagesize();
1326 ULONG page = (ULONG) stack32_pop( context );
1327 ULONG npages = (ULONG) stack32_pop( context );
1328 ULONG hpd = (ULONG) stack32_pop( context );
1329 ULONG pagerdata = (ULONG) stack32_pop( context );
1330 ULONG flags = (ULONG) stack32_pop( context );
1332 TRACE("PageCommit: page: %08lx, npages: %08lx, hpd: %08lx pagerdata: "
1333 "%08lx, flags: %08lx partial stub\n",
1334 page, npages, hpd, pagerdata, flags );
1336 if ( flags & PC_USER )
1337 if ( flags & PC_WRITEABLE )
1338 virt_perm = PAGE_EXECUTE_READWRITE;
1340 virt_perm = PAGE_EXECUTE_READ;
1342 virt_perm = PAGE_NOACCESS;
1344 address = (LPVOID )(page * psize);
1345 ret = VirtualAlloc ( address, ( npages * psize ), MEM_COMMIT, virt_perm );
1346 TRACE("PageCommit: Returning: %08lx\n", (DWORD )ret );
1350 case 0x0002: /* PageDecommit */
1354 DWORD psize = getpagesize();
1355 ULONG page = (ULONG) stack32_pop( context );
1356 ULONG npages = (ULONG) stack32_pop( context );
1357 ULONG flags = (ULONG) stack32_pop( context );
1359 TRACE("PageDecommit: page: %08lx, npages: %08lx, flags: %08lx partial stub\n",
1360 page, npages, flags );
1361 address = (LPVOID )( page * psize );
1362 ret = VirtualFree ( address, ( npages * psize ), MEM_DECOMMIT );
1363 TRACE("PageDecommit: Returning: %s\n", ret ? "TRUE" : "FALSE" );
1366 case 0x000d: /* PageModifyPermissions */
1370 DWORD virt_old_perm;
1371 DWORD virt_new_perm;
1372 MEMORY_BASIC_INFORMATION mbi;
1374 DWORD psize = getpagesize();
1375 ULONG page = stack32_pop ( context );
1376 ULONG npages = stack32_pop ( context );
1377 ULONG permand = stack32_pop ( context );
1378 ULONG permor = stack32_pop ( context );
1380 TRACE("PageModifyPermissions %08lx %08lx %08lx %08lx partial stub\n",
1381 page, npages, permand, permor );
1382 address = (LPVOID )( page * psize );
1384 VirtualQuery ( address, &mbi, sizeof ( MEMORY_BASIC_INFORMATION ));
1385 virt_old_perm = mbi.Protect;
1387 switch ( virt_old_perm & mbi.Protect ) {
1390 case PAGE_EXECUTE_READ:
1391 pg_old_perm = PC_USER;
1393 case PAGE_READWRITE:
1394 case PAGE_WRITECOPY:
1395 case PAGE_EXECUTE_READWRITE:
1396 case PAGE_EXECUTE_WRITECOPY:
1397 pg_old_perm = PC_USER | PC_WRITEABLE;
1404 pg_new_perm = pg_old_perm;
1405 pg_new_perm &= permand & ~PC_STATIC;
1406 pg_new_perm |= permor & ~PC_STATIC;
1408 virt_new_perm = ( virt_old_perm ) & ~0xff;
1409 if ( pg_new_perm & PC_USER )
1411 if ( pg_new_perm & PC_WRITEABLE )
1412 virt_new_perm |= PAGE_EXECUTE_READWRITE;
1414 virt_new_perm |= PAGE_EXECUTE_READ;
1417 if ( ! VirtualProtect ( address, ( npages * psize ), virt_new_perm, &virt_old_perm ) ) {
1418 ERR("Can't change page permissions for %08lx\n", (DWORD )address );
1421 TRACE("Returning: %08lx\n", pg_old_perm );
1424 case 0x000a: /* PageFree */
1427 LPVOID hmem = (LPVOID) stack32_pop( context );
1428 DWORD flags = (DWORD ) stack32_pop( context );
1430 TRACE("PageFree: hmem: %08lx, flags: %08lx partial stub\n",
1431 (DWORD )hmem, flags );
1433 ret = VirtualFree ( hmem, 0, MEM_RELEASE );
1435 TRACE("Returning: %d\n", ret );
1439 case 0x001e: /* GetDemandPageInfo */
1441 DWORD dinfo = (DWORD)stack32_pop( context );
1442 DWORD flags = (DWORD)stack32_pop( context );
1444 /* GetDemandPageInfo is supposed to fill out the struct at
1445 * "dinfo" with various low-level memory management information.
1446 * Apps are certainly not supposed to call this, although it's
1447 * demoed and documented by Pietrek on pages 441-443 of "Windows
1448 * 95 System Programming Secrets" if any program needs a real
1449 * implementation of this.
1452 FIXME("GetDemandPageInfo(%08lx %08lx): stub!\n", dinfo, flags);
1457 if (LOWORD(service) < N_VMM_SERVICE)
1458 FIXME( "Unimplemented service %s (%08lx)\n",
1459 VMM_Service_Name[LOWORD(service)], service);
1461 FIXME( "Unknown service %08lx\n", service);
1465 return 0xffffffff; /* FIXME */
1468 /***********************************************************************
1471 * These ioctls are used by 'MSNET32.DLL'.
1473 * I have been unable to uncover any documentation about the ioctls so
1474 * the implementation of the cases IFS_IOCTL_21 and IFS_IOCTL_2F are
1475 * based on reasonable guesses on information found in the Windows 95 DDK.
1480 * IFSMgr DeviceIO service
1483 #define IFS_IOCTL_21 100
1484 #define IFS_IOCTL_2F 101
1485 #define IFS_IOCTL_GET_RES 102
1486 #define IFS_IOCTL_GET_NETPRO_NAME_A 103
1488 struct win32apireq {
1489 unsigned long ar_proid;
1490 unsigned long ar_eax;
1491 unsigned long ar_ebx;
1492 unsigned long ar_ecx;
1493 unsigned long ar_edx;
1494 unsigned long ar_esi;
1495 unsigned long ar_edi;
1496 unsigned long ar_ebp;
1497 unsigned short ar_error;
1498 unsigned short ar_pad;
1501 static void win32apieq_2_CONTEXT(struct win32apireq *pIn,CONTEXT86 *pCxt)
1503 memset(pCxt,0,sizeof(*pCxt));
1505 pCxt->ContextFlags=CONTEXT86_INTEGER|CONTEXT86_CONTROL;
1506 pCxt->Eax = pIn->ar_eax;
1507 pCxt->Ebx = pIn->ar_ebx;
1508 pCxt->Ecx = pIn->ar_ecx;
1509 pCxt->Edx = pIn->ar_edx;
1510 pCxt->Esi = pIn->ar_esi;
1511 pCxt->Edi = pIn->ar_edi;
1513 /* FIXME: Only partial CONTEXT86_CONTROL */
1514 pCxt->Ebp = pIn->ar_ebp;
1516 /* FIXME: pIn->ar_proid ignored */
1517 /* FIXME: pIn->ar_error ignored */
1518 /* FIXME: pIn->ar_pad ignored */
1521 static void CONTEXT_2_win32apieq(CONTEXT86 *pCxt,struct win32apireq *pOut)
1523 memset(pOut,0,sizeof(struct win32apireq));
1525 pOut->ar_eax = pCxt->Eax;
1526 pOut->ar_ebx = pCxt->Ebx;
1527 pOut->ar_ecx = pCxt->Ecx;
1528 pOut->ar_edx = pCxt->Edx;
1529 pOut->ar_esi = pCxt->Esi;
1530 pOut->ar_edi = pCxt->Edi;
1532 /* FIXME: Only partial CONTEXT86_CONTROL */
1533 pOut->ar_ebp = pCxt->Ebp;
1535 /* FIXME: pOut->ar_proid ignored */
1536 /* FIXME: pOut->ar_error ignored */
1537 /* FIXME: pOut->ar_pad ignored */
1540 static BOOL DeviceIo_IFSMgr(DWORD dwIoControlCode, LPVOID lpvInBuffer, DWORD cbInBuffer,
1541 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
1542 LPDWORD lpcbBytesReturned,
1543 LPOVERLAPPED lpOverlapped)
1546 TRACE("(%ld,%p,%ld,%p,%ld,%p,%p): stub\n",
1548 lpvInBuffer,cbInBuffer,
1549 lpvOutBuffer,cbOutBuffer,
1553 switch (dwIoControlCode)
1558 struct win32apireq *pIn=(struct win32apireq *) lpvInBuffer;
1559 struct win32apireq *pOut=(struct win32apireq *) lpvOutBuffer;
1563 "proid=0x%08lx, eax=0x%08lx, ebx=0x%08lx, ecx=0x%08lx, "
1564 "edx=0x%08lx, esi=0x%08lx, edi=0x%08lx, ebp=0x%08lx, "
1565 "error=0x%04x, pad=0x%04x\n",
1566 (dwIoControlCode==IFS_IOCTL_21)?"IFS_IOCTL_21":"IFS_IOCTL_2F",
1567 pIn->ar_proid, pIn->ar_eax, pIn->ar_ebx, pIn->ar_ecx,
1568 pIn->ar_edx, pIn->ar_esi, pIn->ar_edi, pIn->ar_ebp,
1569 pIn->ar_error, pIn->ar_pad
1572 win32apieq_2_CONTEXT(pIn,&cxt);
1574 if(dwIoControlCode==IFS_IOCTL_21)
1576 DOS3Call(&cxt); /* Call int 21h */
1578 INT_Int2fHandler(&cxt); /* Call int 2Fh */
1581 CONTEXT_2_win32apieq(&cxt,pOut);
1585 case IFS_IOCTL_GET_RES:{
1586 FIXME( "Control 'IFS_IOCTL_GET_RES' not implemented\n");
1589 case IFS_IOCTL_GET_NETPRO_NAME_A:{
1590 FIXME( "Control 'IFS_IOCTL_GET_NETPRO_NAME_A' not implemented\n");
1594 FIXME( "Control %ld not implemented\n", dwIoControlCode);
1601 /********************************************************************************
1604 * Service numbers taken from page 448 of Pietrek's "Windows 95 System
1605 * Programming Secrets". Parameters from experimentation on real Win98.
1609 static DWORD VxDCall_VWin32( DWORD service, CONTEXT86 *context )
1611 switch ( LOWORD(service) )
1613 case 0x0000: /* GetVersion */
1615 DWORD vers = GetVersion();
1616 return (LOBYTE(vers) << 8) | HIBYTE(vers);
1620 case 0x0020: /* Get VMCPD Version */
1622 DWORD parm = (DWORD) stack32_pop(context);
1624 FIXME("Get VMCPD Version(%08lx): partial stub!\n", parm);
1626 /* FIXME: This is what Win98 returns, it may
1627 * not be correct in all situations.
1628 * It makes Bleem! happy though.
1634 case 0x0029: /* Int31/DPMI dispatch */
1636 DWORD callnum = (DWORD) stack32_pop(context);
1637 DWORD parm = (DWORD) stack32_pop(context);
1639 TRACE("Int31/DPMI dispatch(%08lx)\n", callnum);
1641 SET_AX( context, callnum );
1642 SET_CX( context, parm );
1643 INT_Int31Handler(context);
1645 return LOWORD(context->Eax);
1649 case 0x002a: /* Int41 dispatch - parm = int41 service number */
1651 DWORD callnum = (DWORD) stack32_pop(context);
1653 return callnum; /* FIXME: should really call INT_Int41Handler() */
1658 FIXME("Unknown VWin32 service %08lx\n", service);
1666 /***********************************************************************
1669 static BOOL DeviceIo_VCD(DWORD dwIoControlCode,
1670 LPVOID lpvInBuffer, DWORD cbInBuffer,
1671 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
1672 LPDWORD lpcbBytesReturned,
1673 LPOVERLAPPED lpOverlapped)
1677 switch (dwIoControlCode)
1679 case IOCTL_SERIAL_LSRMST_INSERT:
1681 FIXME( "IOCTL_SERIAL_LSRMST_INSERT NIY !\n");
1687 FIXME( "Unknown Control %ld\n", dwIoControlCode);
1696 /***********************************************************************
1700 static void DIOCRegs_2_CONTEXT( DIOC_REGISTERS *pIn, CONTEXT86 *pCxt )
1702 memset( pCxt, 0, sizeof(*pCxt) );
1703 /* Note: segment registers == 0 means that CTX_SEG_OFF_TO_LIN
1704 will interpret 32-bit register contents as linear pointers */
1706 pCxt->ContextFlags=CONTEXT86_INTEGER|CONTEXT86_CONTROL;
1707 pCxt->Eax = pIn->reg_EAX;
1708 pCxt->Ebx = pIn->reg_EBX;
1709 pCxt->Ecx = pIn->reg_ECX;
1710 pCxt->Edx = pIn->reg_EDX;
1711 pCxt->Esi = pIn->reg_ESI;
1712 pCxt->Edi = pIn->reg_EDI;
1714 /* FIXME: Only partial CONTEXT86_CONTROL */
1715 pCxt->EFlags = pIn->reg_Flags;
1718 static void CONTEXT_2_DIOCRegs( CONTEXT86 *pCxt, DIOC_REGISTERS *pOut )
1720 memset( pOut, 0, sizeof(DIOC_REGISTERS) );
1722 pOut->reg_EAX = pCxt->Eax;
1723 pOut->reg_EBX = pCxt->Ebx;
1724 pOut->reg_ECX = pCxt->Ecx;
1725 pOut->reg_EDX = pCxt->Edx;
1726 pOut->reg_ESI = pCxt->Esi;
1727 pOut->reg_EDI = pCxt->Edi;
1729 /* FIXME: Only partial CONTEXT86_CONTROL */
1730 pOut->reg_Flags = pCxt->EFlags;
1733 #define DIOC_AH(regs) (((unsigned char*)&((regs)->reg_EAX))[1])
1734 #define DIOC_AL(regs) (((unsigned char*)&((regs)->reg_EAX))[0])
1735 #define DIOC_BH(regs) (((unsigned char*)&((regs)->reg_EBX))[1])
1736 #define DIOC_BL(regs) (((unsigned char*)&((regs)->reg_EBX))[0])
1737 #define DIOC_DH(regs) (((unsigned char*)&((regs)->reg_EDX))[1])
1738 #define DIOC_DL(regs) (((unsigned char*)&((regs)->reg_EDX))[0])
1740 #define DIOC_AX(regs) (((unsigned short*)&((regs)->reg_EAX))[0])
1741 #define DIOC_BX(regs) (((unsigned short*)&((regs)->reg_EBX))[0])
1742 #define DIOC_CX(regs) (((unsigned short*)&((regs)->reg_ECX))[0])
1743 #define DIOC_DX(regs) (((unsigned short*)&((regs)->reg_EDX))[0])
1745 #define DIOC_SET_CARRY(regs) (((regs)->reg_Flags)|=0x00000001)
1747 static const DWORD VWIN32_DriveTypeInfo[7]={
1752 0x4f12, /* 1.44 M */
1753 0x4f24, /* 2.88 M */
1757 /**********************************************************************
1758 * VWIN32_ReadFloppyParams
1760 * Handler for int 13h (disk I/O).
1762 static VOID VWIN32_ReadFloppyParams(DIOC_REGISTERS *regs)
1765 static BYTE floppy_params[2][13] =
1767 { 0xaf, 0x02, 0x25, 0x02, 0x12, 0x1b, 0xff, 0x6c, 0xf6, 0x0f, 0x08 },
1768 { 0xaf, 0x02, 0x25, 0x02, 0x12, 0x1b, 0xff, 0x6c, 0xf6, 0x0f, 0x08 }
1771 unsigned int i, nr_of_drives = 0;
1772 BYTE drive_nr = DIOC_DL(regs);
1774 struct floppy_drive_params floppy_parm;
1775 char root[] = "A:\\";
1777 TRACE("in [ EDX=%08lx ]\n", regs->reg_EDX );
1779 DIOC_AH(regs) = 0x00; /* success */
1781 for (i = 0; i < MAX_DOS_DRIVES; i++, root[0]++)
1782 if (GetDriveTypeA(root) == DRIVE_REMOVABLE) nr_of_drives++;
1783 DIOC_DL(regs) = nr_of_drives;
1785 if (drive_nr > 1) { /* invalid drive ? */
1789 DIOC_SET_CARRY(regs);
1793 if ( (floppy_fd = DRIVE_OpenDevice( drive_nr, O_NONBLOCK)) == -1)
1795 WARN("Can't determine floppy geometry !\n");
1799 DIOC_SET_CARRY(regs);
1802 r = ioctl(floppy_fd, FDGETDRVPRM, &floppy_parm);
1808 DIOC_SET_CARRY(regs);
1814 DIOC_BL(regs) = floppy_parm.cmos;
1816 /* CH = low eight bits of max cyl
1817 CL = max sec nr (bits 5-0),
1818 hi two bits of max cyl (bits 7-6)
1820 if(DIOC_BL(regs) && (DIOC_BL(regs)<7))
1822 DIOC_DH(regs) = 0x01;
1823 DIOC_CX(regs) = VWIN32_DriveTypeInfo[DIOC_BL(regs)];
1827 DIOC_CX(regs) = 0x0;
1828 DIOC_DX(regs) = 0x0;
1831 regs->reg_EDI = (DWORD)floppy_params[drive_nr];
1835 ERR("Get floppy params failed for drive %d\n",drive_nr);
1836 DIOC_SET_CARRY(regs);
1839 TRACE("out [ EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx EDI=%08lx ]\n",
1840 regs->reg_EAX, regs->reg_EBX, regs->reg_ECX, regs->reg_EDX, regs->reg_EDI);
1842 /* FIXME: Word exits quietly if we return with no error. Why? */
1843 FIXME("Returned ERROR!\n");
1844 DIOC_SET_CARRY(regs);
1847 DIOC_AH(regs) = 0x01;
1848 DIOC_SET_CARRY(regs);
1852 /**********************************************************************
1853 * VWIN32_Int13Handler
1855 * Handler for VWIN32_DIOC_DOS_INT13 (disk I/O).
1857 static VOID VWIN32_Int13Handler( DIOC_REGISTERS *regs)
1859 TRACE("AH=%02x\n",DIOC_AH(regs));
1860 switch(DIOC_AH(regs)) /* AH */
1862 case 0x00: /* RESET DISK SYSTEM */
1863 break; /* no return ? */
1865 case 0x01: /* STATUS OF DISK SYSTEM */
1866 DIOC_AL(regs) = 0; /* successful completion */
1869 case 0x02: /* READ SECTORS INTO MEMORY */
1870 DIOC_AL(regs) = 0; /* number of sectors read */
1871 DIOC_AH(regs) = 0; /* status */
1874 case 0x03: /* WRITE SECTORS FROM MEMORY */
1875 break; /* no return ? */
1877 case 0x04: /* VERIFY DISK SECTOR(S) */
1878 DIOC_AL(regs) = 0; /* number of sectors verified */
1882 case 0x05: /* FORMAT TRACK */
1883 case 0x06: /* FORMAT TRACK AND SET BAD SECTOR FLAGS */
1884 case 0x07: /* FORMAT DRIVE STARTING AT GIVEN TRACK */
1885 /* despite what Ralf Brown says, 0x06 and 0x07 seem to
1886 * set CFLAG, too (at least my BIOS does that) */
1887 DIOC_AH(regs) = 0x0c;
1888 DIOC_SET_CARRY(regs);
1891 case 0x08: /* GET DRIVE PARAMETERS */
1892 if (DIOC_DL(regs) & 0x80) { /* hard disk ? */
1893 DIOC_AH(regs) = 0x07;
1894 DIOC_SET_CARRY(regs);
1896 else /* floppy disk */
1897 VWIN32_ReadFloppyParams(regs);
1900 case 0x09: /* INITIALIZE CONTROLLER WITH DRIVE PARAMETERS */
1901 case 0x0a: /* FIXED DISK - READ LONG (XT,AT,XT286,PS) */
1902 case 0x0b: /* FIXED DISK - WRITE LONG (XT,AT,XT286,PS) */
1903 case 0x0c: /* SEEK TO CYLINDER */
1904 case 0x0d: /* ALTERNATE RESET HARD DISKS */
1905 case 0x10: /* CHECK IF DRIVE READY */
1906 case 0x11: /* RECALIBRATE DRIVE */
1907 case 0x14: /* CONTROLLER INTERNAL DIAGNOSTIC */
1911 case 0x15: /* GET DISK TYPE (AT,XT2,XT286,CONV,PS) */
1912 if (DIOC_DL(regs) & 0x80) { /* hard disk ? */
1913 DIOC_AH(regs) = 3; /* fixed disk */
1914 DIOC_SET_CARRY(regs);
1916 else { /* floppy disk ? */
1917 DIOC_AH(regs) = 2; /* floppy with change detection */
1918 DIOC_SET_CARRY(regs);
1922 case 0x0e: /* READ SECTOR BUFFER (XT only) */
1923 case 0x0f: /* WRITE SECTOR BUFFER (XT only) */
1924 case 0x12: /* CONTROLLER RAM DIAGNOSTIC (XT,PS) */
1925 case 0x13: /* DRIVE DIAGNOSTIC (XT,PS) */
1926 DIOC_AH(regs) = 0x01;
1927 DIOC_SET_CARRY(regs);
1930 case 0x16: /* FLOPPY - CHANGE OF DISK STATUS */
1931 DIOC_AH(regs) = 0; /* FIXME - no change */
1934 case 0x17: /* SET DISK TYPE FOR FORMAT */
1935 if (DIOC_DL(regs) < 4)
1936 DIOC_AH(regs) = 0x00; /* successful completion */
1938 DIOC_AH(regs) = 0x01; /* error */
1941 case 0x18: /* SET MEDIA TYPE FOR FORMAT */
1942 if (DIOC_DL(regs) < 4)
1943 DIOC_AH(regs) = 0x00; /* successful completion */
1945 DIOC_AH(regs) = 0x01; /* error */
1948 case 0x19: /* FIXED DISK - PARK HEADS */
1952 FIXME("Unknown VWIN32 INT13 call AX=%04X\n",DIOC_AX(regs));
1956 static BOOL DeviceIo_VWin32(DWORD dwIoControlCode,
1957 LPVOID lpvInBuffer, DWORD cbInBuffer,
1958 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
1959 LPDWORD lpcbBytesReturned,
1960 LPOVERLAPPED lpOverlapped)
1964 switch (dwIoControlCode)
1966 case VWIN32_DIOC_DOS_INT13:
1968 DIOC_REGISTERS *pIn = (DIOC_REGISTERS *)lpvInBuffer;
1969 DIOC_REGISTERS *pOut = (DIOC_REGISTERS *)lpvOutBuffer;
1971 memcpy(pOut, pIn, sizeof (DIOC_REGISTERS));
1972 VWIN32_Int13Handler(pOut);
1976 case VWIN32_DIOC_DOS_IOCTL:
1977 case 0x10: /* Int 0x21 call, call it VWIN_DIOC_INT21 ? */
1978 case VWIN32_DIOC_DOS_INT25:
1979 case VWIN32_DIOC_DOS_INT26:
1980 case 0x29: /* Int 0x31 call, call it VWIN_DIOC_INT31 ? */
1981 case VWIN32_DIOC_DOS_DRIVEINFO:
1984 DIOC_REGISTERS *pIn = (DIOC_REGISTERS *)lpvInBuffer;
1985 DIOC_REGISTERS *pOut = (DIOC_REGISTERS *)lpvOutBuffer;
1987 TRACE( "Control '%s': "
1988 "eax=0x%08lx, ebx=0x%08lx, ecx=0x%08lx, "
1989 "edx=0x%08lx, esi=0x%08lx, edi=0x%08lx \n",
1990 (dwIoControlCode == VWIN32_DIOC_DOS_IOCTL)? "VWIN32_DIOC_DOS_IOCTL" :
1991 (dwIoControlCode == VWIN32_DIOC_DOS_INT25)? "VWIN32_DIOC_DOS_INT25" :
1992 (dwIoControlCode == VWIN32_DIOC_DOS_INT26)? "VWIN32_DIOC_DOS_INT26" :
1993 (dwIoControlCode == VWIN32_DIOC_DOS_DRIVEINFO)? "VWIN32_DIOC_DOS_DRIVEINFO" : "???",
1994 pIn->reg_EAX, pIn->reg_EBX, pIn->reg_ECX,
1995 pIn->reg_EDX, pIn->reg_ESI, pIn->reg_EDI );
1997 DIOCRegs_2_CONTEXT( pIn, &cxt );
1999 switch (dwIoControlCode)
2001 case VWIN32_DIOC_DOS_IOCTL: DOS3Call( &cxt ); break; /* Call int 21h */
2002 case VWIN32_DIOC_DOS_INT13: INT_Int13Handler( &cxt ); break;
2003 case 0x10: /* Int 0x21 call, call it VWIN_DIOC_INT21 ? */
2004 DOS3Call( &cxt ); break;
2005 case VWIN32_DIOC_DOS_INT25: INT_Int25Handler( &cxt ); break;
2006 case VWIN32_DIOC_DOS_INT26: INT_Int26Handler( &cxt ); break;
2007 case 0x29: /* Int 0x31 call, call it VWIN_DIOC_INT31 ? */
2008 INT_Int31Handler( &cxt ); break;
2009 case VWIN32_DIOC_DOS_DRIVEINFO: DOS3Call( &cxt ); break; /* Call int 21h 730x */
2012 CONTEXT_2_DIOCRegs( &cxt, pOut );
2016 case VWIN32_DIOC_SIMCTRLC:
2017 FIXME( "Control VWIN32_DIOC_SIMCTRLC not implemented\n");
2022 FIXME( "Unknown Control %ld\n", dwIoControlCode);
2030 /* this is the main multimedia device loader */
2031 static BOOL DeviceIo_MMDEVLDR(DWORD dwIoControlCode,
2032 LPVOID lpvInBuffer, DWORD cbInBuffer,
2033 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
2034 LPDWORD lpcbBytesReturned,
2035 LPOVERLAPPED lpOverlapped)
2037 FIXME("(%ld,%p,%ld,%p,%ld,%p,%p): stub\n",
2039 lpvInBuffer,cbInBuffer,
2040 lpvOutBuffer,cbOutBuffer,
2044 switch (dwIoControlCode) {
2047 *(DWORD*)lpvOutBuffer=0;
2048 *lpcbBytesReturned=4;
2053 /* this is used by some Origin games */
2054 static BOOL DeviceIo_MONODEBG(DWORD dwIoControlCode,
2055 LPVOID lpvInBuffer, DWORD cbInBuffer,
2056 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
2057 LPDWORD lpcbBytesReturned,
2058 LPOVERLAPPED lpOverlapped)
2060 switch (dwIoControlCode) {
2061 case 1: /* version */
2062 *(LPDWORD)lpvOutBuffer = 0x20004; /* WC SecretOps */
2064 case 9: /* debug output */
2065 ERR("MONODEBG: %s\n",debugstr_a(lpvInBuffer));
2068 FIXME("(%ld,%p,%ld,%p,%ld,%p,%p): stub\n",
2070 lpvInBuffer,cbInBuffer,
2071 lpvOutBuffer,cbOutBuffer,
2080 static BOOL DeviceIo_PCCARD (DWORD dwIoControlCode,
2081 LPVOID lpvInBuffer, DWORD cbInBuffer,
2082 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
2083 LPDWORD lpcbBytesReturned,
2084 LPOVERLAPPED lpOverlapped)
2086 switch (dwIoControlCode) {
2087 case 0x0000: /* PCCARD_Get_Version */
2088 case 0x0001: /* PCCARD_Card_Services */
2090 FIXME( "(%ld,%p,%ld,%p,%ld,%p,%p): stub\n",
2092 lpvInBuffer,cbInBuffer,
2093 lpvOutBuffer,cbOutBuffer,
2102 /***********************************************************************
2103 * OpenVxDHandle (KERNEL32.@)
2105 * This function is supposed to return the corresponding Ring 0
2106 * ("kernel") handle for a Ring 3 handle in Win9x.
2107 * Evidently, Wine will have problems with this. But we try anyway,
2110 HANDLE WINAPI OpenVxDHandle(HANDLE hHandleRing3)
2112 FIXME( "(0x%08x), stub! (returning Ring 3 handle instead of Ring 0)\n", hHandleRing3);
2113 return hHandleRing3;
2116 static BOOL DeviceIo_HASP(DWORD dwIoControlCode, LPVOID lpvInBuffer, DWORD cbInBuffer,
2117 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
2118 LPDWORD lpcbBytesReturned,
2119 LPOVERLAPPED lpOverlapped)
2122 FIXME("(%ld,%p,%ld,%p,%ld,%p,%p): stub\n",
2124 lpvInBuffer,cbInBuffer,
2125 lpvOutBuffer,cbOutBuffer,