kernel32: Allow to pass NULL as old protection in VirtualProtect for Win9x compatibility.

Sebastian Lackner sebastian at fds-team.de
Mon Feb 15 23:53:14 CST 2016


From: Michael Müller <michael at fds-team.de>

Signed-off-by: Michael Müller <michael at fds-team.de>
Signed-off-by: Sebastian Lackner <sebastian at fds-team.de>
---

Manually tested in a VM, some ancient applications depend on that.

 dlls/kernel32/virtual.c |    8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/dlls/kernel32/virtual.c b/dlls/kernel32/virtual.c
index 03ef38c..4bfc6cc 100644
--- a/dlls/kernel32/virtual.c
+++ b/dlls/kernel32/virtual.c
@@ -235,7 +235,13 @@ BOOL WINAPI VirtualProtect( LPVOID addr, SIZE_T size, DWORD new_prot, LPDWORD ol
 BOOL WINAPI VirtualProtectEx( HANDLE process, LPVOID addr, SIZE_T size,
     DWORD new_prot, LPDWORD old_prot )
 {
-    NTSTATUS status = NtProtectVirtualMemory( process, &addr, &size, new_prot, old_prot );
+    NTSTATUS status;
+    DWORD prot;
+
+    /* Win9x allows to pass NULL as old_prot while it fails on NT */
+    if (!old_prot && (GetVersion() & 0x80000000)) old_prot = &prot;
+
+    status = NtProtectVirtualMemory( process, &addr, &size, new_prot, old_prot );
     if (status) SetLastError( RtlNtStatusToDosError(status) );
     return !status;
 }
-- 
2.7.1



More information about the wine-patches mailing list