Repository navigation
Conversation
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.
devnexen
approved these changes
Nov 21, 2026
devnexen
left a comment
Member
There was a problem hiding this comment.
is consistent with other platforms (i.e. could also be concealed in zend_call_stack.c to avoid header inclusion such as pthread_np.h all over the place)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When configure doesn't find
pthread_attr_getstack(),zend_call_stack_init()falls back to the current stack pointer pluszend_call_stack_default_size(), 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), so the limit lies past the end of the stack. Deep recursion through internal functions then crashes with SIGSEGV instead of throwingError: Maximum call stack size of ... reached.This PR uses
THR_STACK_DEFAULTfor 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/php8xports: their ZTS builds misspthread_attr_getstack()(a port bug, reported separately), and one request recursing througharray_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 detectpthread_attr_getstack()and the main thread (the CLI) are unchanged, so there's no phpt.