summaryrefslogtreecommitdiffstats
path: root/libc/sysdeps/linux
diff options
context:
space:
mode:
Diffstat (limited to 'libc/sysdeps/linux')
-rw-r--r--libc/sysdeps/linux/alpha/sigprocmask.c9
-rw-r--r--libc/sysdeps/linux/avr32/sigaction.c18
-rw-r--r--libc/sysdeps/linux/common/bits/sigset.h152
-rw-r--r--libc/sysdeps/linux/common/longjmp.c3
-rw-r--r--libc/sysdeps/linux/common/mknod.c10
-rw-r--r--libc/sysdeps/linux/common/pause.c2
-rw-r--r--libc/sysdeps/linux/common/ssp.c13
-rw-r--r--libc/sysdeps/linux/common/wait4.c4
-rw-r--r--libc/sysdeps/linux/i386/sigaction.c62
-rw-r--r--libc/sysdeps/linux/mips/bits/signum.h2
-rw-r--r--libc/sysdeps/linux/mips/bits/socket.h1
-rw-r--r--libc/sysdeps/linux/mips/sigaction.c52
-rw-r--r--libc/sysdeps/linux/mips/syscall.S3
-rw-r--r--libc/sysdeps/linux/x86_64/sigaction.c20
-rw-r--r--libc/sysdeps/linux/xtensa/sigaction.c29
15 files changed, 233 insertions, 147 deletions
diff --git a/libc/sysdeps/linux/alpha/sigprocmask.c b/libc/sysdeps/linux/alpha/sigprocmask.c
index f5e3c8d91..832684cef 100644
--- a/libc/sysdeps/linux/alpha/sigprocmask.c
+++ b/libc/sysdeps/linux/alpha/sigprocmask.c
@@ -44,17 +44,18 @@ sigprocmask (int how, const sigset_t *set, sigset_t *oset)
result = osf_sigprocmask(how, setval);
if (result == -1)
- /* If there are ever more than 63 signals, we need to recode this
+ /* If there are ever more than 64 signals, we need to recode this
in assembler since we wouldn't be able to distinguish a mask of
all 1s from -1, but for now, we're doing just fine... */
return result;
if (oset)
{
+ if (_SIGSET_NWORDS == 2) /* typical */
+ oset->__val[1] = 0;
+ if (_SIGSET_NWORDS > 2)
+ memset(oset, 0, sizeof(*oset));
oset->__val[0] = result;
- result = _SIGSET_NWORDS;
- while (--result > 0)
- oset->__val[result] = 0;
}
return 0;
}
diff --git a/libc/sysdeps/linux/avr32/sigaction.c b/libc/sysdeps/linux/avr32/sigaction.c
index 05caec7ee..45d0abb5a 100644
--- a/libc/sysdeps/linux/avr32/sigaction.c
+++ b/libc/sysdeps/linux/avr32/sigaction.c
@@ -27,10 +27,14 @@ int __libc_sigaction(int signum, const struct sigaction *act,
{
struct kernel_sigaction kact, koact;
int result;
+ enum {
+ SIGSET_MIN_SIZE = sizeof(kact.sa_mask) < sizeof(act->sa_mask)
+ ? sizeof(kact.sa_mask) : sizeof(act->sa_mask)
+ };
if (act) {
kact.k_sa_handler = act->sa_handler;
- memcpy(&kact.sa_mask, &act->sa_mask, sizeof (kact.sa_mask));
+ memcpy(&kact.sa_mask, &act->sa_mask, SIGSET_MIN_SIZE);
kact.sa_flags = act->sa_flags;
if (kact.sa_flags & SA_RESTORER)
kact.sa_restorer = act->sa_restorer;
@@ -39,14 +43,16 @@ int __libc_sigaction(int signum, const struct sigaction *act,
kact.sa_flags |= SA_RESTORER;
}
- result = __syscall_rt_sigaction(signum, act ? __ptrvalue(&kact) : NULL,
- oldact ? __ptrvalue(&koact) : NULL,
- _NSIG / 8);
+ /* NB: kernel (as of 2.6.25) will return EINVAL
+ * if sizeof(kact.sa_mask) does not match kernel's sizeof(sigset_t) */
+ result = __syscall_rt_sigaction(signum,
+ act ? __ptrvalue(&kact) : NULL,
+ oldact ? __ptrvalue(&koact) : NULL,
+ sizeof(kact.sa_mask));
if (oldact && result >= 0) {
oldact->sa_handler = koact.k_sa_handler;
- memcpy(&oldact->sa_mask, &koact.sa_mask,
- sizeof(oldact->sa_mask));
+ memcpy(&oldact->sa_mask, &koact.sa_mask, SIGSET_MIN_SIZE);
oldact->sa_flags = koact.sa_flags;
oldact->sa_restorer = koact.sa_restorer;
}
diff --git a/libc/sysdeps/linux/common/bits/sigset.h b/libc/sysdeps/linux/common/bits/sigset.h
index 9a16e5cb9..7ec87eb1d 100644
--- a/libc/sysdeps/linux/common/bits/sigset.h
+++ b/libc/sysdeps/linux/common/bits/sigset.h
@@ -22,13 +22,26 @@
typedef int __sig_atomic_t;
-/* A `sigset_t' has a bit for each signal. */
-
-# define _SIGSET_NWORDS (1024 / (8 * sizeof (unsigned long int)))
-typedef struct
- {
- unsigned long int __val[_SIGSET_NWORDS];
- } __sigset_t;
+/* A 'sigset_t' has a bit for each signal.
+ * glibc has space for 1024 signals (!), but most arches supported
+ * by Linux have 64 signals, and only MIPS has 128.
+ * There seems to be some historical baggage in sparc[64]
+ * where they might have (or had in the past) 32 signals only,
+ * I hope it's irrelevant now.
+ * Signal 0 does not exist, so we have signals 1..64, not 0..63.
+ * Note that struct sigaction has embedded sigset_t,
+ * and this necessitates translation in sigaction()
+ * to convert it to struct kernel_sigaction.
+ * See libc/.../sigaction.c, libc/.../kernel_sigaction.h
+ */
+#if defined(__mips__)
+# define _SIGSET_NWORDS (128 / (8 * sizeof (unsigned long)))
+#else
+# define _SIGSET_NWORDS (64 / (8 * sizeof (unsigned long)))
+#endif
+typedef struct {
+ unsigned long __val[_SIGSET_NWORDS];
+} __sigset_t;
#endif
@@ -47,53 +60,98 @@ typedef struct
# endif
/* Return a mask that includes the bit for SIG only. */
+/* Unsigned cast ensures shift/mask insns are used. */
# define __sigmask(sig) \
- (((unsigned long int) 1) << (((sig) - 1) % (8 * sizeof (unsigned long int))))
+ (((unsigned long) 1) << ((unsigned)((sig) - 1) % (8 * sizeof (unsigned long))))
/* Return the word index for SIG. */
-# define __sigword(sig) (((sig) - 1) / (8 * sizeof (unsigned long int)))
+# define __sigword(sig) ((unsigned)((sig) - 1) / (8 * sizeof (unsigned long)))
+
+/* gcc 4.3.1 is not clever enough to optimize for _SIGSET_NWORDS == 1 and 2,
+ * which are about the only values which can be there */
# if defined __GNUC__ && __GNUC__ >= 2
# define __sigemptyset(set) \
- (__extension__ ({ int __cnt = _SIGSET_NWORDS; \
- sigset_t *__set = (set); \
- while (--__cnt >= 0) __set->__val[__cnt] = 0; \
- 0; }))
+(__extension__ ({ \
+ sigset_t *__set = (set); \
+ if (_SIGSET_NWORDS <= 2) { \
+ __set->__val[0] = 0; \
+ if (_SIGSET_NWORDS == 2) \
+ __set->__val[1] = 0; \
+ } else { \
+ int __cnt = _SIGSET_NWORDS; \
+ while (--__cnt >= 0) __set->__val[__cnt] = 0; \
+ } \
+ 0; \
+}))
# define __sigfillset(set) \
- (__extension__ ({ int __cnt = _SIGSET_NWORDS; \
- sigset_t *__set = (set); \
- while (--__cnt >= 0) __set->__val[__cnt] = ~0UL; \
- 0; }))
+(__extension__ ({ \
+ sigset_t *__set = (set); \
+ if (_SIGSET_NWORDS <= 2) { \
+ __set->__val[0] = ~0UL; \
+ if (_SIGSET_NWORDS == 2) \
+ __set->__val[1] = ~0UL; \
+ } else { \
+ int __cnt = _SIGSET_NWORDS; \
+ while (--__cnt >= 0) __set->__val[__cnt] = ~0UL; \
+ } \
+ 0; \
+}))
# ifdef __USE_GNU
/* The POSIX does not specify for handling the whole signal set in one
command. This is often wanted and so we define three more functions
here. */
# define __sigisemptyset(set) \
- (__extension__ ({ int __cnt = _SIGSET_NWORDS; \
- const sigset_t *__set = (set); \
- int __ret = __set->__val[--__cnt]; \
- while (!__ret && --__cnt >= 0) \
- __ret = __set->__val[__cnt]; \
- __ret == 0; }))
+(__extension__ ({ \
+ long __ret; \
+ const sigset_t *__set = (set); \
+ if (_SIGSET_NWORDS == 1) { \
+ __ret = __set->__val[0]; \
+ } else if (_SIGSET_NWORDS == 2) { \
+ __ret = __set->__val[0] | __set->__val[1]; \
+ } else { \
+ int __cnt = _SIGSET_NWORDS; \
+ __ret = __set->__val[--__cnt]; \
+ while (!__ret && --__cnt >= 0) \
+ __ret = __set->__val[__cnt]; \
+ } \
+ __ret == 0; \
+}))
# define __sigandset(dest, left, right) \
- (__extension__ ({ int __cnt = _SIGSET_NWORDS; \
- sigset_t *__dest = (dest); \
- const sigset_t *__left = (left); \
- const sigset_t *__right = (right); \
- while (--__cnt >= 0) \
- __dest->__val[__cnt] = (__left->__val[__cnt] \
- & __right->__val[__cnt]); \
- 0; }))
+(__extension__ ({ \
+ sigset_t *__dest = (dest); \
+ const sigset_t *__left = (left); \
+ const sigset_t *__right = (right); \
+ if (_SIGSET_NWORDS <= 2) { \
+ __dest->__val[0] = __left->__val[0] & __right->__val[0];\
+ if (_SIGSET_NWORDS == 2) \
+ __dest->__val[1] = __left->__val[1] & __right->__val[1];\
+ } else { \
+ int __cnt = _SIGSET_NWORDS; \
+ while (--__cnt >= 0) \
+ __dest->__val[__cnt] = (__left->__val[__cnt] \
+ & __right->__val[__cnt]); \
+ } \
+ 0; \
+}))
# define __sigorset(dest, left, right) \
- (__extension__ ({ int __cnt = _SIGSET_NWORDS; \
- sigset_t *__dest = (dest); \
- const sigset_t *__left = (left); \
- const sigset_t *__right = (right); \
- while (--__cnt >= 0) \
- __dest->__val[__cnt] = (__left->__val[__cnt] \
- | __right->__val[__cnt]); \
- 0; }))
+(__extension__ ({ \
+ sigset_t *__dest = (dest); \
+ const sigset_t *__left = (left); \
+ const sigset_t *__right = (right); \
+ if (_SIGSET_NWORDS <= 2) { \
+ __dest->__val[0] = __left->__val[0] | __right->__val[0];\
+ if (_SIGSET_NWORDS == 2) \
+ __dest->__val[1] = __left->__val[1] | __right->__val[1];\
+ } else { \
+ int __cnt = _SIGSET_NWORDS; \
+ while (--__cnt >= 0) \
+ __dest->__val[__cnt] = (__left->__val[__cnt] \
+ | __right->__val[__cnt]); \
+ } \
+ 0; \
+}))
# endif
# endif
@@ -108,14 +166,14 @@ extern int __sigdelset (__sigset_t *, int);
libc_hidden_proto(__sigdelset)
# ifdef __USE_EXTERN_INLINES
-# define __SIGSETFN(NAME, BODY, CONST) \
- _EXTERN_INLINE int \
- NAME (CONST __sigset_t *__set, int __sig) \
- { \
- unsigned long int __mask = __sigmask (__sig); \
- unsigned long int __word = __sigword (__sig); \
- return BODY; \
- }
+# define __SIGSETFN(NAME, BODY, CONST) \
+_EXTERN_INLINE int \
+NAME (CONST __sigset_t *__set, int __sig) \
+{ \
+ unsigned long __mask = __sigmask (__sig); \
+ unsigned long __word = __sigword (__sig); \
+ return BODY; \
+}
__SIGSETFN (__sigismember, (__set->__val[__word] & __mask) ? 1 : 0, __const)
__SIGSETFN (__sigaddset, ((__set->__val[__word] |= __mask), 0), )
diff --git a/libc/sysdeps/linux/common/longjmp.c b/libc/sysdeps/linux/common/longjmp.c
index 672754a73..e600c7f13 100644
--- a/libc/sysdeps/linux/common/longjmp.c
+++ b/libc/sysdeps/linux/common/longjmp.c
@@ -38,8 +38,7 @@ void __libc_longjmp (sigjmp_buf env, int val)
if (env[0].__mask_was_saved)
/* Restore the saved signal mask. */
- (void) sigprocmask (SIG_SETMASK, &env[0].__saved_mask,
- (sigset_t *) NULL);
+ (void) sigprocmask (SIG_SETMASK, &env[0].__saved_mask, NULL);
/* Call the machine-dependent function to restore machine state. */
__longjmp (env[0].__jmpbuf, val ?: 1);
diff --git a/libc/sysdeps/linux/common/mknod.c b/libc/sysdeps/linux/common/mknod.c
index 75aff70c8..5c7f9a5fd 100644
--- a/libc/sysdeps/linux/common/mknod.c
+++ b/libc/sysdeps/linux/common/mknod.c
@@ -11,18 +11,14 @@
#include <sys/stat.h>
#include <sys/sysmacros.h>
-libc_hidden_proto(mknod)
+/* libc_hidden_proto(mknod) */
#define __NR___syscall_mknod __NR_mknod
static __inline__ _syscall3(int, __syscall_mknod, const char *, path,
- __kernel_mode_t, mode, __kernel_dev_t, dev);
+ __kernel_mode_t, mode, __kernel_dev_t, dev)
int mknod(const char *path, mode_t mode, dev_t dev)
{
- /* We must convert the dev_t value to a __kernel_dev_t */
- __kernel_dev_t k_dev;
-
- k_dev = ((major(dev) & 0xff) << 8) | (minor(dev) & 0xff);
- return __syscall_mknod(path, mode, k_dev);
+ return __syscall_mknod(path, mode, (__kernel_dev_t)dev);
}
libc_hidden_def(mknod)
diff --git a/libc/sysdeps/linux/common/pause.c b/libc/sysdeps/linux/common/pause.c
index b68ec4a51..7baba1a93 100644
--- a/libc/sysdeps/linux/common/pause.c
+++ b/libc/sysdeps/linux/common/pause.c
@@ -12,6 +12,8 @@
#include <unistd.h>
#include <sysdep-cancel.h>
#include <signal.h>
+/* libc_hidden_proto(__sigpause) */
+/* libc_hidden_proto(sigblock) */
/* Suspend the process until a signal arrives.
This always returns -1 and sets errno to EINTR. */
diff --git a/libc/sysdeps/linux/common/ssp.c b/libc/sysdeps/linux/common/ssp.c
index 73d7113b8..8a84e4893 100644
--- a/libc/sysdeps/linux/common/ssp.c
+++ b/libc/sysdeps/linux/common/ssp.c
@@ -51,16 +51,15 @@ static void block_signals(void)
struct sigaction sa;
sigset_t mask;
- sigfillset(&mask);
-
- sigdelset(&mask, SSP_SIGTYPE); /* Block all signal handlers */
+ __sigfillset(&mask);
+ __sigdelset(&mask, SSP_SIGTYPE); /* Block all signal handlers */
sigprocmask(SIG_BLOCK, &mask, NULL); /* except SSP_SIGTYPE */
/* Make the default handler associated with the signal handler */
- memset(&sa, 0, sizeof(struct sigaction));
- sigfillset(&sa.sa_mask); /* Block all signals */
- sa.sa_flags = 0;
- sa.sa_handler = SIG_DFL;
+ memset(&sa, 0, sizeof(sa));
+ __sigfillset(&sa.sa_mask); /* Block all signals */
+ if (SIG_DFL) /* if it's constant zero, it's already done */
+ sa.sa_handler = SIG_DFL;
sigaction(SSP_SIGTYPE, &sa, NULL);
}
diff --git a/libc/sysdeps/linux/common/wait4.c b/libc/sysdeps/linux/common/wait4.c
index 5c51116fa..4fd866996 100644
--- a/libc/sysdeps/linux/common/wait4.c
+++ b/libc/sysdeps/linux/common/wait4.c
@@ -12,11 +12,11 @@
#include <sys/wait.h>
#include <sys/resource.h>
-libc_hidden_proto(wait4)
+/* libc_hidden_proto(wait4) */
#define __NR___syscall_wait4 __NR_wait4
static __inline__ _syscall4(int, __syscall_wait4, __kernel_pid_t, pid,
- int *, status, int, opts, struct rusage *, rusage);
+ int *, status, int, opts, struct rusage *, rusage)
pid_t wait4(pid_t pid, int *status, int opts, struct rusage *rusage)
{
diff --git a/libc/sysdeps/linux/i386/sigaction.c b/libc/sysdeps/linux/i386/sigaction.c
index 32c8f64bc..e323d0938 100644
--- a/libc/sysdeps/linux/i386/sigaction.c
+++ b/libc/sysdeps/linux/i386/sigaction.c
@@ -39,38 +39,44 @@ extern void restore (void) __asm__ ("__restore") attribute_hidden;
If OACT is not NULL, put the old action for SIG in *OACT. */
int __libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
{
- int result;
- struct kernel_sigaction kact, koact;
+ int result;
+ struct kernel_sigaction kact, koact;
+ enum {
+ SIGSET_MIN_SIZE = sizeof(kact.sa_mask) < sizeof(act->sa_mask)
+ ? sizeof(kact.sa_mask) : sizeof(act->sa_mask)
+ };
#ifdef SIGCANCEL
- if (sig == SIGCANCEL) {
- __set_errno (EINVAL);
- return -1;
- }
+ if (sig == SIGCANCEL) {
+ __set_errno (EINVAL);
+ return -1;
+ }
#endif
- if (act) {
- kact.k_sa_handler = act->sa_handler;
- memcpy (&kact.sa_mask, &act->sa_mask, sizeof (kact.sa_mask));
- kact.sa_flags = act->sa_flags;
-
- kact.sa_flags = act->sa_flags | SA_RESTORER;
- kact.sa_restorer = ((act->sa_flags & SA_SIGINFO)
- ? &restore_rt : &restore);
- }
-
- /* XXX The size argument hopefully will have to be changed to the
- real size of the user-level sigset_t. */
- result = __syscall_rt_sigaction(sig, act ? __ptrvalue (&kact) : NULL,
- oact ? __ptrvalue (&koact) : NULL, _NSIG / 8);
-
- if (oact && result >= 0) {
- oact->sa_handler = koact.k_sa_handler;
- memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (oact->sa_mask));
- oact->sa_flags = koact.sa_flags;
- oact->sa_restorer = koact.sa_restorer;
- }
- return result;
+ if (act) {
+ kact.k_sa_handler = act->sa_handler;
+ memcpy (&kact.sa_mask, &act->sa_mask, SIGSET_MIN_SIZE);
+ kact.sa_flags = act->sa_flags;
+
+ kact.sa_flags = act->sa_flags | SA_RESTORER;
+ kact.sa_restorer = ((act->sa_flags & SA_SIGINFO)
+ ? &restore_rt : &restore);
+ }
+
+ /* NB: kernel (as of 2.6.25) will return EINVAL
+ * if sizeof(kact.sa_mask) does not match kernel's sizeof(sigset_t) */
+ result = __syscall_rt_sigaction(sig,
+ act ? __ptrvalue (&kact) : NULL,
+ oact ? __ptrvalue (&koact) : NULL,
+ sizeof(kact.sa_mask));
+
+ if (oact && result >= 0) {
+ oact->sa_handler = koact.k_sa_handler;
+ memcpy (&oact->sa_mask, &koact.sa_mask, SIGSET_MIN_SIZE);
+ oact->sa_flags = koact.sa_flags;
+ oact->sa_restorer = koact.sa_restorer;
+ }
+ return result;
}
diff --git a/libc/sysdeps/linux/mips/bits/signum.h b/libc/sysdeps/linux/mips/bits/signum.h
index a9b684834..6176b90b9 100644
--- a/libc/sysdeps/linux/mips/bits/signum.h
+++ b/libc/sysdeps/linux/mips/bits/signum.h
@@ -65,7 +65,7 @@
#define SIGXFSZ 31 /* File size limit exceeded (4.2 BSD). */
-#define _NSIG 128 /* Biggest signal number + 1
+#define _NSIG 129 /* Biggest signal number + 1
(including real-time signals). */
#define SIGRTMIN (__libc_current_sigrtmin ())
diff --git a/libc/sysdeps/linux/mips/bits/socket.h b/libc/sysdeps/linux/mips/bits/socket.h
index 0860b4d38..39fadc676 100644
--- a/libc/sysdeps/linux/mips/bits/socket.h
+++ b/libc/sysdeps/linux/mips/bits/socket.h
@@ -270,6 +270,7 @@ struct cmsghdr
extern struct cmsghdr * __NTH (__cmsg_nxthdr (struct msghdr *__mhdr,
struct cmsghdr *__cmsg)) __THROW;
+libc_hidden_proto(__cmsg_nxthdr)
#ifdef __USE_EXTERN_INLINES
# ifndef _EXTERN_INLINE
# define _EXTERN_INLINE extern __inline
diff --git a/libc/sysdeps/linux/mips/sigaction.c b/libc/sysdeps/linux/mips/sigaction.c
index edd265438..ca39740af 100644
--- a/libc/sysdeps/linux/mips/sigaction.c
+++ b/libc/sysdeps/linux/mips/sigaction.c
@@ -47,36 +47,42 @@ static void restore (void) __asm__ ("__restore");
If OACT is not NULL, put the old action for SIG in *OACT. */
int __libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
{
- int result;
- struct kernel_sigaction kact, koact;
-
- if (act) {
- kact.k_sa_handler = act->sa_handler;
- memcpy (&kact.sa_mask, &act->sa_mask, sizeof (kact.sa_mask));
- kact.sa_flags = act->sa_flags;
+ int result;
+ struct kernel_sigaction kact, koact;
+ enum {
+ SIGSET_MIN_SIZE = sizeof(kact.sa_mask) < sizeof(act->sa_mask)
+ ? sizeof(kact.sa_mask) : sizeof(act->sa_mask)
+ };
+
+ if (act) {
+ kact.k_sa_handler = act->sa_handler;
+ memcpy (&kact.sa_mask, &act->sa_mask, SIGSET_MIN_SIZE);
+ kact.sa_flags = act->sa_flags;
# ifdef HAVE_SA_RESTORER
# if _MIPS_SIM == _ABIO32
- kact.sa_restorer = act->sa_restorer;
+ kact.sa_restorer = act->sa_restorer;
# else
- kact.sa_restorer = &restore_rt;
+ kact.sa_restorer = &restore_rt;
# endif
# endif
- }
-
- /* XXX The size argument hopefully will have to be changed to the
- real size of the user-level sigset_t. */
- result = __syscall_rt_sigaction(sig, act ? __ptrvalue (&kact) : NULL,
- oact ? __ptrvalue (&koact) : NULL, _NSIG / 8);
-
- if (oact && result >= 0) {
- oact->sa_handler = koact.k_sa_handler;
- memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (oact->sa_mask));
- oact->sa_flags = koact.sa_flags;
+ }
+
+ /* NB: kernel (as of 2.6.25) will return EINVAL
+ * if sizeof(kact.sa_mask) does not match kernel's sizeof(sigset_t) */
+ result = __syscall_rt_sigaction(sig,
+ act ? __ptrvalue (&kact) : NULL,
+ oact ? __ptrvalue (&koact) : NULL,
+ sizeof(kact.sa_mask));
+
+ if (oact && result >= 0) {
+ oact->sa_handler = koact.k_sa_handler;
+ memcpy (&oact->sa_mask, &koact.sa_mask, SIGSET_MIN_SIZE);
+ oact->sa_flags = koact.sa_flags;
# ifdef HAVE_SA_RESTORER
- oact->sa_restorer = koact.sa_restorer;
+ oact->sa_restorer = koact.sa_restorer;
# endif
- }
- return result;
+ }
+ return result;
}
diff --git a/libc/sysdeps/linux/mips/syscall.S b/libc/sysdeps/linux/mips/syscall.S
index ff6f3d1b4..acb91011d 100644
--- a/libc/sysdeps/linux/mips/syscall.S
+++ b/libc/sysdeps/linux/mips/syscall.S
@@ -32,7 +32,6 @@ syscall:
#ifdef __PIC__
SETUP_GP
#endif
- .set noreorder
move v0, a0 /* Load system call number from first arg. */
move a0, a1 /* Move the next three args up a register. */
move a1, a2
@@ -59,12 +58,12 @@ syscall:
lw v0,7*4(sp) /* for system call restarts */
#endif
syscall /* Do the system call. */
- bnez a3, 1f
#ifdef __mips64
daddiu sp,sp,16
#else
addiu sp,sp,32
#endif
+ bnez a3, 1f
j ra /* Return to caller. */
1:
move a0,v0 /* Pass return val to C function. */
diff --git a/libc/sysdeps/linux/x86_64/sigaction.c b/libc/sysdeps/linux/x86_64/sigaction.c
index 3d9e4ea29..e53e30442 100644
--- a/libc/sysdeps/linux/x86_64/sigaction.c
+++ b/libc/sysdeps/linux/x86_64/sigaction.c
@@ -50,23 +50,29 @@ __libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
{
int result;
struct kernel_sigaction kact, koact;
+ enum {
+ SIGSET_MIN_SIZE = sizeof(kact.sa_mask) < sizeof(act->sa_mask)
+ ? sizeof(kact.sa_mask) : sizeof(act->sa_mask)
+ };
if (act) {
kact.k_sa_handler = act->sa_handler;
- memcpy (&kact.sa_mask, &act->sa_mask, sizeof (sigset_t));
+ memcpy (&kact.sa_mask, &act->sa_mask, SIGSET_MIN_SIZE);
kact.sa_flags = act->sa_flags | SA_RESTORER;
kact.sa_restorer = &restore_rt;
}
- /* XXX The size argument hopefully will have to be changed to the
- real size of the user-level sigset_t. */
- result = INLINE_SYSCALL (rt_sigaction, 4,
- sig, act ? __ptrvalue (&kact) : NULL,
- oact ? __ptrvalue (&koact) : NULL, _NSIG / 8);
+ /* NB: kernel (as of 2.6.25) will return EINVAL
+ * if sizeof(kact.sa_mask) does not match kernel's sizeof(sigset_t) */
+ result = INLINE_SYSCALL (rt_sigaction, 4, sig,
+ act ? __ptrvalue (&kact) : NULL,
+ oact ? __ptrvalue (&koact) : NULL,
+ sizeof(kact.sa_mask));
+
if (oact && result >= 0) {
oact->sa_handler = koact.k_sa_handler;
- memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (sigset_t));
+ memcpy (&oact->sa_mask, &koact.sa_mask, SIGSET_MIN_SIZE);
oact->sa_flags = koact.sa_flags;
oact->sa_restorer = koact.sa_restorer;
}
diff --git a/libc/sysdeps/linux/xtensa/sigaction.c b/libc/sysdeps/linux/xtensa/sigaction.c
index 790a8f21f..c6c24fc36 100644
--- a/libc/sysdeps/linux/xtensa/sigaction.c
+++ b/libc/sysdeps/linux/xtensa/sigaction.c
@@ -20,14 +20,18 @@ extern void __default_sa_restorer (void);
/* Experimentally off - libc_hidden_proto(memcpy) */
int __libc_sigaction (int signum, const struct sigaction *act,
- struct sigaction *oldact)
+ struct sigaction *oact)
{
- struct kernel_sigaction kact, koldact;
+ struct kernel_sigaction kact, koact;
int result;
+ enum {
+ SIGSET_MIN_SIZE = sizeof(kact.sa_mask) < sizeof(act->sa_mask)
+ ? sizeof(kact.sa_mask) : sizeof(act->sa_mask)
+ };
if (act) {
kact.k_sa_handler = act->sa_handler;
- memcpy(&kact.sa_mask, &act->sa_mask, sizeof (kact.sa_mask));
+ memcpy(&kact.sa_mask, &act->sa_mask, SIGSET_MIN_SIZE);
kact.sa_flags = act->sa_flags;
if (kact.sa_flags & SA_RESTORER) {
@@ -38,15 +42,18 @@ int __libc_sigaction (int signum, const struct sigaction *act,
}
}
- result = __syscall_rt_sigaction(signum, act ? __ptrvalue (&kact) : NULL,
- oldact ? __ptrvalue (&koldact) : NULL,
- _NSIG / 8);
+ /* NB: kernel (as of 2.6.25) will return EINVAL
+ * if sizeof(kact.sa_mask) does not match kernel's sizeof(sigset_t) */
+ result = __syscall_rt_sigaction(signum,
+ act ? __ptrvalue (&kact) : NULL,
+ oact ? __ptrvalue (&koact) : NULL,
+ sizeof(kact.sa_mask));
- if (oldact && result >= 0) {
- oldact->sa_handler = koldact.k_sa_handler;
- memcpy(&oldact->sa_mask, &koldact.sa_mask, sizeof(oldact->sa_mask));
- oldact->sa_flags = koldact.sa_flags;
- oldact->sa_restorer = koldact.sa_restorer;
+ if (oact && result >= 0) {
+ oact->sa_handler = koact.k_sa_handler;
+ memcpy(&oact->sa_mask, &koact.sa_mask, SIGSET_MIN_SIZE);
+ oact->sa_flags = koact.sa_flags;
+ oact->sa_restorer = koact.sa_restorer;
}
return result;