sigwaitinfo.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* Copyright (C) 1997,1998,2000,2002,2003,2004 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <http://www.gnu.org/licenses/>. */
  14. #include <pthreadP.h>
  15. #include <errno.h>
  16. #include <signal.h>
  17. #define __need_NULL
  18. #include <stddef.h>
  19. #include <string.h>
  20. #include <sysdep-cancel.h>
  21. #include <sys/syscall.h>
  22. #ifdef __NR_rt_sigtimedwait
  23. static int
  24. do_sigwaitinfo (const sigset_t *set, siginfo_t *info)
  25. {
  26. #ifdef SIGCANCEL
  27. sigset_t tmpset;
  28. if (set != NULL
  29. && (__builtin_expect (__sigismember (set, SIGCANCEL), 0)
  30. # ifdef SIGSETXID
  31. || __builtin_expect (__sigismember (set, SIGSETXID), 0)
  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. /* XXX The size argument hopefully will have to be changed to the
  46. real size of the user-level sigset_t. */
  47. int result = INLINE_SYSCALL (rt_sigtimedwait, 4, set,
  48. info, NULL, _NSIG / 8);
  49. /* The kernel generates a SI_TKILL code in si_code in case tkill is
  50. used. tkill is transparently used in raise(). Since having
  51. SI_TKILL as a code is useful in general we fold the results
  52. here. */
  53. if (result != -1 && info != NULL && info->si_code == SI_TKILL)
  54. info->si_code = SI_USER;
  55. return result;
  56. }
  57. /* Return any pending signal or wait for one for the given time. */
  58. int
  59. __sigwaitinfo (const sigset_t *set, siginfo_t *info)
  60. {
  61. if (SINGLE_THREAD_P)
  62. return do_sigwaitinfo (set, info);
  63. int oldtype = LIBC_CANCEL_ASYNC ();
  64. /* XXX The size argument hopefully will have to be changed to the
  65. real size of the user-level sigset_t. */
  66. int result = do_sigwaitinfo (set, info);
  67. LIBC_CANCEL_RESET (oldtype);
  68. return result;
  69. }
  70. weak_alias (__sigwaitinfo, sigwaitinfo)
  71. #endif