Skip to content

zend_call_stack.c: AIX backend - #22906

Merged
NattyNarwhal merged 6 commits into
php:masterfrom
NattyNarwhal:aix-stack-limit
Jul 31, 2026
Merged

zend_call_stack.c: AIX backend#22906
NattyNarwhal merged 6 commits into
php:masterfrom
NattyNarwhal:aix-stack-limit

Conversation

@NattyNarwhal

Copy link
Copy Markdown
Member

Uses pthread_getthrds_np (so requires pthread linked, by default on ZTS, needs to be added for NTS). The stack size part is weird, but works in testing.

An alternative approach is using procfs, but I didn't bother with this due to it not working on PASE (and the pthread approach works for the main thread too).

Comment thread Zend/zend_call_stack.c
Comment thread Zend/zend_call_stack.c Outdated
Comment thread Zend/zend_call_stack.c
@NattyNarwhal
NattyNarwhal marked this pull request as ready for review July 30, 2026 04:55
@NattyNarwhal
NattyNarwhal requested a review from arnaud-lb as a code owner July 30, 2026 04:55
@devnexen

Copy link
Copy Markdown
Member

question: do you need to update zend_call_stack_default_size() ?

@NattyNarwhal

Copy link
Copy Markdown
Member Author

question: do you need to update zend_call_stack_default_size() ?

Good point; looks like based on measuring (on PASE), it looks like 192 KB for threads (IBM claims 96, but I think that's for 32-bit, so ifdef).

For the main thread, I think AIX sets a 32 MB stack limit in ulimit by default (which, ulimit could be measured as a fallback path perhaps), but I can't find a consistent source for that. PASE seems to default to unlimited which caps at 256 MB.

@devnexen

Copy link
Copy Markdown
Member

Once you re done, Zend/stack_limits would need to be run (and stack_limits_010.phpt will need an update for sure). Nice to bring AIX support regardless 👍🏼.

@NattyNarwhal

Copy link
Copy Markdown
Member Author

stack_limits_010.phpt will need an update for sure

The annoying thing is that the exact stack size returned for the main thread seems annoyingly variable between systems (at least on PASE with its default unlimited stack size) and thus I can't use an exact size. Not sure what the best strategy for that test is; round to some close enough number like page size?

@devnexen

Copy link
Copy Markdown
Member

ah right ... in that case, the simplest would be to test ranges unless @arnaud-lb has a better suggestion :)

@arnaud-lb

Copy link
Copy Markdown
Member

The annoying thing is that the exact stack size returned for the main thread seems annoyingly variable between systems (at least on PASE with its default unlimited stack size) and thus I can't use an exact size. Not sure what the best strategy for that test is; round to some close enough number like page size?

What is the size reported by zend_call_stack_get() when the stack size is unlimited? (I would expect the cap of 256MB?)

In stack_limit_010.phpt anything that allows to check that the stack size detection is not completely off would be good, but the most accurate the better. This test assumes a system with default settings.

@NattyNarwhal

Copy link
Copy Markdown
Member Author

What is the size reported by zend_call_stack_get() when the stack size is unlimited? (I would expect the cap of 256MB?)

0xffffbe0 on one system, but on another system, I get a value like 0xffffed0. I'm assuming there's stuff on the top of the stack that's reserved by the system that gets taken off when reporting the stack size for the main thread. It's all pretty close to the limit.

(FWIW, if I try capping the stack value to AIX's default value of 32 MB, I also get the same variance, just capped at i.e. 0x1fffc40 vs. 0x1fffed0. So the variable amount is being taken off from the declared maximum value.)

@arnaud-lb

Copy link
Copy Markdown
Member

Let's skip this test on AIX/PASE for now then

@NattyNarwhal

Copy link
Copy Markdown
Member Author

Let's skip this test on AIX/PASE for now then

It needs an environment variable set, so it'll be skipped automatically, but I can add an explicit one in case

@arnaud-lb

Copy link
Copy Markdown
Member

A condition based on PHP_OS_FAMILY in the --SKIPIF-- section would work?

Uses pthread_getthrds_np (so requires pthread linked, by default on ZTS,
needs to be added for NTS). The stack size part is weird, but works in
testing.

An alternative approach is using procfs, but I didn't bother with this
due to it not working on PASE (and the pthread approach works for the
main thread too).
...and pass a NULL register buffer, since this is only used with
suspended threads. something that'll never happen if we invoke it on
ourself. We still need to pass the size though.
Zero out the pthread struct, check if the pointers are nil, add extra
comment about stackaddr
AIX adjusts the top address of the stack on the main thread in an
unpredictable way, and this is used to calculate the size for the
main thread.
@NattyNarwhal
NattyNarwhal merged commit 415a415 into php:master Jul 31, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants