Reputation: 30825
I am getting segmentation fault despite having a signal handler for SIGSEGV
. The first time data is written to protected memory, I 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?
Upvotes: 3
Views: 1447
Reputation: 32538
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.
Upvotes: 4
Reputation: 92384
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.
Upvotes: 2