__rt_sigtimedwait.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * __rt_sigtimedwait() for uClibc
  4. *
  5. * Copyright (C) 2006 by Steven Hill <sjhill@realitydiluted.com>
  6. * Copyright (C) 2000-2004 by Erik Andersen <andersen@codepoet.org>
  7. *
  8. * GNU Library General Public License (LGPL) version 2 or later.
  9. */
  10. #include <sys/syscall.h>
  11. #ifdef __NR_rt_sigtimedwait
  12. # include <signal.h>
  13. # include <cancel.h>
  14. # ifdef SIGCANCEL /* defined only in NPTL's pthreadP.h */
  15. # define __need_NULL
  16. # include <stddef.h>
  17. # include <string.h>
  18. # endif
  19. int __NC(sigtimedwait)(const sigset_t *set, siginfo_t *info,
  20. const struct timespec *timeout)
  21. {
  22. # ifdef SIGCANCEL
  23. sigset_t tmpset;
  24. if (set != NULL && (__builtin_expect (__sigismember (set, SIGCANCEL), 0)
  25. # ifdef SIGSETXID
  26. || __builtin_expect (__sigismember (set, SIGSETXID), 0)
  27. # endif
  28. ))
  29. {
  30. /* Create a temporary mask without the bit for SIGCANCEL set. */
  31. // We are not copying more than we have to.
  32. memcpy (&tmpset, set, _NSIG / 8);
  33. __sigdelset (&tmpset, SIGCANCEL);
  34. # ifdef SIGSETXID
  35. __sigdelset (&tmpset, SIGSETXID);
  36. # endif
  37. set = &tmpset;
  38. }
  39. # endif
  40. /* if this is enabled, enable the disabled section in sigwait.c */
  41. # if defined SI_TKILL && defined SI_USER
  42. /* XXX The size argument hopefully will have to be changed to the
  43. real size of the user-level sigset_t. */
  44. /* on uClibc we use the kernel sigset_t size */
  45. int result = INLINE_SYSCALL(rt_sigtimedwait, 4, set, info,
  46. timeout, __SYSCALL_SIGSET_T_SIZE);
  47. /* The kernel generates a SI_TKILL code in si_code in case tkill is
  48. used. tkill is transparently used in raise(). Since having
  49. SI_TKILL as a code is useful in general we fold the results
  50. here. */
  51. if (result != -1 && info != NULL && info->si_code == SI_TKILL)
  52. info->si_code = SI_USER;
  53. return result;
  54. # else
  55. /* on uClibc we use the kernel sigset_t size */
  56. return INLINE_SYSCALL(rt_sigtimedwait, 4, set, info,
  57. timeout, __SYSCALL_SIGSET_T_SIZE);
  58. # endif
  59. }
  60. CANCELLABLE_SYSCALL(int, sigtimedwait,
  61. (const sigset_t *set, siginfo_t *info, const struct timespec *timeout),
  62. (set, info, timeout))
  63. lt_libc_hidden(sigtimedwait)
  64. #endif