fix (hopefully) all hard-coded 8's for kernel sigset_t size
authorRich Felker <dalias@aerifal.cx>
Fri, 10 Aug 2012 02:52:13 +0000 (22:52 -0400)
committerRich Felker <dalias@aerifal.cx>
Fri, 10 Aug 2012 02:52:13 +0000 (22:52 -0400)
some minor changes to how hard-coded sets for thread-related purposes
are handled were also needed, since the old object sizes were not
necessarily sufficient. things have gotten a bit ugly in this area,
and i think a cleanup is in order at some point, but for now the goal
is just to get the code working on all supported archs including mips,
which was badly broken by linux rejecting syscalls with the wrong
sigset_t size.

14 files changed:
src/internal/pthread_impl.h
src/linux/epoll_pwait.c
src/linux/signalfd.c
src/select/pselect.c
src/signal/raise.c
src/signal/siglongjmp.c
src/signal/sigpending.c
src/signal/sigsuspend.c
src/signal/sigtimedwait.c
src/thread/pthread_create.c
src/thread/pthread_self.c
src/thread/pthread_sigmask.c
src/thread/synccall.c
src/time/timer_create.c

index 46d8fdd..56b92b2 100644 (file)
@@ -90,9 +90,12 @@ struct __timer {
 #define SIGCANCEL 33
 #define SIGSYNCCALL 34
 
 #define SIGCANCEL 33
 #define SIGSYNCCALL 34
 
-#define SIGPT_SET ((sigset_t *)(unsigned long [1+(sizeof(long)==4)]){ \
+#define SIGALL_SET ((sigset_t *)(const unsigned long long [2]){ -1,-1 })
+#define SIGPT_SET \
+       ((sigset_t *)(const unsigned long [__SYSCALL_SSLEN/sizeof(long)]){ \
        [sizeof(long)==4] = 3UL<<(32*(sizeof(long)>4)) })
        [sizeof(long)==4] = 3UL<<(32*(sizeof(long)>4)) })
-#define SIGTIMER_SET ((sigset_t *)(unsigned long [1+(sizeof(long)==4)]){ \
+#define SIGTIMER_SET \
+       ((sigset_t *)(const unsigned long [__SYSCALL_SSLEN/sizeof(long)]){ \
         0x80000000 })
 
 pthread_t __pthread_self_init(void);
         0x80000000 })
 
 pthread_t __pthread_self_init(void);
index 39ad5b7..3ecdbb5 100644 (file)
@@ -3,5 +3,5 @@
 
 int epoll_pwait(int fd, struct epoll_event *ev, int cnt, int to, const sigset_t *sigs)
 {
 
 int epoll_pwait(int fd, struct epoll_event *ev, int cnt, int to, const sigset_t *sigs)
 {
-       return syscall(SYS_epoll_pwait, fd, ev, cnt, to, sigs, 8);
+       return syscall(SYS_epoll_pwait, fd, ev, cnt, to, sigs, __SYSCALL_SSLEN);
 }
 }
index 99c3514..1a6c03c 100644 (file)
@@ -3,5 +3,5 @@
 
 int signalfd(int fd, const sigset_t *sigs, int flags)
 {
 
 int signalfd(int fd, const sigset_t *sigs, int flags)
 {
-       return syscall(SYS_signalfd, fd, sigs, 8);
+       return syscall(SYS_signalfd, fd, sigs, __SYSCALL_SSLEN);
 }
 }
