[php-src] PR #25643: Fix stack limit fallback on FreeBSD threads
| From: | osbre | Date: | Sat, 21 Nov 2026 12:58:54 +0000 |
| Subject: | [php-src] PR #25643: Fix stack limit fallback on FreeBSD threads | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-40876@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/25643
Author: osbre
When configure doesn't find
pthread_attr_getstack(),
zend_call_stack_init() falls back to the current stack pointer plus
[zend_call_stack_default_size()](https://github.com/php/php-src/blob/e7e5bb18168b4504b7ae555309c866117c990525/Zend/zend_call_stack.h#L79-L81),
which is 4 MiB for every FreeBSD thread. But libthr gives new threads 2 MiB on 64-bit and 1 MiB on
32-bit
([THR_STACK_DEFAULT](https://github.com/freebsd/freebsd-src/blob/6dc19a71f70c99b36e4384aff75b3d71033e71c5/lib/libthr/thread/thr_private.h#L313)),
so the limit lies past the end of the stack. Deep recursion through internal functions then crashes
with SIGSEGV instead of throwing Error: Maximum call stack size of ... reached.
This PR uses THR_STACK_DEFAULT for threads other than the main one, like the macOS
branch does. The main thread keeps 4 MiB.
I hit this with FrankenPHP built against FreeBSD's lang/php8x ports: their ZTS
builds miss pthread_attr_getstack() (a port bug, reported separately), and one request
recursing through array_map() took down the whole server.
Tested on FreeBSD 15.1/arm64 with a ZTS build of PHP-8.4 configured with
ac_cv_func_pthread_attr_getstack=no, under FrankenPHP: before, the server crashes;
after, the request gets the Error and the server keeps serving. Builds that detect
pthread_attr_getstack() and the main thread (the CLI) are unchanged, so there's no
phpt.