__rt_sigtimedwait.c 2.7 KB

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