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>
25 #include <sigsetops.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. */
51 is_internal_signal (int sig
)
53 return (sig
== SIGCANCEL
) || (sig
== SIGSETXID
);
56 /* Remove internal glibc signal from the mask. */
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. */
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
,
77 /* Block all signals, including internal glibc ones. */
79 internal_signal_block_all (internal_sigset_t
*oset
)
81 INTERNAL_SYSCALL_CALL (rt_sigprocmask
, SIG_BLOCK
, &sigall_set
, oset
,
85 /* Restore current process signal mask. */
87 internal_signal_restore_set (const internal_sigset_t
*set
)
89 INTERNAL_SYSCALL_CALL (rt_sigprocmask
, SIG_SETMASK
, set
, NULL
,
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. */
104 signal_unblock_sigtimer (void)
106 INTERNAL_SYSCALL_CALL (rt_sigprocmask
, SIG_UNBLOCK
, &sigtimer_set
, NULL
,