Commit 0d7a572a095 for php
commit 0d7a572a095b2cc8ee5efaf0ea975114cde31509
Author: Ostap Brehin <osbre@protonmail.com>
Date: Sat Nov 21 11:53:30 2026 +0000
Zend: 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.
Close GH-25643
diff --git a/NEWS b/NEWS
index dd7e8988250..f8f4bd9e633 100644
--- a/NEWS
+++ b/NEWS
@@ -31,6 +31,8 @@ PHP NEWS
(Nicolas Grekas)
. Fixed stack limit on OpenBSD threads other than the main one.
(Ostap Brehin)
+ . Fixed stack limit fallback on FreeBSD threads other than the main one.
+ (Ostap Brehin)
- Curl:
. Fixed curl_reset() retaining CURLOPT_PRIVATE after reset. (lacatoire)
diff --git a/Zend/zend_call_stack.h b/Zend/zend_call_stack.h
index 566634deeb6..62629e0fd63 100644
--- a/Zend/zend_call_stack.h
+++ b/Zend/zend_call_stack.h
@@ -27,6 +27,9 @@
#ifdef __APPLE__
# include <pthread.h>
#endif
+#ifdef __FreeBSD__
+# include <pthread_np.h>
+#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__)