__rt_sigtimedwait.c 2.2 KB

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