+/* In Linux 2.4 synchronous signals (sigtrap & co) can be delivered if
+ * they are blocked, in Linux 2.6 the default handler is invoked
+ * instead that usually coredumps. One might hastily think that adding
+ * SA_NODEFER helps, but until ~2.6.13 if SA_NODEFER is specified then
+ * the whole sa_mask is ignored and instead of not adding the signal
+ * in question to the mask. That means if it's not blockable the
+ * signal must be unblocked at the beginning of signal handlers.
+ */
+static volatile int sigaction_nodefer_works = -1;
+
+static void
+sigaction_nodefer_test_handler(int signal, siginfo_t *info, void *void_context)
+{
+ sigset_t empty, current;
+ int i;
+ sigemptyset(&empty);
+ sigprocmask(SIG_BLOCK, &empty, ¤t);
+ for(i = 1; i < NSIG; i++)
+ if (sigismember(¤t, i) != ((i == SIGABRT) ? 1 : 0)) {
+ FSHOW_SIGNAL((stderr, "SA_NODEFER doesn't work, signal %d\n", i));
+ sigaction_nodefer_works = 0;
+ }
+ if (sigaction_nodefer_works == -1)
+ sigaction_nodefer_works = 1;
+}
+
+static void
+see_if_sigaction_nodefer_works()
+{
+ struct sigaction sa, old_sa;
+
+ sa.sa_flags = SA_SIGINFO | SA_NODEFER;
+ sa.sa_sigaction = sigaction_nodefer_test_handler;
+ sigemptyset(&sa.sa_mask);
+ sigaddset(&sa.sa_mask, SIGABRT);
+ sigaction(SIGUSR1, &sa, &old_sa);
+ /* Make sure no signals are blocked. */
+ {
+ sigset_t empty;
+ sigemptyset(&empty);
+ sigprocmask(SIG_SETMASK, &empty, 0);
+ }
+ kill(getpid(), SIGUSR1);
+ while (sigaction_nodefer_works == -1);
+ sigaction(SIGUSR1, &old_sa, NULL);
+}
+
+static void
+unblock_me_trampoline(int signal, siginfo_t *info, void *void_context)
+{
+ sigset_t unblock;
+ sigemptyset(&unblock);
+ sigaddset(&unblock, signal);
+ thread_sigmask(SIG_UNBLOCK, &unblock, 0);
+ interrupt_handle_now_handler(signal, info, void_context);
+}
+
+static void
+low_level_unblock_me_trampoline(int signal, siginfo_t *info, void *void_context)
+{
+ sigset_t unblock;
+ sigemptyset(&unblock);
+ sigaddset(&unblock, signal);
+ thread_sigmask(SIG_UNBLOCK, &unblock, 0);
+ (*interrupt_low_level_handlers[signal])(signal, info, void_context);
+}
+