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

sigaltstack? #12

Open
bakinat opened this issue Mar 3, 2016 · 4 comments
Open

sigaltstack? #12

bakinat opened this issue Mar 3, 2016 · 4 comments

Comments

@bakinat
Copy link

bakinat commented Mar 3, 2016

This is great work.
I see you use SA_ONSTACK so I assume you intended to provide an alternate stack (which is better for this case) but I don't see anywhere an initialization with sigaltstack - or maybe I missed something?
Per sigaction man page, in such case the default stack is used (which I assume is as if SA_ONSTACK has not been given)

@vmarkovtsev
Copy link
Owner

Thanks, sigaltstack() was overseen. Looks likr backtrace() still works on an alternative stack, so I should just add this function call with some allocated mem.

@bakinat
Copy link
Author

bakinat commented Mar 3, 2016

I don't see how can backtrace() use an alternative stack if sigaltstack wasn't called, but I may be wrong.
Anyway, one more question and few suggestions:

  1. Question: How do you determine the size of kNeededMemory?
  2. Suggestion: it would be useful to enable the actual printing through some callback (which may default to stderr as you did). For example, if someone would like to write the stack trace into a log file instead.
  3. Suggestion: if addr2line fails you can still print a line similar to http://stackoverflow.com/a/1925461
  4. Suggestion: you might want to have user control over whether you fork in the handler.
    Thanks again.

@vmarkovtsev
Copy link
Owner

  1. I calculated the worst case memory consumption with the longest lines and added some reserve.
  2. Implemented.
  3. I will try to research on this, thanks. Looks like some time is needed.
  4. Skipping fork() means much instability with multithreaded apps. If can be coded for sure, but I have no enthusiasm with this. A PR would be accepted though.

And the bad news is, sigaltstack() screws backtrace() with glibc, after all. I left the support, but it is disabled by default, since nobody usually wants an empty trace. I'd like to know if there is a way to run backtrace() on a different stack...

@bakinat
Copy link
Author

bakinat commented Mar 7, 2016

Thanks. I actually agree with you on 4.
About sigaltstack, first I would use SIGSTKSZ and not SIGMINSTKSZ, but I realize this will not help backtrace. Still, in this mode the handler can just print the failure point (using addr2line on siginfo_t->si_addr) with the advantage of handling stack overflow in case of infinite recursion as well.
To make backtrace work, I assume there might be a way to get the pointer to the original stack (ucontext_t->uc_stack?), but it will probably require some work.
Anyway, this looks good enough for now :)
Thanks again!

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

No branches or pull requests

2 participants