about summary refs log tree commit diff
path: root/src/signal/sigaction.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2012-02-27 18:51:02 -0500
committerRich Felker <dalias@aerifal.cx>2012-02-27 18:51:02 -0500
commitdac084a4c5f52bb3b121675320c47d3c3614174e (patch)
tree4bedab31901416ccf1093b083dba7df5a699096d /src/signal/sigaction.c
parent834255a3ffb5be208024e66b1f794d9f4201413c (diff)
downloadmusl-dac084a4c5f52bb3b121675320c47d3c3614174e.tar.gz
musl-dac084a4c5f52bb3b121675320c47d3c3614174e.tar.xz
musl-dac084a4c5f52bb3b121675320c47d3c3614174e.zip
work around "signal loses thread pointer" issue with "approach 2"
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.
Diffstat (limited to 'src/signal/sigaction.c')
-rw-r--r--src/signal/sigaction.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/signal/sigaction.c b/src/signal/sigaction.c
index 18956c6b..5bc9383b 100644
--- a/src/signal/sigaction.c
+++ b/src/signal/sigaction.c
@@ -3,9 +3,13 @@
 #include <errno.h>
 #include "syscall.h"
 #include "pthread_impl.h"
+#include "libc.h"
 
 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 {
@@ -23,6 +27,7 @@ int __libc_sigaction(int sig, const struct sigaction *sa, struct sigaction *old)
 		pksa = (long)&ksa;
 	}
 	if (old) pkold = (long)&kold;
+	__pthread_self_def();
 	if (syscall(SYS_rt_sigaction, sig, pksa, pkold, 8))
 		return -1;
 	if (old) {