diff options
Diffstat (limited to 'libc')
-rw-r--r-- | libc/signal/Makefile.in | 4 | ||||
-rw-r--r-- | libc/signal/sigwait.c | 82 | ||||
-rw-r--r-- | libc/sysdeps/linux/common/__rt_sigtimedwait.c | 88 | ||||
-rw-r--r-- | libc/sysdeps/linux/common/__rt_sigwaitinfo.c | 95 | ||||
-rw-r--r-- | libc/sysdeps/linux/common/sigprocmask.c | 1 |
5 files changed, 246 insertions, 24 deletions
diff --git a/libc/signal/Makefile.in b/libc/signal/Makefile.in index 26a8f0c56..f21e5ebaa 100644 --- a/libc/signal/Makefile.in +++ b/libc/signal/Makefile.in @@ -11,6 +11,10 @@ CSRC:= allocrtsig.c killpg.c raise.c sigaction.c sigaddset.c sigandset.c \ sigorset.c sigpause.c sigrelse.c sigset.c sigsetmask.c sigsetops.c \ sysv_signal.c sigwait.c +ifeq ($(UCLIBC_HAS_THREADS_NATIVE),y) +CSRC:=$(filter-out raise.c,$(CSRC)) +endif + ifneq ($(strip $(ARCH_OBJS)),) CSRC:=$(filter-out $(notdir $(ARCH_OBJS:.o=.c)),$(CSRC)) endif diff --git a/libc/signal/sigwait.c b/libc/signal/sigwait.c index 13d65ed5e..c8a93dfb2 100644 --- a/libc/signal/sigwait.c +++ b/libc/signal/sigwait.c @@ -1,7 +1,8 @@ /* vi: set sw=4 ts=4: */ /* sigwait * - * Copyright (C) 2003 by Erik Andersen <andersen@uclibc.org> + * Copyright (C) 2006 by Steven J. Hill <sjhill@realitydiluted.com> + * Copyright (C) 2003-2005 by Erik Andersen <andersen@uclibc.org> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -24,7 +25,81 @@ #include <signal.h> #include <string.h> -#undef sigwait +#ifdef __UCLIBC_HAS_THREADS_NATIVE__ +# include <sysdep-cancel.h> + +# ifdef __NR_rt_sigtimedwait + +/* Return any pending signal or wait for one for the given time. */ +static int do_sigwait(const sigset_t *set, int *sig) +{ + int ret; + +# ifdef SIGCANCEL + sigset_t tmpset; + if (set != NULL + && (__builtin_expect (__sigismember (set, SIGCANCEL), 0) +# ifdef SIGSETXID + || __builtin_expect (__sigismember (set, SIGSETXID), 0) +# endif + )) + { + /* Create a temporary mask without the bit for SIGCANCEL set. */ + // We are not copying more than we have to. +# ifdef IS_IN_libc + __memcpy(&tmpset, set, _NSIG / 8); +# else + memcpy(&tmpset, set, _NSIG / 8); +# endif + __sigdelset(&tmpset, SIGCANCEL); +# ifdef SIGSETXID + __sigdelset(&tmpset, SIGSETXID); +# endif + set = &tmpset; + } +# endif + + /* XXX The size argument hopefully will have to be changed to the + real size of the user-level sigset_t. */ +# ifdef INTERNAL_SYSCALL + INTERNAL_SYSCALL_DECL(err); + do + ret = INTERNAL_SYSCALL (rt_sigtimedwait, err, 4, set, NULL, + NULL, _NSIG / 8); + while (INTERNAL_SYSCALL_ERROR_P (ret, err) + && INTERNAL_SYSCALL_ERRNO (ret, err) == EINTR); + if (! INTERNAL_SYSCALL_ERROR_P (ret, err)) + { + *sig = ret; + ret = 0; + } +else + ret = INTERNAL_SYSCALL_ERRNO (ret, err); +# else +# error INTERNAL_SYSCALL must be defined!!! +# endif + + return ret; +} + +int __sigwait (const sigset_t *set, int *sig) +{ + if(SINGLE_THREAD_P) + return do_sigwait(set, sig); + + int oldtype = LIBC_CANCEL_ASYNC(); + + int result = do_sigwait(set, sig); + + LIBC_CANCEL_RESET(oldtype); + + return result; +} +# else +# error We must have rt_sigtimedwait defined!!! +# endif +#else +# undef sigwait int attribute_hidden __sigwait (const sigset_t *set, int *sig) { int ret = 1; @@ -34,6 +109,5 @@ int attribute_hidden __sigwait (const sigset_t *set, int *sig) } return 1; } - -/* psm: keep this weak, because the one in libpthread.so could overwrite it */ +#endif weak_alias(__sigwait, sigwait) diff --git a/libc/sysdeps/linux/common/__rt_sigtimedwait.c b/libc/sysdeps/linux/common/__rt_sigtimedwait.c index 09409fe81..f468222af 100644 --- a/libc/sysdeps/linux/common/__rt_sigtimedwait.c +++ b/libc/sysdeps/linux/common/__rt_sigtimedwait.c @@ -2,6 +2,7 @@ /* * __rt_sigtimedwait() for uClibc * + * Copyright (C) 2006 by Steven Hill <sjhill@realitydiluted.com> * Copyright (C) 2000-2004 by Erik Andersen <andersen@codepoet.org> * * GNU Library General Public License (LGPL) version 2 or later. @@ -9,35 +10,84 @@ #include "syscalls.h" #include <signal.h> -#define __need_NULL -#include <stddef.h> + #ifdef __NR_rt_sigtimedwait -#define __NR___rt_sigtimedwait __NR_rt_sigtimedwait -static _syscall4(int, __rt_sigtimedwait, const sigset_t *, set, siginfo_t *, info, - const struct timespec *, timeout, size_t, setsize); -int attribute_hidden __sigwaitinfo(const sigset_t * set, siginfo_t * info) +# ifdef __UCLIBC_HAS_THREADS_NATIVE__ +# include <sysdep-cancel.h> + +static int do_sigtimedwait(const sigset_t *set, siginfo_t *info, + const struct timespec *timeout) { - return __rt_sigtimedwait(set, info, NULL, _NSIG / 8); +# ifdef SIGCANCEL + sigset_t tmpset; + + if (set != NULL && (__builtin_expect (__sigismember (set, SIGCANCEL), 0) +# ifdef SIGSETXID + || __builtin_expect (__sigismember (set, SIGSETXID), 0) +# endif + )) + { + /* Create a temporary mask without the bit for SIGCANCEL set. */ + // We are not copying more than we have to. + __memcpy (&tmpset, set, _NSIG / 8); + __sigdelset (&tmpset, SIGCANCEL); +# ifdef SIGSETXID + __sigdelset (&tmpset, SIGSETXID); +# endif + set = &tmpset; + } +# endif + + /* XXX The size argument hopefully will have to be changed to the + real size of the user-level sigset_t. */ + int result = INLINE_SYSCALL (rt_sigtimedwait, 4, set, info, + timeout, _NSIG / 8); + + /* The kernel generates a SI_TKILL code in si_code in case tkill is + used. tkill is transparently used in raise(). Since having + SI_TKILL as a code is useful in general we fold the results + here. */ + if (result != -1 && info != NULL && info->si_code == SI_TKILL) + info->si_code = SI_USER; + + return result; } +/* Return any pending signal or wait for one for the given time. */ +int __sigtimedwait(const sigset_t *set, siginfo_t *info, + const struct timespec *timeout) +{ + if(SINGLE_THREAD_P) + return do_sigtimedwait(set, info, timeout); + + int oldtype = LIBC_CANCEL_ASYNC(); + + /* XXX The size argument hopefully will have to be changed to the + real size of the user-level sigset_t. */ + int result = do_sigtimedwait(set, info, timeout); + + LIBC_CANCEL_RESET(oldtype); + + return result; +} +# else +# define __need_NULL +# include <stddef.h> +# define __NR___rt_sigtimedwait __NR_rt_sigtimedwait +static _syscall4(int, __rt_sigtimedwait, const sigset_t *, set, + siginfo_t *, info, const struct timespec *, timeout, + size_t, setsize); + int attribute_hidden __sigtimedwait(const sigset_t * set, siginfo_t * info, - const struct timespec *timeout) + const struct timespec *timeout) { return __rt_sigtimedwait(set, info, timeout, _NSIG / 8); } +# endif #else -int attribute_hidden __sigwaitinfo(const sigset_t * set, siginfo_t * info) -{ - if (set == NULL) - __set_errno(EINVAL); - else - __set_errno(ENOSYS); - return -1; -} - int attribute_hidden __sigtimedwait(const sigset_t * set, siginfo_t * info, - const struct timespec *timeout) + const struct timespec *timeout) { if (set == NULL) __set_errno(EINVAL); @@ -46,6 +96,4 @@ int attribute_hidden __sigtimedwait(const sigset_t * set, siginfo_t * info, return -1; } #endif -/* keep these weak so that libpthread can overwrite them */ weak_alias(__sigtimedwait,sigtimedwait) -weak_alias(__sigwaitinfo,sigwaitinfo) diff --git a/libc/sysdeps/linux/common/__rt_sigwaitinfo.c b/libc/sysdeps/linux/common/__rt_sigwaitinfo.c new file mode 100644 index 000000000..81c34435f --- /dev/null +++ b/libc/sysdeps/linux/common/__rt_sigwaitinfo.c @@ -0,0 +1,95 @@ +/* vi: set sw=4 ts=4: */ +/* + * __rt_sigwaitinfo() for uClibc + * + * Copyright (C) 2006 by Steven Hill <sjhill@realitydiluted.com> + * Copyright (C) 2000-2004 by Erik Andersen <andersen@codepoet.org> + * + * GNU Library General Public License (LGPL) version 2 or later. + */ + +#include "syscalls.h" +#include <signal.h> + +#ifdef __NR_rt_sigtimedwait + +# ifdef __UCLIBC_HAS_THREADS_NATIVE__ +# include <sysdep-cancel.h> + +static int do_sigwaitinfo(const sigset_t *set, siginfo_t *info) +{ +# ifdef SIGCANCEL + sigset_t tmpset; + + if (set != NULL && (__builtin_expect (__sigismember (set, SIGCANCEL), 0) +# ifdef SIGSETXID + || __builtin_expect (__sigismember (set, SIGSETXID), 0) +# endif + )) + { + /* Create a temporary mask without the bit for SIGCANCEL set. */ + // We are not copying more than we have to. + __memcpy (&tmpset, set, _NSIG / 8); + __sigdelset (&tmpset, SIGCANCEL); +# ifdef SIGSETXID + __sigdelset (&tmpset, SIGSETXID); +# endif + set = &tmpset; + } +# endif + + /* XXX The size argument hopefully will have to be changed to the + real size of the user-level sigset_t. */ + int result = INLINE_SYSCALL (rt_sigtimedwait, 4, set, info, + NULL, _NSIG / 8); + + /* The kernel generates a SI_TKILL code in si_code in case tkill is + used. tkill is transparently used in raise(). Since having + SI_TKILL as a code is useful in general we fold the results + here. */ + if (result != -1 && info != NULL && info->si_code == SI_TKILL) + info->si_code = SI_USER; + + return result; +} + +/* Return any pending signal or wait for one for the given time. */ +int __sigwaitinfo(const sigset_t *set, siginfo_t *info) +{ + if(SINGLE_THREAD_P) + return do_sigwaitinfo(set, info); + + int oldtype = LIBC_CANCEL_ASYNC(); + + /* XXX The size argument hopefully will have to be changed to the + real size of the user-level sigset_t. */ + int result = do_sigwaitinfo(set, info); + + LIBC_CANCEL_RESET(oldtype); + + return result; +} +# else +# define __need_NULL +# include <stddef.h> +# define __NR___rt_sigwaitinfo __NR_rt_sigwaitinfo +static _syscall4(int, __rt_sigwaitinfo, const sigset_t *, set, + siginfo_t *, info, const struct timespec *, timeout, + size_t, setsize); + +int attribute_hidden __sigwaitinfo(const sigset_t * set, siginfo_t * info) +{ + return __rt_sigwaitinfo(set, info, NULL, _NSIG / 8); +} +# endif +#else +int attribute_hidden __sigwaitinfo(const sigset_t * set, siginfo_t * info) +{ + if (set == NULL) + __set_errno(EINVAL); + else + __set_errno(ENOSYS); + return -1; +} +#endif +weak_alias(__sigwaitinfo,sigwaitinfo) diff --git a/libc/sysdeps/linux/common/sigprocmask.c b/libc/sysdeps/linux/common/sigprocmask.c index c555bb51b..803f5b4ae 100644 --- a/libc/sysdeps/linux/common/sigprocmask.c +++ b/libc/sysdeps/linux/common/sigprocmask.c @@ -2,6 +2,7 @@ /* * sigprocmask() for uClibc * + * Copyright (C) 2006 by Steven J. Hill <sjhill@uclibc.org> * Copyright (C) 2000-2004 by Erik Andersen <andersen@codepoet.org> * * GNU Library General Public License (LGPL) version 2 or later. |