Segmentation Error in Segmentation Error Handler

Is there any specific behavior for segmentation errors that occur in falut segmentation handler on Linux? Will there be another call to the same handler? If so, then on all platforms it is defined and so on. Thanks.

+4
source share
2 answers

How the answer depends on how you installed your signal handler. If you installed a signal handler using an obsolete signal() call, it will either be reset by the signal handler for the default handler, or it will block the signal being processed before calling your signal handler. If it blocks a signal, it unlocks it after the signal handler returns.

If you use sigaction() , you have control over which signals are blocked during the call of the signal handler. If you indicate so, you can invoke infinite recursion.

You can create a secure wrapper around sigaction() , which has an API like signal() :

 sighandler_t safe_signal (int sig, sighandler_t h) { struct sigaction sa; struct sigaction osa; sa.sa_handler = h; sigemptyset(&sa.sa_mask); sa.sa_flags = 0; if (sigaction(sig, &sa, &osa) < 0) { return SIG_ERR; } return osa.sa_handler; } 

This blocks all signals for the duration of the signal handler call, which is restored after the signal handler returns.

+2
source

From C-11 standard, 7.14.1.1 ,

When a signal occurs, and the func function points to a function, this is an implementation - it is determined whether the signal equivalent is (sig, SIG_DFL); is executed, or the implementation prevents some implementation-specific set of signals ( at least including sig ), until the processing of the current signal is completed;

So Standard says it is an implementation that determines whether it allows recursive calls to a single signal handler. Therefore, I would conclude that the behavior is defined, but the implementation is defined!

But this is a complete mess if the segfault handler itself exaggerates :)

+1
source

All Articles