Module: wine Branch: master Commit: a82238fad52761114ab2488d422fad3f70dbb854 URL: https://gitlab.winehq.org/wine/wine/-/commit/a82238fad52761114ab2488d422fad3...
Author: Alexandre Julliard julliard@winehq.org Date: Tue Jun 13 12:17:32 2023 +0200
ntdll: Allocate 64-bit and kernel stacks in high memory.
---
dlls/ntdll/unix/thread.c | 8 ++++---- dlls/ntdll/unix/unix_private.h | 5 ++++- dlls/ntdll/unix/virtual.c | 5 +++-- 3 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/dlls/ntdll/unix/thread.c b/dlls/ntdll/unix/thread.c index e821fa680ce..d312ed6a066 100644 --- a/dlls/ntdll/unix/thread.c +++ b/dlls/ntdll/unix/thread.c @@ -1180,7 +1180,7 @@ NTSTATUS init_thread_stack( TEB *teb, ULONG_PTR limit, SIZE_T reserve_size, SIZE NTSTATUS status;
/* kernel stack */ - if ((status = virtual_alloc_thread_stack( &stack, 0, 0, kernel_stack_size, kernel_stack_size, FALSE ))) + if ((status = virtual_alloc_thread_stack( &stack, limit_4g, 0, kernel_stack_size, kernel_stack_size, FALSE ))) return status; thread_data->kernel_stack = stack.DeallocationStack;
@@ -1191,7 +1191,7 @@ NTSTATUS init_thread_stack( TEB *teb, ULONG_PTR limit, SIZE_T reserve_size, SIZE ((get_machine_context_size( main_image_info.Machine ) + 7) & ~7) + sizeof(ULONG64);
/* 64-bit stack */ - if ((status = virtual_alloc_thread_stack( &stack, 0, 0, 0x40000, 0x40000, TRUE ))) return status; + if ((status = virtual_alloc_thread_stack( &stack, limit_4g, 0, 0x40000, 0x40000, TRUE ))) return status; cpu = (WOW64_CPURESERVED *)(((ULONG_PTR)stack.StackBase - cpusize) & ~15); cpu->Machine = main_image_info.Machine;
@@ -1201,8 +1201,8 @@ NTSTATUS init_thread_stack( TEB *teb, ULONG_PTR limit, SIZE_T reserve_size, SIZE teb->DeallocationStack = stack.DeallocationStack;
/* 32-bit stack */ - if ((status = virtual_alloc_thread_stack( &stack, 0, limit ? limit : 0x7fffffff, - reserve_size, commit_size, TRUE ))) + if (!limit || limit >= limit_2g) limit = limit_2g - 1; + if ((status = virtual_alloc_thread_stack( &stack, 0, limit, reserve_size, commit_size, TRUE ))) return status; wow_teb->Tib.StackBase = PtrToUlong( stack.StackBase ); wow_teb->Tib.StackLimit = PtrToUlong( stack.StackLimit ); diff --git a/dlls/ntdll/unix/unix_private.h b/dlls/ntdll/unix/unix_private.h index b7ea96bb20a..1f49d957e0d 100644 --- a/dlls/ntdll/unix/unix_private.h +++ b/dlls/ntdll/unix/unix_private.h @@ -44,6 +44,9 @@ extern WORD native_machine DECLSPEC_HIDDEN;
static const BOOL is_win64 = (sizeof(void *) > sizeof(int));
+static const ULONG_PTR limit_2g = (ULONG_PTR)1 << 31; +static const ULONG_PTR limit_4g = (ULONG_PTR)((ULONGLONG)1 << 32); + static inline BOOL is_machine_64bit( WORD machine ) { return (machine == IMAGE_FILE_MACHINE_AMD64 || machine == IMAGE_FILE_MACHINE_ARM64); @@ -513,7 +516,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 ? 0x7fffffff : 0, + return NtMapViewOfSection( mapping, NtCurrentProcess(), ptr, is_win64 && wow_peb ? limit_2g - 1 : 0, 0, NULL, size, ViewShare, 0, protect ); }
diff --git a/dlls/ntdll/unix/virtual.c b/dlls/ntdll/unix/virtual.c index a7f4d7412e5..b062ac5038a 100644 --- a/dlls/ntdll/unix/virtual.c +++ b/dlls/ntdll/unix/virtual.c @@ -3352,7 +3352,7 @@ TEB *virtual_alloc_first_teb(void) exit(1); }
- NtAllocateVirtualMemory( NtCurrentProcess(), &teb_block, is_win64 ? 0x7fffffff : 0, &total, + NtAllocateVirtualMemory( NtCurrentProcess(), &teb_block, is_win64 ? limit_2g - 1 : 0, &total, MEM_RESERVE | MEM_TOP_DOWN, PAGE_READWRITE ); teb_block_pos = 30; ptr = (char *)teb_block + 30 * block_size; @@ -3390,7 +3390,8 @@ NTSTATUS virtual_alloc_teb( TEB **ret_teb ) { SIZE_T total = 32 * block_size;
- if ((status = NtAllocateVirtualMemory( NtCurrentProcess(), &ptr, is_win64 && is_wow64() ? 0x7fffffff : 0, + if ((status = NtAllocateVirtualMemory( NtCurrentProcess(), &ptr, + is_win64 && is_wow64() ? limit_2g - 1 : 0, &total, MEM_RESERVE, PAGE_READWRITE ))) { server_leave_uninterrupted_section( &virtual_mutex, &sigset );