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
24 #include "wine/port.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(vxd
);
38 * VMM VxDCall service names are (mostly) taken from Stan Mitchell's
39 * "Inside the Windows 95 File System"
42 #define N_VMM_SERVICE 41
44 static const char * const VMM_Service_Name
[N_VMM_SERVICE
] =
46 "PageReserve", /* 0x0000 */
47 "PageCommit", /* 0x0001 */
48 "PageDecommit", /* 0x0002 */
49 "PagerRegister", /* 0x0003 */
50 "PagerQuery", /* 0x0004 */
51 "HeapAllocate", /* 0x0005 */
52 "ContextCreate", /* 0x0006 */
53 "ContextDestroy", /* 0x0007 */
54 "PageAttach", /* 0x0008 */
55 "PageFlush", /* 0x0009 */
56 "PageFree", /* 0x000A */
57 "ContextSwitch", /* 0x000B */
58 "HeapReAllocate", /* 0x000C */
59 "PageModifyPermissions", /* 0x000D */
60 "PageQuery", /* 0x000E */
61 "GetCurrentContext", /* 0x000F */
62 "HeapFree", /* 0x0010 */
63 "RegOpenKey", /* 0x0011 */
64 "RegCreateKey", /* 0x0012 */
65 "RegCloseKey", /* 0x0013 */
66 "RegDeleteKey", /* 0x0014 */
67 "RegSetValue", /* 0x0015 */
68 "RegDeleteValue", /* 0x0016 */
69 "RegQueryValue", /* 0x0017 */
70 "RegEnumKey", /* 0x0018 */
71 "RegEnumValue", /* 0x0019 */
72 "RegQueryValueEx", /* 0x001A */
73 "RegSetValueEx", /* 0x001B */
74 "RegFlushKey", /* 0x001C */
75 "RegQueryInfoKey", /* 0x001D */
76 "GetDemandPageInfo", /* 0x001E */
77 "BlockOnID", /* 0x001F */
78 "SignalID", /* 0x0020 */
79 "RegLoadKey", /* 0x0021 */
80 "RegUnLoadKey", /* 0x0022 */
81 "RegSaveKey", /* 0x0023 */
82 "RegRemapPreDefKey", /* 0x0024 */
83 "PageChangePager", /* 0x0025 */
84 "RegQueryMultipleValues", /* 0x0026 */
85 "RegReplaceKey", /* 0x0027 */
86 "<KERNEL32.101>" /* 0x0028 -- What does this do??? */
89 /* PageReserve arena values */
90 #define PR_PRIVATE 0x80000400 /* anywhere in private arena */
91 #define PR_SHARED 0x80060000 /* anywhere in shared arena */
92 #define PR_SYSTEM 0x80080000 /* anywhere in system arena */
94 /* PageReserve flags */
95 #define PR_FIXED 0x00000008 /* don't move during PageReAllocate */
96 #define PR_4MEG 0x00000001 /* allocate on 4mb boundary */
97 #define PR_STATIC 0x00000010 /* see PageReserve documentation */
99 /* PageCommit default pager handle values */
100 #define PD_ZEROINIT 0x00000001 /* swappable zero-initialized pages */
101 #define PD_NOINIT 0x00000002 /* swappable uninitialized pages */
102 #define PD_FIXEDZERO 0x00000003 /* fixed zero-initialized pages */
103 #define PD_FIXED 0x00000004 /* fixed uninitialized pages */
105 /* PageCommit flags */
106 #define PC_FIXED 0x00000008 /* pages are permanently locked */
107 #define PC_LOCKED 0x00000080 /* pages are made present and locked */
108 #define PC_LOCKEDIFDP 0x00000100 /* pages are locked if swap via DOS */
109 #define PC_WRITEABLE 0x00020000 /* make the pages writeable */
110 #define PC_USER 0x00040000 /* make the pages ring 3 accessible */
111 #define PC_INCR 0x40000000 /* increment "pagerdata" each page */
112 #define PC_PRESENT 0x80000000 /* make pages initially present */
113 #define PC_STATIC 0x20000000 /* allow commit in PR_STATIC object */
114 #define PC_DIRTY 0x08000000 /* make pages initially dirty */
115 #define PC_CACHEDIS 0x00100000 /* Allocate uncached pages - new for WDM */
116 #define PC_CACHEWT 0x00080000 /* Allocate write through cache pages - new for WDM */
117 #define PC_PAGEFLUSH 0x00008000 /* Touch device mapped pages on alloc - new for WDM */
119 /* PageCommitContig additional flags */
120 #define PCC_ZEROINIT 0x00000001 /* zero-initialize new pages */
121 #define PCC_NOLIN 0x10000000 /* don't map to any linear address */
124 /* Pop a DWORD from the 32-bit stack */
125 static inline DWORD
stack32_pop( CONTEXT86
*context
)
127 DWORD ret
= *(DWORD
*)context
->Esp
;
128 context
->Esp
+= sizeof(DWORD
);
133 /***********************************************************************
134 * VxDCall (VMM.VXD.@)
136 DWORD WINAPI
VMM_VxDCall( DWORD service
, CONTEXT86
*context
)
140 switch ( LOWORD(service
) )
142 case 0x0000: /* PageReserve */
146 DWORD psize
= getpagesize();
147 ULONG page
= (ULONG
) stack32_pop( context
);
148 ULONG npages
= (ULONG
) stack32_pop( context
);
149 ULONG flags
= (ULONG
) stack32_pop( context
);
151 TRACE("PageReserve: page: %08lx, npages: %08lx, flags: %08lx partial stub!\n",
152 page
, npages
, flags
);
154 if ( page
== PR_SYSTEM
) {
155 ERR("Can't reserve ring 1 memory\n");
158 /* FIXME: This has to be handled separately for the separate
159 address-spaces we now have */
160 if ( page
== PR_PRIVATE
|| page
== PR_SHARED
) page
= 0;
161 /* FIXME: Handle flags in some way */
162 address
= (LPVOID
)(page
* psize
);
163 ret
= VirtualAlloc ( address
, ( npages
* psize
), MEM_RESERVE
, 0 );
164 TRACE("PageReserve: returning: %p\n", ret
);
171 case 0x0001: /* PageCommit */
176 DWORD psize
= getpagesize();
177 ULONG page
= (ULONG
) stack32_pop( context
);
178 ULONG npages
= (ULONG
) stack32_pop( context
);
179 ULONG hpd
= (ULONG
) stack32_pop( context
);
180 ULONG pagerdata
= (ULONG
) stack32_pop( context
);
181 ULONG flags
= (ULONG
) stack32_pop( context
);
183 TRACE("PageCommit: page: %08lx, npages: %08lx, hpd: %08lx pagerdata: "
184 "%08lx, flags: %08lx partial stub\n",
185 page
, npages
, hpd
, pagerdata
, flags
);
187 if ( flags
& PC_USER
)
188 if ( flags
& PC_WRITEABLE
)
189 virt_perm
= PAGE_EXECUTE_READWRITE
;
191 virt_perm
= PAGE_EXECUTE_READ
;
193 virt_perm
= PAGE_NOACCESS
;
195 address
= (LPVOID
)(page
* psize
);
196 ret
= VirtualAlloc ( address
, ( npages
* psize
), MEM_COMMIT
, virt_perm
);
197 TRACE("PageCommit: Returning: %p\n", ret
);
202 case 0x0002: /* PageDecommit */
206 DWORD psize
= getpagesize();
207 ULONG page
= (ULONG
) stack32_pop( context
);
208 ULONG npages
= (ULONG
) stack32_pop( context
);
209 ULONG flags
= (ULONG
) stack32_pop( context
);
211 TRACE("PageDecommit: page: %08lx, npages: %08lx, flags: %08lx partial stub\n",
212 page
, npages
, flags
);
213 address
= (LPVOID
)( page
* psize
);
214 ret
= VirtualFree ( address
, ( npages
* psize
), MEM_DECOMMIT
);
215 TRACE("PageDecommit: Returning: %s\n", ret
? "TRUE" : "FALSE" );
219 case 0x000d: /* PageModifyPermissions */
225 MEMORY_BASIC_INFORMATION mbi
;
227 DWORD psize
= getpagesize();
228 ULONG page
= stack32_pop ( context
);
229 ULONG npages
= stack32_pop ( context
);
230 ULONG permand
= stack32_pop ( context
);
231 ULONG permor
= stack32_pop ( context
);
233 TRACE("PageModifyPermissions %08lx %08lx %08lx %08lx partial stub\n",
234 page
, npages
, permand
, permor
);
235 address
= (LPVOID
)( page
* psize
);
237 VirtualQuery ( address
, &mbi
, sizeof ( MEMORY_BASIC_INFORMATION
));
238 virt_old_perm
= mbi
.Protect
;
240 switch ( virt_old_perm
& mbi
.Protect
) {
243 case PAGE_EXECUTE_READ
:
244 pg_old_perm
= PC_USER
;
248 case PAGE_EXECUTE_READWRITE
:
249 case PAGE_EXECUTE_WRITECOPY
:
250 pg_old_perm
= PC_USER
| PC_WRITEABLE
;
257 pg_new_perm
= pg_old_perm
;
258 pg_new_perm
&= permand
& ~PC_STATIC
;
259 pg_new_perm
|= permor
& ~PC_STATIC
;
261 virt_new_perm
= ( virt_old_perm
) & ~0xff;
262 if ( pg_new_perm
& PC_USER
)
264 if ( pg_new_perm
& PC_WRITEABLE
)
265 virt_new_perm
|= PAGE_EXECUTE_READWRITE
;
267 virt_new_perm
|= PAGE_EXECUTE_READ
;
270 if ( ! VirtualProtect ( address
, ( npages
* psize
), virt_new_perm
, &virt_old_perm
) ) {
271 ERR("Can't change page permissions for %p\n", address
);
274 TRACE("Returning: %08lx\n", pg_old_perm
);
278 case 0x000a: /* PageFree */
281 LPVOID hmem
= (LPVOID
) stack32_pop( context
);
282 DWORD flags
= (DWORD
) stack32_pop( context
);
284 TRACE("PageFree: hmem: %p, flags: %08lx partial stub\n",
287 ret
= VirtualFree ( hmem
, 0, MEM_RELEASE
);
288 TRACE("Returning: %d\n", ret
);
292 case 0x0011: /* RegOpenKey */
293 stack32_pop( context
); /* kkey */
294 stack32_pop( context
); /* lpszSubKey */
295 stack32_pop( context
); /* retkey */
296 /* return RegOpenKeyExA( hkey, lpszSubKey, 0, KEY_ALL_ACCESS, retkey ); */
299 ERR( "Using the native Win95 advapi32.dll is no longer supported.\n" );
300 ERR( "Please configure advapi32 to builtin.\n" );
303 return ERROR_CALL_NOT_IMPLEMENTED
;
305 case 0x0012: /* RegCreateKey */
306 stack32_pop( context
); /* hkey */
307 stack32_pop( context
); /* lpszSubKey */
308 stack32_pop( context
); /* retkey */
309 /* return RegCreateKeyA( hkey, lpszSubKey, retkey ); */
312 ERR( "Using the native Win95 advapi32.dll is no longer supported.\n" );
313 ERR( "Please configure advapi32 to builtin.\n" );
316 return ERROR_CALL_NOT_IMPLEMENTED
;
318 case 0x0013: /* RegCloseKey */
319 stack32_pop( context
); /* hkey */
320 /* return RegCloseKey( hkey ); */
321 return ERROR_CALL_NOT_IMPLEMENTED
;
323 case 0x0014: /* RegDeleteKey */
324 stack32_pop( context
); /* hkey */
325 stack32_pop( context
); /* lpszSubKey */
326 /* return RegDeleteKeyA( hkey, lpszSubKey ); */
327 return ERROR_CALL_NOT_IMPLEMENTED
;
329 case 0x0015: /* RegSetValue */
330 stack32_pop( context
); /* hkey */
331 stack32_pop( context
); /* lpszSubKey */
332 stack32_pop( context
); /* dwType */
333 stack32_pop( context
); /* lpszData */
334 stack32_pop( context
); /* cbData */
335 /* return RegSetValueA( hkey, lpszSubKey, dwType, lpszData, cbData ); */
336 return ERROR_CALL_NOT_IMPLEMENTED
;
338 case 0x0016: /* RegDeleteValue */
339 stack32_pop( context
); /* hkey */
340 stack32_pop( context
); /* lpszValue */
341 /* return RegDeleteValueA( hkey, lpszValue ); */
342 return ERROR_CALL_NOT_IMPLEMENTED
;
344 case 0x0017: /* RegQueryValue */
345 stack32_pop( context
); /* hkey */
346 stack32_pop( context
); /* lpszSubKey */
347 stack32_pop( context
); /* lpszData */
348 stack32_pop( context
); /* lpcbData */
349 /* return RegQueryValueA( hkey, lpszSubKey, lpszData, lpcbData ); */
350 return ERROR_CALL_NOT_IMPLEMENTED
;
352 case 0x0018: /* RegEnumKey */
353 stack32_pop( context
); /* hkey */
354 stack32_pop( context
); /* iSubkey */
355 stack32_pop( context
); /* lpszName */
356 stack32_pop( context
); /* lpcchName */
357 /* return RegEnumKeyA( hkey, iSubkey, lpszName, lpcchName ); */
358 return ERROR_CALL_NOT_IMPLEMENTED
;
360 case 0x0019: /* RegEnumValue */
361 stack32_pop( context
); /* hkey */
362 stack32_pop( context
); /* iValue */
363 stack32_pop( context
); /* lpszValue */
364 stack32_pop( context
); /* lpcchValue */
365 stack32_pop( context
); /* lpReserved */
366 stack32_pop( context
); /* lpdwType */
367 stack32_pop( context
); /* lpbData */
368 stack32_pop( context
); /* lpcbData */
369 /* return RegEnumValueA( hkey, iValue, lpszValue, lpcchValue, lpReserved, lpdwType, lpbData, lpcbData ); */
370 return ERROR_CALL_NOT_IMPLEMENTED
;
372 case 0x001A: /* RegQueryValueEx */
373 stack32_pop( context
); /* hkey */
374 stack32_pop( context
); /* lpszValue */
375 stack32_pop( context
); /* lpReserved */
376 stack32_pop( context
); /* lpdwType */
377 stack32_pop( context
); /* lpbData */
378 stack32_pop( context
); /* lpcbData */
379 /* return RegQueryValueExA( hkey, lpszValue, lpReserved, lpdwType, lpbData, lpcbData ); */
380 return ERROR_CALL_NOT_IMPLEMENTED
;
382 case 0x001B: /* RegSetValueEx */
383 stack32_pop( context
); /* hkey */
384 stack32_pop( context
); /* lpszValue */
385 stack32_pop( context
); /* dwReserved */
386 stack32_pop( context
); /* dwType */
387 stack32_pop( context
); /* lpbData */
388 stack32_pop( context
); /* cbData */
389 /* return RegSetValueExA( hkey, lpszValue, dwReserved, dwType, lpbData, cbData ); */
390 return ERROR_CALL_NOT_IMPLEMENTED
;
392 case 0x001C: /* RegFlushKey */
393 stack32_pop( context
); /* hkey */
394 /* return RegFlushKey( hkey ); */
395 return ERROR_CALL_NOT_IMPLEMENTED
;
397 case 0x001D: /* RegQueryInfoKey */
398 /* NOTE: This VxDCall takes only a subset of the parameters that the
399 corresponding Win32 API call does. The implementation in Win95
400 ADVAPI32 sets all output parameters not mentioned here to zero. */
401 stack32_pop( context
); /* hkey */
402 stack32_pop( context
); /* lpcSubKeys */
403 stack32_pop( context
); /* lpcchMaxSubKey */
404 stack32_pop( context
); /* lpcValues */
405 stack32_pop( context
); /* lpcchMaxValueName */
406 stack32_pop( context
); /* lpcchMaxValueData */
407 /* return RegQueryInfoKeyA( hkey, lpcSubKeys, lpcchMaxSubKey, lpcValues, lpcchMaxValueName, lpcchMaxValueData ); */
408 return ERROR_CALL_NOT_IMPLEMENTED
;
410 case 0x001e: /* GetDemandPageInfo */
412 DWORD dinfo
= (DWORD
)stack32_pop( context
);
413 DWORD flags
= (DWORD
)stack32_pop( context
);
415 /* GetDemandPageInfo is supposed to fill out the struct at
416 * "dinfo" with various low-level memory management information.
417 * Apps are certainly not supposed to call this, although it's
418 * demoed and documented by Pietrek on pages 441-443 of "Windows
419 * 95 System Programming Secrets" if any program needs a real
420 * implementation of this.
423 FIXME("GetDemandPageInfo(%08lx %08lx): stub!\n", dinfo
, flags
);
428 case 0x0021: /* RegLoadKey */
430 HKEY hkey
= (HKEY
) stack32_pop( context
);
431 LPCSTR lpszSubKey
= (LPCSTR
)stack32_pop( context
);
432 LPCSTR lpszFile
= (LPCSTR
)stack32_pop( context
);
433 FIXME("RegLoadKey(%p,%s,%s): stub\n",hkey
, debugstr_a(lpszSubKey
), debugstr_a(lpszFile
));
434 return ERROR_CALL_NOT_IMPLEMENTED
;
437 case 0x0022: /* RegUnLoadKey */
439 HKEY hkey
= (HKEY
) stack32_pop( context
);
440 LPCSTR lpszSubKey
= (LPCSTR
)stack32_pop( context
);
441 FIXME("RegUnLoadKey(%p,%s): stub\n",hkey
, debugstr_a(lpszSubKey
));
442 return ERROR_CALL_NOT_IMPLEMENTED
;
445 case 0x0023: /* RegSaveKey */
447 HKEY hkey
= (HKEY
) stack32_pop( context
);
448 LPCSTR lpszFile
= (LPCSTR
)stack32_pop( context
);
449 LPSECURITY_ATTRIBUTES sa
= (LPSECURITY_ATTRIBUTES
)stack32_pop( context
);
450 FIXME("RegSaveKey(%p,%s,%p): stub\n",hkey
, debugstr_a(lpszFile
),sa
);
451 return ERROR_CALL_NOT_IMPLEMENTED
;
454 #if 0 /* Functions are not yet implemented in misc/registry.c */
455 case 0x0024: /* RegRemapPreDefKey */
456 case 0x0026: /* RegQueryMultipleValues */
459 case 0x0027: /* RegReplaceKey */
461 HKEY hkey
= (HKEY
) stack32_pop( context
);
462 LPCSTR lpszSubKey
= (LPCSTR
)stack32_pop( context
);
463 LPCSTR lpszNewFile
= (LPCSTR
)stack32_pop( context
);
464 LPCSTR lpszOldFile
= (LPCSTR
)stack32_pop( context
);
465 FIXME("RegReplaceKey(%p,%s,%s,%s): stub\n", hkey
, debugstr_a(lpszSubKey
),
466 debugstr_a(lpszNewFile
),debugstr_a(lpszOldFile
));
467 return ERROR_CALL_NOT_IMPLEMENTED
;
471 if (LOWORD(service
) < N_VMM_SERVICE
)
472 FIXME( "Unimplemented service %s (%08lx)\n",
473 VMM_Service_Name
[LOWORD(service
)], service
);
475 FIXME( "Unknown service %08lx\n", service
);
476 return 0xffffffff; /* FIXME */