Skip to content

Commit b320aab

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. close GH-13319
1 parent ce2d263 commit b320aab

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ PHP NEWS
1212
. Fixed bug GH-13178 (Iterator positions incorrect when converting packed
1313
array to hashed). (ilutov)
1414
. Fixed zend fiber build for solaris default mode (32 bits). (David Carlier)
15+
. Fixed zend call stack size for macOs/arm64. (David Carlier)
1516

1617
- Curl:
1718
. Deprecated the CURLOPT_BINARYTRANSFER constant. (divinity76)

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: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,9 @@ 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-
if (pthread_main_np()) {
430+
#if !defined(__aarch64__)
431+
if (pthread_main_np())
432+
{
431433
/* pthread_get_stacksize_np() returns a too low value for the main
432434
* thread in OSX 10.9, 10.10:
433435
* https://mail.openjdk.org/pipermail/hotspot-dev/2013-October/011353.html
@@ -437,7 +439,10 @@ static bool zend_call_stack_get_macos(zend_call_stack *stack)
437439
/* Stack size is 8MiB by default for main threads
438440
* https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Multithreading/CreatingThreads/CreatingThreads.html */
439441
max_size = 8 * 1024 * 1024;
440-
} else {
442+
}
443+
else
444+
#endif
445+
{
441446
max_size = pthread_get_stacksize_np(pthread_self());
442447
}
443448

0 commit comments

Comments
 (0)