From 149e7502400e24d27fe3f9159d2a936af71c7a19 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Sat, 30 Jul 2022 02:51:49 +0200 Subject: [PATCH] win32u: Support wow64 in NtAllocateVirtualMemory calls. --- dlls/win32u/dc.c | 4 ++-- dlls/win32u/dib.c | 4 ++-- dlls/win32u/gdiobj.c | 4 ++-- dlls/win32u/win32u_private.h | 9 +++++++++ 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/dlls/win32u/dc.c b/dlls/win32u/dc.c index 131927a4707..a8c651dd28f 100644 --- a/dlls/win32u/dc.c +++ b/dlls/win32u/dc.c @@ -112,8 +112,8 @@ static DC_ATTR *alloc_dc_attr(void) { SIZE_T size = system_info.AllocationGranularity; bucket->entries = NULL; - if (!NtAllocateVirtualMemory( GetCurrentProcess(), (void **)&bucket->entries, 0, &size, - MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE )) + if (!NtAllocateVirtualMemory( GetCurrentProcess(), (void **)&bucket->entries, zero_bits(), + &size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE )) { bucket->next_free = NULL; bucket->next_unused = bucket->entries + 1; diff --git a/dlls/win32u/dib.c b/dlls/win32u/dib.c index 7a6df3da7cc..e7a5a50e201 100644 --- a/dlls/win32u/dib.c +++ b/dlls/win32u/dib.c @@ -1548,8 +1548,8 @@ HBITMAP WINAPI NtGdiCreateDIBSection( HDC hdc, HANDLE section, DWORD offset, con { SIZE_T size = bmp->dib.dsBmih.biSizeImage; offset = 0; - if (NtAllocateVirtualMemory( GetCurrentProcess(), &bmp->dib.dsBm.bmBits, 0, &size, - MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE )) + if (NtAllocateVirtualMemory( GetCurrentProcess(), &bmp->dib.dsBm.bmBits, zero_bits(), + &size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE )) goto error; } bmp->dib.dshSection = section; diff --git a/dlls/win32u/gdiobj.c b/dlls/win32u/gdiobj.c index aaeed2ba676..e42d076bc5b 100644 --- a/dlls/win32u/gdiobj.c +++ b/dlls/win32u/gdiobj.c @@ -566,8 +566,8 @@ static void init_gdi_shared(void) { SIZE_T size = sizeof(*gdi_shared); - if (NtAllocateVirtualMemory( GetCurrentProcess(), (void **)&gdi_shared, 0, &size, - MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE )) + if (NtAllocateVirtualMemory( GetCurrentProcess(), (void **)&gdi_shared, zero_bits(), + &size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE )) return; next_unused = gdi_shared->Handles + FIRST_GDI_HANDLE; diff --git a/dlls/win32u/win32u_private.h b/dlls/win32u/win32u_private.h index d4b86d1e6a9..6d492f2e73b 100644 --- a/dlls/win32u/win32u_private.h +++ b/dlls/win32u/win32u_private.h @@ -494,6 +494,15 @@ static inline BOOL is_win9x(void) return NtCurrentTeb()->Peb->OSPlatformId == VER_PLATFORM_WIN32s; } +static inline ULONG_PTR zero_bits(void) +{ +#ifdef _WIN64 + return !NtCurrentTeb()->WowTebOffset ? 0 : 0x7fffffff; +#else + return 0; +#endif +} + static inline const char *debugstr_us( const UNICODE_STRING *us ) { if (!us) return ""; -- 2.11.4.GIT