Commit a82238fa authored by Alexandre Julliard's avatar Alexandre Julliard

ntdll: Allocate 64-bit and kernel stacks in high memory.

parent 11cd5113
......@@ -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 );
......
......@@ -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 );
}
......
......@@ -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 );
......
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