internal-signals.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* Special use of signals internally. Linux version.
  2. Copyright (C) 2014-2019 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. #ifndef __INTERNAL_SIGNALS_H
  16. # define __INTERNAL_SIGNALS_H
  17. #include <signal.h>
  18. #include <sigsetops.h>
  19. #include <stdbool.h>
  20. #include <sysdep.h>
  21. /* The signal used for asynchronous cancelation. */
  22. #define SIGCANCEL __SIGRTMIN
  23. /* Signal needed for the kernel-supported POSIX timer implementation.
  24. We can reuse the cancellation signal since we can distinguish
  25. cancellation from timer expirations. */
  26. #define SIGTIMER SIGCANCEL
  27. /* Signal used to implement the setuid et.al. functions. */
  28. #define SIGSETXID (__SIGRTMIN + 1)
  29. /* Return is sig is used internally. */
  30. static inline bool
  31. __is_internal_signal (int sig)
  32. {
  33. return (sig == SIGCANCEL) || (sig == SIGSETXID);
  34. }
  35. /* Remove internal glibc signal from the mask. */
  36. static inline void
  37. __clear_internal_signals (sigset_t *set)
  38. {
  39. __sigdelset (set, SIGCANCEL);
  40. __sigdelset (set, SIGSETXID);
  41. }
  42. #define SIGALL_SET \
  43. ((__sigset_t) { .__val = {[0 ... _SIGSET_NWORDS-1 ] = -1 } })
  44. /* Block all signals, including internal glibc ones. */
  45. static inline int
  46. __libc_signal_block_all (sigset_t *set)
  47. {
  48. INTERNAL_SYSCALL_DECL (err);
  49. return INTERNAL_SYSCALL (rt_sigprocmask, err, 4, SIG_BLOCK, &SIGALL_SET,
  50. set, _NSIG / 8);
  51. }
  52. /* Block all application signals (excluding internal glibc ones). */
  53. static inline int
  54. __libc_signal_block_app (sigset_t *set)
  55. {
  56. sigset_t allset = SIGALL_SET;
  57. __clear_internal_signals (&allset);
  58. INTERNAL_SYSCALL_DECL (err);
  59. return INTERNAL_SYSCALL (rt_sigprocmask, err, 4, SIG_BLOCK, &allset, set,
  60. _NSIG / 8);
  61. }
  62. /* Restore current process signal mask. */
  63. static inline int
  64. __libc_signal_restore_set (const sigset_t *set)
  65. {
  66. INTERNAL_SYSCALL_DECL (err);
  67. return INTERNAL_SYSCALL (rt_sigprocmask, err, 4, SIG_SETMASK, set, NULL,
  68. _NSIG / 8);
  69. }
  70. /* Used to communicate with signal handler. */
  71. extern struct xid_command *__xidcmd attribute_hidden;
  72. #endif