Skip to content

Commit 8165853

Browse files
committed
zend call stack fixing stack limit for macOs arm64.
8MB sounded a prudent size for older 10.9 macOs release, however with newer mac with arm64, it triggers a stack overflow.
1 parent fa02793 commit 8165853

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

Zend/tests/stack_limit/stack_limit_010.phpt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ $stack = zend_test_zend_call_stack_get();
1515
var_dump($stack);
1616

1717
$expectedMaxSize = match(php_uname('s')) {
18-
'Darwin' => 8*1024*1024,
18+
'Darwin' => match(php_uname('m')) {
19+
'x86_64' => 8*1024*1024,
20+
'arm64' => 8372224,
21+
},
1922
'FreeBSD' => match(php_uname('m')) {
2023
'amd64' => 512*1024*1024 - 4096,
2124
'i386' => 64*1024*1024 - 4096,

Zend/zend_call_stack.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ static bool zend_call_stack_get_macos(zend_call_stack *stack)
428428
size_t max_size;
429429

430430
if (pthread_main_np()) {
431+
#if !defined(__aarch64__)
431432
/* pthread_get_stacksize_np() returns a too low value for the main
432433
* thread in OSX 10.9, 10.10:
433434
* https://mail.openjdk.org/pipermail/hotspot-dev/2013-October/011353.html
@@ -437,6 +438,9 @@ static bool zend_call_stack_get_macos(zend_call_stack *stack)
437438
/* Stack size is 8MiB by default for main threads
438439
* https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Multithreading/CreatingThreads/CreatingThreads.html */
439440
max_size = 8 * 1024 * 1024;
441+
#else
442+
max_size = pthread_get_stacksize_np(pthread_self());
443+
#endif
440444
} else {
441445
max_size = pthread_get_stacksize_np(pthread_self());
442446
}

0 commit comments

Comments
 (0)