[php-src] PHP-8.5: Zend: Fix stack limit fallback on FreeBSD threads
| From: | Ostap Brehin via David Carlier | Date: | Sat, 21 Nov 2026 14:10:54 +0000 |
| Subject: | [php-src] PHP-8.5: Zend: Fix stack limit fallback on FreeBSD threads | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-144002@lists.php.net to get a copy of this message | ||
Author: Ostap Brehin (osbre)
Committer: David Carlier (devnexen)
Date: 2026-11-21T14:08:28Z
Commit: https://github.com/php/php-src/commit/0d7a572a095b2cc8ee5efaf0ea975114cde31509
Raw diff: https://github.com/php/php-src/commit/0d7a572a095b2cc8ee5efaf0ea975114cde31509.diff
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
Changed paths:
M NEWS
M Zend/zend_call_stack.h
Diff:
diff --git a/NEWS b/NEWS
index dd7e89882509..f8f4bd9e6331 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 566634deeb68..62629e0fd639 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__)