Skip to content

Commit 04cd85a

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 04cd85a

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,16 @@ static bool zend_call_stack_get_macos(zend_call_stack *stack)
427427
void *base = pthread_get_stackaddr_np(pthread_self());
428428
size_t max_size;
429429

430+
// TODO it seems it is just a bug of pthread_get_stacksize_np on earlier
431+
// macOs releases which had been fixed since, we might able to drop
432+
// the hardcoded part altogether for PHP 9 ?
433+
#if defined(__aarch64__)
434+
/*
435+
* 8 mb for the main thread triggers a stack overflow.
436+
* instead we derive it from pthread_get_stacksize_np.
437+
*/
438+
max_size = pthread_get_stacksize_np(pthread_self());
439+
#else
430440
if (pthread_main_np()) {
431441
/* pthread_get_stacksize_np() returns a too low value for the main
432442
* thread in OSX 10.9, 10.10:
@@ -440,6 +450,7 @@ static bool zend_call_stack_get_macos(zend_call_stack *stack)
440450
} else {
441451
max_size = pthread_get_stacksize_np(pthread_self());
442452
}
453+
#endif
443454

444455
stack->base = base;
445456
stack->max_size = max_size;

0 commit comments

Comments
 (0)