Skip to content
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

pthread_get_stacksize_np returns incorrect values for the main thread on OS X 10.9 #43347

Open
Tracked by #49355
jrmuizel opened this issue Jul 19, 2017 · 8 comments
Open
Tracked by #49355
Labels
A-stack-probe Area: stack probing and guard pages C-bug Category: This is a bug. P-medium Medium priority T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@jrmuizel
Copy link
Contributor

See:
robovm/robovm#274
https://groups.google.com/forum/#!topic/address-sanitizer/7_abqFZ5wXw
http://mail.openjdk.java.net/pipermail/hotspot-dev/2013-October/011388.html

pthread_get_stacksize_np returns 512KB for the main thread instead of the 8MB that it's supposed to. This causes us to allocate our guard page in the middle of the stack.

@nagisa nagisa added I-nominated T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Jul 20, 2017
@nagisa
Copy link
Member

nagisa commented Jul 20, 2017

Are we sure OS X doesn’t just put the guard page on the main thread by default?

@jrmuizel
Copy link
Contributor Author

All of the evidence that I've seen suggests that OS X already has guard pages in place.
https://github.com/opensource-apple/xnu/blob/10.12/bsd/kern/kern_exec.c#L4782

@jrmuizel
Copy link
Contributor Author

In fact there should be guard pages in place for all other threads too.
See _pthread_allocate in https://opensource.apple.com/source/libpthread/libpthread-218.1.3/src/pthread.c.auto.html

@jrmuizel
Copy link
Contributor Author

It looks like calling pthread_get_stacksize_np returns all kinds of different things on different versions of OS X.

On 10.8 it gives a hard coded 8MB
10.9 and 10.10 give a hard coded 512KB
10.11 hard codes 8MB
10.12 seems to actual give the correct result (i.e. if the executable has a different stack size specified using LC_LOAD or adjusted using rlimit) This is communicated with an environment variable called main_stack.

It seems like the only way to reliably get the stack size of the main thread is to use mach_vm_region_info()

@alexcrichton
Copy link
Member

Discussed during triage today, the conclusion was that this doesn't seem super high priority, so P-medium.

It seems like we should just remove the main stack guard page on OSX like we've already done on Linux.

@ishitatsuyuki
Copy link
Contributor

@steveklabnik
Copy link
Member

Triage: no changes I'm aware of

@kvark
Copy link
Contributor

kvark commented Mar 19, 2021

Was running on OS 11.3 beta and hit a stack overflow with 512K (in debug).
Edit: nvm, the thread in my case was created elsewhere, not by Rust.

@yaahc yaahc added the A-stack-probe Area: stack probing and guard pages label Jun 1, 2022
MarcusCalhoun-Lopez added a commit to MarcusCalhoun-Lopez/macports-legacy-support that referenced this issue May 6, 2024
MarcusCalhoun-Lopez added a commit to MarcusCalhoun-Lopez/macports-legacy-support that referenced this issue May 6, 2024
MarcusCalhoun-Lopez added a commit to MarcusCalhoun-Lopez/macports-legacy-support that referenced this issue May 7, 2024
MarcusCalhoun-Lopez added a commit to MarcusCalhoun-Lopez/macports-legacy-support that referenced this issue May 8, 2024
MarcusCalhoun-Lopez added a commit to MarcusCalhoun-Lopez/macports-legacy-support that referenced this issue May 8, 2024
MarcusCalhoun-Lopez added a commit to MarcusCalhoun-Lopez/macports-legacy-support that referenced this issue May 10, 2024
MarcusCalhoun-Lopez added a commit to MarcusCalhoun-Lopez/macports-legacy-support that referenced this issue May 10, 2024
MarcusCalhoun-Lopez added a commit to MarcusCalhoun-Lopez/macports-legacy-support that referenced this issue May 13, 2024
MarcusCalhoun-Lopez added a commit to MarcusCalhoun-Lopez/macports-legacy-support that referenced this issue May 13, 2024
MarcusCalhoun-Lopez added a commit to MarcusCalhoun-Lopez/macports-legacy-support that referenced this issue May 14, 2024
MarcusCalhoun-Lopez added a commit to MarcusCalhoun-Lopez/macports-legacy-support that referenced this issue May 14, 2024
MarcusCalhoun-Lopez added a commit to MarcusCalhoun-Lopez/macports-legacy-support that referenced this issue May 14, 2024
MarcusCalhoun-Lopez added a commit to MarcusCalhoun-Lopez/macports-legacy-support that referenced this issue May 14, 2024
MarcusCalhoun-Lopez added a commit to MarcusCalhoun-Lopez/macports-legacy-support that referenced this issue May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-stack-probe Area: stack probing and guard pages C-bug Category: This is a bug. P-medium Medium priority T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

8 participants