__rt_sigtimedwait.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 __UCLIBC_HAS_THREADS_NATIVE__
  15. # include <pthreadP.h> /* SIGCANCEL */
  16. # endif
  17. # ifdef SIGCANCEL
  18. # define __need_NULL
  19. # include <stddef.h>
  20. # include <string.h>
  21. # endif
  22. int __NC(sigtimedwait)(const sigset_t *set, siginfo_t *info,
  23. const struct timespec *timeout)
  24. {
  25. # ifdef SIGCANCEL
  26. sigset_t tmpset;
  27. if (set != NULL && (unlikely (__sigismember (set, SIGCANCEL))
  28. # ifdef SIGSETXID
  29. || unlikely (__sigismember (set, SIGSETXID))
  30. # endif
  31. ))
  32. {
  33. /* Create a temporary mask without the bit for SIGCANCEL set. */
  34. // We are not copying more than we have to.
  35. memcpy (&tmpset, set, _NSIG / 8);
  36. __sigdelset (&tmpset, SIGCANCEL);
  37. # ifdef SIGSETXID
  38. __sigdelset (&tmpset, SIGSETXID);
  39. # endif
  40. set = &tmpset;
  41. }
  42. # endif
  43. /* if this is enabled, enable the disabled section in sigwait.c */
  44. # if defined SI_TKILL && defined SI_USER
  45. /* XXX The size argument hopefully will have to be changed to the
  46. real size of the user-level sigset_t. */
  47. /* on uClibc we use the kernel sigset_t size */
  48. int result = INLINE_SYSCALL(rt_sigtimedwait, 4, set, info,
  49. timeout, __SYSCALL_SIGSET_T_SIZE);
  50. /* The kernel generates a SI_TKILL code in si_code in case tkill is
  51. used. tkill is transparently used in raise(). Since having
  52. SI_TKILL as a code is useful in general we fold the results
  53. here. */
  54. if (result != -1 && info != NULL && info->si_code == SI_TKILL)
  55. info->si_code = SI_USER;
  56. return result;
  57. # else
  58. /* on uClibc we use the kernel sigset_t size */
  59. return INLINE_SYSCALL(rt_sigtimedwait, 4, set, info,
  60. timeout, __SYSCALL_SIGSET_T_SIZE);
  61. # endif
  62. }
  63. CANCELLABLE_SYSCALL(int, sigtimedwait,
  64. (const sigset_t *set, siginfo_t *info, const struct timespec *timeout),
  65. (set, info, timeout))
  66. lt_libc_hidden(sigtimedwait)
  67. #endif