0

I was going through Linux Programmer's Manual about Alternative Signal Stack.

http://www.kernel.org/doc/man-pages/online/pages/man2/sigaltstack.2.html

I see that sigaltstack() is used when user's stack is corrupted or when it overflows. My problem is how to detect at run time if the stack is corrupt ?

In my running program in production, I want to go for alternate signal stack, if my program detects, stack got corrupted. Is it the right question to ask ? People in some threads talk about using debugging tools like Valgrind ( and possibly others) but unfortunately the luxury is not available in production.

skaffman
  • 398,947
  • 96
  • 818
  • 769
ultimate cause
  • 2,264
  • 4
  • 27
  • 44

1 Answers1

0

You can't really detect a corrupt stack from the process itself - once your stack is corrupt, your whole program (including whatever functions/variables you could try to use to detect corruption) is unpredictable.

And you can't really repair a corrupted stack even if you could detect it. There is no telling what damage was cause by running code on a corrupt stack. So the best (probably only) thing to do is just quit at that point anyway.

Read the man page completely, the reason it gives for using the alternate stack is a good one (handling SIGSEGV). Although you can't generally repair that either, so quitting is pretty much the only thing you can do then.

Mat
  • 202,337
  • 40
  • 393
  • 406
  • I already read that, I dint point it out though. I understand that. So I don't really see any significance of this feature, simply because with the mechanism given I have to just for precaution reserve memory for alternate stack; may it or may not happen. – ultimate cause Aug 15 '11 at 09:00
  • 1
    Another use for the SIGSEGV handler is to get a stack trace in out-of-memory or exhausted stack situations. That is usefull, but will only work if you have an alternate stack, and your "primary" stack is not corrupt (otherwise the stack trace is meaningless) – Mat Aug 15 '11 at 09:05
  • Hi Mat, I will appreciate if you can please answer this question - http://stackoverflow.com/questions/29761742/examinig-alternate-signal-stack-different-ways-to-allocate-it – Sandeep Apr 21 '15 at 02:19