'Is there a way to block only asynchronous delivery of SIGSEGV or to find out the delivery mode?

In a C/C++ program, I am using mprotect together with an installed signal handler for SIGSEGV (using GNU libsigsegv) to implement write barriers (for generational GC). The memory protection fault signal is delivered synchronously by the kernel when the write barrier is hit.

In order to be sure that the signal handler is always being called synchronously (otherwise my code could deadlock), I would like to block asynchronous delivery of the SIGSEGV signal (e.g. through kill (2)). Is there a way to do this? Or is there a way for the signal handler to find out whether the signal was delivered synchronously?



Solution 1:[1]

With the signal API you can't. But there is a workaround:

You may use realtime-extension and use SA_SIGINFO in the action flags to get a siginfo_t in your handler. In this structure you will find the pid of the emitter of the signal and can then ignore the delivery if it is not the pid of your running process?

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jean-Baptiste Yunès