Module: wine Branch: master Commit: 3ac808e46e4795e14c5b999aa39fd9cd15f95279 URL: https://gitlab.winehq.org/wine/wine/-/commit/3ac808e46e4795e14c5b999aa39fd9c...
Author: Alexandre Julliard julliard@winehq.org Date: Wed Aug 16 13:48:43 2023 +0200
ntdll: Set Wow64 user space limit based on LARGE_ADDRESS_AWARE.
Based on a patch by Billy Laws.
---
dlls/ntdll/unix/env.c | 1 + dlls/ntdll/unix/thread.c | 2 +- dlls/ntdll/unix/unix_private.h | 3 ++- dlls/ntdll/unix/virtual.c | 7 +++---- 4 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/dlls/ntdll/unix/env.c b/dlls/ntdll/unix/env.c index 8aa41aba183..9cd71e4b020 100644 --- a/dlls/ntdll/unix/env.c +++ b/dlls/ntdll/unix/env.c @@ -1864,6 +1864,7 @@ static void init_peb( RTL_USER_PROCESS_PARAMETERS *params, void *module ) NtCurrentTeb()->WowTebOffset = teb_offset; NtCurrentTeb()->Tib.ExceptionList = (void *)((char *)NtCurrentTeb() + teb_offset); wow_peb = (PEB32 *)((char *)peb + page_size); + user_space_wow_limit = ((main_image_info.ImageCharacteristics & IMAGE_FILE_LARGE_ADDRESS_AWARE) ? limit_4g : limit_2g) - 1; set_thread_id( NtCurrentTeb(), GetCurrentProcessId(), GetCurrentThreadId() ); ERR( "starting %s in experimental wow64 mode\n", debugstr_us(¶ms->ImagePathName) ); break; diff --git a/dlls/ntdll/unix/thread.c b/dlls/ntdll/unix/thread.c index d312ed6a066..0c433fef4c2 100644 --- a/dlls/ntdll/unix/thread.c +++ b/dlls/ntdll/unix/thread.c @@ -1201,7 +1201,7 @@ NTSTATUS init_thread_stack( TEB *teb, ULONG_PTR limit, SIZE_T reserve_size, SIZE teb->DeallocationStack = stack.DeallocationStack;
/* 32-bit stack */ - if (!limit || limit >= limit_2g) limit = limit_2g - 1; + if (!limit || limit > user_space_wow_limit) limit = user_space_wow_limit; if ((status = virtual_alloc_thread_stack( &stack, 0, limit, reserve_size, commit_size, TRUE ))) return status; wow_teb->Tib.StackBase = PtrToUlong( stack.StackBase ); diff --git a/dlls/ntdll/unix/unix_private.h b/dlls/ntdll/unix/unix_private.h index 6862d74b863..701ff58b066 100644 --- a/dlls/ntdll/unix/unix_private.h +++ b/dlls/ntdll/unix/unix_private.h @@ -63,6 +63,7 @@ static inline TEB64 *NtCurrentTeb64(void) { return (TEB64 *)NtCurrentTeb()->GdiB #endif
extern WOW_PEB *wow_peb DECLSPEC_HIDDEN; +extern ULONG_PTR user_space_wow_limit DECLSPEC_HIDDEN;
static inline WOW_TEB *get_wow_teb( TEB *teb ) { @@ -516,7 +517,7 @@ static inline NTSTATUS map_section( HANDLE mapping, void **ptr, SIZE_T *size, UL { *ptr = NULL; *size = 0; - return NtMapViewOfSection( mapping, NtCurrentProcess(), ptr, is_win64 && wow_peb ? limit_2g - 1 : 0, + return NtMapViewOfSection( mapping, NtCurrentProcess(), ptr, user_space_wow_limit, 0, NULL, size, ViewShare, 0, protect ); }
diff --git a/dlls/ntdll/unix/virtual.c b/dlls/ntdll/unix/virtual.c index 62fc1c9dd1f..897c92b6349 100644 --- a/dlls/ntdll/unix/virtual.c +++ b/dlls/ntdll/unix/virtual.c @@ -181,6 +181,7 @@ static void *working_set_limit = (void *)0x7fff0000;
static struct file_view *arm64ec_view;
+ULONG_PTR user_space_wow_limit = 0; struct _KUSER_SHARED_DATA *user_shared_data = (void *)0x7ffe0000;
/* TEB allocation blocks */ @@ -568,8 +569,7 @@ static void mmap_init( const struct preload_info *preload_info ) static void *get_wow_user_space_limit(void) { #ifdef _WIN64 - if (main_image_info.ImageCharacteristics & IMAGE_FILE_LARGE_ADDRESS_AWARE) return (void *)0xffff0000; - return (void *)0x7fff0000; + return (void *)(user_space_wow_limit & ~granularity_mask); #endif return user_space_limit; } @@ -3422,8 +3422,7 @@ NTSTATUS virtual_alloc_teb( TEB **ret_teb ) { SIZE_T total = 32 * block_size;
- if ((status = NtAllocateVirtualMemory( NtCurrentProcess(), &ptr, - is_win64 && is_wow64() ? limit_2g - 1 : 0, + if ((status = NtAllocateVirtualMemory( NtCurrentProcess(), &ptr, user_space_wow_limit, &total, MEM_RESERVE, PAGE_READWRITE ))) { server_leave_uninterrupted_section( &virtual_mutex, &sigset );