index f28887f..48fcefe 100644 (file)
@@ -4,7 +4,7 @@
 
 int pselect(int n, fd_set *rfds, fd_set *wfds, fd_set *efds, const struct timespec *ts, const sigset_t *mask)
 {
 
 int pselect(int n, fd_set *rfds, fd_set *wfds, fd_set *efds, const struct timespec *ts, const sigset_t *mask)
 {
-       long data[2] = { (long)mask, 8 };
+       long data[2] = { (long)mask, __SYSCALL_SSLEN };
        struct timespec ts_tmp;
        if (ts) ts_tmp = *ts;
        return syscall_cp(SYS_pselect6, n, rfds, wfds, efds, ts ? &ts_tmp : 0, data);
        struct timespec ts_tmp;
        if (ts) ts_tmp = *ts;
        return syscall_cp(SYS_pselect6, n, rfds, wfds, efds, ts ? &ts_tmp : 0, data);
index 71e0505..c0814fa 100644 (file)
@@ -2,15 +2,16 @@
 #include <errno.h>
 #include <stdint.h>
 #include "syscall.h"
 #include <errno.h>
 #include <stdint.h>
 #include "syscall.h"
+#include "pthread_impl.h"
 
 int raise(int sig)
 {
        int pid, tid, ret;
        sigset_t set;
 
 int raise(int sig)
 {
        int pid, tid, ret;
        sigset_t set;
-       __syscall(SYS_rt_sigprocmask, SIG_BLOCK, (uint64_t[]){-1}, &set, 8);
+       __syscall(SYS_rt_sigprocmask, SIG_BLOCK, SIGALL_SET, &set, __SYSCALL_SSLEN);
        tid = syscall(SYS_gettid);
        pid = syscall(SYS_getpid);
        ret = syscall(SYS_tgkill, pid, tid, sig);
        tid = syscall(SYS_gettid);
        pid = syscall(SYS_getpid);
        ret = syscall(SYS_tgkill, pid, tid, sig);
-       __syscall(SYS_rt_sigprocmask, SIG_SETMASK, &set, 0, 8);
+       __syscall(SYS_rt_sigprocmask, SIG_SETMASK, &set, 0, __SYSCALL_SSLEN);
        return ret;
 }
        return ret;
 }
index 9b4a539..e9a6131 100644 (file)
@@ -5,7 +5,7 @@
 
 void siglongjmp(sigjmp_buf buf, int ret)
 {
 
 void siglongjmp(sigjmp_buf buf, int ret)
 {
-       if (buf->__fl)
-               __syscall(SYS_rt_sigprocmask, SIG_SETMASK, buf->__ss, 0, 8);
+       if (buf->__fl) __syscall(SYS_rt_sigprocmask, SIG_SETMASK,
+               buf->__ss, 0, __SYSCALL_SSLEN);
        longjmp(buf->__jb, ret);
 }
        longjmp(buf->__jb, ret);
 }
index f6b8972..46ce303 100644 (file)
@@ -3,5 +3,5 @@
 
 int sigpending(sigset_t *set)
 {
 
 int sigpending(sigset_t *set)
 {
-       return syscall(SYS_rt_sigpending, set, 8);
+       return syscall(SYS_rt_sigpending, set, __SYSCALL_SSLEN);
 }
 }
index cd3a7b5..bdfaeee 100644 (file)
@@ -4,5 +4,5 @@
 
 int sigsuspend(const sigset_t *mask)
 {
 
 int sigsuspend(const sigset_t *mask)
 {
-       return syscall_cp(SYS_rt_sigsuspend, mask, 8);
+       return syscall_cp(SYS_rt_sigsuspend, mask, __SYSCALL_SSLEN);
 }
 }
index 7eea58a..f62db2f 100644 (file)
@@ -6,7 +6,8 @@
 int sigtimedwait(const sigset_t *mask, siginfo_t *si, const struct timespec *timeout)
 {
        int ret;
 int sigtimedwait(const sigset_t *mask, siginfo_t *si, const struct timespec *timeout)
 {
        int ret;
-       do ret = syscall_cp(SYS_rt_sigtimedwait, mask, si, timeout, 8);
+       do ret = syscall_cp(SYS_rt_sigtimedwait, mask,
+               si, timeout, __SYSCALL_SSLEN);
        while (ret<0 && errno==EINTR);
        return ret;
 }
        while (ret<0 && errno==EINTR);
        return ret;
 }
index 94dc308..52b48d6 100644 (file)
@@ -38,7 +38,8 @@ void pthread_exit(void *result)
        if (self->detached && self->map_base) {
                if (self->detached == 2)
                        __syscall(SYS_set_tid_address, 0);
        if (self->detached && self->map_base) {
                if (self->detached == 2)
                        __syscall(SYS_set_tid_address, 0);
-               __syscall(SYS_rt_sigprocmask, SIG_BLOCK, (uint64_t[]){-1},0,8);
+               __syscall(SYS_rt_sigprocmask, SIG_BLOCK,
+                       SIGALL_SET, 0, __SYSCALL_SSLEN);
                __unmapself(self->map_base, self->map_size);
        }
 
                __unmapself(self->map_base, self->map_size);
        }
 
@@ -61,7 +62,8 @@ static int start(void *p)
 {
        pthread_t self = p;
        if (self->unblock_cancel)
 {
        pthread_t self = p;
        if (self->unblock_cancel)
-               __syscall(SYS_rt_sigprocmask, SIG_UNBLOCK, SIGPT_SET, 0, 8);
+               __syscall(SYS_rt_sigprocmask, SIG_UNBLOCK,
+                       SIGPT_SET, 0, __SYSCALL_SSLEN);
        pthread_exit(self->start(self->start_arg));
        return 0;
 }
        pthread_exit(self->start(self->start_arg));
        return 0;
 }
index f68896f..a8cc80b 100644 (file)
@@ -8,7 +8,8 @@ weak_alias(dummy, __pthread_tsd_main);
 
 static int init_main_thread()
 {
 
 static int init_main_thread()
 {
-       __syscall(SYS_rt_sigprocmask, SIG_UNBLOCK, SIGPT_SET, 0, 8);
+       __syscall(SYS_rt_sigprocmask, SIG_UNBLOCK,
+               SIGPT_SET, 0, __SYSCALL_SSLEN);
        if (__set_thread_area(&main_thread) < 0) return -1;
        main_thread.canceldisable = libc.canceldisable;
        main_thread.tsd = (void **)__pthread_tsd_main;
        if (__set_thread_area(&main_thread) < 0) return -1;
        main_thread.canceldisable = libc.canceldisable;
        main_thread.tsd = (void **)__pthread_tsd_main;
index decc38f..cddc2bc 100644 (file)
@@ -6,8 +6,8 @@
 int pthread_sigmask(int how, const sigset_t *set, sigset_t *old)
 {
        int ret;
 int pthread_sigmask(int how, const sigset_t *set, sigset_t *old)
 {
        int ret;
-       if (how > 2U) return EINVAL;
-       ret = -__syscall(SYS_rt_sigprocmask, how, set, old, 8);
+       if ((unsigned)how - SIG_BLOCK > 2U) return EINVAL;
+       ret = -__syscall(SYS_rt_sigprocmask, how, set, old, __SYSCALL_SSLEN);
        if (!ret && old) {
                if (sizeof old->__bits[0] == 8) {
                        old->__bits[0] &= ~0x380000000ULL;
        if (!ret && old) {
                if (sizeof old->__bits[0] == 8) {
                        old->__bits[0] &= ~0x380000000ULL;
index 1520b3b..fd377cb 100644 (file)
@@ -61,7 +61,8 @@ void __synccall(void (*func)(void *), void *ctx)
 
        pthread_rwlock_wrlock(&lock);
 
 
        pthread_rwlock_wrlock(&lock);
 
-       __syscall(SYS_rt_sigprocmask, SIG_BLOCK, (uint64_t[]){-1}, &oldmask, 8);
+       __syscall(SYS_rt_sigprocmask, SIG_BLOCK, SIGALL_SET,
+               &oldmask, __SYSCALL_SSLEN);
 
        sem_init(&chaindone, 0, 0);
        sem_init(&chainlock, 0, 1);
 
        sem_init(&chaindone, 0, 0);
        sem_init(&chainlock, 0, 1);
@@ -93,7 +94,8 @@ void __synccall(void (*func)(void *), void *ctx)
        sa.sa_handler = SIG_IGN;
        __libc_sigaction(SIGSYNCCALL, &sa, 0);
 
        sa.sa_handler = SIG_IGN;
        __libc_sigaction(SIGSYNCCALL, &sa, 0);
 
-       __syscall(SYS_rt_sigprocmask, SIG_SETMASK, &oldmask, 0, 8);
+       __syscall(SYS_rt_sigprocmask, SIG_SETMASK,
+               &oldmask, 0, __SYSCALL_SSLEN);
 
        pthread_rwlock_unlock(&lock);
 }
 
        pthread_rwlock_unlock(&lock);
 }
index 6cff16f..813678a 100644 (file)
@@ -51,7 +51,8 @@ static void install_handler()
                .sa_flags = SA_SIGINFO | SA_RESTART
        };
        __libc_sigaction(SIGTIMER, &sa, 0);
                .sa_flags = SA_SIGINFO | SA_RESTART
        };
        __libc_sigaction(SIGTIMER, &sa, 0);
-       __syscall(SYS_rt_sigprocmask, SIG_UNBLOCK, SIGTIMER_SET, 0, 8);
+       __syscall(SYS_rt_sigprocmask, SIG_UNBLOCK,
+               SIGTIMER_SET, 0, __SYSCALL_SSLEN);
 }
 
 static void *start(void *arg)
 }
 
 static void *start(void *arg)