From 044e4fe3c87a8a051fa650aa95fb48d4cafa5810 Mon Sep 17 00:00:00 2001 From: Arnaud Le Blanc Date: Sat, 3 Dec 2022 12:49:47 +0100 Subject: [PATCH] Use GetCurrentThreadStackLimits() --- Zend/tests/stack_limit_010.phpt | 2 +- Zend/zend_call_stack.c | 34 +++++++-------------------------- 2 files changed, 8 insertions(+), 28 deletions(-) diff --git a/Zend/tests/stack_limit_010.phpt b/Zend/tests/stack_limit_010.phpt index 36bb8bb0e0741..a4ca3fd17a2d1 100644 --- a/Zend/tests/stack_limit_010.phpt +++ b/Zend/tests/stack_limit_010.phpt @@ -20,7 +20,7 @@ $expectedMaxSize = match(php_uname('s')) { 'i386' => 64*1024*1024 - 4096, }, 'Linux' => 8*1024*1024, - 'Windows' => 67108864 - 4*4096, // Set by sapi/cli/config.w32 + 'Windows NT' => 67108864 - 4*4096, // Set by sapi/cli/config.w32 }; printf("Expected max_size: 0x%x\n", $expectedMaxSize); diff --git a/Zend/zend_call_stack.c b/Zend/zend_call_stack.c index f77773319b5e8..6b5a3d679a59d 100644 --- a/Zend/zend_call_stack.c +++ b/Zend/zend_call_stack.c @@ -24,8 +24,7 @@ #include "zend_call_stack.h" #include #ifdef ZEND_WIN32 -# include -# include +# include #else /* ZEND_WIN32 */ # include # ifdef HAVE_UNISTD_H @@ -331,35 +330,16 @@ static bool zend_call_stack_get_freebsd(zend_call_stack *stack) #ifdef ZEND_WIN32 static bool zend_call_stack_get_win32(zend_call_stack *stack) { - MEMORY_BASIC_INFORMATION stack_info; - int8_t *base; + ULONG_PTR low, high; + GetCurrentThreadStackLimits(&low, &high); -#ifdef _M_ARM64 - return false; -#endif - -#ifdef _M_X64 - base = (void*)((NT_TIB64*)NtCurrentTeb())->StackBase; -#else - base = (void*)((NT_TIB*)NtCurrentTeb())->StackBase; -#endif - - memset(&stack_info, 0, sizeof(MEMORY_BASIC_INFORMATION)); - size_t result_size = VirtualQuery(&stack_info, &stack_info, sizeof(MEMORY_BASIC_INFORMATION)); - ZEND_ASSERT(result_size >= sizeof(MEMORY_BASIC_INFORMATION)); - - int8_t* end = (int8_t*)stack_info.AllocationBase; - ZEND_ASSERT(base > end); - - size_t max_size = (size_t)(base - end); + stack->base = (void*)high; + stack->max_size = (uintptr_t)high - (uintptr_t)low; // Last pages are not usable // http://blogs.msdn.com/b/satyem/archive/2012/08/13/thread-s-stack-memory-management.aspx - ZEND_ASSERT(max_size > 4*4096); - max_size -= 4*4096; - - stack->base = base; - stack->max_size = max_size; + ZEND_ASSERT(stack->max_size > 4*4096); + stack->max_size -= 4*4096; return true; }