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>
42 #include "kernel_private.h"
43 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(vxd);
48 * VMM VxDCall service names are (mostly) taken from Stan Mitchell's
49 * "Inside the Windows 95 File System"
52 #define N_VMM_SERVICE 41
54 static const char * const VMM_Service_Name[N_VMM_SERVICE] =
56 "PageReserve", /* 0x0000 */
57 "PageCommit", /* 0x0001 */
58 "PageDecommit", /* 0x0002 */
59 "PagerRegister", /* 0x0003 */
60 "PagerQuery", /* 0x0004 */
61 "HeapAllocate", /* 0x0005 */
62 "ContextCreate", /* 0x0006 */
63 "ContextDestroy", /* 0x0007 */
64 "PageAttach", /* 0x0008 */
65 "PageFlush", /* 0x0009 */
66 "PageFree", /* 0x000A */
67 "ContextSwitch", /* 0x000B */
68 "HeapReAllocate", /* 0x000C */
69 "PageModifyPermissions", /* 0x000D */
70 "PageQuery", /* 0x000E */
71 "GetCurrentContext", /* 0x000F */
72 "HeapFree", /* 0x0010 */
73 "RegOpenKey", /* 0x0011 */
74 "RegCreateKey", /* 0x0012 */
75 "RegCloseKey", /* 0x0013 */
76 "RegDeleteKey", /* 0x0014 */
77 "RegSetValue", /* 0x0015 */
78 "RegDeleteValue", /* 0x0016 */
79 "RegQueryValue", /* 0x0017 */
80 "RegEnumKey", /* 0x0018 */
81 "RegEnumValue", /* 0x0019 */
82 "RegQueryValueEx", /* 0x001A */
83 "RegSetValueEx", /* 0x001B */
84 "RegFlushKey", /* 0x001C */
85 "RegQueryInfoKey", /* 0x001D */
86 "GetDemandPageInfo", /* 0x001E */
87 "BlockOnID", /* 0x001F */
88 "SignalID", /* 0x0020 */
89 "RegLoadKey", /* 0x0021 */
90 "RegUnLoadKey", /* 0x0022 */
91 "RegSaveKey", /* 0x0023 */
92 "RegRemapPreDefKey", /* 0x0024 */
93 "PageChangePager", /* 0x0025 */
94 "RegQueryMultipleValues", /* 0x0026 */
95 "RegReplaceKey", /* 0x0027 */
96 "<KERNEL32.101>" /* 0x0028 -- What does this do??? */
99 /* PageReserve arena values */
100 #define PR_PRIVATE 0x80000400 /* anywhere in private arena */
101 #define PR_SHARED 0x80060000 /* anywhere in shared arena */
102 #define PR_SYSTEM 0x80080000 /* anywhere in system arena */
104 /* PageReserve flags */
105 #define PR_FIXED 0x00000008 /* don't move during PageReAllocate */
106 #define PR_4MEG 0x00000001 /* allocate on 4mb boundary */
107 #define PR_STATIC 0x00000010 /* see PageReserve documentation */
109 /* PageCommit default pager handle values */
110 #define PD_ZEROINIT 0x00000001 /* swappable zero-initialized pages */
111 #define PD_NOINIT 0x00000002 /* swappable uninitialized pages */
112 #define PD_FIXEDZERO 0x00000003 /* fixed zero-initialized pages */
113 #define PD_FIXED 0x00000004 /* fixed uninitialized pages */
115 /* PageCommit flags */
116 #define PC_FIXED 0x00000008 /* pages are permanently locked */
117 #define PC_LOCKED 0x00000080 /* pages are made present and locked */
118 #define PC_LOCKEDIFDP 0x00000100 /* pages are locked if swap via DOS */
119 #define PC_WRITEABLE 0x00020000 /* make the pages writeable */
120 #define PC_USER 0x00040000 /* make the pages ring 3 accessible */
121 #define PC_INCR 0x40000000 /* increment "pagerdata" each page */
122 #define PC_PRESENT 0x80000000 /* make pages initially present */
123 #define PC_STATIC 0x20000000 /* allow commit in PR_STATIC object */
124 #define PC_DIRTY 0x08000000 /* make pages initially dirty */
125 #define PC_CACHEDIS 0x00100000 /* Allocate uncached pages - new for WDM */
126 #define PC_CACHEWT 0x00080000 /* Allocate write through cache pages - new for WDM */
127 #define PC_PAGEFLUSH 0x00008000 /* Touch device mapped pages on alloc - new for WDM */
129 /* PageCommitContig additional flags */
130 #define PCC_ZEROINIT 0x00000001 /* zero-initialize new pages */
131 #define PCC_NOLIN 0x10000000 /* don't map to any linear address */
134 /* Pop a DWORD from the 32-bit stack */
135 static inline DWORD stack32_pop( CONTEXT86 *context )
137 DWORD ret = *(DWORD *)context->Esp;
138 context->Esp += sizeof(DWORD);
143 /******************************************************************************
144 * The following is a massive duplication of the advapi32 code.
145 * Unfortunately sharing the code is not possible since the native
146 * Win95 advapi32 depends on it. Someday we should probably stop
147 * supporting native Win95 advapi32 altogether...
151 #define HKEY_SPECIAL_ROOT_FIRST HKEY_CLASSES_ROOT
152 #define HKEY_SPECIAL_ROOT_LAST HKEY_DYN_DATA
153 #define NB_SPECIAL_ROOT_KEYS ((UINT)HKEY_SPECIAL_ROOT_LAST - (UINT)HKEY_SPECIAL_ROOT_FIRST + 1)
155 static HKEY special_root_keys[NB_SPECIAL_ROOT_KEYS];
157 static const WCHAR name_CLASSES_ROOT[] =
158 {'M','a','c','h','i','n','e','\\',
159 'S','o','f','t','w','a','r','e','\\',
160 'C','l','a','s','s','e','s',0};
161 static const WCHAR name_LOCAL_MACHINE[] =
162 {'M','a','c','h','i','n','e',0};
163 static const WCHAR name_USERS[] =
165 static const WCHAR name_PERFORMANCE_DATA[] =
166 {'P','e','r','f','D','a','t','a',0};
167 static const WCHAR name_CURRENT_CONFIG[] =
168 {'M','a','c','h','i','n','e','\\',
169 'S','y','s','t','e','m','\\',
170 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
171 'H','a','r','d','w','a','r','e','P','r','o','f','i','l','e','s','\\',
172 'C','u','r','r','e','n','t',0};
173 static const WCHAR name_DYN_DATA[] =
174 {'D','y','n','D','a','t','a',0};
176 #define DECL_STR(key) { sizeof(name_##key)-sizeof(WCHAR), sizeof(name_##key), (LPWSTR)name_##key }
177 static UNICODE_STRING root_key_names[NB_SPECIAL_ROOT_KEYS] =
179 DECL_STR(CLASSES_ROOT),
180 { 0, 0, NULL }, /* HKEY_CURRENT_USER is determined dynamically */
181 DECL_STR(LOCAL_MACHINE),
183 DECL_STR(PERFORMANCE_DATA),
184 DECL_STR(CURRENT_CONFIG),
190 /* check if value type needs string conversion (Ansi<->Unicode) */
191 inline static int is_string( DWORD type )
193 return (type == REG_SZ) || (type == REG_EXPAND_SZ) || (type == REG_MULTI_SZ);
196 /* create one of the HKEY_* special root keys */
197 static HKEY create_special_root_hkey( HKEY hkey, DWORD access )
200 int idx = (UINT)hkey - (UINT)HKEY_SPECIAL_ROOT_FIRST;
202 if (hkey == HKEY_CURRENT_USER)
204 if (RtlOpenCurrentUser( access, &hkey )) return 0;
208 OBJECT_ATTRIBUTES attr;
210 attr.Length = sizeof(attr);
211 attr.RootDirectory = 0;
212 attr.ObjectName = &root_key_names[idx];
214 attr.SecurityDescriptor = NULL;
215 attr.SecurityQualityOfService = NULL;
216 if (NtCreateKey( &hkey, access, &attr, 0, NULL, 0, NULL )) return 0;
219 if (!(ret = InterlockedCompareExchangePointer( (PVOID) &special_root_keys[idx], hkey, 0 )))
222 NtClose( hkey ); /* somebody beat us to it */
226 /* map the hkey from special root to normal key if necessary */
227 inline static HKEY get_special_root_hkey( HKEY hkey )
231 if ((hkey >= HKEY_SPECIAL_ROOT_FIRST) && (hkey <= HKEY_SPECIAL_ROOT_LAST))
233 if (!(ret = special_root_keys[(UINT)hkey - (UINT)HKEY_SPECIAL_ROOT_FIRST]))
234 ret = create_special_root_hkey( hkey, KEY_ALL_ACCESS );
240 /******************************************************************************
243 static DWORD VMM_RegCreateKeyA( HKEY hkey, LPCSTR name, PHKEY retkey )
245 OBJECT_ATTRIBUTES attr;
246 UNICODE_STRING nameW;
250 if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
252 attr.Length = sizeof(attr);
253 attr.RootDirectory = hkey;
254 attr.ObjectName = &nameW;
256 attr.SecurityDescriptor = NULL;
257 attr.SecurityQualityOfService = NULL;
258 RtlInitAnsiString( &nameA, name );
260 if (!(status = RtlAnsiStringToUnicodeString( &nameW, &nameA, TRUE )))
262 status = NtCreateKey( retkey, KEY_ALL_ACCESS, &attr, 0, NULL,
263 REG_OPTION_NON_VOLATILE, NULL );
264 RtlFreeUnicodeString( &nameW );
266 return RtlNtStatusToDosError( status );
270 /******************************************************************************
273 DWORD WINAPI VMM_RegOpenKeyExA(HKEY hkey, LPCSTR name, DWORD reserved, REGSAM access, PHKEY retkey)
275 OBJECT_ATTRIBUTES attr;
276 UNICODE_STRING nameW;
280 if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
282 attr.Length = sizeof(attr);
283 attr.RootDirectory = hkey;
284 attr.ObjectName = &nameW;
286 attr.SecurityDescriptor = NULL;
287 attr.SecurityQualityOfService = NULL;
289 RtlInitAnsiString( &nameA, name );
290 if (!(status = RtlAnsiStringToUnicodeString( &nameW, &nameA, TRUE )))
292 status = NtOpenKey( retkey, access, &attr );
293 RtlFreeUnicodeString( &nameW );
295 return RtlNtStatusToDosError( status );
299 /******************************************************************************
302 static DWORD VMM_RegCloseKey( HKEY hkey )
304 if (!hkey || hkey >= (HKEY)0x80000000) return ERROR_SUCCESS;
305 return RtlNtStatusToDosError( NtClose( hkey ) );
309 /******************************************************************************
312 static DWORD VMM_RegDeleteKeyA( HKEY hkey, LPCSTR name )
317 if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
319 if (!name || !*name) return RtlNtStatusToDosError( NtDeleteKey( hkey ) );
320 if (!(ret = VMM_RegOpenKeyExA( hkey, name, 0, 0, &tmp )))
322 ret = RtlNtStatusToDosError( NtDeleteKey( tmp ) );
329 /******************************************************************************
332 static DWORD VMM_RegSetValueExA( HKEY hkey, LPCSTR name, DWORD reserved, DWORD type,
333 CONST BYTE *data, DWORD count )
335 UNICODE_STRING nameW;
340 if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
348 /* if user forgot to count terminating null, add it (yes NT does this) */
349 if (data[count-1] && !data[count]) count++;
351 RtlMultiByteToUnicodeSize( &lenW, data, count );
352 if (!(dataW = HeapAlloc( GetProcessHeap(), 0, lenW ))) return ERROR_OUTOFMEMORY;
353 RtlMultiByteToUnicodeN( dataW, lenW, NULL, data, count );
355 data = (BYTE *)dataW;
358 RtlInitAnsiString( &nameA, name );
359 if (!(status = RtlAnsiStringToUnicodeString( &nameW, &nameA, TRUE )))
361 status = NtSetValueKey( hkey, &nameW, 0, type, data, count );
362 RtlFreeUnicodeString( &nameW );
364 if (dataW) HeapFree( GetProcessHeap(), 0, dataW );
365 return RtlNtStatusToDosError( status );
369 /******************************************************************************
372 static DWORD VMM_RegSetValueA( HKEY hkey, LPCSTR name, DWORD type, LPCSTR data, DWORD count )
377 if (type != REG_SZ) return ERROR_INVALID_PARAMETER;
379 if (name && name[0]) /* need to create the subkey */
381 if ((ret = VMM_RegCreateKeyA( hkey, name, &subkey )) != ERROR_SUCCESS) return ret;
383 ret = VMM_RegSetValueExA( subkey, NULL, 0, REG_SZ, (LPBYTE)data, strlen(data)+1 );
384 if (subkey != hkey) NtClose( subkey );
389 /******************************************************************************
390 * VMM_RegDeleteValueA
392 static DWORD VMM_RegDeleteValueA( HKEY hkey, LPCSTR name )
394 UNICODE_STRING nameW;
398 if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
400 RtlInitAnsiString( &nameA, name );
401 if (!(status = RtlAnsiStringToUnicodeString( &nameW, &nameA, TRUE )))
403 status = NtDeleteValueKey( hkey, &nameW );
404 RtlFreeUnicodeString( &nameW );
406 return RtlNtStatusToDosError( status );
410 /******************************************************************************
411 * VMM_RegQueryValueExA
413 static DWORD VMM_RegQueryValueExA( HKEY hkey, LPCSTR name, LPDWORD reserved, LPDWORD type,
414 LPBYTE data, LPDWORD count )
418 UNICODE_STRING nameW;
420 char buffer[256], *buf_ptr = buffer;
421 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)buffer;
422 static const int info_size = offsetof( KEY_VALUE_PARTIAL_INFORMATION, Data );
424 if ((data && !count) || reserved) return ERROR_INVALID_PARAMETER;
425 if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
427 RtlInitAnsiString( &nameA, name );
428 if ((status = RtlAnsiStringToUnicodeString( &nameW, &nameA, TRUE )))
429 return RtlNtStatusToDosError(status);
431 status = NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation,
432 buffer, sizeof(buffer), &total_size );
433 if (status && status != STATUS_BUFFER_OVERFLOW) goto done;
435 /* we need to fetch the contents for a string type even if not requested,
436 * because we need to compute the length of the ASCII string. */
437 if (data || is_string(info->Type))
439 /* retry with a dynamically allocated buffer */
440 while (status == STATUS_BUFFER_OVERFLOW)
442 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
443 if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
445 status = STATUS_NO_MEMORY;
448 info = (KEY_VALUE_PARTIAL_INFORMATION *)buf_ptr;
449 status = NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation,
450 buf_ptr, total_size, &total_size );
455 if (is_string(info->Type))
457 DWORD len = WideCharToMultiByte( CP_ACP, 0, (WCHAR *)(buf_ptr + info_size),
458 (total_size - info_size) /sizeof(WCHAR),
459 NULL, 0, NULL, NULL );
462 if (len > *count) status = STATUS_BUFFER_OVERFLOW;
465 WideCharToMultiByte( CP_ACP, 0, (WCHAR *)(buf_ptr + info_size),
466 (total_size - info_size) /sizeof(WCHAR),
467 data, len, NULL, NULL );
468 /* if the type is REG_SZ and data is not 0-terminated
469 * and there is enough space in the buffer NT appends a \0 */
470 if (len < *count && data[len-1]) data[len] = 0;
473 total_size = len + info_size;
477 if (total_size - info_size > *count) status = STATUS_BUFFER_OVERFLOW;
478 else memcpy( data, buf_ptr + info_size, total_size - info_size );
481 else if (status != STATUS_BUFFER_OVERFLOW) goto done;
484 if (type) *type = info->Type;
485 if (count) *count = total_size - info_size;
488 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
489 RtlFreeUnicodeString( &nameW );
490 return RtlNtStatusToDosError(status);
494 /******************************************************************************
497 static DWORD VMM_RegQueryValueA( HKEY hkey, LPCSTR name, LPSTR data, LPLONG count )
504 if ((ret = VMM_RegOpenKeyExA( hkey, name, 0, KEY_ALL_ACCESS, &subkey )) != ERROR_SUCCESS)
507 ret = VMM_RegQueryValueExA( subkey, NULL, NULL, NULL, (LPBYTE)data, count );
508 if (subkey != hkey) NtClose( subkey );
509 if (ret == ERROR_FILE_NOT_FOUND)
511 /* return empty string if default value not found */
513 if (count) *count = 1;
520 /******************************************************************************
523 static DWORD VMM_RegEnumValueA( HKEY hkey, DWORD index, LPSTR value, LPDWORD val_count,
524 LPDWORD reserved, LPDWORD type, LPBYTE data, LPDWORD count )
528 char buffer[256], *buf_ptr = buffer;
529 KEY_VALUE_FULL_INFORMATION *info = (KEY_VALUE_FULL_INFORMATION *)buffer;
530 static const int info_size = offsetof( KEY_VALUE_FULL_INFORMATION, Name );
532 TRACE("(%p,%ld,%p,%p,%p,%p,%p,%p)\n",
533 hkey, index, value, val_count, reserved, type, data, count );
535 /* NT only checks count, not val_count */
536 if ((data && !count) || reserved) return ERROR_INVALID_PARAMETER;
537 if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
539 total_size = info_size + (MAX_PATH + 1) * sizeof(WCHAR);
540 if (data) total_size += *count;
541 total_size = min( sizeof(buffer), total_size );
543 status = NtEnumerateValueKey( hkey, index, KeyValueFullInformation,
544 buffer, total_size, &total_size );
545 if (status && status != STATUS_BUFFER_OVERFLOW) goto done;
547 /* we need to fetch the contents for a string type even if not requested,
548 * because we need to compute the length of the ASCII string. */
549 if (value || data || is_string(info->Type))
551 /* retry with a dynamically allocated buffer */
552 while (status == STATUS_BUFFER_OVERFLOW)
554 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
555 if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
556 return ERROR_NOT_ENOUGH_MEMORY;
557 info = (KEY_VALUE_FULL_INFORMATION *)buf_ptr;
558 status = NtEnumerateValueKey( hkey, index, KeyValueFullInformation,
559 buf_ptr, total_size, &total_size );
562 if (status) goto done;
564 if (is_string(info->Type))
567 RtlUnicodeToMultiByteSize( &len, (WCHAR *)(buf_ptr + info->DataOffset),
568 total_size - info->DataOffset );
571 if (len > *count) status = STATUS_BUFFER_OVERFLOW;
574 RtlUnicodeToMultiByteN( data, len, NULL, (WCHAR *)(buf_ptr + info->DataOffset),
575 total_size - info->DataOffset );
576 /* if the type is REG_SZ and data is not 0-terminated
577 * and there is enough space in the buffer NT appends a \0 */
578 if (len < *count && data[len-1]) data[len] = 0;
581 info->DataLength = len;
585 if (total_size - info->DataOffset > *count) status = STATUS_BUFFER_OVERFLOW;
586 else memcpy( data, buf_ptr + info->DataOffset, total_size - info->DataOffset );
589 if (value && !status)
593 RtlUnicodeToMultiByteSize( &len, info->Name, info->NameLength );
594 if (len >= *val_count)
596 status = STATUS_BUFFER_OVERFLOW;
599 len = *val_count - 1;
600 RtlUnicodeToMultiByteN( value, len, NULL, info->Name, info->NameLength );
606 RtlUnicodeToMultiByteN( value, len, NULL, info->Name, info->NameLength );
612 else status = STATUS_SUCCESS;
614 if (type) *type = info->Type;
615 if (count) *count = info->DataLength;
618 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
619 return RtlNtStatusToDosError(status);
623 /******************************************************************************
626 static DWORD VMM_RegEnumKeyA( HKEY hkey, DWORD index, LPSTR name, DWORD name_len )
629 char buffer[256], *buf_ptr = buffer;
630 KEY_NODE_INFORMATION *info = (KEY_NODE_INFORMATION *)buffer;
633 if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
635 status = NtEnumerateKey( hkey, index, KeyNodeInformation,
636 buffer, sizeof(buffer), &total_size );
638 while (status == STATUS_BUFFER_OVERFLOW)
640 /* retry with a dynamically allocated buffer */
641 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
642 if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
643 return ERROR_NOT_ENOUGH_MEMORY;
644 info = (KEY_NODE_INFORMATION *)buf_ptr;
645 status = NtEnumerateKey( hkey, index, KeyNodeInformation,
646 buf_ptr, total_size, &total_size );
653 RtlUnicodeToMultiByteSize( &len, info->Name, info->NameLength );
654 if (len >= name_len) status = STATUS_BUFFER_OVERFLOW;
657 RtlUnicodeToMultiByteN( name, len, NULL, info->Name, info->NameLength );
662 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
663 return RtlNtStatusToDosError( status );
667 /******************************************************************************
668 * VMM_RegQueryInfoKeyA
670 * NOTE: This VxDCall takes only a subset of the parameters that the
671 * corresponding Win32 API call does. The implementation in Win95
672 * ADVAPI32 sets all output parameters not mentioned here to zero.
674 static DWORD VMM_RegQueryInfoKeyA( HKEY hkey, LPDWORD subkeys, LPDWORD max_subkey,
675 LPDWORD values, LPDWORD max_value, LPDWORD max_data )
678 KEY_FULL_INFORMATION info;
681 if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
683 status = NtQueryKey( hkey, KeyFullInformation, &info, sizeof(info), &total_size );
684 if (status && status != STATUS_BUFFER_OVERFLOW) return RtlNtStatusToDosError( status );
686 if (subkeys) *subkeys = info.SubKeys;
687 if (max_subkey) *max_subkey = info.MaxNameLen;
688 if (values) *values = info.Values;
689 if (max_value) *max_value = info.MaxValueNameLen;
690 if (max_data) *max_data = info.MaxValueDataLen;
691 return ERROR_SUCCESS;
695 /***********************************************************************
698 static DWORD VxDCall_VMM( DWORD service, CONTEXT86 *context )
700 switch ( LOWORD(service) )
702 case 0x0011: /* RegOpenKey */
704 HKEY hkey = (HKEY) stack32_pop( context );
705 LPCSTR lpszSubKey = (LPCSTR)stack32_pop( context );
706 PHKEY retkey = (PHKEY)stack32_pop( context );
707 return VMM_RegOpenKeyExA( hkey, lpszSubKey, 0, KEY_ALL_ACCESS, retkey );
710 case 0x0012: /* RegCreateKey */
712 HKEY hkey = (HKEY) stack32_pop( context );
713 LPCSTR lpszSubKey = (LPCSTR)stack32_pop( context );
714 PHKEY retkey = (PHKEY)stack32_pop( context );
715 return VMM_RegCreateKeyA( hkey, lpszSubKey, retkey );
718 case 0x0013: /* RegCloseKey */
720 HKEY hkey = (HKEY)stack32_pop( context );
721 return VMM_RegCloseKey( hkey );
724 case 0x0014: /* RegDeleteKey */
726 HKEY hkey = (HKEY) stack32_pop( context );
727 LPCSTR lpszSubKey = (LPCSTR)stack32_pop( context );
728 return VMM_RegDeleteKeyA( hkey, lpszSubKey );
731 case 0x0015: /* RegSetValue */
733 HKEY hkey = (HKEY) stack32_pop( context );
734 LPCSTR lpszSubKey = (LPCSTR)stack32_pop( context );
735 DWORD dwType = (DWORD) stack32_pop( context );
736 LPCSTR lpszData = (LPCSTR)stack32_pop( context );
737 DWORD cbData = (DWORD) stack32_pop( context );
738 return VMM_RegSetValueA( hkey, lpszSubKey, dwType, lpszData, cbData );
741 case 0x0016: /* RegDeleteValue */
743 HKEY hkey = (HKEY) stack32_pop( context );
744 LPSTR lpszValue = (LPSTR)stack32_pop( context );
745 return VMM_RegDeleteValueA( hkey, lpszValue );
748 case 0x0017: /* RegQueryValue */
750 HKEY hkey = (HKEY) stack32_pop( context );
751 LPSTR lpszSubKey = (LPSTR) stack32_pop( context );
752 LPSTR lpszData = (LPSTR) stack32_pop( context );
753 LPDWORD lpcbData = (LPDWORD)stack32_pop( context );
754 return VMM_RegQueryValueA( hkey, lpszSubKey, lpszData, lpcbData );
757 case 0x0018: /* RegEnumKey */
759 HKEY hkey = (HKEY) stack32_pop( context );
760 DWORD iSubkey = (DWORD)stack32_pop( context );
761 LPSTR lpszName = (LPSTR)stack32_pop( context );
762 DWORD lpcchName = (DWORD)stack32_pop( context );
763 return VMM_RegEnumKeyA( hkey, iSubkey, lpszName, lpcchName );
766 case 0x0019: /* RegEnumValue */
768 HKEY hkey = (HKEY) stack32_pop( context );
769 DWORD iValue = (DWORD) stack32_pop( context );
770 LPSTR lpszValue = (LPSTR) stack32_pop( context );
771 LPDWORD lpcchValue = (LPDWORD)stack32_pop( context );
772 LPDWORD lpReserved = (LPDWORD)stack32_pop( context );
773 LPDWORD lpdwType = (LPDWORD)stack32_pop( context );
774 LPBYTE lpbData = (LPBYTE) stack32_pop( context );
775 LPDWORD lpcbData = (LPDWORD)stack32_pop( context );
776 return VMM_RegEnumValueA( hkey, iValue, lpszValue, lpcchValue,
777 lpReserved, lpdwType, lpbData, lpcbData );
780 case 0x001A: /* RegQueryValueEx */
782 HKEY hkey = (HKEY) stack32_pop( context );
783 LPSTR lpszValue = (LPSTR) stack32_pop( context );
784 LPDWORD lpReserved = (LPDWORD)stack32_pop( context );
785 LPDWORD lpdwType = (LPDWORD)stack32_pop( context );
786 LPBYTE lpbData = (LPBYTE) stack32_pop( context );
787 LPDWORD lpcbData = (LPDWORD)stack32_pop( context );
788 return VMM_RegQueryValueExA( hkey, lpszValue, lpReserved,
789 lpdwType, lpbData, lpcbData );
792 case 0x001B: /* RegSetValueEx */
794 HKEY hkey = (HKEY) stack32_pop( context );
795 LPSTR lpszValue = (LPSTR) stack32_pop( context );
796 DWORD dwReserved = (DWORD) stack32_pop( context );
797 DWORD dwType = (DWORD) stack32_pop( context );
798 LPBYTE lpbData = (LPBYTE)stack32_pop( context );
799 DWORD cbData = (DWORD) stack32_pop( context );
800 return VMM_RegSetValueExA( hkey, lpszValue, dwReserved,
801 dwType, lpbData, cbData );
804 case 0x001C: /* RegFlushKey */
806 HKEY hkey = (HKEY)stack32_pop( context );
807 FIXME( "RegFlushKey(%p): stub\n", hkey );
808 return ERROR_SUCCESS;
811 case 0x001D: /* RegQueryInfoKey */
813 /* NOTE: This VxDCall takes only a subset of the parameters that the
814 corresponding Win32 API call does. The implementation in Win95
815 ADVAPI32 sets all output parameters not mentioned here to zero. */
817 HKEY hkey = (HKEY) stack32_pop( context );
818 LPDWORD lpcSubKeys = (LPDWORD)stack32_pop( context );
819 LPDWORD lpcchMaxSubKey = (LPDWORD)stack32_pop( context );
820 LPDWORD lpcValues = (LPDWORD)stack32_pop( context );
821 LPDWORD lpcchMaxValueName = (LPDWORD)stack32_pop( context );
822 LPDWORD lpcchMaxValueData = (LPDWORD)stack32_pop( context );
823 return VMM_RegQueryInfoKeyA( hkey, lpcSubKeys, lpcchMaxSubKey,
824 lpcValues, lpcchMaxValueName, lpcchMaxValueData );
827 case 0x0021: /* RegLoadKey */
829 HKEY hkey = (HKEY) stack32_pop( context );
830 LPCSTR lpszSubKey = (LPCSTR)stack32_pop( context );
831 LPCSTR lpszFile = (LPCSTR)stack32_pop( context );
832 FIXME("RegLoadKey(%p,%s,%s): stub\n",hkey, debugstr_a(lpszSubKey), debugstr_a(lpszFile));
833 return ERROR_SUCCESS;
836 case 0x0022: /* RegUnLoadKey */
838 HKEY hkey = (HKEY) stack32_pop( context );
839 LPCSTR lpszSubKey = (LPCSTR)stack32_pop( context );
840 FIXME("RegUnLoadKey(%p,%s): stub\n",hkey, debugstr_a(lpszSubKey));
841 return ERROR_SUCCESS;
844 case 0x0023: /* RegSaveKey */
846 HKEY hkey = (HKEY) stack32_pop( context );
847 LPCSTR lpszFile = (LPCSTR)stack32_pop( context );
848 LPSECURITY_ATTRIBUTES sa = (LPSECURITY_ATTRIBUTES)stack32_pop( context );
849 FIXME("RegSaveKey(%p,%s,%p): stub\n",hkey, debugstr_a(lpszFile),sa);
850 return ERROR_SUCCESS;
853 #if 0 /* Functions are not yet implemented in misc/registry.c */
854 case 0x0024: /* RegRemapPreDefKey */
855 case 0x0026: /* RegQueryMultipleValues */
858 case 0x0027: /* RegReplaceKey */
860 HKEY hkey = (HKEY) stack32_pop( context );
861 LPCSTR lpszSubKey = (LPCSTR)stack32_pop( context );
862 LPCSTR lpszNewFile= (LPCSTR)stack32_pop( context );
863 LPCSTR lpszOldFile= (LPCSTR)stack32_pop( context );
864 FIXME("RegReplaceKey(%p,%s,%s,%s): stub\n", hkey, debugstr_a(lpszSubKey),
865 debugstr_a(lpszNewFile),debugstr_a(lpszOldFile));
866 return ERROR_SUCCESS;
869 case 0x0000: /* PageReserve */
873 DWORD psize = getpagesize();
874 ULONG page = (ULONG) stack32_pop( context );
875 ULONG npages = (ULONG) stack32_pop( context );
876 ULONG flags = (ULONG) stack32_pop( context );
878 TRACE("PageReserve: page: %08lx, npages: %08lx, flags: %08lx partial stub!\n",
879 page, npages, flags );
881 if ( page == PR_SYSTEM ) {
882 ERR("Can't reserve ring 1 memory\n");
885 /* FIXME: This has to be handled separately for the separate
886 address-spaces we now have */
887 if ( page == PR_PRIVATE || page == PR_SHARED ) page = 0;
888 /* FIXME: Handle flags in some way */
889 address = (LPVOID )(page * psize);
890 ret = VirtualAlloc ( address, ( npages * psize ), MEM_RESERVE, 0 );
891 TRACE("PageReserve: returning: %08lx\n", (DWORD )ret );
898 case 0x0001: /* PageCommit */
903 DWORD psize = getpagesize();
904 ULONG page = (ULONG) stack32_pop( context );
905 ULONG npages = (ULONG) stack32_pop( context );
906 ULONG hpd = (ULONG) stack32_pop( context );
907 ULONG pagerdata = (ULONG) stack32_pop( context );
908 ULONG flags = (ULONG) stack32_pop( context );
910 TRACE("PageCommit: page: %08lx, npages: %08lx, hpd: %08lx pagerdata: "
911 "%08lx, flags: %08lx partial stub\n",
912 page, npages, hpd, pagerdata, flags );
914 if ( flags & PC_USER )
915 if ( flags & PC_WRITEABLE )
916 virt_perm = PAGE_EXECUTE_READWRITE;
918 virt_perm = PAGE_EXECUTE_READ;
920 virt_perm = PAGE_NOACCESS;
922 address = (LPVOID )(page * psize);
923 ret = VirtualAlloc ( address, ( npages * psize ), MEM_COMMIT, virt_perm );
924 TRACE("PageCommit: Returning: %08lx\n", (DWORD )ret );
928 case 0x0002: /* PageDecommit */
932 DWORD psize = getpagesize();
933 ULONG page = (ULONG) stack32_pop( context );
934 ULONG npages = (ULONG) stack32_pop( context );
935 ULONG flags = (ULONG) stack32_pop( context );
937 TRACE("PageDecommit: page: %08lx, npages: %08lx, flags: %08lx partial stub\n",
938 page, npages, flags );
939 address = (LPVOID )( page * psize );
940 ret = VirtualFree ( address, ( npages * psize ), MEM_DECOMMIT );
941 TRACE("PageDecommit: Returning: %s\n", ret ? "TRUE" : "FALSE" );
944 case 0x000d: /* PageModifyPermissions */
950 MEMORY_BASIC_INFORMATION mbi;
952 DWORD psize = getpagesize();
953 ULONG page = stack32_pop ( context );
954 ULONG npages = stack32_pop ( context );
955 ULONG permand = stack32_pop ( context );
956 ULONG permor = stack32_pop ( context );
958 TRACE("PageModifyPermissions %08lx %08lx %08lx %08lx partial stub\n",
959 page, npages, permand, permor );
960 address = (LPVOID )( page * psize );
962 VirtualQuery ( address, &mbi, sizeof ( MEMORY_BASIC_INFORMATION ));
963 virt_old_perm = mbi.Protect;
965 switch ( virt_old_perm & mbi.Protect ) {
968 case PAGE_EXECUTE_READ:
969 pg_old_perm = PC_USER;
973 case PAGE_EXECUTE_READWRITE:
974 case PAGE_EXECUTE_WRITECOPY:
975 pg_old_perm = PC_USER | PC_WRITEABLE;
982 pg_new_perm = pg_old_perm;
983 pg_new_perm &= permand & ~PC_STATIC;
984 pg_new_perm |= permor & ~PC_STATIC;
986 virt_new_perm = ( virt_old_perm ) & ~0xff;
987 if ( pg_new_perm & PC_USER )
989 if ( pg_new_perm & PC_WRITEABLE )
990 virt_new_perm |= PAGE_EXECUTE_READWRITE;
992 virt_new_perm |= PAGE_EXECUTE_READ;
995 if ( ! VirtualProtect ( address, ( npages * psize ), virt_new_perm, &virt_old_perm ) ) {
996 ERR("Can't change page permissions for %08lx\n", (DWORD )address );
999 TRACE("Returning: %08lx\n", pg_old_perm );
1002 case 0x000a: /* PageFree */
1005 LPVOID hmem = (LPVOID) stack32_pop( context );
1006 DWORD flags = (DWORD ) stack32_pop( context );
1008 TRACE("PageFree: hmem: %08lx, flags: %08lx partial stub\n",
1009 (DWORD )hmem, flags );
1011 ret = VirtualFree ( hmem, 0, MEM_RELEASE );
1013 TRACE("Returning: %d\n", ret );
1017 case 0x001e: /* GetDemandPageInfo */
1019 DWORD dinfo = (DWORD)stack32_pop( context );
1020 DWORD flags = (DWORD)stack32_pop( context );
1022 /* GetDemandPageInfo is supposed to fill out the struct at
1023 * "dinfo" with various low-level memory management information.
1024 * Apps are certainly not supposed to call this, although it's
1025 * demoed and documented by Pietrek on pages 441-443 of "Windows
1026 * 95 System Programming Secrets" if any program needs a real
1027 * implementation of this.
1030 FIXME("GetDemandPageInfo(%08lx %08lx): stub!\n", dinfo, flags);
1035 if (LOWORD(service) < N_VMM_SERVICE)
1036 FIXME( "Unimplemented service %s (%08lx)\n",
1037 VMM_Service_Name[LOWORD(service)], service);
1039 FIXME( "Unknown service %08lx\n", service);
1043 return 0xffffffff; /* FIXME */
1047 /********************************************************************************
1050 * Service numbers taken from page 448 of Pietrek's "Windows 95 System
1051 * Programming Secrets". Parameters from experimentation on real Win98.
1055 static DWORD VxDCall_VWin32( DWORD service, CONTEXT86 *context )
1057 switch ( LOWORD(service) )
1059 case 0x0000: /* GetVersion */
1061 DWORD vers = GetVersion();
1062 return (LOBYTE(vers) << 8) | HIBYTE(vers);
1066 case 0x0020: /* Get VMCPD Version */
1068 DWORD parm = (DWORD) stack32_pop(context);
1070 FIXME("Get VMCPD Version(%08lx): partial stub!\n", parm);
1072 /* FIXME: This is what Win98 returns, it may
1073 * not be correct in all situations.
1074 * It makes Bleem! happy though.
1080 case 0x0029: /* Int31/DPMI dispatch */
1082 DWORD callnum = (DWORD) stack32_pop(context);
1083 DWORD parm = (DWORD) stack32_pop(context);
1085 TRACE("Int31/DPMI dispatch(%08lx)\n", callnum);
1087 context->Eax = callnum;
1088 context->Ecx = parm;
1089 INSTR_CallBuiltinHandler( context, 0x31 );
1091 return LOWORD(context->Eax);
1095 case 0x002a: /* Int41 dispatch - parm = int41 service number */
1097 DWORD callnum = (DWORD) stack32_pop(context);
1099 return callnum; /* FIXME: should really call INT_Int41Handler() */
1104 FIXME("Unknown VWin32 service %08lx\n", service);
1112 /***********************************************************************
1113 * VxDCall0 (KERNEL32.1)
1114 * VxDCall1 (KERNEL32.2)
1115 * VxDCall2 (KERNEL32.3)
1116 * VxDCall3 (KERNEL32.4)
1117 * VxDCall4 (KERNEL32.5)
1118 * VxDCall5 (KERNEL32.6)
1119 * VxDCall6 (KERNEL32.7)
1120 * VxDCall7 (KERNEL32.8)
1121 * VxDCall8 (KERNEL32.9)
1123 void VxDCall( DWORD service, CONTEXT86 *context )
1127 TRACE( "(%08lx, ...)\n", service);
1129 switch(HIWORD(service))
1131 case 0x0001: /* VMM */
1132 ret = VxDCall_VMM( service, context );
1134 case 0x002a: /* VWIN32 */
1135 ret = VxDCall_VWin32( service, context );
1138 FIXME( "Unknown/unimplemented VxD (%08lx)\n", service);
1139 ret = 0xffffffff; /* FIXME */
1146 /***********************************************************************
1147 * OpenVxDHandle (KERNEL32.@)
1149 * This function is supposed to return the corresponding Ring 0
1150 * ("kernel") handle for a Ring 3 handle in Win9x.
1151 * Evidently, Wine will have problems with this. But we try anyway,
1154 HANDLE WINAPI OpenVxDHandle(HANDLE hHandleRing3)
1156 FIXME( "(%p), stub! (returning Ring 3 handle instead of Ring 0)\n", hHandleRing3);
1157 return hHandleRing3;