Skip to content

Commit 044e4fe

Browse files
committed
Use GetCurrentThreadStackLimits()
1 parent 0dde863 commit 044e4fe

File tree

2 files changed

+8
-28
lines changed

2 files changed

+8
-28
lines changed

Zend/tests/stack_limit_010.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ $expectedMaxSize = match(php_uname('s')) {
2020
'i386' => 64*1024*1024 - 4096,
2121
},
2222
'Linux' => 8*1024*1024,
23-
'Windows' => 67108864 - 4*4096, // Set by sapi/cli/config.w32
23+
'Windows NT' => 67108864 - 4*4096, // Set by sapi/cli/config.w32
2424
};
2525

2626
printf("Expected max_size: 0x%x\n", $expectedMaxSize);

Zend/zend_call_stack.c

+7-27
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
#include "zend_call_stack.h"
2525
#include <stdint.h>
2626
#ifdef ZEND_WIN32
27-
# include <winnt.h>
28-
# include <memoryapi.h>
27+
# include <processthreadsapi.h>
2928
#else /* ZEND_WIN32 */
3029
# include <sys/resource.h>
3130
# ifdef HAVE_UNISTD_H
@@ -331,35 +330,16 @@ static bool zend_call_stack_get_freebsd(zend_call_stack *stack)
331330
#ifdef ZEND_WIN32
332331
static bool zend_call_stack_get_win32(zend_call_stack *stack)
333332
{
334-
MEMORY_BASIC_INFORMATION stack_info;
335-
int8_t *base;
333+
ULONG_PTR low, high;
334+
GetCurrentThreadStackLimits(&low, &high);
336335

337-
#ifdef _M_ARM64
338-
return false;
339-
#endif
340-
341-
#ifdef _M_X64
342-
base = (void*)((NT_TIB64*)NtCurrentTeb())->StackBase;
343-
#else
344-
base = (void*)((NT_TIB*)NtCurrentTeb())->StackBase;
345-
#endif
346-
347-
memset(&stack_info, 0, sizeof(MEMORY_BASIC_INFORMATION));
348-
size_t result_size = VirtualQuery(&stack_info, &stack_info, sizeof(MEMORY_BASIC_INFORMATION));
349-
ZEND_ASSERT(result_size >= sizeof(MEMORY_BASIC_INFORMATION));
350-
351-
int8_t* end = (int8_t*)stack_info.AllocationBase;
352-
ZEND_ASSERT(base > end);
353-
354-
size_t max_size = (size_t)(base - end);
336+
stack->base = (void*)high;
337+
stack->max_size = (uintptr_t)high - (uintptr_t)low;
355338

356339
// Last pages are not usable
357340
// http://blogs.msdn.com/b/satyem/archive/2012/08/13/thread-s-stack-memory-management.aspx
358-
ZEND_ASSERT(max_size > 4*4096);
359-
max_size -= 4*4096;
360-
361-
stack->base = base;
362-
stack->max_size = max_size;
341+
ZEND_ASSERT(stack->max_size > 4*4096);
342+
stack->max_size -= 4*4096;
363343

364344
return true;
365345
}

0 commit comments

Comments
 (0)