sigwaitinfo.c 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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, write to the Free
  13. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 02111-1307 USA. */
  15. #include <pthreadP.h>
  16. #include <errno.h>
  17. #include <signal.h>
  18. #define __need_NULL
  19. #include <stddef.h>
  20. #include <string.h>
  21. #include <sysdep-cancel.h>
  22. #include <sys/syscall.h>
  23. #ifdef __NR_rt_sigtimedwait
  24. static int
  25. do_sigwaitinfo (const sigset_t *set, siginfo_t *info)
  26. {
  27. #ifdef SIGCANCEL
  28. sigset_t tmpset;
  29. if (set != NULL
  30. && (__builtin_expect (__sigismember (set, SIGCANCEL), 0)
  31. # ifdef SIGSETXID
  32. || __builtin_expect (__sigismember (set, SIGSETXID), 0)
  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. /* XXX The size argument hopefully will have to be changed to the
  47. real size of the user-level sigset_t. */
  48. int result = INLINE_SYSCALL (rt_sigtimedwait, 4, set,
  49. info, NULL, _NSIG / 8);
  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. }
  58. /* Return any pending signal or wait for one for the given time. */
  59. int
  60. __sigwaitinfo (const sigset_t *set, siginfo_t *info)
  61. {
  62. if (SINGLE_THREAD_P)
  63. return do_sigwaitinfo (set, info);
  64. int oldtype = LIBC_CANCEL_ASYNC ();
  65. /* XXX The size argument hopefully will have to be changed to the
  66. real size of the user-level sigset_t. */
  67. int result = do_sigwaitinfo (set, info);
  68. LIBC_CANCEL_RESET (oldtype);
  69. return result;
  70. }
  71. weak_alias (__sigwaitinfo, sigwaitinfo)
  72. #endif