开发者

Segmentation Fault in presence of Signal Handler

I am getting segmentation fault despite having a signal handler for SIGSEGV. The first time data is written to protected memory, I开发者_StackOverflow社区 can see that signal handler is called, but before the signal handler exits, segmentation fault appears.

What can be causing it? Isn't my SIGSEGV handler supposed to catch all the segmentation faults?


I could see where if the segmentation fault is related to the stack pointer accessing memory where it's not allowed by the OS, then you won't be able to make any calls with the current stack pointer for your process ... that includes calls to signal handlers. In other words the compiler-created prologue for your signal handler function has to setup an activation record on the stack ... if the stack pointer itself is invalid, then that won't be possible. One way this could happen is by overflowing a memory array that then writes-over the activation record for the currently executing function.

You can define another area of memory to be used as a stack for your signal handlers though sigaltstack(), and then setting the SA_ONSTACK option in sigaction() for the signal. This might be something you might want to try.

Finally, you could also run into issues if you're using non-async-safe functions or somehow are accessing pointers or memory that is outside the memory segment allotted to your process by the OS in your signal handler.


If your signal handler in turn provokes another signal that of course is not caught by your signal handler as you would then have a kind of infinite loop.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