use alt signal stack when present for implementation-internal signals
authorRich Felker <dalias@aerifal.cx>
Sat, 20 Aug 2022 16:24:49 +0000 (12:24 -0400)
committerRich Felker <dalias@aerifal.cx>
Sat, 20 Aug 2022 16:24:49 +0000 (12:24 -0400)
a request for this behavior has been open for a long time. the
motivation is that application code, particularly under some language
runtimes designed around very-low-footprint coroutine type constructs,
may be operating with extremely small stack sizes unsuitable for
receiving signals, using a separate signal stack for any signals it
might handle.

progress on this was blocked at one point trying to determine whether
the implementation is actually entitled to clobber the alt stack, but
the phrasing "available to the implementation" in the POSIX spec for
sigaltstack seems to make it clear that the application cannot rely on
the contents of this memory to be preserved in the absence of signal
delivery (on the abstract machine, excluding implementation-internal
signals) and that we can therefore use it for delivery of signals that
"don't exist" on the abstract machine.

no change is made for SIGTIMER since it is always blocked when used,
and accepted via sigwaitinfo rather than execution of the signal
handler.

src/linux/membarrier.c
src/thread/pthread_cancel.c
src/thread/synccall.c

index 343f736..f64fe7e 100644 (file)
@@ -35,7 +35,7 @@ int __membarrier(int cmd, int flags)
                __tl_lock();
                sem_init(&barrier_sem, 0, 0);
                struct sigaction sa = {
-                       .sa_flags = SA_RESTART,
+                       .sa_flags = SA_RESTART | SA_ONSTACK,
                        .sa_handler = bcast_barrier
                };
                memset(&sa.sa_mask, -1, sizeof sa.sa_mask);
index 2f9d5e9..2d3a98e 100644 (file)
@@ -77,7 +77,7 @@ void __testcancel()
 static void init_cancellation()
 {
        struct sigaction sa = {
-               .sa_flags = SA_SIGINFO | SA_RESTART,
+               .sa_flags = SA_SIGINFO | SA_RESTART | SA_ONSTACK,
                .sa_sigaction = cancel_handler
        };
        memset(&sa.sa_mask, -1, _NSIG/8);
index d58c851..a6b177c 100644 (file)
@@ -45,7 +45,7 @@ void __synccall(void (*func)(void *), void *ctx)
 {
        sigset_t oldmask;
        int cs, i, r;
-       struct sigaction sa = { .sa_flags = SA_RESTART, .sa_handler = handler };
+       struct sigaction sa = { .sa_flags = SA_RESTART | SA_ONSTACK, .sa_handler = handler };
        pthread_t self = __pthread_self(), td;
        int count = 0;