diff options
| -rw-r--r-- | libc/signal/sigempty.c | 6 | ||||
| -rw-r--r-- | libc/signal/sigfillset.c | 6 | ||||
| -rw-r--r-- | libc/signal/sigset-cvt-mask.h | 20 | ||||
| -rw-r--r-- | libc/sysdeps/linux/common/bits/sigset.h | 124 | ||||
| -rw-r--r-- | libc/sysdeps/linux/common/sigsuspend.c | 4 |
5 files changed, 100 insertions, 60 deletions
diff --git a/libc/signal/sigempty.c b/libc/signal/sigempty.c index 7d8687bd1..56b62bc65 100644 --- a/libc/signal/sigempty.c +++ b/libc/signal/sigempty.c @@ -23,16 +23,18 @@ /* Experimentally off - libc_hidden_proto(memset) */ /* Clear all signals from SET. */ -libc_hidden_proto(sigemptyset) +/* libc_hidden_proto(sigemptyset) */ int sigemptyset (sigset_t *set) { +#if 0 /* is it really required by standards?! */ if (set == NULL) { __set_errno (EINVAL); return -1; } +#endif - memset (set, 0, sizeof (sigset_t)); + __sigemptyset (set); return 0; } diff --git a/libc/signal/sigfillset.c b/libc/signal/sigfillset.c index 96ab459dc..b0b093032 100644 --- a/libc/signal/sigfillset.c +++ b/libc/signal/sigfillset.c @@ -23,17 +23,19 @@ /* Experimentally off - libc_hidden_proto(memset) */ /* Set all signals in SET. */ -libc_hidden_proto(sigfillset) +/* libc_hidden_proto(sigfillset) */ int sigfillset (sigset_t *set) { +#if 0 /* is it really required by standards?! */ if (set == NULL) { __set_errno (EINVAL); return -1; } +#endif - memset (set, 0xff, sizeof (sigset_t)); + __sigfillset (set); /* If the implementation uses a cancellation signal don't set the bit. */ #ifdef SIGCANCEL diff --git a/libc/signal/sigset-cvt-mask.h b/libc/signal/sigset-cvt-mask.h index 7b2f4cdce..76dd01c7e 100644 --- a/libc/signal/sigset-cvt-mask.h +++ b/libc/signal/sigset-cvt-mask.h @@ -19,22 +19,14 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -static __inline__ int __attribute__ ((unused)) +static __inline__ void __attribute__ ((unused)) sigset_set_old_mask (sigset_t *set, int mask) { - unsigned long int *ptr; - int cnt; - - ptr = &set->__val[0]; - - *ptr++ = (unsigned int) mask; - - cnt = _SIGSET_NWORDS - 2; - do - *ptr++ = 0ul; - while (--cnt >= 0); - - return 0; + if (_SIGSET_NWORDS == 2) /* typical */ + set->__val[1] = 0; + if (_SIGSET_NWORDS > 2) + memset(set, 0, sizeof(*set)); + set->__val[0] = (unsigned int) mask; } static __inline__ int __attribute__ ((unused)) diff --git a/libc/sysdeps/linux/common/bits/sigset.h b/libc/sysdeps/linux/common/bits/sigset.h index 6e748d351..75fa32604 100644 --- a/libc/sysdeps/linux/common/bits/sigset.h +++ b/libc/sysdeps/linux/common/bits/sigset.h @@ -49,52 +49,96 @@ typedef struct /* 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 @@ -109,14 +153,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/sigsuspend.c b/libc/sysdeps/linux/common/sigsuspend.c index b69431be9..789eeda89 100644 --- a/libc/sysdeps/linux/common/sigsuspend.c +++ b/libc/sysdeps/linux/common/sigsuspend.c @@ -47,8 +47,8 @@ int sigsuspend(const sigset_t * mask) # endif #else # define __NR___syscall_sigsuspend __NR_sigsuspend -static inline _syscall3(int, __syscall_sigsuspend, int, a, unsigned long int, b, - unsigned long int, c); +static __inline__ _syscall3(int, __syscall_sigsuspend, int, a, unsigned long int, b, + unsigned long int, c) int sigsuspend(const sigset_t * set) { |
