nptl-signals.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* Special use of signals in NPTL internals. Linux version.
  2. Copyright (C) 2014-2017 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <signal.h>
  16. /* The signal used for asynchronous cancelation. */
  17. #define SIGCANCEL __SIGRTMIN
  18. /* Signal needed for the kernel-supported POSIX timer implementation.
  19. We can reuse the cancellation signal since we can distinguish
  20. cancellation from timer expirations. */
  21. #define SIGTIMER SIGCANCEL
  22. /* Signal used to implement the setuid et.al. functions. */
  23. #define SIGSETXID (__SIGRTMIN + 1)
  24. /* Return is sig is used internally. */
  25. static inline int
  26. __nptl_is_internal_signal (int sig)
  27. {
  28. return (sig == SIGCANCEL) || (sig == SIGTIMER) || (sig == SIGSETXID);
  29. }
  30. /* Remove internal glibc signal from the mask. */
  31. static inline void
  32. __nptl_clear_internal_signals (sigset_t *set)
  33. {
  34. __sigdelset (set, SIGCANCEL);
  35. __sigdelset (set, SIGTIMER);
  36. __sigdelset (set, SIGSETXID);
  37. }
  38. #define SIGALL_SET \
  39. ((__sigset_t) { .__val = {[0 ... _SIGSET_NWORDS-1 ] = -1 } })
  40. /* Block all signals, including internal glibc ones. */
  41. static inline int
  42. __libc_signal_block_all (sigset_t *set)
  43. {
  44. INTERNAL_SYSCALL_DECL (err);
  45. return INTERNAL_SYSCALL (rt_sigprocmask, err, 4, SIG_BLOCK, &SIGALL_SET,
  46. set, _NSIG / 8);
  47. }
  48. /* Block all application signals (excluding internal glibc ones). */
  49. static inline int
  50. __libc_signal_block_app (sigset_t *set)
  51. {
  52. sigset_t allset = SIGALL_SET;
  53. __nptl_clear_internal_signals (&allset);
  54. INTERNAL_SYSCALL_DECL (err);
  55. return INTERNAL_SYSCALL (rt_sigprocmask, err, 4, SIG_BLOCK, &allset, set,
  56. _NSIG / 8);
  57. }
  58. /* Restore current process signal mask. */
  59. static inline int
  60. __libc_signal_restore_set (const sigset_t *set)
  61. {
  62. INTERNAL_SYSCALL_DECL (err);
  63. return INTERNAL_SYSCALL (rt_sigprocmask, err, 4, SIG_SETMASK, set, NULL,
  64. _NSIG / 8);
  65. }
  66. /* Used to communicate with signal handler. */
  67. extern struct xid_command *__xidcmd attribute_hidden;