From e0fedddd5756a89abfb5108208a6ae18e75d881a Mon Sep 17 00:00:00 2001 From: Ostap Brehin Date: Sat, 21 Nov 2026 11:53:30 +0000 Subject: [PATCH] Fix stack limit fallback on FreeBSD threads libthr gives threads a 2 MiB stack on 64-bit (1 MiB on 32-bit), not 4 MiB, therefore the fallback limit was past the end of the stack. --- Zend/zend_call_stack.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Zend/zend_call_stack.h b/Zend/zend_call_stack.h index 566634deeb68..62629e0fd639 100644 --- a/Zend/zend_call_stack.h +++ b/Zend/zend_call_stack.h @@ -27,6 +27,9 @@ #ifdef __APPLE__ # include #endif +#ifdef __FreeBSD__ +# include +#endif #ifdef ZEND_CHECK_STACK_LIMIT @@ -76,7 +79,14 @@ static inline size_t zend_call_stack_default_size(void) #ifdef __linux__ return 8 * 1024 * 1024; #endif -#if defined(__FreeBSD__) || defined(__NetBSD__) +#ifdef __FreeBSD__ + // libthr: THR_STACK_DEFAULT in lib/libthr/thread/thr_private.h + if (pthread_main_np() == 0) { + return sizeof(void *) / 4 * 1024 * 1024; + } + return 4 * 1024 * 1024; +#endif +#ifdef __NetBSD__ return 4 * 1024 * 1024; #endif #if defined(__DragonFly__)