Add D3D capability.
[wine/wine-gecko.git] / win32 / device.c
blobea5342a3b62db36da3601f7f814269456b19d588
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 /* int 13 stuff */
50 #ifdef HAVE_SYS_IOCTL_H
51 # include <sys/ioctl.h>
52 #endif
53 #include <fcntl.h>
54 #ifdef linux
55 # include <linux/fd.h>
56 #endif
57 #include "drive.h"
59 WINE_DEFAULT_DEBUG_CHANNEL(file);
62 static BOOL DeviceIo_VTDAPI(DWORD dwIoControlCode,
63 LPVOID lpvInBuffer, DWORD cbInBuffer,
64 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
65 LPDWORD lpcbBytesReturned,
66 LPOVERLAPPED lpOverlapped);
67 static BOOL DeviceIo_MONODEBG(DWORD dwIoControlCode,
68 LPVOID lpvInBuffer, DWORD cbInBuffer,
69 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
70 LPDWORD lpcbBytesReturned,
71 LPOVERLAPPED lpOverlapped);
72 static BOOL DeviceIo_MMDEVLDR(DWORD dwIoControlCode,
73 LPVOID lpvInBuffer, DWORD cbInBuffer,
74 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
75 LPDWORD lpcbBytesReturned,
76 LPOVERLAPPED lpOverlapped);
78 static DWORD VxDCall_VMM( DWORD service, CONTEXT86 *context );
80 static BOOL DeviceIo_IFSMgr(DWORD dwIoControlCode,
81 LPVOID lpvInBuffer, DWORD cbInBuffer,
82 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
83 LPDWORD lpcbBytesReturned,
84 LPOVERLAPPED lpOverlapped);
86 static BOOL DeviceIo_VCD(DWORD dwIoControlCode,
87 LPVOID lpvInBuffer, DWORD cbInBuffer,
88 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
89 LPDWORD lpcbBytesReturned,
90 LPOVERLAPPED lpOverlapped);
92 static DWORD VxDCall_VWin32( DWORD service, CONTEXT86 *context );
94 static BOOL DeviceIo_VWin32(DWORD dwIoControlCode,
95 LPVOID lpvInBuffer, DWORD cbInBuffer,
96 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
97 LPDWORD lpcbBytesReturned,
98 LPOVERLAPPED lpOverlapped);
100 static BOOL DeviceIo_PCCARD (DWORD dwIoControlCode,
101 LPVOID lpvInBuffer, DWORD cbInBuffer,
102 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
103 LPDWORD lpcbBytesReturned,
104 LPOVERLAPPED lpOverlapped);
106 static BOOL DeviceIo_HASP (DWORD dwIoControlCode,
107 LPVOID lpvInBuffer, DWORD cbInBuffer,
108 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
109 LPDWORD lpcbBytesReturned,
110 LPOVERLAPPED lpOverlapped);
112 * VxD names are taken from the Win95 DDK
115 struct VxDInfo
117 LPCSTR name;
118 WORD id;
119 DWORD (*vxdcall)(DWORD, CONTEXT86 *);
120 BOOL (*deviceio)(DWORD, LPVOID, DWORD,
121 LPVOID, DWORD, LPDWORD, LPOVERLAPPED);
124 static const struct VxDInfo VxDList[] =
126 /* Standard VxD IDs */
127 { "VMM", 0x0001, VxDCall_VMM, NULL },
128 { "DEBUG", 0x0002, NULL, NULL },
129 { "VPICD", 0x0003, NULL, NULL },
130 { "VDMAD", 0x0004, NULL, NULL },
131 { "VTD", 0x0005, NULL, NULL },
132 { "V86MMGR", 0x0006, NULL, NULL },
133 { "PAGESWAP", 0x0007, NULL, NULL },
134 { "PARITY", 0x0008, NULL, NULL },
135 { "REBOOT", 0x0009, NULL, NULL },
136 { "VDD", 0x000A, NULL, NULL },
137 { "VSD", 0x000B, NULL, NULL },
138 { "VMD", 0x000C, NULL, NULL },
139 { "VKD", 0x000D, NULL, NULL },
140 { "VCD", 0x000E, NULL, DeviceIo_VCD },
141 { "VPD", 0x000F, NULL, NULL },
142 { "BLOCKDEV", 0x0010, NULL, NULL },
143 { "VMCPD", 0x0011, NULL, NULL },
144 { "EBIOS", 0x0012, NULL, NULL },
145 { "BIOSXLAT", 0x0013, NULL, NULL },
146 { "VNETBIOS", 0x0014, NULL, NULL },
147 { "DOSMGR", 0x0015, NULL, NULL },
148 { "WINLOAD", 0x0016, NULL, NULL },
149 { "SHELL", 0x0017, NULL, NULL },
150 { "VMPOLL", 0x0018, NULL, NULL },
151 { "VPROD", 0x0019, NULL, NULL },
152 { "DOSNET", 0x001A, NULL, NULL },
153 { "VFD", 0x001B, NULL, NULL },
154 { "VDD2", 0x001C, NULL, NULL },
155 { "WINDEBUG", 0x001D, NULL, NULL },
156 { "TSRLOAD", 0x001E, NULL, NULL },
157 { "BIOSHOOK", 0x001F, NULL, NULL },
158 { "INT13", 0x0020, NULL, NULL },
159 { "PAGEFILE", 0x0021, NULL, NULL },
160 { "SCSI", 0x0022, NULL, NULL },
161 { "MCA_POS", 0x0023, NULL, NULL },
162 { "SCSIFD", 0x0024, NULL, NULL },
163 { "VPEND", 0x0025, NULL, NULL },
164 { "VPOWERD", 0x0026, NULL, NULL },
165 { "VXDLDR", 0x0027, NULL, NULL },
166 { "NDIS", 0x0028, NULL, NULL },
167 { "BIOS_EXT", 0x0029, NULL, NULL },
168 { "VWIN32", 0x002A, VxDCall_VWin32, DeviceIo_VWin32 },
169 { "VCOMM", 0x002B, NULL, NULL },
170 { "SPOOLER", 0x002C, NULL, NULL },
171 { "WIN32S", 0x002D, NULL, NULL },
172 { "DEBUGCMD", 0x002E, NULL, NULL },
174 { "VNB", 0x0031, NULL, NULL },
175 { "SERVER", 0x0032, NULL, NULL },
176 { "CONFIGMG", 0x0033, NULL, NULL },
177 { "DWCFGMG", 0x0034, NULL, NULL },
178 { "SCSIPORT", 0x0035, NULL, NULL },
179 { "VFBACKUP", 0x0036, NULL, NULL },
180 { "ENABLE", 0x0037, NULL, NULL },
181 { "VCOND", 0x0038, NULL, NULL },
183 { "EFAX", 0x003A, NULL, NULL },
184 { "DSVXD", 0x003B, NULL, NULL },
185 { "ISAPNP", 0x003C, NULL, NULL },
186 { "BIOS", 0x003D, NULL, NULL },
187 { "WINSOCK", 0x003E, NULL, NULL },
188 { "WSOCK", 0x003E, NULL, NULL },
189 { "WSIPX", 0x003F, NULL, NULL },
190 { "IFSMgr", 0x0040, NULL, DeviceIo_IFSMgr },
191 { "VCDFSD", 0x0041, NULL, NULL },
192 { "MRCI2", 0x0042, NULL, NULL },
193 { "PCI", 0x0043, NULL, NULL },
194 { "PELOADER", 0x0044, NULL, NULL },
195 { "EISA", 0x0045, NULL, NULL },
196 { "DRAGCLI", 0x0046, NULL, NULL },
197 { "DRAGSRV", 0x0047, NULL, NULL },
198 { "PERF", 0x0048, NULL, NULL },
199 { "AWREDIR", 0x0049, NULL, NULL },
201 /* Far East support */
202 { "ETEN", 0x0060, NULL, NULL },
203 { "CHBIOS", 0x0061, NULL, NULL },
204 { "VMSGD", 0x0062, NULL, NULL },
205 { "VPPID", 0x0063, NULL, NULL },
206 { "VIME", 0x0064, NULL, NULL },
207 { "VHBIOSD", 0x0065, NULL, NULL },
209 /* Multimedia OEM IDs */
210 { "VTDAPI", 0x0442, NULL, DeviceIo_VTDAPI },
211 { "MMDEVLDR", 0x044A, NULL, DeviceIo_MMDEVLDR },
213 /* Network Device IDs */
214 { "VNetSup", 0x0480, NULL, NULL },
215 { "VRedir", 0x0481, NULL, NULL },
216 { "VBrowse", 0x0482, NULL, NULL },
217 { "VSHARE", 0x0483, NULL, NULL },
218 { "IFSMgr", 0x0484, NULL, NULL },
219 { "MEMPROBE", 0x0485, NULL, NULL },
220 { "VFAT", 0x0486, NULL, NULL },
221 { "NWLINK", 0x0487, NULL, NULL },
222 { "VNWLINK", 0x0487, NULL, NULL },
223 { "NWSUP", 0x0487, NULL, NULL },
224 { "VTDI", 0x0488, NULL, NULL },
225 { "VIP", 0x0489, NULL, NULL },
226 { "VTCP", 0x048A, NULL, NULL },
227 { "VCache", 0x048B, NULL, NULL },
228 { "VUDP", 0x048C, NULL, NULL },
229 { "VAsync", 0x048D, NULL, NULL },
230 { "NWREDIR", 0x048E, NULL, NULL },
231 { "STAT80", 0x048F, NULL, NULL },
232 { "SCSIPORT", 0x0490, NULL, NULL },
233 { "FILESEC", 0x0491, NULL, NULL },
234 { "NWSERVER", 0x0492, NULL, NULL },
235 { "SECPROV", 0x0493, NULL, NULL },
236 { "NSCL", 0x0494, NULL, NULL },
237 { "WSTCP", 0x0495, NULL, NULL },
238 { "NDIS2SUP", 0x0496, NULL, NULL },
239 { "MSODISUP", 0x0497, NULL, NULL },
240 { "Splitter", 0x0498, NULL, NULL },
241 { "PPP", 0x0499, NULL, NULL },
242 { "VDHCP", 0x049A, NULL, NULL },
243 { "VNBT", 0x049B, NULL, NULL },
244 { "LOGGER", 0x049D, NULL, NULL },
245 { "EFILTER", 0x049E, NULL, NULL },
246 { "FFILTER", 0x049F, NULL, NULL },
247 { "TFILTER", 0x04A0, NULL, NULL },
248 { "AFILTER", 0x04A1, NULL, NULL },
249 { "IRLAMP", 0x04A2, NULL, NULL },
251 { "PCCARD", 0x097C, NULL, DeviceIo_PCCARD },
252 { "HASP95", 0x3721, NULL, DeviceIo_HASP },
254 /* WINE additions, ids unknown */
255 { "MONODEBG.VXD", 0x4242, NULL, DeviceIo_MONODEBG },
257 { NULL, 0, NULL, NULL }
261 * VMM VxDCall service names are (mostly) taken from Stan Mitchell's
262 * "Inside the Windows 95 File System"
265 #define N_VMM_SERVICE 41
267 LPCSTR VMM_Service_Name[N_VMM_SERVICE] =
269 "PageReserve", /* 0x0000 */
270 "PageCommit", /* 0x0001 */
271 "PageDecommit", /* 0x0002 */
272 "PagerRegister", /* 0x0003 */
273 "PagerQuery", /* 0x0004 */
274 "HeapAllocate", /* 0x0005 */
275 "ContextCreate", /* 0x0006 */
276 "ContextDestroy", /* 0x0007 */
277 "PageAttach", /* 0x0008 */
278 "PageFlush", /* 0x0009 */
279 "PageFree", /* 0x000A */
280 "ContextSwitch", /* 0x000B */
281 "HeapReAllocate", /* 0x000C */
282 "PageModifyPermissions", /* 0x000D */
283 "PageQuery", /* 0x000E */
284 "GetCurrentContext", /* 0x000F */
285 "HeapFree", /* 0x0010 */
286 "RegOpenKey", /* 0x0011 */
287 "RegCreateKey", /* 0x0012 */
288 "RegCloseKey", /* 0x0013 */
289 "RegDeleteKey", /* 0x0014 */
290 "RegSetValue", /* 0x0015 */
291 "RegDeleteValue", /* 0x0016 */
292 "RegQueryValue", /* 0x0017 */
293 "RegEnumKey", /* 0x0018 */
294 "RegEnumValue", /* 0x0019 */
295 "RegQueryValueEx", /* 0x001A */
296 "RegSetValueEx", /* 0x001B */
297 "RegFlushKey", /* 0x001C */
298 "RegQueryInfoKey", /* 0x001D */
299 "GetDemandPageInfo", /* 0x001E */
300 "BlockOnID", /* 0x001F */
301 "SignalID", /* 0x0020 */
302 "RegLoadKey", /* 0x0021 */
303 "RegUnLoadKey", /* 0x0022 */
304 "RegSaveKey", /* 0x0023 */
305 "RegRemapPreDefKey", /* 0x0024 */
306 "PageChangePager", /* 0x0025 */
307 "RegQueryMultipleValues", /* 0x0026 */
308 "RegReplaceKey", /* 0x0027 */
309 "<KERNEL32.101>" /* 0x0028 -- What does this do??? */
312 /* PageReserve arena values */
313 #define PR_PRIVATE 0x80000400 /* anywhere in private arena */
314 #define PR_SHARED 0x80060000 /* anywhere in shared arena */
315 #define PR_SYSTEM 0x80080000 /* anywhere in system arena */
317 /* PageReserve flags */
318 #define PR_FIXED 0x00000008 /* don't move during PageReAllocate */
319 #define PR_4MEG 0x00000001 /* allocate on 4mb boundary */
320 #define PR_STATIC 0x00000010 /* see PageReserve documentation */
322 /* PageCommit default pager handle values */
323 #define PD_ZEROINIT 0x00000001 /* swappable zero-initialized pages */
324 #define PD_NOINIT 0x00000002 /* swappable uninitialized pages */
325 #define PD_FIXEDZERO 0x00000003 /* fixed zero-initialized pages */
326 #define PD_FIXED 0x00000004 /* fixed uninitialized pages */
328 /* PageCommit flags */
329 #define PC_FIXED 0x00000008 /* pages are permanently locked */
330 #define PC_LOCKED 0x00000080 /* pages are made present and locked */
331 #define PC_LOCKEDIFDP 0x00000100 /* pages are locked if swap via DOS */
332 #define PC_WRITEABLE 0x00020000 /* make the pages writeable */
333 #define PC_USER 0x00040000 /* make the pages ring 3 accessible */
334 #define PC_INCR 0x40000000 /* increment "pagerdata" each page */
335 #define PC_PRESENT 0x80000000 /* make pages initially present */
336 #define PC_STATIC 0x20000000 /* allow commit in PR_STATIC object */
337 #define PC_DIRTY 0x08000000 /* make pages initially dirty */
338 #define PC_CACHEDIS 0x00100000 /* Allocate uncached pages - new for WDM */
339 #define PC_CACHEWT 0x00080000 /* Allocate write through cache pages - new for WDM */
340 #define PC_PAGEFLUSH 0x00008000 /* Touch device mapped pages on alloc - new for WDM */
342 /* PageCommitContig additional flags */
343 #define PCC_ZEROINIT 0x00000001 /* zero-initialize new pages */
344 #define PCC_NOLIN 0x10000000 /* don't map to any linear address */
348 HANDLE DEVICE_Open( LPCWSTR filenameW, DWORD access, LPSECURITY_ATTRIBUTES sa )
350 const struct VxDInfo *info;
351 char filename[MAX_PATH];
353 if (!WideCharToMultiByte(CP_ACP, 0, filenameW, -1, filename, MAX_PATH, NULL, NULL))
355 SetLastError( ERROR_FILE_NOT_FOUND );
356 return 0;
359 for (info = VxDList; info->name; info++)
360 if (!strncasecmp( info->name, filename, strlen(info->name) ))
361 return FILE_CreateDevice( info->id | 0x10000, access, sa );
363 FIXME( "Unknown/unsupported VxD %s. Try setting Windows version to 'nt40' or 'win31'.\n",
364 filename);
365 SetLastError( ERROR_FILE_NOT_FOUND );
366 return 0;
369 static DWORD DEVICE_GetClientID( HANDLE handle )
371 DWORD ret = 0;
372 SERVER_START_REQ( get_file_info )
374 req->handle = handle;
375 if (!wine_server_call( req ) && (reply->type == FILE_TYPE_UNKNOWN))
376 ret = reply->attr;
378 SERVER_END_REQ;
379 return ret;
382 static const struct VxDInfo *DEVICE_GetInfo( DWORD clientID )
384 const struct VxDInfo *info = NULL;
386 if (clientID & 0x10000)
388 for (info = VxDList; info->name; info++)
389 if (info->id == LOWORD(clientID)) break;
391 return info;
394 /****************************************************************************
395 * DeviceIoControl (KERNEL32.@)
396 * This is one of those big ugly nasty procedure which can do
397 * a million and one things when it comes to devices. It can also be
398 * used for VxD communication.
400 * A return value of FALSE indicates that something has gone wrong which
401 * GetLastError can decipher.
403 BOOL WINAPI DeviceIoControl(HANDLE hDevice, DWORD dwIoControlCode,
404 LPVOID lpvInBuffer, DWORD cbInBuffer,
405 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
406 LPDWORD lpcbBytesReturned,
407 LPOVERLAPPED lpOverlapped)
409 DWORD clientID;
411 TRACE( "(%p,%ld,%p,%ld,%p,%ld,%p,%p)\n",
412 hDevice,dwIoControlCode,lpvInBuffer,cbInBuffer,
413 lpvOutBuffer,cbOutBuffer,lpcbBytesReturned,lpOverlapped );
415 if (!(clientID = DEVICE_GetClientID( hDevice )))
417 SetLastError( ERROR_INVALID_PARAMETER );
418 return FALSE;
421 /* Check if this is a user defined control code for a VxD */
422 if( HIWORD( dwIoControlCode ) == 0 )
424 const struct VxDInfo *info;
425 if (!(info = DEVICE_GetInfo( clientID )))
427 FIXME( "No device found for id %lx\n", clientID);
429 else if ( info->deviceio )
431 return info->deviceio( dwIoControlCode,
432 lpvInBuffer, cbInBuffer,
433 lpvOutBuffer, cbOutBuffer,
434 lpcbBytesReturned, lpOverlapped );
436 else
438 FIXME( "Unimplemented control %ld for VxD device %s\n",
439 dwIoControlCode, info->name ? info->name : "???" );
440 /* FIXME: this is for invalid calls on W98SE,
441 * but maybe we should use ERROR_CALL_NOT_IMPLEMENTED
442 * instead ? */
443 SetLastError( ERROR_INVALID_FUNCTION );
446 else
448 char str[3];
450 strcpy(str, "A:");
451 str[0] += LOBYTE(clientID);
452 if (GetDriveTypeA(str) == DRIVE_CDROM)
453 return CDROM_DeviceIoControl(clientID, hDevice, dwIoControlCode, lpvInBuffer, cbInBuffer,
454 lpvOutBuffer, cbOutBuffer, lpcbBytesReturned,
455 lpOverlapped);
456 else switch( dwIoControlCode )
458 case FSCTL_DELETE_REPARSE_POINT:
459 case FSCTL_DISMOUNT_VOLUME:
460 case FSCTL_GET_COMPRESSION:
461 case FSCTL_GET_REPARSE_POINT:
462 case FSCTL_LOCK_VOLUME:
463 case FSCTL_QUERY_ALLOCATED_RANGES:
464 case FSCTL_SET_COMPRESSION:
465 case FSCTL_SET_REPARSE_POINT:
466 case FSCTL_SET_SPARSE:
467 case FSCTL_SET_ZERO_DATA:
468 case FSCTL_UNLOCK_VOLUME:
469 case IOCTL_DISK_CHECK_VERIFY:
470 case IOCTL_DISK_EJECT_MEDIA:
471 case IOCTL_DISK_FORMAT_TRACKS:
472 case IOCTL_DISK_GET_DRIVE_GEOMETRY:
473 case IOCTL_DISK_GET_DRIVE_LAYOUT:
474 case IOCTL_DISK_GET_MEDIA_TYPES:
475 case IOCTL_DISK_GET_PARTITION_INFO:
476 case IOCTL_DISK_LOAD_MEDIA:
477 case IOCTL_DISK_MEDIA_REMOVAL:
478 case IOCTL_DISK_PERFORMANCE:
479 case IOCTL_DISK_REASSIGN_BLOCKS:
480 case IOCTL_DISK_SET_DRIVE_LAYOUT:
481 case IOCTL_DISK_SET_PARTITION_INFO:
482 case IOCTL_DISK_VERIFY:
483 case IOCTL_SERIAL_LSRMST_INSERT:
484 case IOCTL_STORAGE_CHECK_VERIFY:
485 case IOCTL_STORAGE_EJECT_MEDIA:
486 case IOCTL_STORAGE_GET_MEDIA_TYPES:
487 case IOCTL_STORAGE_LOAD_MEDIA:
488 case IOCTL_STORAGE_MEDIA_REMOVAL:
489 FIXME( "unimplemented dwIoControlCode=%08lx\n", dwIoControlCode);
490 SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
491 return FALSE;
492 break;
493 default:
494 FIXME( "ignored dwIoControlCode=%08lx\n",dwIoControlCode);
495 SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
496 return FALSE;
497 break;
500 return FALSE;
503 /***********************************************************************
504 * DeviceIo_VTDAPI
506 static BOOL DeviceIo_VTDAPI(DWORD dwIoControlCode, LPVOID lpvInBuffer, DWORD cbInBuffer,
507 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
508 LPDWORD lpcbBytesReturned,
509 LPOVERLAPPED lpOverlapped)
511 BOOL retv = TRUE;
513 switch (dwIoControlCode)
515 case 5:
516 if (lpvOutBuffer && (cbOutBuffer>=4))
517 *(DWORD*)lpvOutBuffer = GetTickCount();
519 if (lpcbBytesReturned)
520 *lpcbBytesReturned = 4;
522 break;
524 default:
525 FIXME( "Control %ld not implemented\n", dwIoControlCode);
526 retv = FALSE;
527 break;
530 return retv;
533 /***********************************************************************
534 * VxDCall0 (KERNEL32.1)
535 * VxDCall1 (KERNEL32.2)
536 * VxDCall2 (KERNEL32.3)
537 * VxDCall3 (KERNEL32.4)
538 * VxDCall4 (KERNEL32.5)
539 * VxDCall5 (KERNEL32.6)
540 * VxDCall6 (KERNEL32.7)
541 * VxDCall7 (KERNEL32.8)
542 * VxDCall8 (KERNEL32.9)
544 void VxDCall( DWORD service, CONTEXT86 *context )
546 DWORD ret = 0xffffffff; /* FIXME */
547 int i;
549 TRACE( "(%08lx, ...)\n", service);
551 for (i = 0; VxDList[i].name; i++)
552 if (VxDList[i].id == HIWORD(service))
553 break;
555 if (!VxDList[i].name)
556 FIXME( "Unknown VxD (%08lx)\n", service);
557 else if (!VxDList[i].vxdcall)
558 FIXME( "Unimplemented VxD (%08lx)\n", service);
559 else
560 ret = VxDList[i].vxdcall( service, context );
562 context->Eax = ret;
566 /******************************************************************************
567 * The following is a massive duplication of the advapi32 code.
568 * Unfortunately sharing the code is not possible since the native
569 * Win95 advapi32 depends on it. Someday we should probably stop
570 * supporting native Win95 advapi32 altogether...
574 #define HKEY_SPECIAL_ROOT_FIRST HKEY_CLASSES_ROOT
575 #define HKEY_SPECIAL_ROOT_LAST HKEY_DYN_DATA
576 #define NB_SPECIAL_ROOT_KEYS ((UINT)HKEY_SPECIAL_ROOT_LAST - (UINT)HKEY_SPECIAL_ROOT_FIRST + 1)
578 static HKEY special_root_keys[NB_SPECIAL_ROOT_KEYS];
580 static const WCHAR name_CLASSES_ROOT[] =
581 {'M','a','c','h','i','n','e','\\',
582 'S','o','f','t','w','a','r','e','\\',
583 'C','l','a','s','s','e','s',0};
584 static const WCHAR name_LOCAL_MACHINE[] =
585 {'M','a','c','h','i','n','e',0};
586 static const WCHAR name_USERS[] =
587 {'U','s','e','r',0};
588 static const WCHAR name_PERFORMANCE_DATA[] =
589 {'P','e','r','f','D','a','t','a',0};
590 static const WCHAR name_CURRENT_CONFIG[] =
591 {'M','a','c','h','i','n','e','\\',
592 'S','y','s','t','e','m','\\',
593 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
594 'H','a','r','d','w','a','r','e','P','r','o','f','i','l','e','s','\\',
595 'C','u','r','r','e','n','t',0};
596 static const WCHAR name_DYN_DATA[] =
597 {'D','y','n','D','a','t','a',0};
599 #define DECL_STR(key) { sizeof(name_##key)-sizeof(WCHAR), sizeof(name_##key), (LPWSTR)name_##key }
600 static UNICODE_STRING root_key_names[NB_SPECIAL_ROOT_KEYS] =
602 DECL_STR(CLASSES_ROOT),
603 { 0, 0, NULL }, /* HKEY_CURRENT_USER is determined dynamically */
604 DECL_STR(LOCAL_MACHINE),
605 DECL_STR(USERS),
606 DECL_STR(PERFORMANCE_DATA),
607 DECL_STR(CURRENT_CONFIG),
608 DECL_STR(DYN_DATA)
610 #undef DECL_STR
613 /* check if value type needs string conversion (Ansi<->Unicode) */
614 inline static int is_string( DWORD type )
616 return (type == REG_SZ) || (type == REG_EXPAND_SZ) || (type == REG_MULTI_SZ);
619 /* create one of the HKEY_* special root keys */
620 static HKEY create_special_root_hkey( HKEY hkey, DWORD access )
622 HKEY ret = 0;
623 int idx = (UINT)hkey - (UINT)HKEY_SPECIAL_ROOT_FIRST;
625 if (hkey == HKEY_CURRENT_USER)
627 if (RtlOpenCurrentUser( access, &hkey )) return 0;
629 else
631 OBJECT_ATTRIBUTES attr;
633 attr.Length = sizeof(attr);
634 attr.RootDirectory = 0;
635 attr.ObjectName = &root_key_names[idx];
636 attr.Attributes = 0;
637 attr.SecurityDescriptor = NULL;
638 attr.SecurityQualityOfService = NULL;
639 if (NtCreateKey( &hkey, access, &attr, 0, NULL, 0, NULL )) return 0;
642 if (!(ret = InterlockedCompareExchangePointer( (PVOID) &special_root_keys[idx], hkey, 0 )))
643 ret = hkey;
644 else
645 NtClose( hkey ); /* somebody beat us to it */
646 return ret;
649 /* map the hkey from special root to normal key if necessary */
650 inline static HKEY get_special_root_hkey( HKEY hkey )
652 HKEY ret = hkey;
654 if ((hkey >= HKEY_SPECIAL_ROOT_FIRST) && (hkey <= HKEY_SPECIAL_ROOT_LAST))
656 if (!(ret = special_root_keys[(UINT)hkey - (UINT)HKEY_SPECIAL_ROOT_FIRST]))
657 ret = create_special_root_hkey( hkey, KEY_ALL_ACCESS );
659 return ret;
663 /******************************************************************************
664 * VMM_RegCreateKeyA
666 static DWORD VMM_RegCreateKeyA( HKEY hkey, LPCSTR name, PHKEY retkey )
668 OBJECT_ATTRIBUTES attr;
669 UNICODE_STRING nameW;
670 ANSI_STRING nameA;
671 NTSTATUS status;
673 if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
675 attr.Length = sizeof(attr);
676 attr.RootDirectory = hkey;
677 attr.ObjectName = &nameW;
678 attr.Attributes = 0;
679 attr.SecurityDescriptor = NULL;
680 attr.SecurityQualityOfService = NULL;
681 RtlInitAnsiString( &nameA, name );
683 if (!(status = RtlAnsiStringToUnicodeString( &nameW, &nameA, TRUE )))
685 status = NtCreateKey( retkey, KEY_ALL_ACCESS, &attr, 0, NULL,
686 REG_OPTION_NON_VOLATILE, NULL );
687 RtlFreeUnicodeString( &nameW );
689 return RtlNtStatusToDosError( status );
693 /******************************************************************************
694 * VMM_RegOpenKeyExA
696 DWORD WINAPI VMM_RegOpenKeyExA(HKEY hkey, LPCSTR name, DWORD reserved, REGSAM access, PHKEY retkey)
698 OBJECT_ATTRIBUTES attr;
699 UNICODE_STRING nameW;
700 STRING nameA;
701 NTSTATUS status;
703 if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
705 attr.Length = sizeof(attr);
706 attr.RootDirectory = hkey;
707 attr.ObjectName = &nameW;
708 attr.Attributes = 0;
709 attr.SecurityDescriptor = NULL;
710 attr.SecurityQualityOfService = NULL;
712 RtlInitAnsiString( &nameA, name );
713 if (!(status = RtlAnsiStringToUnicodeString( &nameW, &nameA, TRUE )))
715 status = NtOpenKey( retkey, access, &attr );
716 RtlFreeUnicodeString( &nameW );
718 return RtlNtStatusToDosError( status );
722 /******************************************************************************
723 * VMM_RegCloseKey
725 static DWORD VMM_RegCloseKey( HKEY hkey )
727 if (!hkey || hkey >= (HKEY)0x80000000) return ERROR_SUCCESS;
728 return RtlNtStatusToDosError( NtClose( hkey ) );
732 /******************************************************************************
733 * VMM_RegDeleteKeyA
735 static DWORD VMM_RegDeleteKeyA( HKEY hkey, LPCSTR name )
737 DWORD ret;
738 HKEY tmp;
740 if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
742 if (!name || !*name) return RtlNtStatusToDosError( NtDeleteKey( hkey ) );
743 if (!(ret = VMM_RegOpenKeyExA( hkey, name, 0, 0, &tmp )))
745 ret = RtlNtStatusToDosError( NtDeleteKey( tmp ) );
746 NtClose( tmp );
748 return ret;
752 /******************************************************************************
753 * VMM_RegSetValueExA
755 static DWORD VMM_RegSetValueExA( HKEY hkey, LPCSTR name, DWORD reserved, DWORD type,
756 CONST BYTE *data, DWORD count )
758 UNICODE_STRING nameW;
759 ANSI_STRING nameA;
760 WCHAR *dataW = NULL;
761 NTSTATUS status;
763 if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
765 if (is_string(type))
767 DWORD lenW;
769 if (count)
771 /* if user forgot to count terminating null, add it (yes NT does this) */
772 if (data[count-1] && !data[count]) count++;
774 RtlMultiByteToUnicodeSize( &lenW, data, count );
775 if (!(dataW = HeapAlloc( GetProcessHeap(), 0, lenW ))) return ERROR_OUTOFMEMORY;
776 RtlMultiByteToUnicodeN( dataW, lenW, NULL, data, count );
777 count = lenW;
778 data = (BYTE *)dataW;
781 RtlInitAnsiString( &nameA, name );
782 if (!(status = RtlAnsiStringToUnicodeString( &nameW, &nameA, TRUE )))
784 status = NtSetValueKey( hkey, &nameW, 0, type, data, count );
785 RtlFreeUnicodeString( &nameW );
787 if (dataW) HeapFree( GetProcessHeap(), 0, dataW );
788 return RtlNtStatusToDosError( status );
792 /******************************************************************************
793 * VMM_RegSetValueA
795 static DWORD VMM_RegSetValueA( HKEY hkey, LPCSTR name, DWORD type, LPCSTR data, DWORD count )
797 HKEY subkey = hkey;
798 DWORD ret;
800 if (type != REG_SZ) return ERROR_INVALID_PARAMETER;
802 if (name && name[0]) /* need to create the subkey */
804 if ((ret = VMM_RegCreateKeyA( hkey, name, &subkey )) != ERROR_SUCCESS) return ret;
806 ret = VMM_RegSetValueExA( subkey, NULL, 0, REG_SZ, (LPBYTE)data, strlen(data)+1 );
807 if (subkey != hkey) NtClose( subkey );
808 return ret;
812 /******************************************************************************
813 * VMM_RegDeleteValueA
815 static DWORD VMM_RegDeleteValueA( HKEY hkey, LPCSTR name )
817 UNICODE_STRING nameW;
818 STRING nameA;
819 NTSTATUS status;
821 if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
823 RtlInitAnsiString( &nameA, name );
824 if (!(status = RtlAnsiStringToUnicodeString( &nameW, &nameA, TRUE )))
826 status = NtDeleteValueKey( hkey, &nameW );
827 RtlFreeUnicodeString( &nameW );
829 return RtlNtStatusToDosError( status );
833 /******************************************************************************
834 * VMM_RegQueryValueExA
836 static DWORD VMM_RegQueryValueExA( HKEY hkey, LPCSTR name, LPDWORD reserved, LPDWORD type,
837 LPBYTE data, LPDWORD count )
839 NTSTATUS status;
840 ANSI_STRING nameA;
841 UNICODE_STRING nameW;
842 DWORD total_size;
843 char buffer[256], *buf_ptr = buffer;
844 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)buffer;
845 static const int info_size = offsetof( KEY_VALUE_PARTIAL_INFORMATION, Data );
847 if ((data && !count) || reserved) return ERROR_INVALID_PARAMETER;
848 if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
850 RtlInitAnsiString( &nameA, name );
851 if ((status = RtlAnsiStringToUnicodeString( &nameW, &nameA, TRUE )))
852 return RtlNtStatusToDosError(status);
854 status = NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation,
855 buffer, sizeof(buffer), &total_size );
856 if (status && status != STATUS_BUFFER_OVERFLOW) goto done;
858 /* we need to fetch the contents for a string type even if not requested,
859 * because we need to compute the length of the ASCII string. */
860 if (data || is_string(info->Type))
862 /* retry with a dynamically allocated buffer */
863 while (status == STATUS_BUFFER_OVERFLOW)
865 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
866 if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
868 status = STATUS_NO_MEMORY;
869 goto done;
871 info = (KEY_VALUE_PARTIAL_INFORMATION *)buf_ptr;
872 status = NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation,
873 buf_ptr, total_size, &total_size );
876 if (!status)
878 if (is_string(info->Type))
880 DWORD len = WideCharToMultiByte( CP_ACP, 0, (WCHAR *)(buf_ptr + info_size),
881 (total_size - info_size) /sizeof(WCHAR),
882 NULL, 0, NULL, NULL );
883 if (data && len)
885 if (len > *count) status = STATUS_BUFFER_OVERFLOW;
886 else
888 WideCharToMultiByte( CP_ACP, 0, (WCHAR *)(buf_ptr + info_size),
889 (total_size - info_size) /sizeof(WCHAR),
890 data, len, NULL, NULL );
891 /* if the type is REG_SZ and data is not 0-terminated
892 * and there is enough space in the buffer NT appends a \0 */
893 if (len < *count && data[len-1]) data[len] = 0;
896 total_size = len + info_size;
898 else if (data)
900 if (total_size - info_size > *count) status = STATUS_BUFFER_OVERFLOW;
901 else memcpy( data, buf_ptr + info_size, total_size - info_size );
904 else if (status != STATUS_BUFFER_OVERFLOW) goto done;
907 if (type) *type = info->Type;
908 if (count) *count = total_size - info_size;
910 done:
911 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
912 RtlFreeUnicodeString( &nameW );
913 return RtlNtStatusToDosError(status);
917 /******************************************************************************
918 * VMM_RegQueryValueA
920 static DWORD VMM_RegQueryValueA( HKEY hkey, LPCSTR name, LPSTR data, LPLONG count )
922 DWORD ret;
923 HKEY subkey = hkey;
925 if (name && name[0])
927 if ((ret = VMM_RegOpenKeyExA( hkey, name, 0, KEY_ALL_ACCESS, &subkey )) != ERROR_SUCCESS)
928 return ret;
930 ret = VMM_RegQueryValueExA( subkey, NULL, NULL, NULL, (LPBYTE)data, count );
931 if (subkey != hkey) NtClose( subkey );
932 if (ret == ERROR_FILE_NOT_FOUND)
934 /* return empty string if default value not found */
935 if (data) *data = 0;
936 if (count) *count = 1;
937 ret = ERROR_SUCCESS;
939 return ret;
943 /******************************************************************************
944 * VMM_RegEnumValueA
946 static DWORD VMM_RegEnumValueA( HKEY hkey, DWORD index, LPSTR value, LPDWORD val_count,
947 LPDWORD reserved, LPDWORD type, LPBYTE data, LPDWORD count )
949 NTSTATUS status;
950 DWORD total_size;
951 char buffer[256], *buf_ptr = buffer;
952 KEY_VALUE_FULL_INFORMATION *info = (KEY_VALUE_FULL_INFORMATION *)buffer;
953 static const int info_size = offsetof( KEY_VALUE_FULL_INFORMATION, Name );
955 TRACE("(%p,%ld,%p,%p,%p,%p,%p,%p)\n",
956 hkey, index, value, val_count, reserved, type, data, count );
958 /* NT only checks count, not val_count */
959 if ((data && !count) || reserved) return ERROR_INVALID_PARAMETER;
960 if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
962 total_size = info_size + (MAX_PATH + 1) * sizeof(WCHAR);
963 if (data) total_size += *count;
964 total_size = min( sizeof(buffer), total_size );
966 status = NtEnumerateValueKey( hkey, index, KeyValueFullInformation,
967 buffer, total_size, &total_size );
968 if (status && status != STATUS_BUFFER_OVERFLOW) goto done;
970 /* we need to fetch the contents for a string type even if not requested,
971 * because we need to compute the length of the ASCII string. */
972 if (value || data || is_string(info->Type))
974 /* retry with a dynamically allocated buffer */
975 while (status == STATUS_BUFFER_OVERFLOW)
977 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
978 if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
979 return ERROR_NOT_ENOUGH_MEMORY;
980 info = (KEY_VALUE_FULL_INFORMATION *)buf_ptr;
981 status = NtEnumerateValueKey( hkey, index, KeyValueFullInformation,
982 buf_ptr, total_size, &total_size );
985 if (status) goto done;
987 if (is_string(info->Type))
989 DWORD len;
990 RtlUnicodeToMultiByteSize( &len, (WCHAR *)(buf_ptr + info->DataOffset),
991 total_size - info->DataOffset );
992 if (data && len)
994 if (len > *count) status = STATUS_BUFFER_OVERFLOW;
995 else
997 RtlUnicodeToMultiByteN( data, len, NULL, (WCHAR *)(buf_ptr + info->DataOffset),
998 total_size - info->DataOffset );
999 /* if the type is REG_SZ and data is not 0-terminated
1000 * and there is enough space in the buffer NT appends a \0 */
1001 if (len < *count && data[len-1]) data[len] = 0;
1004 info->DataLength = len;
1006 else if (data)
1008 if (total_size - info->DataOffset > *count) status = STATUS_BUFFER_OVERFLOW;
1009 else memcpy( data, buf_ptr + info->DataOffset, total_size - info->DataOffset );
1012 if (value && !status)
1014 DWORD len;
1016 RtlUnicodeToMultiByteSize( &len, info->Name, info->NameLength );
1017 if (len >= *val_count)
1019 status = STATUS_BUFFER_OVERFLOW;
1020 if (*val_count)
1022 len = *val_count - 1;
1023 RtlUnicodeToMultiByteN( value, len, NULL, info->Name, info->NameLength );
1024 value[len] = 0;
1027 else
1029 RtlUnicodeToMultiByteN( value, len, NULL, info->Name, info->NameLength );
1030 value[len] = 0;
1031 *val_count = len;
1035 else status = STATUS_SUCCESS;
1037 if (type) *type = info->Type;
1038 if (count) *count = info->DataLength;
1040 done:
1041 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
1042 return RtlNtStatusToDosError(status);
1046 /******************************************************************************
1047 * VMM_RegEnumKeyA
1049 static DWORD VMM_RegEnumKeyA( HKEY hkey, DWORD index, LPSTR name, DWORD name_len )
1051 NTSTATUS status;
1052 char buffer[256], *buf_ptr = buffer;
1053 KEY_NODE_INFORMATION *info = (KEY_NODE_INFORMATION *)buffer;
1054 DWORD total_size;
1056 if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
1058 status = NtEnumerateKey( hkey, index, KeyNodeInformation,
1059 buffer, sizeof(buffer), &total_size );
1061 while (status == STATUS_BUFFER_OVERFLOW)
1063 /* retry with a dynamically allocated buffer */
1064 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
1065 if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
1066 return ERROR_NOT_ENOUGH_MEMORY;
1067 info = (KEY_NODE_INFORMATION *)buf_ptr;
1068 status = NtEnumerateKey( hkey, index, KeyNodeInformation,
1069 buf_ptr, total_size, &total_size );
1072 if (!status)
1074 DWORD len;
1076 RtlUnicodeToMultiByteSize( &len, info->Name, info->NameLength );
1077 if (len >= name_len) status = STATUS_BUFFER_OVERFLOW;
1078 else
1080 RtlUnicodeToMultiByteN( name, len, NULL, info->Name, info->NameLength );
1081 name[len] = 0;
1085 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
1086 return RtlNtStatusToDosError( status );
1090 /******************************************************************************
1091 * VMM_RegQueryInfoKeyA
1093 * NOTE: This VxDCall takes only a subset of the parameters that the
1094 * corresponding Win32 API call does. The implementation in Win95
1095 * ADVAPI32 sets all output parameters not mentioned here to zero.
1097 static DWORD VMM_RegQueryInfoKeyA( HKEY hkey, LPDWORD subkeys, LPDWORD max_subkey,
1098 LPDWORD values, LPDWORD max_value, LPDWORD max_data )
1100 NTSTATUS status;
1101 KEY_FULL_INFORMATION info;
1102 DWORD total_size;
1104 if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
1106 status = NtQueryKey( hkey, KeyFullInformation, &info, sizeof(info), &total_size );
1107 if (status && status != STATUS_BUFFER_OVERFLOW) return RtlNtStatusToDosError( status );
1109 if (subkeys) *subkeys = info.SubKeys;
1110 if (max_subkey) *max_subkey = info.MaxNameLen;
1111 if (values) *values = info.Values;
1112 if (max_value) *max_value = info.MaxValueNameLen;
1113 if (max_data) *max_data = info.MaxValueDataLen;
1114 return ERROR_SUCCESS;
1118 /***********************************************************************
1119 * VxDCall_VMM
1121 static DWORD VxDCall_VMM( DWORD service, CONTEXT86 *context )
1123 switch ( LOWORD(service) )
1125 case 0x0011: /* RegOpenKey */
1127 HKEY hkey = (HKEY) stack32_pop( context );
1128 LPCSTR lpszSubKey = (LPCSTR)stack32_pop( context );
1129 PHKEY retkey = (PHKEY)stack32_pop( context );
1130 return VMM_RegOpenKeyExA( hkey, lpszSubKey, 0, KEY_ALL_ACCESS, retkey );
1133 case 0x0012: /* RegCreateKey */
1135 HKEY hkey = (HKEY) stack32_pop( context );
1136 LPCSTR lpszSubKey = (LPCSTR)stack32_pop( context );
1137 PHKEY retkey = (PHKEY)stack32_pop( context );
1138 return VMM_RegCreateKeyA( hkey, lpszSubKey, retkey );
1141 case 0x0013: /* RegCloseKey */
1143 HKEY hkey = (HKEY)stack32_pop( context );
1144 return VMM_RegCloseKey( hkey );
1147 case 0x0014: /* RegDeleteKey */
1149 HKEY hkey = (HKEY) stack32_pop( context );
1150 LPCSTR lpszSubKey = (LPCSTR)stack32_pop( context );
1151 return VMM_RegDeleteKeyA( hkey, lpszSubKey );
1154 case 0x0015: /* RegSetValue */
1156 HKEY hkey = (HKEY) stack32_pop( context );
1157 LPCSTR lpszSubKey = (LPCSTR)stack32_pop( context );
1158 DWORD dwType = (DWORD) stack32_pop( context );
1159 LPCSTR lpszData = (LPCSTR)stack32_pop( context );
1160 DWORD cbData = (DWORD) stack32_pop( context );
1161 return VMM_RegSetValueA( hkey, lpszSubKey, dwType, lpszData, cbData );
1164 case 0x0016: /* RegDeleteValue */
1166 HKEY hkey = (HKEY) stack32_pop( context );
1167 LPSTR lpszValue = (LPSTR)stack32_pop( context );
1168 return VMM_RegDeleteValueA( hkey, lpszValue );
1171 case 0x0017: /* RegQueryValue */
1173 HKEY hkey = (HKEY) stack32_pop( context );
1174 LPSTR lpszSubKey = (LPSTR) stack32_pop( context );
1175 LPSTR lpszData = (LPSTR) stack32_pop( context );
1176 LPDWORD lpcbData = (LPDWORD)stack32_pop( context );
1177 return VMM_RegQueryValueA( hkey, lpszSubKey, lpszData, lpcbData );
1180 case 0x0018: /* RegEnumKey */
1182 HKEY hkey = (HKEY) stack32_pop( context );
1183 DWORD iSubkey = (DWORD)stack32_pop( context );
1184 LPSTR lpszName = (LPSTR)stack32_pop( context );
1185 DWORD lpcchName = (DWORD)stack32_pop( context );
1186 return VMM_RegEnumKeyA( hkey, iSubkey, lpszName, lpcchName );
1189 case 0x0019: /* RegEnumValue */
1191 HKEY hkey = (HKEY) stack32_pop( context );
1192 DWORD iValue = (DWORD) stack32_pop( context );
1193 LPSTR lpszValue = (LPSTR) stack32_pop( context );
1194 LPDWORD lpcchValue = (LPDWORD)stack32_pop( context );
1195 LPDWORD lpReserved = (LPDWORD)stack32_pop( context );
1196 LPDWORD lpdwType = (LPDWORD)stack32_pop( context );
1197 LPBYTE lpbData = (LPBYTE) stack32_pop( context );
1198 LPDWORD lpcbData = (LPDWORD)stack32_pop( context );
1199 return VMM_RegEnumValueA( hkey, iValue, lpszValue, lpcchValue,
1200 lpReserved, lpdwType, lpbData, lpcbData );
1203 case 0x001A: /* RegQueryValueEx */
1205 HKEY hkey = (HKEY) stack32_pop( context );
1206 LPSTR lpszValue = (LPSTR) stack32_pop( context );
1207 LPDWORD lpReserved = (LPDWORD)stack32_pop( context );
1208 LPDWORD lpdwType = (LPDWORD)stack32_pop( context );
1209 LPBYTE lpbData = (LPBYTE) stack32_pop( context );
1210 LPDWORD lpcbData = (LPDWORD)stack32_pop( context );
1211 return VMM_RegQueryValueExA( hkey, lpszValue, lpReserved,
1212 lpdwType, lpbData, lpcbData );
1215 case 0x001B: /* RegSetValueEx */
1217 HKEY hkey = (HKEY) stack32_pop( context );
1218 LPSTR lpszValue = (LPSTR) stack32_pop( context );
1219 DWORD dwReserved = (DWORD) stack32_pop( context );
1220 DWORD dwType = (DWORD) stack32_pop( context );
1221 LPBYTE lpbData = (LPBYTE)stack32_pop( context );
1222 DWORD cbData = (DWORD) stack32_pop( context );
1223 return VMM_RegSetValueExA( hkey, lpszValue, dwReserved,
1224 dwType, lpbData, cbData );
1227 case 0x001C: /* RegFlushKey */
1229 HKEY hkey = (HKEY)stack32_pop( context );
1230 FIXME( "RegFlushKey(%p): stub\n", hkey );
1231 return ERROR_SUCCESS;
1234 case 0x001D: /* RegQueryInfoKey */
1236 /* NOTE: This VxDCall takes only a subset of the parameters that the
1237 corresponding Win32 API call does. The implementation in Win95
1238 ADVAPI32 sets all output parameters not mentioned here to zero. */
1240 HKEY hkey = (HKEY) stack32_pop( context );
1241 LPDWORD lpcSubKeys = (LPDWORD)stack32_pop( context );
1242 LPDWORD lpcchMaxSubKey = (LPDWORD)stack32_pop( context );
1243 LPDWORD lpcValues = (LPDWORD)stack32_pop( context );
1244 LPDWORD lpcchMaxValueName = (LPDWORD)stack32_pop( context );
1245 LPDWORD lpcchMaxValueData = (LPDWORD)stack32_pop( context );
1246 return VMM_RegQueryInfoKeyA( hkey, lpcSubKeys, lpcchMaxSubKey,
1247 lpcValues, lpcchMaxValueName, lpcchMaxValueData );
1250 case 0x0021: /* RegLoadKey */
1252 HKEY hkey = (HKEY) stack32_pop( context );
1253 LPCSTR lpszSubKey = (LPCSTR)stack32_pop( context );
1254 LPCSTR lpszFile = (LPCSTR)stack32_pop( context );
1255 FIXME("RegLoadKey(%p,%s,%s): stub\n",hkey, debugstr_a(lpszSubKey), debugstr_a(lpszFile));
1256 return ERROR_SUCCESS;
1259 case 0x0022: /* RegUnLoadKey */
1261 HKEY hkey = (HKEY) stack32_pop( context );
1262 LPCSTR lpszSubKey = (LPCSTR)stack32_pop( context );
1263 FIXME("RegUnLoadKey(%p,%s): stub\n",hkey, debugstr_a(lpszSubKey));
1264 return ERROR_SUCCESS;
1267 case 0x0023: /* RegSaveKey */
1269 HKEY hkey = (HKEY) stack32_pop( context );
1270 LPCSTR lpszFile = (LPCSTR)stack32_pop( context );
1271 LPSECURITY_ATTRIBUTES sa = (LPSECURITY_ATTRIBUTES)stack32_pop( context );
1272 FIXME("RegSaveKey(%p,%s,%p): stub\n",hkey, debugstr_a(lpszFile),sa);
1273 return ERROR_SUCCESS;
1276 #if 0 /* Functions are not yet implemented in misc/registry.c */
1277 case 0x0024: /* RegRemapPreDefKey */
1278 case 0x0026: /* RegQueryMultipleValues */
1279 #endif
1281 case 0x0027: /* RegReplaceKey */
1283 HKEY hkey = (HKEY) stack32_pop( context );
1284 LPCSTR lpszSubKey = (LPCSTR)stack32_pop( context );
1285 LPCSTR lpszNewFile= (LPCSTR)stack32_pop( context );
1286 LPCSTR lpszOldFile= (LPCSTR)stack32_pop( context );
1287 FIXME("RegReplaceKey(%p,%s,%s,%s): stub\n", hkey, debugstr_a(lpszSubKey),
1288 debugstr_a(lpszNewFile),debugstr_a(lpszOldFile));
1289 return ERROR_SUCCESS;
1292 case 0x0000: /* PageReserve */
1294 LPVOID address;
1295 LPVOID ret;
1296 DWORD psize = getpagesize();
1297 ULONG page = (ULONG) stack32_pop( context );
1298 ULONG npages = (ULONG) stack32_pop( context );
1299 ULONG flags = (ULONG) stack32_pop( context );
1301 TRACE("PageReserve: page: %08lx, npages: %08lx, flags: %08lx partial stub!\n",
1302 page, npages, flags );
1304 if ( page == PR_SYSTEM ) {
1305 ERR("Can't reserve ring 1 memory\n");
1306 return -1;
1308 /* FIXME: This has to be handled separately for the separate
1309 address-spaces we now have */
1310 if ( page == PR_PRIVATE || page == PR_SHARED ) page = 0;
1311 /* FIXME: Handle flags in some way */
1312 address = (LPVOID )(page * psize);
1313 ret = VirtualAlloc ( address, ( npages * psize ), MEM_RESERVE, 0 );
1314 TRACE("PageReserve: returning: %08lx\n", (DWORD )ret );
1315 if ( ret == NULL )
1316 return -1;
1317 else
1318 return (DWORD )ret;
1321 case 0x0001: /* PageCommit */
1323 LPVOID address;
1324 LPVOID ret;
1325 DWORD virt_perm;
1326 DWORD psize = getpagesize();
1327 ULONG page = (ULONG) stack32_pop( context );
1328 ULONG npages = (ULONG) stack32_pop( context );
1329 ULONG hpd = (ULONG) stack32_pop( context );
1330 ULONG pagerdata = (ULONG) stack32_pop( context );
1331 ULONG flags = (ULONG) stack32_pop( context );
1333 TRACE("PageCommit: page: %08lx, npages: %08lx, hpd: %08lx pagerdata: "
1334 "%08lx, flags: %08lx partial stub\n",
1335 page, npages, hpd, pagerdata, flags );
1337 if ( flags & PC_USER )
1338 if ( flags & PC_WRITEABLE )
1339 virt_perm = PAGE_EXECUTE_READWRITE;
1340 else
1341 virt_perm = PAGE_EXECUTE_READ;
1342 else
1343 virt_perm = PAGE_NOACCESS;
1345 address = (LPVOID )(page * psize);
1346 ret = VirtualAlloc ( address, ( npages * psize ), MEM_COMMIT, virt_perm );
1347 TRACE("PageCommit: Returning: %08lx\n", (DWORD )ret );
1348 return (DWORD )ret;
1351 case 0x0002: /* PageDecommit */
1353 LPVOID address;
1354 BOOL ret;
1355 DWORD psize = getpagesize();
1356 ULONG page = (ULONG) stack32_pop( context );
1357 ULONG npages = (ULONG) stack32_pop( context );
1358 ULONG flags = (ULONG) stack32_pop( context );
1360 TRACE("PageDecommit: page: %08lx, npages: %08lx, flags: %08lx partial stub\n",
1361 page, npages, flags );
1362 address = (LPVOID )( page * psize );
1363 ret = VirtualFree ( address, ( npages * psize ), MEM_DECOMMIT );
1364 TRACE("PageDecommit: Returning: %s\n", ret ? "TRUE" : "FALSE" );
1365 return ret;
1367 case 0x000d: /* PageModifyPermissions */
1369 DWORD pg_old_perm;
1370 DWORD pg_new_perm;
1371 DWORD virt_old_perm;
1372 DWORD virt_new_perm;
1373 MEMORY_BASIC_INFORMATION mbi;
1374 LPVOID address;
1375 DWORD psize = getpagesize();
1376 ULONG page = stack32_pop ( context );
1377 ULONG npages = stack32_pop ( context );
1378 ULONG permand = stack32_pop ( context );
1379 ULONG permor = stack32_pop ( context );
1381 TRACE("PageModifyPermissions %08lx %08lx %08lx %08lx partial stub\n",
1382 page, npages, permand, permor );
1383 address = (LPVOID )( page * psize );
1385 VirtualQuery ( address, &mbi, sizeof ( MEMORY_BASIC_INFORMATION ));
1386 virt_old_perm = mbi.Protect;
1388 switch ( virt_old_perm & mbi.Protect ) {
1389 case PAGE_READONLY:
1390 case PAGE_EXECUTE:
1391 case PAGE_EXECUTE_READ:
1392 pg_old_perm = PC_USER;
1393 break;
1394 case PAGE_READWRITE:
1395 case PAGE_WRITECOPY:
1396 case PAGE_EXECUTE_READWRITE:
1397 case PAGE_EXECUTE_WRITECOPY:
1398 pg_old_perm = PC_USER | PC_WRITEABLE;
1399 break;
1400 case PAGE_NOACCESS:
1401 default:
1402 pg_old_perm = 0;
1403 break;
1405 pg_new_perm = pg_old_perm;
1406 pg_new_perm &= permand & ~PC_STATIC;
1407 pg_new_perm |= permor & ~PC_STATIC;
1409 virt_new_perm = ( virt_old_perm ) & ~0xff;
1410 if ( pg_new_perm & PC_USER )
1412 if ( pg_new_perm & PC_WRITEABLE )
1413 virt_new_perm |= PAGE_EXECUTE_READWRITE;
1414 else
1415 virt_new_perm |= PAGE_EXECUTE_READ;
1418 if ( ! VirtualProtect ( address, ( npages * psize ), virt_new_perm, &virt_old_perm ) ) {
1419 ERR("Can't change page permissions for %08lx\n", (DWORD )address );
1420 return 0xffffffff;
1422 TRACE("Returning: %08lx\n", pg_old_perm );
1423 return pg_old_perm;
1425 case 0x000a: /* PageFree */
1427 BOOL ret;
1428 LPVOID hmem = (LPVOID) stack32_pop( context );
1429 DWORD flags = (DWORD ) stack32_pop( context );
1431 TRACE("PageFree: hmem: %08lx, flags: %08lx partial stub\n",
1432 (DWORD )hmem, flags );
1434 ret = VirtualFree ( hmem, 0, MEM_RELEASE );
1435 context->Eax = ret;
1436 TRACE("Returning: %d\n", ret );
1438 return 0;
1440 case 0x001e: /* GetDemandPageInfo */
1442 DWORD dinfo = (DWORD)stack32_pop( context );
1443 DWORD flags = (DWORD)stack32_pop( context );
1445 /* GetDemandPageInfo is supposed to fill out the struct at
1446 * "dinfo" with various low-level memory management information.
1447 * Apps are certainly not supposed to call this, although it's
1448 * demoed and documented by Pietrek on pages 441-443 of "Windows
1449 * 95 System Programming Secrets" if any program needs a real
1450 * implementation of this.
1453 FIXME("GetDemandPageInfo(%08lx %08lx): stub!\n", dinfo, flags);
1455 return 0;
1457 default:
1458 if (LOWORD(service) < N_VMM_SERVICE)
1459 FIXME( "Unimplemented service %s (%08lx)\n",
1460 VMM_Service_Name[LOWORD(service)], service);
1461 else
1462 FIXME( "Unknown service %08lx\n", service);
1463 break;
1466 return 0xffffffff; /* FIXME */
1469 /***********************************************************************
1470 * DeviceIo_IFSMgr
1471 * NOTES
1472 * These ioctls are used by 'MSNET32.DLL'.
1474 * I have been unable to uncover any documentation about the ioctls so
1475 * the implementation of the cases IFS_IOCTL_21 and IFS_IOCTL_2F are
1476 * based on reasonable guesses on information found in the Windows 95 DDK.
1481 * IFSMgr DeviceIO service
1484 #define IFS_IOCTL_21 100
1485 #define IFS_IOCTL_2F 101
1486 #define IFS_IOCTL_GET_RES 102
1487 #define IFS_IOCTL_GET_NETPRO_NAME_A 103
1489 struct win32apireq {
1490 unsigned long ar_proid;
1491 unsigned long ar_eax;
1492 unsigned long ar_ebx;
1493 unsigned long ar_ecx;
1494 unsigned long ar_edx;
1495 unsigned long ar_esi;
1496 unsigned long ar_edi;
1497 unsigned long ar_ebp;
1498 unsigned short ar_error;
1499 unsigned short ar_pad;
1502 static void win32apieq_2_CONTEXT(struct win32apireq *pIn,CONTEXT86 *pCxt)
1504 memset(pCxt,0,sizeof(*pCxt));
1506 pCxt->ContextFlags=CONTEXT86_INTEGER|CONTEXT86_CONTROL;
1507 pCxt->Eax = pIn->ar_eax;
1508 pCxt->Ebx = pIn->ar_ebx;
1509 pCxt->Ecx = pIn->ar_ecx;
1510 pCxt->Edx = pIn->ar_edx;
1511 pCxt->Esi = pIn->ar_esi;
1512 pCxt->Edi = pIn->ar_edi;
1514 /* FIXME: Only partial CONTEXT86_CONTROL */
1515 pCxt->Ebp = pIn->ar_ebp;
1517 /* FIXME: pIn->ar_proid ignored */
1518 /* FIXME: pIn->ar_error ignored */
1519 /* FIXME: pIn->ar_pad ignored */
1522 static void CONTEXT_2_win32apieq(CONTEXT86 *pCxt,struct win32apireq *pOut)
1524 memset(pOut,0,sizeof(struct win32apireq));
1526 pOut->ar_eax = pCxt->Eax;
1527 pOut->ar_ebx = pCxt->Ebx;
1528 pOut->ar_ecx = pCxt->Ecx;
1529 pOut->ar_edx = pCxt->Edx;
1530 pOut->ar_esi = pCxt->Esi;
1531 pOut->ar_edi = pCxt->Edi;
1533 /* FIXME: Only partial CONTEXT86_CONTROL */
1534 pOut->ar_ebp = pCxt->Ebp;
1536 /* FIXME: pOut->ar_proid ignored */
1537 /* FIXME: pOut->ar_error ignored */
1538 /* FIXME: pOut->ar_pad ignored */
1541 static BOOL DeviceIo_IFSMgr(DWORD dwIoControlCode, LPVOID lpvInBuffer, DWORD cbInBuffer,
1542 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
1543 LPDWORD lpcbBytesReturned,
1544 LPOVERLAPPED lpOverlapped)
1546 BOOL retv = TRUE;
1547 TRACE("(%ld,%p,%ld,%p,%ld,%p,%p): stub\n",
1548 dwIoControlCode,
1549 lpvInBuffer,cbInBuffer,
1550 lpvOutBuffer,cbOutBuffer,
1551 lpcbBytesReturned,
1552 lpOverlapped);
1554 switch (dwIoControlCode)
1556 case IFS_IOCTL_21:
1557 case IFS_IOCTL_2F:{
1558 CONTEXT86 cxt;
1559 struct win32apireq *pIn=(struct win32apireq *) lpvInBuffer;
1560 struct win32apireq *pOut=(struct win32apireq *) lpvOutBuffer;
1562 TRACE(
1563 "Control '%s': "
1564 "proid=0x%08lx, eax=0x%08lx, ebx=0x%08lx, ecx=0x%08lx, "
1565 "edx=0x%08lx, esi=0x%08lx, edi=0x%08lx, ebp=0x%08lx, "
1566 "error=0x%04x, pad=0x%04x\n",
1567 (dwIoControlCode==IFS_IOCTL_21)?"IFS_IOCTL_21":"IFS_IOCTL_2F",
1568 pIn->ar_proid, pIn->ar_eax, pIn->ar_ebx, pIn->ar_ecx,
1569 pIn->ar_edx, pIn->ar_esi, pIn->ar_edi, pIn->ar_ebp,
1570 pIn->ar_error, pIn->ar_pad
1573 win32apieq_2_CONTEXT(pIn,&cxt);
1575 if(dwIoControlCode==IFS_IOCTL_21)
1577 if(Dosvm.CallBuiltinHandler || DPMI_LoadDosSystem())
1578 Dosvm.CallBuiltinHandler( &cxt, 0x21 );
1580 else
1582 if(Dosvm.CallBuiltinHandler || DPMI_LoadDosSystem())
1583 Dosvm.CallBuiltinHandler( &cxt, 0x2f );
1586 CONTEXT_2_win32apieq(&cxt,pOut);
1588 retv = TRUE;
1589 } break;
1590 case IFS_IOCTL_GET_RES:{
1591 FIXME( "Control 'IFS_IOCTL_GET_RES' not implemented\n");
1592 retv = FALSE;
1593 } break;
1594 case IFS_IOCTL_GET_NETPRO_NAME_A:{
1595 FIXME( "Control 'IFS_IOCTL_GET_NETPRO_NAME_A' not implemented\n");
1596 retv = FALSE;
1597 } break;
1598 default:
1599 FIXME( "Control %ld not implemented\n", dwIoControlCode);
1600 retv = FALSE;
1603 return retv;
1606 /********************************************************************************
1607 * VxDCall_VWin32
1609 * Service numbers taken from page 448 of Pietrek's "Windows 95 System
1610 * Programming Secrets". Parameters from experimentation on real Win98.
1614 static DWORD VxDCall_VWin32( DWORD service, CONTEXT86 *context )
1616 switch ( LOWORD(service) )
1618 case 0x0000: /* GetVersion */
1620 DWORD vers = GetVersion();
1621 return (LOBYTE(vers) << 8) | HIBYTE(vers);
1623 break;
1625 case 0x0020: /* Get VMCPD Version */
1627 DWORD parm = (DWORD) stack32_pop(context);
1629 FIXME("Get VMCPD Version(%08lx): partial stub!\n", parm);
1631 /* FIXME: This is what Win98 returns, it may
1632 * not be correct in all situations.
1633 * It makes Bleem! happy though.
1636 return 0x0405;
1639 case 0x0029: /* Int31/DPMI dispatch */
1641 DWORD callnum = (DWORD) stack32_pop(context);
1642 DWORD parm = (DWORD) stack32_pop(context);
1644 TRACE("Int31/DPMI dispatch(%08lx)\n", callnum);
1646 SET_AX( context, callnum );
1647 SET_CX( context, parm );
1648 if(Dosvm.CallBuiltinHandler || DPMI_LoadDosSystem())
1649 Dosvm.CallBuiltinHandler( context, 0x31 );
1651 return LOWORD(context->Eax);
1653 break;
1655 case 0x002a: /* Int41 dispatch - parm = int41 service number */
1657 DWORD callnum = (DWORD) stack32_pop(context);
1659 return callnum; /* FIXME: should really call INT_Int41Handler() */
1661 break;
1663 default:
1664 FIXME("Unknown VWin32 service %08lx\n", service);
1665 break;
1668 return 0xffffffff;
1672 /***********************************************************************
1673 * DeviceIo_VCD
1675 static BOOL DeviceIo_VCD(DWORD dwIoControlCode,
1676 LPVOID lpvInBuffer, DWORD cbInBuffer,
1677 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
1678 LPDWORD lpcbBytesReturned,
1679 LPOVERLAPPED lpOverlapped)
1681 BOOL retv = TRUE;
1683 switch (dwIoControlCode)
1685 case IOCTL_SERIAL_LSRMST_INSERT:
1687 FIXME( "IOCTL_SERIAL_LSRMST_INSERT NIY !\n");
1688 retv = FALSE;
1690 break;
1692 default:
1693 FIXME( "Unknown Control %ld\n", dwIoControlCode);
1694 retv = FALSE;
1695 break;
1698 return retv;
1702 /***********************************************************************
1703 * DeviceIo_VWin32
1706 static void DIOCRegs_2_CONTEXT( DIOC_REGISTERS *pIn, CONTEXT86 *pCxt )
1708 memset( pCxt, 0, sizeof(*pCxt) );
1709 /* Note: segment registers == 0 means that CTX_SEG_OFF_TO_LIN
1710 will interpret 32-bit register contents as linear pointers */
1712 pCxt->ContextFlags=CONTEXT86_INTEGER|CONTEXT86_CONTROL;
1713 pCxt->Eax = pIn->reg_EAX;
1714 pCxt->Ebx = pIn->reg_EBX;
1715 pCxt->Ecx = pIn->reg_ECX;
1716 pCxt->Edx = pIn->reg_EDX;
1717 pCxt->Esi = pIn->reg_ESI;
1718 pCxt->Edi = pIn->reg_EDI;
1720 /* FIXME: Only partial CONTEXT86_CONTROL */
1721 pCxt->EFlags = pIn->reg_Flags;
1724 static void CONTEXT_2_DIOCRegs( CONTEXT86 *pCxt, DIOC_REGISTERS *pOut )
1726 memset( pOut, 0, sizeof(DIOC_REGISTERS) );
1728 pOut->reg_EAX = pCxt->Eax;
1729 pOut->reg_EBX = pCxt->Ebx;
1730 pOut->reg_ECX = pCxt->Ecx;
1731 pOut->reg_EDX = pCxt->Edx;
1732 pOut->reg_ESI = pCxt->Esi;
1733 pOut->reg_EDI = pCxt->Edi;
1735 /* FIXME: Only partial CONTEXT86_CONTROL */
1736 pOut->reg_Flags = pCxt->EFlags;
1739 #define DIOC_AH(regs) (((unsigned char*)&((regs)->reg_EAX))[1])
1740 #define DIOC_AL(regs) (((unsigned char*)&((regs)->reg_EAX))[0])
1741 #define DIOC_BH(regs) (((unsigned char*)&((regs)->reg_EBX))[1])
1742 #define DIOC_BL(regs) (((unsigned char*)&((regs)->reg_EBX))[0])
1743 #define DIOC_DH(regs) (((unsigned char*)&((regs)->reg_EDX))[1])
1744 #define DIOC_DL(regs) (((unsigned char*)&((regs)->reg_EDX))[0])
1746 #define DIOC_AX(regs) (((unsigned short*)&((regs)->reg_EAX))[0])
1747 #define DIOC_BX(regs) (((unsigned short*)&((regs)->reg_EBX))[0])
1748 #define DIOC_CX(regs) (((unsigned short*)&((regs)->reg_ECX))[0])
1749 #define DIOC_DX(regs) (((unsigned short*)&((regs)->reg_EDX))[0])
1751 #define DIOC_SET_CARRY(regs) (((regs)->reg_Flags)|=0x00000001)
1753 static const DWORD VWIN32_DriveTypeInfo[7]={
1754 0x0000, /* none */
1755 0x2709, /* 360 K */
1756 0x4f0f, /* 1.2 M */
1757 0x4f09, /* 720 K */
1758 0x4f12, /* 1.44 M */
1759 0x4f24, /* 2.88 M */
1760 0x4f24 /* 2.88 M */
1763 /**********************************************************************
1764 * VWIN32_ReadFloppyParams
1766 * Handler for int 13h (disk I/O).
1768 static VOID VWIN32_ReadFloppyParams(DIOC_REGISTERS *regs)
1770 #ifdef linux
1771 static BYTE floppy_params[2][13] =
1773 { 0xaf, 0x02, 0x25, 0x02, 0x12, 0x1b, 0xff, 0x6c, 0xf6, 0x0f, 0x08 },
1774 { 0xaf, 0x02, 0x25, 0x02, 0x12, 0x1b, 0xff, 0x6c, 0xf6, 0x0f, 0x08 }
1777 unsigned int i, nr_of_drives = 0;
1778 BYTE drive_nr = DIOC_DL(regs);
1779 int floppy_fd,r;
1780 struct floppy_drive_params floppy_parm;
1781 char root[] = "A:\\";
1783 TRACE("in [ EDX=%08lx ]\n", regs->reg_EDX );
1785 DIOC_AH(regs) = 0x00; /* success */
1787 for (i = 0; i < MAX_DOS_DRIVES; i++, root[0]++)
1788 if (GetDriveTypeA(root) == DRIVE_REMOVABLE) nr_of_drives++;
1789 DIOC_DL(regs) = nr_of_drives;
1791 if (drive_nr > 1) { /* invalid drive ? */
1792 DIOC_BX(regs) = 0;
1793 DIOC_CX(regs) = 0;
1794 DIOC_DH(regs) = 0;
1795 DIOC_SET_CARRY(regs);
1796 return;
1799 if ( (floppy_fd = DRIVE_OpenDevice( drive_nr, O_NONBLOCK)) == -1)
1801 WARN("Can't determine floppy geometry !\n");
1802 DIOC_BX(regs) = 0;
1803 DIOC_CX(regs) = 0;
1804 DIOC_DH(regs) = 0;
1805 DIOC_SET_CARRY(regs);
1806 return;
1808 r = ioctl(floppy_fd, FDGETDRVPRM, &floppy_parm);
1810 close(floppy_fd);
1812 if(r<0)
1814 DIOC_SET_CARRY(regs);
1815 return;
1818 regs->reg_ECX = 0;
1819 DIOC_AL(regs) = 0;
1820 DIOC_BL(regs) = floppy_parm.cmos;
1822 /* CH = low eight bits of max cyl
1823 CL = max sec nr (bits 5-0),
1824 hi two bits of max cyl (bits 7-6)
1825 DH = max head nr */
1826 if(DIOC_BL(regs) && (DIOC_BL(regs)<7))
1828 DIOC_DH(regs) = 0x01;
1829 DIOC_CX(regs) = VWIN32_DriveTypeInfo[DIOC_BL(regs)];
1831 else
1833 DIOC_CX(regs) = 0x0;
1834 DIOC_DX(regs) = 0x0;
1837 regs->reg_EDI = (DWORD)floppy_params[drive_nr];
1839 if(!regs->reg_EDI)
1841 ERR("Get floppy params failed for drive %d\n",drive_nr);
1842 DIOC_SET_CARRY(regs);
1845 TRACE("out [ EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx EDI=%08lx ]\n",
1846 regs->reg_EAX, regs->reg_EBX, regs->reg_ECX, regs->reg_EDX, regs->reg_EDI);
1848 /* FIXME: Word exits quietly if we return with no error. Why? */
1849 FIXME("Returned ERROR!\n");
1850 DIOC_SET_CARRY(regs);
1852 #else
1853 DIOC_AH(regs) = 0x01;
1854 DIOC_SET_CARRY(regs);
1855 #endif
1858 /**********************************************************************
1859 * VWIN32_Int13Handler
1861 * Handler for VWIN32_DIOC_DOS_INT13 (disk I/O).
1863 static VOID VWIN32_Int13Handler( DIOC_REGISTERS *regs)
1865 TRACE("AH=%02x\n",DIOC_AH(regs));
1866 switch(DIOC_AH(regs)) /* AH */
1868 case 0x00: /* RESET DISK SYSTEM */
1869 break; /* no return ? */
1871 case 0x01: /* STATUS OF DISK SYSTEM */
1872 DIOC_AL(regs) = 0; /* successful completion */
1873 break;
1875 case 0x02: /* READ SECTORS INTO MEMORY */
1876 DIOC_AL(regs) = 0; /* number of sectors read */
1877 DIOC_AH(regs) = 0; /* status */
1878 break;
1880 case 0x03: /* WRITE SECTORS FROM MEMORY */
1881 break; /* no return ? */
1883 case 0x04: /* VERIFY DISK SECTOR(S) */
1884 DIOC_AL(regs) = 0; /* number of sectors verified */
1885 DIOC_AH(regs) = 0;
1886 break;
1888 case 0x05: /* FORMAT TRACK */
1889 case 0x06: /* FORMAT TRACK AND SET BAD SECTOR FLAGS */
1890 case 0x07: /* FORMAT DRIVE STARTING AT GIVEN TRACK */
1891 /* despite what Ralf Brown says, 0x06 and 0x07 seem to
1892 * set CFLAG, too (at least my BIOS does that) */
1893 DIOC_AH(regs) = 0x0c;
1894 DIOC_SET_CARRY(regs);
1895 break;
1897 case 0x08: /* GET DRIVE PARAMETERS */
1898 if (DIOC_DL(regs) & 0x80) { /* hard disk ? */
1899 DIOC_AH(regs) = 0x07;
1900 DIOC_SET_CARRY(regs);
1902 else /* floppy disk */
1903 VWIN32_ReadFloppyParams(regs);
1904 break;
1906 case 0x09: /* INITIALIZE CONTROLLER WITH DRIVE PARAMETERS */
1907 case 0x0a: /* FIXED DISK - READ LONG (XT,AT,XT286,PS) */
1908 case 0x0b: /* FIXED DISK - WRITE LONG (XT,AT,XT286,PS) */
1909 case 0x0c: /* SEEK TO CYLINDER */
1910 case 0x0d: /* ALTERNATE RESET HARD DISKS */
1911 case 0x10: /* CHECK IF DRIVE READY */
1912 case 0x11: /* RECALIBRATE DRIVE */
1913 case 0x14: /* CONTROLLER INTERNAL DIAGNOSTIC */
1914 DIOC_AH(regs) = 0;
1915 break;
1917 case 0x15: /* GET DISK TYPE (AT,XT2,XT286,CONV,PS) */
1918 if (DIOC_DL(regs) & 0x80) { /* hard disk ? */
1919 DIOC_AH(regs) = 3; /* fixed disk */
1920 DIOC_SET_CARRY(regs);
1922 else { /* floppy disk ? */
1923 DIOC_AH(regs) = 2; /* floppy with change detection */
1924 DIOC_SET_CARRY(regs);
1926 break;
1928 case 0x0e: /* READ SECTOR BUFFER (XT only) */
1929 case 0x0f: /* WRITE SECTOR BUFFER (XT only) */
1930 case 0x12: /* CONTROLLER RAM DIAGNOSTIC (XT,PS) */
1931 case 0x13: /* DRIVE DIAGNOSTIC (XT,PS) */
1932 DIOC_AH(regs) = 0x01;
1933 DIOC_SET_CARRY(regs);
1934 break;
1936 case 0x16: /* FLOPPY - CHANGE OF DISK STATUS */
1937 DIOC_AH(regs) = 0; /* FIXME - no change */
1938 break;
1940 case 0x17: /* SET DISK TYPE FOR FORMAT */
1941 if (DIOC_DL(regs) < 4)
1942 DIOC_AH(regs) = 0x00; /* successful completion */
1943 else
1944 DIOC_AH(regs) = 0x01; /* error */
1945 break;
1947 case 0x18: /* SET MEDIA TYPE FOR FORMAT */
1948 if (DIOC_DL(regs) < 4)
1949 DIOC_AH(regs) = 0x00; /* successful completion */
1950 else
1951 DIOC_AH(regs) = 0x01; /* error */
1952 break;
1954 case 0x19: /* FIXED DISK - PARK HEADS */
1955 break;
1957 default:
1958 FIXME("Unknown VWIN32 INT13 call AX=%04X\n",DIOC_AX(regs));
1962 static BOOL DeviceIo_VWin32(DWORD dwIoControlCode,
1963 LPVOID lpvInBuffer, DWORD cbInBuffer,
1964 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
1965 LPDWORD lpcbBytesReturned,
1966 LPOVERLAPPED lpOverlapped)
1968 BOOL retv = TRUE;
1970 switch (dwIoControlCode)
1972 case VWIN32_DIOC_DOS_INT13:
1974 DIOC_REGISTERS *pIn = (DIOC_REGISTERS *)lpvInBuffer;
1975 DIOC_REGISTERS *pOut = (DIOC_REGISTERS *)lpvOutBuffer;
1977 memcpy(pOut, pIn, sizeof (DIOC_REGISTERS));
1978 VWIN32_Int13Handler(pOut);
1979 break;
1982 case VWIN32_DIOC_DOS_IOCTL:
1983 case 0x10: /* Int 0x21 call, call it VWIN_DIOC_INT21 ? */
1984 case VWIN32_DIOC_DOS_INT25:
1985 case VWIN32_DIOC_DOS_INT26:
1986 case 0x29: /* Int 0x31 call, call it VWIN_DIOC_INT31 ? */
1987 case VWIN32_DIOC_DOS_DRIVEINFO:
1989 CONTEXT86 cxt;
1990 DIOC_REGISTERS *pIn = (DIOC_REGISTERS *)lpvInBuffer;
1991 DIOC_REGISTERS *pOut = (DIOC_REGISTERS *)lpvOutBuffer;
1992 BYTE intnum = 0;
1994 TRACE( "Control '%s': "
1995 "eax=0x%08lx, ebx=0x%08lx, ecx=0x%08lx, "
1996 "edx=0x%08lx, esi=0x%08lx, edi=0x%08lx \n",
1997 (dwIoControlCode == VWIN32_DIOC_DOS_IOCTL)? "VWIN32_DIOC_DOS_IOCTL" :
1998 (dwIoControlCode == VWIN32_DIOC_DOS_INT25)? "VWIN32_DIOC_DOS_INT25" :
1999 (dwIoControlCode == VWIN32_DIOC_DOS_INT26)? "VWIN32_DIOC_DOS_INT26" :
2000 (dwIoControlCode == VWIN32_DIOC_DOS_DRIVEINFO)? "VWIN32_DIOC_DOS_DRIVEINFO" : "???",
2001 pIn->reg_EAX, pIn->reg_EBX, pIn->reg_ECX,
2002 pIn->reg_EDX, pIn->reg_ESI, pIn->reg_EDI );
2004 DIOCRegs_2_CONTEXT( pIn, &cxt );
2006 switch (dwIoControlCode)
2008 case VWIN32_DIOC_DOS_IOCTL: /* Call int 21h */
2009 case 0x10: /* Int 0x21 call, call it VWIN_DIOC_INT21 ? */
2010 case VWIN32_DIOC_DOS_DRIVEINFO: /* Call int 21h 730x */
2011 intnum = 0x21;
2012 break;
2013 case VWIN32_DIOC_DOS_INT25:
2014 intnum = 0x25;
2015 break;
2016 case VWIN32_DIOC_DOS_INT26:
2017 intnum = 0x26;
2018 break;
2019 case 0x29: /* Int 0x31 call, call it VWIN_DIOC_INT31 ? */
2020 intnum = 0x31;
2021 break;
2024 if(Dosvm.CallBuiltinHandler || DPMI_LoadDosSystem())
2025 Dosvm.CallBuiltinHandler( &cxt, intnum );
2027 CONTEXT_2_DIOCRegs( &cxt, pOut );
2029 break;
2031 case VWIN32_DIOC_SIMCTRLC:
2032 FIXME( "Control VWIN32_DIOC_SIMCTRLC not implemented\n");
2033 retv = FALSE;
2034 break;
2036 default:
2037 FIXME( "Unknown Control %ld\n", dwIoControlCode);
2038 retv = FALSE;
2039 break;
2042 return retv;
2045 /* this is the main multimedia device loader */
2046 static BOOL DeviceIo_MMDEVLDR(DWORD dwIoControlCode,
2047 LPVOID lpvInBuffer, DWORD cbInBuffer,
2048 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
2049 LPDWORD lpcbBytesReturned,
2050 LPOVERLAPPED lpOverlapped)
2052 FIXME("(%ld,%p,%ld,%p,%ld,%p,%p): stub\n",
2053 dwIoControlCode,
2054 lpvInBuffer,cbInBuffer,
2055 lpvOutBuffer,cbOutBuffer,
2056 lpcbBytesReturned,
2057 lpOverlapped
2059 switch (dwIoControlCode) {
2060 case 5:
2061 /* Hmm. */
2062 *(DWORD*)lpvOutBuffer=0;
2063 *lpcbBytesReturned=4;
2064 return TRUE;
2066 return FALSE;
2068 /* this is used by some Origin games */
2069 static BOOL DeviceIo_MONODEBG(DWORD dwIoControlCode,
2070 LPVOID lpvInBuffer, DWORD cbInBuffer,
2071 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
2072 LPDWORD lpcbBytesReturned,
2073 LPOVERLAPPED lpOverlapped)
2075 switch (dwIoControlCode) {
2076 case 1: /* version */
2077 *(LPDWORD)lpvOutBuffer = 0x20004; /* WC SecretOps */
2078 break;
2079 case 9: /* debug output */
2080 ERR("MONODEBG: %s\n",debugstr_a(lpvInBuffer));
2081 break;
2082 default:
2083 FIXME("(%ld,%p,%ld,%p,%ld,%p,%p): stub\n",
2084 dwIoControlCode,
2085 lpvInBuffer,cbInBuffer,
2086 lpvOutBuffer,cbOutBuffer,
2087 lpcbBytesReturned,
2088 lpOverlapped
2090 break;
2092 return TRUE;
2094 /* pccard */
2095 static BOOL DeviceIo_PCCARD (DWORD dwIoControlCode,
2096 LPVOID lpvInBuffer, DWORD cbInBuffer,
2097 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
2098 LPDWORD lpcbBytesReturned,
2099 LPOVERLAPPED lpOverlapped)
2101 switch (dwIoControlCode) {
2102 case 0x0000: /* PCCARD_Get_Version */
2103 case 0x0001: /* PCCARD_Card_Services */
2104 default:
2105 FIXME( "(%ld,%p,%ld,%p,%ld,%p,%p): stub\n",
2106 dwIoControlCode,
2107 lpvInBuffer,cbInBuffer,
2108 lpvOutBuffer,cbOutBuffer,
2109 lpcbBytesReturned,
2110 lpOverlapped
2112 break;
2114 return FALSE;
2117 /***********************************************************************
2118 * OpenVxDHandle (KERNEL32.@)
2120 * This function is supposed to return the corresponding Ring 0
2121 * ("kernel") handle for a Ring 3 handle in Win9x.
2122 * Evidently, Wine will have problems with this. But we try anyway,
2123 * maybe it helps...
2125 HANDLE WINAPI OpenVxDHandle(HANDLE hHandleRing3)
2127 FIXME( "(0x%p), stub! (returning Ring 3 handle instead of Ring 0)\n", hHandleRing3);
2128 return hHandleRing3;
2131 static BOOL DeviceIo_HASP(DWORD dwIoControlCode, LPVOID lpvInBuffer, DWORD cbInBuffer,
2132 LPVOID lpvOutBuffer, DWORD cbOutBuffer,
2133 LPDWORD lpcbBytesReturned,
2134 LPOVERLAPPED lpOverlapped)
2136 BOOL retv = TRUE;
2137 FIXME("(%ld,%p,%ld,%p,%ld,%p,%p): stub\n",
2138 dwIoControlCode,
2139 lpvInBuffer,cbInBuffer,
2140 lpvOutBuffer,cbOutBuffer,
2141 lpcbBytesReturned,
2142 lpOverlapped);
2144 return retv;