2 * VMM VxD implementation
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(vxd
);
33 * VMM VxDCall service names are (mostly) taken from Stan Mitchell's
34 * "Inside the Windows 95 File System"
37 #define N_VMM_SERVICE 41
39 static const char * const VMM_Service_Name
[N_VMM_SERVICE
] =
41 "PageReserve", /* 0x0000 */
42 "PageCommit", /* 0x0001 */
43 "PageDecommit", /* 0x0002 */
44 "PagerRegister", /* 0x0003 */
45 "PagerQuery", /* 0x0004 */
46 "HeapAllocate", /* 0x0005 */
47 "ContextCreate", /* 0x0006 */
48 "ContextDestroy", /* 0x0007 */
49 "PageAttach", /* 0x0008 */
50 "PageFlush", /* 0x0009 */
51 "PageFree", /* 0x000A */
52 "ContextSwitch", /* 0x000B */
53 "HeapReAllocate", /* 0x000C */
54 "PageModifyPermissions", /* 0x000D */
55 "PageQuery", /* 0x000E */
56 "GetCurrentContext", /* 0x000F */
57 "HeapFree", /* 0x0010 */
58 "RegOpenKey", /* 0x0011 */
59 "RegCreateKey", /* 0x0012 */
60 "RegCloseKey", /* 0x0013 */
61 "RegDeleteKey", /* 0x0014 */
62 "RegSetValue", /* 0x0015 */
63 "RegDeleteValue", /* 0x0016 */
64 "RegQueryValue", /* 0x0017 */
65 "RegEnumKey", /* 0x0018 */
66 "RegEnumValue", /* 0x0019 */
67 "RegQueryValueEx", /* 0x001A */
68 "RegSetValueEx", /* 0x001B */
69 "RegFlushKey", /* 0x001C */
70 "RegQueryInfoKey", /* 0x001D */
71 "GetDemandPageInfo", /* 0x001E */
72 "BlockOnID", /* 0x001F */
73 "SignalID", /* 0x0020 */
74 "RegLoadKey", /* 0x0021 */
75 "RegUnLoadKey", /* 0x0022 */
76 "RegSaveKey", /* 0x0023 */
77 "RegRemapPreDefKey", /* 0x0024 */
78 "PageChangePager", /* 0x0025 */
79 "RegQueryMultipleValues", /* 0x0026 */
80 "RegReplaceKey", /* 0x0027 */
81 "<KERNEL32.101>" /* 0x0028 -- What does this do??? */
84 /* PageReserve arena values */
85 #define PR_PRIVATE 0x80000400 /* anywhere in private arena */
86 #define PR_SHARED 0x80060000 /* anywhere in shared arena */
87 #define PR_SYSTEM 0x80080000 /* anywhere in system arena */
89 /* PageReserve flags */
90 #define PR_FIXED 0x00000008 /* don't move during PageReAllocate */
91 #define PR_4MEG 0x00000001 /* allocate on 4mb boundary */
92 #define PR_STATIC 0x00000010 /* see PageReserve documentation */
94 /* PageCommit default pager handle values */
95 #define PD_ZEROINIT 0x00000001 /* swappable zero-initialized pages */
96 #define PD_NOINIT 0x00000002 /* swappable uninitialized pages */
97 #define PD_FIXEDZERO 0x00000003 /* fixed zero-initialized pages */
98 #define PD_FIXED 0x00000004 /* fixed uninitialized pages */
100 /* PageCommit flags */
101 #define PC_FIXED 0x00000008 /* pages are permanently locked */
102 #define PC_LOCKED 0x00000080 /* pages are made present and locked */
103 #define PC_LOCKEDIFDP 0x00000100 /* pages are locked if swap via DOS */
104 #define PC_WRITABLE 0x00020000 /* make the pages writable */
105 #define PC_USER 0x00040000 /* make the pages ring 3 accessible */
106 #define PC_INCR 0x40000000 /* increment "pagerdata" each page */
107 #define PC_PRESENT 0x80000000 /* make pages initially present */
108 #define PC_STATIC 0x20000000 /* allow commit in PR_STATIC object */
109 #define PC_DIRTY 0x08000000 /* make pages initially dirty */
110 #define PC_CACHEDIS 0x00100000 /* Allocate uncached pages - new for WDM */
111 #define PC_CACHEWT 0x00080000 /* Allocate write through cache pages - new for WDM */
112 #define PC_PAGEFLUSH 0x00008000 /* Touch device mapped pages on alloc - new for WDM */
114 /* PageCommitContig additional flags */
115 #define PCC_ZEROINIT 0x00000001 /* zero-initialize new pages */
116 #define PCC_NOLIN 0x10000000 /* don't map to any linear address */
119 static const DWORD page_size
= 0x1000; /* we only care about x86 */
121 /* Pop a DWORD from the 32-bit stack */
122 static inline DWORD
stack32_pop( CONTEXT
*context
)
124 DWORD ret
= *(DWORD
*)context
->Esp
;
125 context
->Esp
+= sizeof(DWORD
);
130 /***********************************************************************
131 * VxDCall (VMM.VXD.@)
133 DWORD WINAPI
VMM_VxDCall( DWORD service
, CONTEXT
*context
)
137 switch ( LOWORD(service
) )
139 case 0x0000: /* PageReserve */
143 ULONG page
= stack32_pop( context
);
144 ULONG npages
= stack32_pop( context
);
145 ULONG flags
= stack32_pop( context
);
147 TRACE("PageReserve: page: %08x, npages: %08x, flags: %08x partial stub!\n",
148 page
, npages
, flags
);
150 if ( page
== PR_SYSTEM
) {
151 ERR("Can't reserve ring 1 memory\n");
154 /* FIXME: This has to be handled separately for the separate
155 address-spaces we now have */
156 if ( page
== PR_PRIVATE
|| page
== PR_SHARED
) page
= 0;
157 /* FIXME: Handle flags in some way */
158 address
= (LPVOID
)(page
* page_size
);
159 ret
= VirtualAlloc ( address
, npages
* page_size
, MEM_RESERVE
, PAGE_EXECUTE_READWRITE
);
160 TRACE("PageReserve: returning: %p\n", ret
);
167 case 0x0001: /* PageCommit */
172 ULONG page
= stack32_pop( context
);
173 ULONG npages
= stack32_pop( context
);
174 ULONG hpd
= stack32_pop( context
);
175 ULONG pagerdata
= stack32_pop( context
);
176 ULONG flags
= stack32_pop( context
);
178 TRACE("PageCommit: page: %08x, npages: %08x, hpd: %08x pagerdata: "
179 "%08x, flags: %08x partial stub\n",
180 page
, npages
, hpd
, pagerdata
, flags
);
182 if ( flags
& PC_USER
)
183 if ( flags
& PC_WRITABLE
)
184 virt_perm
= PAGE_EXECUTE_READWRITE
;
186 virt_perm
= PAGE_EXECUTE_READ
;
188 virt_perm
= PAGE_NOACCESS
;
190 address
= (LPVOID
)(page
* page_size
);
191 ret
= VirtualAlloc ( address
, npages
* page_size
, MEM_COMMIT
, virt_perm
);
192 TRACE("PageCommit: Returning: %p\n", ret
);
197 case 0x0002: /* PageDecommit */
201 ULONG page
= stack32_pop( context
);
202 ULONG npages
= stack32_pop( context
);
203 ULONG flags
= stack32_pop( context
);
205 TRACE("PageDecommit: page: %08x, npages: %08x, flags: %08x partial stub\n",
206 page
, npages
, flags
);
207 address
= (LPVOID
)( page
* page_size
);
208 ret
= VirtualFree ( address
, npages
* page_size
, MEM_DECOMMIT
);
209 TRACE("PageDecommit: Returning: %s\n", ret
? "TRUE" : "FALSE" );
213 case 0x000d: /* PageModifyPermissions */
219 MEMORY_BASIC_INFORMATION mbi
;
221 ULONG page
= stack32_pop ( context
);
222 ULONG npages
= stack32_pop ( context
);
223 ULONG permand
= stack32_pop ( context
);
224 ULONG permor
= stack32_pop ( context
);
226 TRACE("PageModifyPermissions %08x %08x %08x %08x partial stub\n",
227 page
, npages
, permand
, permor
);
228 address
= (LPVOID
)( page
* page_size
);
230 VirtualQuery ( address
, &mbi
, sizeof ( MEMORY_BASIC_INFORMATION
));
231 virt_old_perm
= mbi
.Protect
;
233 switch ( virt_old_perm
& mbi
.Protect
) {
236 case PAGE_EXECUTE_READ
:
237 pg_old_perm
= PC_USER
;
241 case PAGE_EXECUTE_READWRITE
:
242 case PAGE_EXECUTE_WRITECOPY
:
243 pg_old_perm
= PC_USER
| PC_WRITABLE
;
250 pg_new_perm
= pg_old_perm
;
251 pg_new_perm
&= permand
& ~PC_STATIC
;
252 pg_new_perm
|= permor
& ~PC_STATIC
;
254 virt_new_perm
= ( virt_old_perm
) & ~0xff;
255 if ( pg_new_perm
& PC_USER
)
257 if ( pg_new_perm
& PC_WRITABLE
)
258 virt_new_perm
|= PAGE_EXECUTE_READWRITE
;
260 virt_new_perm
|= PAGE_EXECUTE_READ
;
263 if ( ! VirtualProtect ( address
, npages
* page_size
, virt_new_perm
, &virt_old_perm
) ) {
264 ERR("Can't change page permissions for %p\n", address
);
267 TRACE("Returning: %08x\n", pg_old_perm
);
271 case 0x000a: /* PageFree */
274 LPVOID hmem
= (LPVOID
) stack32_pop( context
);
275 DWORD flags
= stack32_pop( context
);
277 TRACE("PageFree: hmem: %p, flags: %08x partial stub\n",
280 ret
= VirtualFree ( hmem
, 0, MEM_RELEASE
);
281 TRACE("Returning: %d\n", ret
);
285 case 0x0011: /* RegOpenKey */
286 stack32_pop( context
); /* kkey */
287 stack32_pop( context
); /* lpszSubKey */
288 stack32_pop( context
); /* retkey */
289 /* return RegOpenKeyExA( hkey, lpszSubKey, 0, KEY_ALL_ACCESS, retkey ); */
292 ERR( "Using the native Win95 advapi32.dll is no longer supported.\n" );
293 ERR( "Please configure advapi32 to builtin.\n" );
296 return ERROR_CALL_NOT_IMPLEMENTED
;
298 case 0x0012: /* RegCreateKey */
299 stack32_pop( context
); /* hkey */
300 stack32_pop( context
); /* lpszSubKey */
301 stack32_pop( context
); /* retkey */
302 /* return RegCreateKeyA( hkey, lpszSubKey, retkey ); */
305 ERR( "Using the native Win95 advapi32.dll is no longer supported.\n" );
306 ERR( "Please configure advapi32 to builtin.\n" );
309 return ERROR_CALL_NOT_IMPLEMENTED
;
311 case 0x0013: /* RegCloseKey */
312 stack32_pop( context
); /* hkey */
313 /* return RegCloseKey( hkey ); */
314 return ERROR_CALL_NOT_IMPLEMENTED
;
316 case 0x0014: /* RegDeleteKey */
317 stack32_pop( context
); /* hkey */
318 stack32_pop( context
); /* lpszSubKey */
319 /* return RegDeleteKeyA( hkey, lpszSubKey ); */
320 return ERROR_CALL_NOT_IMPLEMENTED
;
322 case 0x0015: /* RegSetValue */
323 stack32_pop( context
); /* hkey */
324 stack32_pop( context
); /* lpszSubKey */
325 stack32_pop( context
); /* dwType */
326 stack32_pop( context
); /* lpszData */
327 stack32_pop( context
); /* cbData */
328 /* return RegSetValueA( hkey, lpszSubKey, dwType, lpszData, cbData ); */
329 return ERROR_CALL_NOT_IMPLEMENTED
;
331 case 0x0016: /* RegDeleteValue */
332 stack32_pop( context
); /* hkey */
333 stack32_pop( context
); /* lpszValue */
334 /* return RegDeleteValueA( hkey, lpszValue ); */
335 return ERROR_CALL_NOT_IMPLEMENTED
;
337 case 0x0017: /* RegQueryValue */
338 stack32_pop( context
); /* hkey */
339 stack32_pop( context
); /* lpszSubKey */
340 stack32_pop( context
); /* lpszData */
341 stack32_pop( context
); /* lpcbData */
342 /* return RegQueryValueA( hkey, lpszSubKey, lpszData, lpcbData ); */
343 return ERROR_CALL_NOT_IMPLEMENTED
;
345 case 0x0018: /* RegEnumKey */
346 stack32_pop( context
); /* hkey */
347 stack32_pop( context
); /* iSubkey */
348 stack32_pop( context
); /* lpszName */
349 stack32_pop( context
); /* lpcchName */
350 /* return RegEnumKeyA( hkey, iSubkey, lpszName, lpcchName ); */
351 return ERROR_CALL_NOT_IMPLEMENTED
;
353 case 0x0019: /* RegEnumValue */
354 stack32_pop( context
); /* hkey */
355 stack32_pop( context
); /* iValue */
356 stack32_pop( context
); /* lpszValue */
357 stack32_pop( context
); /* lpcchValue */
358 stack32_pop( context
); /* lpReserved */
359 stack32_pop( context
); /* lpdwType */
360 stack32_pop( context
); /* lpbData */
361 stack32_pop( context
); /* lpcbData */
362 /* return RegEnumValueA( hkey, iValue, lpszValue, lpcchValue, lpReserved, lpdwType, lpbData, lpcbData ); */
363 return ERROR_CALL_NOT_IMPLEMENTED
;
365 case 0x001A: /* RegQueryValueEx */
366 stack32_pop( context
); /* hkey */
367 stack32_pop( context
); /* lpszValue */
368 stack32_pop( context
); /* lpReserved */
369 stack32_pop( context
); /* lpdwType */
370 stack32_pop( context
); /* lpbData */
371 stack32_pop( context
); /* lpcbData */
372 /* return RegQueryValueExA( hkey, lpszValue, lpReserved, lpdwType, lpbData, lpcbData ); */
373 return ERROR_CALL_NOT_IMPLEMENTED
;
375 case 0x001B: /* RegSetValueEx */
376 stack32_pop( context
); /* hkey */
377 stack32_pop( context
); /* lpszValue */
378 stack32_pop( context
); /* dwReserved */
379 stack32_pop( context
); /* dwType */
380 stack32_pop( context
); /* lpbData */
381 stack32_pop( context
); /* cbData */
382 /* return RegSetValueExA( hkey, lpszValue, dwReserved, dwType, lpbData, cbData ); */
383 return ERROR_CALL_NOT_IMPLEMENTED
;
385 case 0x001C: /* RegFlushKey */
386 stack32_pop( context
); /* hkey */
387 /* return RegFlushKey( hkey ); */
388 return ERROR_CALL_NOT_IMPLEMENTED
;
390 case 0x001D: /* RegQueryInfoKey */
391 /* NOTE: This VxDCall takes only a subset of the parameters that the
392 corresponding Win32 API call does. The implementation in Win95
393 ADVAPI32 sets all output parameters not mentioned here to zero. */
394 stack32_pop( context
); /* hkey */
395 stack32_pop( context
); /* lpcSubKeys */
396 stack32_pop( context
); /* lpcchMaxSubKey */
397 stack32_pop( context
); /* lpcValues */
398 stack32_pop( context
); /* lpcchMaxValueName */
399 stack32_pop( context
); /* lpcchMaxValueData */
400 /* return RegQueryInfoKeyA( hkey, lpcSubKeys, lpcchMaxSubKey, lpcValues, lpcchMaxValueName, lpcchMaxValueData ); */
401 return ERROR_CALL_NOT_IMPLEMENTED
;
403 case 0x001e: /* GetDemandPageInfo */
405 DWORD dinfo
= stack32_pop( context
);
406 DWORD flags
= stack32_pop( context
);
408 /* GetDemandPageInfo is supposed to fill out the struct at
409 * "dinfo" with various low-level memory management information.
410 * Apps are certainly not supposed to call this, although it's
411 * demoed and documented by Pietrek on pages 441-443 of "Windows
412 * 95 System Programming Secrets" if any program needs a real
413 * implementation of this.
416 FIXME("GetDemandPageInfo(%08x %08x): stub!\n", dinfo
, flags
);
421 case 0x0021: /* RegLoadKey */
423 HKEY hkey
= (HKEY
) stack32_pop( context
);
424 LPCSTR lpszSubKey
= (LPCSTR
)stack32_pop( context
);
425 LPCSTR lpszFile
= (LPCSTR
)stack32_pop( context
);
426 FIXME("RegLoadKey(%p,%s,%s): stub\n",hkey
, debugstr_a(lpszSubKey
), debugstr_a(lpszFile
));
427 return ERROR_CALL_NOT_IMPLEMENTED
;
430 case 0x0022: /* RegUnLoadKey */
432 HKEY hkey
= (HKEY
) stack32_pop( context
);
433 LPCSTR lpszSubKey
= (LPCSTR
)stack32_pop( context
);
434 FIXME("RegUnLoadKey(%p,%s): stub\n",hkey
, debugstr_a(lpszSubKey
));
435 return ERROR_CALL_NOT_IMPLEMENTED
;
438 case 0x0023: /* RegSaveKey */
440 HKEY hkey
= (HKEY
) stack32_pop( context
);
441 LPCSTR lpszFile
= (LPCSTR
)stack32_pop( context
);
442 LPSECURITY_ATTRIBUTES sa
= (LPSECURITY_ATTRIBUTES
)stack32_pop( context
);
443 FIXME("RegSaveKey(%p,%s,%p): stub\n",hkey
, debugstr_a(lpszFile
),sa
);
444 return ERROR_CALL_NOT_IMPLEMENTED
;
447 #if 0 /* Functions are not yet implemented in misc/registry.c */
448 case 0x0024: /* RegRemapPreDefKey */
449 case 0x0026: /* RegQueryMultipleValues */
452 case 0x0027: /* RegReplaceKey */
454 HKEY hkey
= (HKEY
) stack32_pop( context
);
455 LPCSTR lpszSubKey
= (LPCSTR
)stack32_pop( context
);
456 LPCSTR lpszNewFile
= (LPCSTR
)stack32_pop( context
);
457 LPCSTR lpszOldFile
= (LPCSTR
)stack32_pop( context
);
458 FIXME("RegReplaceKey(%p,%s,%s,%s): stub\n", hkey
, debugstr_a(lpszSubKey
),
459 debugstr_a(lpszNewFile
),debugstr_a(lpszOldFile
));
460 return ERROR_CALL_NOT_IMPLEMENTED
;
464 if (LOWORD(service
) < N_VMM_SERVICE
)
465 FIXME( "Unimplemented service %s (%08x)\n",
466 VMM_Service_Name
[LOWORD(service
)], service
);
468 FIXME( "Unknown service %08x\n", service
);
469 return 0xffffffff; /* FIXME */