|
24 | 24 | #include "zend_call_stack.h"
|
25 | 25 | #include <stdint.h>
|
26 | 26 | #ifdef ZEND_WIN32
|
27 |
| -# include <winnt.h> |
28 |
| -# include <memoryapi.h> |
| 27 | +# include <processthreadsapi.h> |
29 | 28 | #else /* ZEND_WIN32 */
|
30 | 29 | # include <sys/resource.h>
|
31 | 30 | # ifdef HAVE_UNISTD_H
|
@@ -331,35 +330,16 @@ static bool zend_call_stack_get_freebsd(zend_call_stack *stack)
|
331 | 330 | #ifdef ZEND_WIN32
|
332 | 331 | static bool zend_call_stack_get_win32(zend_call_stack *stack)
|
333 | 332 | {
|
334 |
| - MEMORY_BASIC_INFORMATION stack_info; |
335 |
| - int8_t *base; |
| 333 | + ULONG_PTR low, high; |
| 334 | + GetCurrentThreadStackLimits(&low, &high); |
336 | 335 |
|
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; |
355 | 338 |
|
356 | 339 | // Last pages are not usable
|
357 | 340 | // 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; |
363 | 343 |
|
364 | 344 | return true;
|
365 | 345 | }
|
|
0 commit comments