__rt_sigtimedwait.c 2.1 KB

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