Commit 3ac808e4 authored by Alexandre Julliard's avatar Alexandre Julliard

ntdll: Set Wow64 user space limit based on LARGE_ADDRESS_AWARE.

Based on a patch by Billy Laws.
parent 5f1b91e5
......@@ -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(&params->ImagePathName) );
break;
......
......@@ -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 );
......
......@@ -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 );
}
......
......@@ -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 );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment