mips: FIx clone3 implementation (BZ 31325)
[glibc.git] / sysdeps / unix / sysv / linux / internal-signals.h
bloba6fae59aaa60033714f2c2b0cc2e1b463578d47f
1 /* Special use of signals internally. Linux version.
2 Copyright (C) 2014-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #ifndef __INTERNAL_SIGNALS_H
20 # define __INTERNAL_SIGNALS_H
22 #include <internal-sigset.h>
23 #include <limits.h>
24 #include <signal.h>
25 #include <sigsetops.h>
26 #include <stdbool.h>
27 #include <stddef.h>
28 #include <sysdep.h>
30 /* The signal used for asynchronous cancelation. */
31 #define SIGCANCEL __SIGRTMIN
34 /* Signal needed for the kernel-supported POSIX timer implementation.
35 We can reuse the cancellation signal since we can distinguish
36 cancellation from timer expirations. */
37 #define SIGTIMER SIGCANCEL
40 /* Signal used to implement the setuid et.al. functions. */
41 #define SIGSETXID (__SIGRTMIN + 1)
44 /* How many signal numbers need to be reserved for libpthread's private uses
45 (SIGCANCEL and SIGSETXID). */
46 #define RESERVED_SIGRT 2
49 /* Return is sig is used internally. */
50 static inline bool
51 is_internal_signal (int sig)
53 return (sig == SIGCANCEL) || (sig == SIGSETXID);
56 /* Remove internal glibc signal from the mask. */
57 static inline void
58 clear_internal_signals (sigset_t *set)
60 __sigdelset (set, SIGCANCEL);
61 __sigdelset (set, SIGSETXID);
64 static const internal_sigset_t sigall_set = {
65 .__val = {[0 ... __NSIG_WORDS-1 ] = -1 }
68 /* Obtain and change blocked signals, including internal glibc ones. */
69 static inline int
70 internal_sigprocmask (int how, const internal_sigset_t *set,
71 internal_sigset_t *oldset)
73 return INTERNAL_SYSCALL_CALL (rt_sigprocmask, how, set, oldset,
74 __NSIG_BYTES);
77 /* Block all signals, including internal glibc ones. */
78 static inline void
79 internal_signal_block_all (internal_sigset_t *oset)
81 INTERNAL_SYSCALL_CALL (rt_sigprocmask, SIG_BLOCK, &sigall_set, oset,
82 __NSIG_BYTES);
85 /* Restore current process signal mask. */
86 static inline void
87 internal_signal_restore_set (const internal_sigset_t *set)
89 INTERNAL_SYSCALL_CALL (rt_sigprocmask, SIG_SETMASK, set, NULL,
90 __NSIG_BYTES);
94 /* It is used on timer_create code directly on sigwaitinfo call, so it can not
95 use the internal_sigset_t definitions. */
96 static const sigset_t sigtimer_set = {
97 .__val = { [0] = __sigmask (SIGTIMER),
98 [1 ... _SIGSET_NWORDS-1] = 0
102 /* Unblock only SIGTIMER. */
103 static inline void
104 signal_unblock_sigtimer (void)
106 INTERNAL_SYSCALL_CALL (rt_sigprocmask, SIG_UNBLOCK, &sigtimer_set, NULL,
107 __NSIG_BYTES);
110 #endif