work around "signal loses thread pointer" issue with "approach 2"
[musl] / src / signal / sigaction.c
index 9a36226..5bc9383 100644 (file)
@@ -3,11 +3,12 @@
 #include <errno.h>
 #include "syscall.h"
 #include "pthread_impl.h"
+#include "libc.h"
 
-static void restorer()
-{
-       syscall0(__NR_rt_sigreturn);
-}
+void __restore(), __restore_rt();
+
+static pthread_t dummy(void) { return 0; }
+weak_alias(dummy, __pthread_self_def);
 
 int __libc_sigaction(int sig, const struct sigaction *sa, struct sigaction *old)
 {
@@ -21,12 +22,13 @@ int __libc_sigaction(int sig, const struct sigaction *sa, struct sigaction *old)
        if (sa) {
                ksa.handler = sa->sa_handler;
                ksa.flags = sa->sa_flags | SA_RESTORER;
-               ksa.restorer = restorer;
+               ksa.restorer = (sa->sa_flags & SA_SIGINFO) ? __restore_rt : __restore;
                ksa.mask = sa->sa_mask;
                pksa = (long)&ksa;
        }
        if (old) pkold = (long)&kold;
-       if (syscall4(__NR_rt_sigaction, sig, pksa, pkold, 8))
+       __pthread_self_def();
+       if (syscall(SYS_rt_sigaction, sig, pksa, pkold, 8))
                return -1;
        if (old) {
                old->sa_handler = kold.handler;
@@ -38,7 +40,7 @@ int __libc_sigaction(int sig, const struct sigaction *sa, struct sigaction *old)
 
 int __sigaction(int sig, const struct sigaction *sa, struct sigaction *old)
 {
-       if (sig == SIGCANCEL || sig == SIGSYSCALL) {
+       if (sig-32U < 3) {
                errno = EINVAL;
                return -1;
        }