Corruption of Stack and using Alternate Signal Stack
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 co开发者_JAVA技巧rrupt ?
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.
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.
精彩评论