Skip to content

zend stack: prepare zend_call_stack_get implementation for OpenBSD. #11578

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 7, 2023

Conversation

devnexen
Copy link
Member

@devnexen devnexen commented Jul 2, 2023

No description provided.

Copy link
Member

@arnaud-lb arnaud-lb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Comment on lines 448 to 449
// TODO may need more leeway for the main thread
stack->max_size = ss.ss_size;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we able to get the actual ss_sp for the main thread? Does the stack reside in its own memory mapping, and can we find the address of this mapping?

Otherwise, do we have a way to estimate the right size for the leeway? Does it depend on the arguments and environment size?

Copy link
Member Author

@devnexen devnexen Jul 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we able to get the actual ss_sp for the main thread?

Yes, if pthread_stackseg_np succeeds you always get it.

Does the stack reside in its own memory mapping, and can we find the address of this mapping?

Otherwise, do we have a way to estimate the right size for the leeway? Does it depend on the arguments and environment size?

Looking at openbsd source, it seems the proper calculation is done already since years now, back in the days you needed to do the alignment yourself. What you re looking at is the main thread case and it depends on the arguments and environment indeed, done in the kernel side of things here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible that the alignment is not enough to take sgap and sizeof(arginfo) into account? VM_PSSTRINGS is vm->vm_minsaddr - sizeof(arginfo) - sgap, and sgap appears to be in [0..pagesize], so I understand that VM_PSSTRINGS can be more than 1 page way from vm_minsaddr. In that case, we would need to add 1 page of leeway.

@arnaud-lb
Copy link
Member

This looks good to me. In case I'm correct about VM_PSSTRINGS, could you remove one page from max_size? Otherwise could you remove the TODO comment?

This PR supports detecting stack boundaries on OpenBSD when linking with pthread; do you plan to add support for non-pthread in a separate PR?

@devnexen devnexen force-pushed the zend_call_stack_openbsd branch from f41843e to 4f4eab9 Compare July 7, 2023 13:22
@devnexen
Copy link
Member Author

devnexen commented Jul 7, 2023

This looks good to me. In case I'm correct about VM_PSSTRINGS, could you remove one page from max_size? Otherwise could you remove the TODO comment?

This PR supports detecting stack boundaries on OpenBSD when linking with pthread; do you plan to add support for non-pthread in a separate PR?

Yes that s part of the plan indeed. Cheers.

@devnexen devnexen merged commit 75e9980 into php:master Jul 7, 2023
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.

2 participants