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

Usage of SA_ONSTACK may want to arrange for a large sigaltstack #110

Closed
alexcrichton opened this issue Sep 19, 2019 · 2 comments · Fixed by #130
Closed

Usage of SA_ONSTACK may want to arrange for a large sigaltstack #110

alexcrichton opened this issue Sep 19, 2019 · 2 comments · Fixed by #130
Assignees

Comments

@alexcrichton
Copy link
Contributor

I was recently developing Rust support for coz since I was curious how it could help us analyze compile times (in rustc and cargo themselves), and in developing Rust support for coz one thing I was initially baffled by was that coz-run programs would always segfault very quickly! Digging in it looked like the first SIGPROF signal was segfaulting on the first stack access.

Rust programs, by default, configure a pretty small sigaltstack for SIGSEGV so they can print "you just overflowed the stack" if the stack was overflowed. It looks like coz's own usage of SA_ONSTACK for SIGPROF causes coz itself to run on the Rust standard library's tiny stack, which immediately stack overflows. For reference the Rust standard library allocates SIGSTKSZ which I think is around 8k, and the stack frame for the first function called by SIGPROF was around 8k, hence the segfault.

I managed to work around this by setting up a much larger sigaltstack whenever coz is used, but I figured it might be good to report this for anyone else who runs into it!

@ccurtsinger
Copy link
Member

I don't see any harm in doing this for all programs run with coz, not just with rust.

@alexcrichton
Copy link
Contributor Author

Thinking on this a bit more, is SA_ONSTACK still needed with the SIGPROF handler? From some local testing if SA_ONSTACK is used but no stack is configured with sigaltstack, I think it just uses the thread's current stack to deliver the signal, which should be appropriate in most cases for libcoz?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants