work around "signal loses thread pointer" issue with "approach 2"
authorRich Felker <dalias@aerifal.cx>
Mon, 27 Feb 2012 23:51:02 +0000 (18:51 -0500)
committerRich Felker <dalias@aerifal.cx>
Mon, 27 Feb 2012 23:51:02 +0000 (18:51 -0500)
this was discussed on the mailing list and no consensus on the
preferred solution was reached, so in anticipation of a release, i'm
just committing a minimally-invasive solution that avoids the problem
by ensuring that multi-threaded-capable programs will always have
initialized the thread pointer before any signal handler can run.

in the long term we may switch to initializing the thread pointer at
program start time whenever the program has the potential to access
any per-thread data.

src/signal/sigaction.c
src/thread/pthread_self.c

index 18956c6..5bc9383 100644 (file)
@@ -3,9 +3,13 @@
 #include <errno.h>
 #include "syscall.h"
 #include "pthread_impl.h"
 #include <errno.h>
 #include "syscall.h"
 #include "pthread_impl.h"
+#include "libc.h"
 
 void __restore(), __restore_rt();
 
 
 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)
 {
        struct {
 int __libc_sigaction(int sig, const struct sigaction *sa, struct sigaction *old)
 {
        struct {
@@ -23,6 +27,7 @@ int __libc_sigaction(int sig, const struct sigaction *sa, struct sigaction *old)
                pksa = (long)&ksa;
        }
        if (old) pkold = (long)&kold;
                pksa = (long)&ksa;
        }
        if (old) pkold = (long)&kold;
+       __pthread_self_def();
        if (syscall(SYS_rt_sigaction, sig, pksa, pkold, 8))
                return -1;
        if (old) {
        if (syscall(SYS_rt_sigaction, sig, pksa, pkold, 8))
                return -1;
        if (old) {
index cc2ddfb..51f12bb 100644 (file)
@@ -19,7 +19,7 @@ static int init_main_thread()
        return 0;
 }
 
        return 0;
 }
 
-pthread_t pthread_self()
+pthread_t __pthread_self_def()
 {
        static int init, failed;
        if (!init) {
 {
        static int init, failed;
        if (!init) {
@@ -31,4 +31,5 @@ pthread_t pthread_self()
        return __pthread_self();
 }
 
        return __pthread_self();
 }
 
-weak_alias(pthread_self, __pthread_self_init);
+weak_alias(__pthread_self_def, pthread_self);
+weak_alias(__pthread_self_def, __pthread_self_init);