On Mon, 21 Jul 2003 21:15:43 -0700, "David Schwartz"
Post by Marc RochkindFor this signal and a few others that can be generated by a fault detected
by hardware, if they are genuinely generated by a fault, as opposed to
being generated synthetically by, say, kill, a special rule applies: You
can catch them or ignore them, but one thing you can't do it execute the
instruction that follows the one that caused the fault. In other words,
returning from a signal handler or a direct SIG_IGN both result in program
termination.
Really? Even if you reset the signal handler?
I think it depends on the implementation. In some cases, if we return
from the handler, then the signal is again delivered, and so on...
My understanding about what's supposed to happen is that when you return
from the signal handler, it should resume executing exactly where it
stopped, thus generating another segmentation violation. This allows code to
'fix' the circumstances that caused the segmentation violation (if it can
and wants to) and then resume execution.
If one wants to continue execution, a more typical approach I
think would be to longjmp() somewhere else, thus side-stepping
the faulting instruction.
Obviously, that's not going to be portable.
Not necesarily unportable though - for example, if the SIGSEGV
is caused by a memory protection violation, we could use mprotect()
to repair the error and then return (though mprotect() isn't in
SUSv3's list of async-signal-safe funtions...).
Cheers,
Michael