internal-signals.h 2.5 KB

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