jmp_buf overhaul fixing several issues
authorRich Felker <dalias@aerifal.cx>
Wed, 4 Jul 2012 00:07:33 +0000 (20:07 -0400)
committerRich Felker <dalias@aerifal.cx>
Wed, 4 Jul 2012 00:07:33 +0000 (20:07 -0400)
on arm, the location of the saved-signal-mask flag and mask were off
by one between sigsetjmp and siglongjmp, causing incorrect behavior
restoring the signal mask. this is because the siglongjmp code assumed
an extra slot was in the non-sig jmp_buf for the flag, but arm did not
have this. now, the extra slot is removed for all archs since it was
useless.

also, arm eabi requires jmp_buf to have 8-byte alignment. we achieve
that using long long as the type rather than with non-portable gcc
attribute tags.

arch/arm/bits/setjmp.h
arch/i386/bits/setjmp.h
arch/x86_64/bits/setjmp.h
include/setjmp.h
src/signal/siglongjmp.c
src/signal/sigsetjmp.c

index a4baec4..3938cb8 100644 (file)
@@ -1 +1 @@
-typedef unsigned long jmp_buf [64];
+typedef unsigned long long jmp_buf[32];
index b6595bd..5610be9 100644 (file)
@@ -1 +1 @@
-typedef unsigned long jmp_buf [7];
+typedef unsigned long jmp_buf[6];
index c5b9e4a..81d4968 100644 (file)
@@ -1 +1 @@
-typedef unsigned long jmp_buf [9];
+typedef unsigned long jmp_buf[8];
index 83ad749..28ff92e 100644 (file)
@@ -11,7 +11,11 @@ extern "C" {
 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
  || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
  || defined(_BSD_SOURCE)
 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
  || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
  || defined(_BSD_SOURCE)
-typedef unsigned long sigjmp_buf[(128+sizeof(jmp_buf))/sizeof(long)];
+typedef struct {
+       jmp_buf __jb;
+       unsigned long __fl;
+       unsigned long __ss[128];
+} sigjmp_buf[1];
 int sigsetjmp (sigjmp_buf, int);
 void siglongjmp (sigjmp_buf, int);
 #endif
 int sigsetjmp (sigjmp_buf, int);
 void siglongjmp (sigjmp_buf, int);
 #endif
index 600d560..9b4a539 100644 (file)
@@ -1,12 +1,11 @@
 #include <setjmp.h>
 #include <signal.h>
 #include <stdlib.h>
 #include <setjmp.h>
 #include <signal.h>
 #include <stdlib.h>
+#include "syscall.h"
 
 void siglongjmp(sigjmp_buf buf, int ret)
 {
 
 void siglongjmp(sigjmp_buf buf, int ret)
 {
-       unsigned long *flag = buf + sizeof(jmp_buf)/sizeof(long) - 1;
-       sigset_t *mask = (void *)(flag + 1);
-       if (*flag)
-               sigprocmask (SIG_SETMASK, mask, NULL);
-       longjmp((void *)buf, ret);
+       if (buf->__fl)
+               __syscall(SYS_rt_sigprocmask, SIG_SETMASK, buf->__ss, 0, 8);
+       longjmp(buf->__jb, ret);
 }
 }
index 5c93707..01ba0df 100644 (file)
@@ -9,9 +9,7 @@
 
 int sigsetjmp(sigjmp_buf buf, int save)
 {
 
 int sigsetjmp(sigjmp_buf buf, int save)
 {
-       unsigned long *flag = buf + sizeof(jmp_buf)/sizeof(long);
-       sigset_t *mask = (void *)(flag + 1);
-       if ((*flag = save))
-               sigprocmask (SIG_SETMASK, NULL, mask);
-       return setjmp((void *)buf);
+       if ((buf->__fl = save))
+               pthread_sigmask(SIG_SETMASK, 0, (sigset_t *)buf->__ss);
+       return setjmp(buf->__jb);
 }
 }