1 /* A GNU-like <signal.h>.
3 Copyright (C) 2006-2024 Free Software Foundation, Inc.
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
10 This file 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
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
19 @PRAGMA_SYSTEM_HEADER@
23 #if defined __need_sig_atomic_t || defined __need_sigset_t || defined _GL_ALREADY_INCLUDING_SIGNAL_H || (defined _SIGNAL_H && !defined __SIZEOF_PTHREAD_MUTEX_T)
24 /* Special invocation convention:
25 - Inside glibc header files.
26 - On glibc systems we have a sequence of nested includes
27 <signal.h> -> <ucontext.h> -> <signal.h>.
28 In this situation, the functions are not yet declared, therefore we cannot
29 provide the C++ aliases.
30 - On glibc systems with GCC 4.3 we have a sequence of nested includes
31 <csignal> -> </usr/include/signal.h> -> <sys/ucontext.h> -> <signal.h>.
32 In this situation, some of the functions are not yet declared, therefore
33 we cannot provide the C++ aliases. */
35 # @INCLUDE_NEXT@ @NEXT_SIGNAL_H@
38 /* Normal invocation convention. */
40 #ifndef _@GUARD_PREFIX@_SIGNAL_H
42 #define _GL_ALREADY_INCLUDING_SIGNAL_H
44 /* Define pid_t, uid_t.
45 Also, mingw defines sigset_t not in <signal.h>, but in <sys/types.h>.
46 On Solaris 10, <signal.h> includes <sys/types.h>, which eventually includes
47 us; so include <sys/types.h> now, before the second inclusion guard. */
48 #include <sys/types.h>
50 /* The include_next requires a split double-inclusion guard. */
51 #@INCLUDE_NEXT@ @NEXT_SIGNAL_H@
53 #undef _GL_ALREADY_INCLUDING_SIGNAL_H
55 #ifndef _@GUARD_PREFIX@_SIGNAL_H
56 #define _@GUARD_PREFIX@_SIGNAL_H
58 /* This file uses GNULIB_POSIXCHECK, HAVE_RAW_DECL_*. */
59 #if !_GL_CONFIG_H_INCLUDED
60 #error "Please include config.h first."
63 /* For testing the OpenBSD version. */
64 #if (@GNULIB_PTHREAD_SIGMASK@ || defined GNULIB_POSIXCHECK) \
65 && defined __OpenBSD__
66 # include <sys/param.h>
69 /* Mac OS X 10.3, FreeBSD < 8.0, OpenBSD < 5.1, OSF/1 4.0, Solaris 2.6, Android,
70 OS/2 kLIBC declare pthread_sigmask in <pthread.h>, not in <signal.h>.
71 But avoid namespace pollution on glibc systems.*/
72 #if (@GNULIB_PTHREAD_SIGMASK@ || defined GNULIB_POSIXCHECK) \
73 && ((defined __APPLE__ && defined __MACH__) \
74 || (defined __FreeBSD__ && __FreeBSD__ < 8) \
75 || (defined __OpenBSD__ && OpenBSD < 201205) \
76 || defined __osf__ || defined __sun || defined __ANDROID__ \
77 || defined __KLIBC__) \
78 && ! defined __GLIBC__
82 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
84 /* The definition of _GL_ARG_NONNULL is copied here. */
86 /* The definition of _GL_WARN_ON_USE is copied here. */
88 /* On AIX, sig_atomic_t already includes volatile. C99 requires that
89 'volatile sig_atomic_t' ignore the extra modifier, but C89 did not.
90 Hence, redefine this to a non-volatile type as needed. */
91 #if ! @HAVE_TYPE_VOLATILE_SIG_ATOMIC_T@
92 # if !GNULIB_defined_sig_atomic_t
93 typedef int rpl_sig_atomic_t
;
95 # define sig_atomic_t rpl_sig_atomic_t
96 # define GNULIB_defined_sig_atomic_t 1
100 /* A set or mask of signals. */
102 # if !GNULIB_defined_sigset_t
103 typedef unsigned int sigset_t
;
104 # define GNULIB_defined_sigset_t 1
108 /* Define sighandler_t, the type of signal handlers. A GNU extension. */
109 #if !@HAVE_SIGHANDLER_T@
113 # if !GNULIB_defined_sighandler_t
114 typedef void (*sighandler_t
) (int);
115 # define GNULIB_defined_sighandler_t 1
123 #if @GNULIB_SIGNAL_H_SIGPIPE@
125 /* Define SIGPIPE to a value that does not overlap with other signals. */
127 # define GNULIB_defined_SIGPIPE 1
128 /* To actually use SIGPIPE, you also need the gnulib modules 'sigprocmask',
134 /* Maximum signal number + 1. */
136 # if defined __TANDEM
142 #if @GNULIB_PTHREAD_SIGMASK@
143 # if @REPLACE_PTHREAD_SIGMASK@
144 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
145 # undef pthread_sigmask
146 # define pthread_sigmask rpl_pthread_sigmask
148 _GL_FUNCDECL_RPL (pthread_sigmask
, int,
150 const sigset_t
*restrict new_mask
,
151 sigset_t
*restrict old_mask
));
152 _GL_CXXALIAS_RPL (pthread_sigmask
, int,
154 const sigset_t
*restrict new_mask
,
155 sigset_t
*restrict old_mask
));
157 # if !(@HAVE_PTHREAD_SIGMASK@ || defined pthread_sigmask)
158 _GL_FUNCDECL_SYS (pthread_sigmask
, int,
160 const sigset_t
*restrict new_mask
,
161 sigset_t
*restrict old_mask
));
163 _GL_CXXALIAS_SYS (pthread_sigmask
, int,
165 const sigset_t
*restrict new_mask
,
166 sigset_t
*restrict old_mask
));
169 _GL_CXXALIASWARN (pthread_sigmask
);
171 #elif defined GNULIB_POSIXCHECK
172 # undef pthread_sigmask
173 # if HAVE_RAW_DECL_PTHREAD_SIGMASK
174 _GL_WARN_ON_USE (pthread_sigmask
, "pthread_sigmask is not portable - "
175 "use gnulib module pthread_sigmask for portability");
182 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
184 # define raise rpl_raise
186 _GL_FUNCDECL_RPL (raise
, int, (int sig
));
187 _GL_CXXALIAS_RPL (raise
, int, (int sig
));
190 _GL_FUNCDECL_SYS (raise
, int, (int sig
));
192 _GL_CXXALIAS_SYS (raise
, int, (int sig
));
195 _GL_CXXALIASWARN (raise
);
197 #elif defined GNULIB_POSIXCHECK
199 /* Assume raise is always declared. */
200 _GL_WARN_ON_USE (raise
, "raise can crash on native Windows - "
201 "use gnulib module raise for portability");
205 #if @GNULIB_SIGPROCMASK@
206 # if !@HAVE_POSIX_SIGNALBLOCKING@
208 # ifndef GNULIB_defined_signal_blocking
209 # define GNULIB_defined_signal_blocking 1
212 /* Maximum signal number + 1. */
217 /* This code supports only 32 signals. */
218 # if !GNULIB_defined_verify_NSIG_constraint
219 typedef int verify_NSIG_constraint
[NSIG
<= 32 ? 1 : -1];
220 # define GNULIB_defined_verify_NSIG_constraint 1
225 /* When also using extern inline, suppress the use of static inline in
226 standard headers of problematic Apple configurations, as Libc at
227 least through Libc-825.26 (2013-04-09) mishandles it; see, e.g.,
228 <https://lists.gnu.org/r/bug-gnulib/2012-12/msg00023.html>.
229 Perhaps Apple will fix this some day. */
230 #if (defined _GL_EXTERN_INLINE_IN_USE && defined __APPLE__ \
231 && (defined __i386__ || defined __x86_64__))
239 /* Test whether a given signal is contained in a signal set. */
240 # if @HAVE_POSIX_SIGNALBLOCKING@
241 /* This function is defined as a macro on Mac OS X. */
242 # if defined __cplusplus && defined GNULIB_NAMESPACE
246 _GL_FUNCDECL_SYS (sigismember
, int, (const sigset_t
*set
, int sig
)
247 _GL_ARG_NONNULL ((1)));
249 _GL_CXXALIAS_SYS (sigismember
, int, (const sigset_t
*set
, int sig
));
250 _GL_CXXALIASWARN (sigismember
);
252 /* Initialize a signal set to the empty set. */
253 # if @HAVE_POSIX_SIGNALBLOCKING@
254 /* This function is defined as a macro on Mac OS X. */
255 # if defined __cplusplus && defined GNULIB_NAMESPACE
259 _GL_FUNCDECL_SYS (sigemptyset
, int, (sigset_t
*set
) _GL_ARG_NONNULL ((1)));
261 _GL_CXXALIAS_SYS (sigemptyset
, int, (sigset_t
*set
));
262 _GL_CXXALIASWARN (sigemptyset
);
264 /* Add a signal to a signal set. */
265 # if @HAVE_POSIX_SIGNALBLOCKING@
266 /* This function is defined as a macro on Mac OS X. */
267 # if defined __cplusplus && defined GNULIB_NAMESPACE
271 _GL_FUNCDECL_SYS (sigaddset
, int, (sigset_t
*set
, int sig
)
272 _GL_ARG_NONNULL ((1)));
274 _GL_CXXALIAS_SYS (sigaddset
, int, (sigset_t
*set
, int sig
));
275 _GL_CXXALIASWARN (sigaddset
);
277 /* Remove a signal from a signal set. */
278 # if @HAVE_POSIX_SIGNALBLOCKING@
279 /* This function is defined as a macro on Mac OS X. */
280 # if defined __cplusplus && defined GNULIB_NAMESPACE
284 _GL_FUNCDECL_SYS (sigdelset
, int, (sigset_t
*set
, int sig
)
285 _GL_ARG_NONNULL ((1)));
287 _GL_CXXALIAS_SYS (sigdelset
, int, (sigset_t
*set
, int sig
));
288 _GL_CXXALIASWARN (sigdelset
);
290 /* Fill a signal set with all possible signals. */
291 # if @HAVE_POSIX_SIGNALBLOCKING@
292 /* This function is defined as a macro on Mac OS X. */
293 # if defined __cplusplus && defined GNULIB_NAMESPACE
297 _GL_FUNCDECL_SYS (sigfillset
, int, (sigset_t
*set
) _GL_ARG_NONNULL ((1)));
299 _GL_CXXALIAS_SYS (sigfillset
, int, (sigset_t
*set
));
300 _GL_CXXALIASWARN (sigfillset
);
302 /* Return the set of those blocked signals that are pending. */
303 # if !@HAVE_POSIX_SIGNALBLOCKING@
304 _GL_FUNCDECL_SYS (sigpending
, int, (sigset_t
*set
) _GL_ARG_NONNULL ((1)));
306 _GL_CXXALIAS_SYS (sigpending
, int, (sigset_t
*set
));
307 _GL_CXXALIASWARN (sigpending
);
309 /* If OLD_SET is not NULL, put the current set of blocked signals in *OLD_SET.
310 Then, if SET is not NULL, affect the current set of blocked signals by
311 combining it with *SET as indicated in OPERATION.
312 In this implementation, you are not allowed to change a signal handler
313 while the signal is blocked. */
314 # if !@HAVE_POSIX_SIGNALBLOCKING@
315 # define SIG_BLOCK 0 /* blocked_set = blocked_set | *set; */
316 # define SIG_SETMASK 1 /* blocked_set = *set; */
317 # define SIG_UNBLOCK 2 /* blocked_set = blocked_set & ~*set; */
318 _GL_FUNCDECL_SYS (sigprocmask
, int,
320 const sigset_t
*restrict set
,
321 sigset_t
*restrict old_set
));
323 _GL_CXXALIAS_SYS (sigprocmask
, int,
325 const sigset_t
*restrict set
,
326 sigset_t
*restrict old_set
));
327 _GL_CXXALIASWARN (sigprocmask
);
329 /* Install the handler FUNC for signal SIG, and return the previous
334 # if !GNULIB_defined_function_taking_int_returning_void_t
335 typedef void (*_gl_function_taking_int_returning_void_t
) (int);
336 # define GNULIB_defined_function_taking_int_returning_void_t 1
341 # if !@HAVE_POSIX_SIGNALBLOCKING@
342 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
343 # define signal rpl_signal
345 _GL_FUNCDECL_RPL (signal
, _gl_function_taking_int_returning_void_t
,
346 (int sig
, _gl_function_taking_int_returning_void_t func
));
347 _GL_CXXALIAS_RPL (signal
, _gl_function_taking_int_returning_void_t
,
348 (int sig
, _gl_function_taking_int_returning_void_t func
));
350 /* On OpenBSD, the declaration of 'signal' may not be present at this point,
351 because it occurs in <sys/signal.h>, not <signal.h> directly. */
352 # if defined __OpenBSD__
353 _GL_FUNCDECL_SYS (signal
, _gl_function_taking_int_returning_void_t
,
354 (int sig
, _gl_function_taking_int_returning_void_t func
));
356 _GL_CXXALIAS_SYS (signal
, _gl_function_taking_int_returning_void_t
,
357 (int sig
, _gl_function_taking_int_returning_void_t func
));
360 _GL_CXXALIASWARN (signal
);
363 # if !@HAVE_POSIX_SIGNALBLOCKING@ && GNULIB_defined_SIGPIPE
364 /* Raise signal SIGPIPE. */
365 _GL_EXTERN_C
int _gl_raise_SIGPIPE (void);
368 #elif defined GNULIB_POSIXCHECK
370 # if HAVE_RAW_DECL_SIGADDSET
371 _GL_WARN_ON_USE (sigaddset
, "sigaddset is unportable - "
372 "use the gnulib module sigprocmask for portability");
375 # if HAVE_RAW_DECL_SIGDELSET
376 _GL_WARN_ON_USE (sigdelset
, "sigdelset is unportable - "
377 "use the gnulib module sigprocmask for portability");
380 # if HAVE_RAW_DECL_SIGEMPTYSET
381 _GL_WARN_ON_USE (sigemptyset
, "sigemptyset is unportable - "
382 "use the gnulib module sigprocmask for portability");
385 # if HAVE_RAW_DECL_SIGFILLSET
386 _GL_WARN_ON_USE (sigfillset
, "sigfillset is unportable - "
387 "use the gnulib module sigprocmask for portability");
390 # if HAVE_RAW_DECL_SIGISMEMBER
391 _GL_WARN_ON_USE (sigismember
, "sigismember is unportable - "
392 "use the gnulib module sigprocmask for portability");
395 # if HAVE_RAW_DECL_SIGPENDING
396 _GL_WARN_ON_USE (sigpending
, "sigpending is unportable - "
397 "use the gnulib module sigprocmask for portability");
400 # if HAVE_RAW_DECL_SIGPROCMASK
401 _GL_WARN_ON_USE (sigprocmask
, "sigprocmask is unportable - "
402 "use the gnulib module sigprocmask for portability");
404 #endif /* @GNULIB_SIGPROCMASK@ */
407 #if @GNULIB_SIGACTION@
408 # if !@HAVE_SIGACTION@
410 # if !@HAVE_SIGINFO_T@
412 # if !GNULIB_defined_siginfo_types
414 /* Present to allow compilation, but unsupported by gnulib. */
421 /* Present to allow compilation, but unsupported by gnulib. */
432 union sigval si_value
;
434 typedef struct siginfo_t siginfo_t
;
436 # define GNULIB_defined_siginfo_types 1
439 # endif /* !@HAVE_SIGINFO_T@ */
441 /* We assume that platforms which lack the sigaction() function also lack
442 the 'struct sigaction' type, and vice versa. */
444 # if !GNULIB_defined_struct_sigaction
450 void (*_sa_handler
) (int);
451 /* Present to allow compilation, but unsupported by gnulib. POSIX
452 says that implementations may, but not must, make sa_sigaction
453 overlap with sa_handler, but we know of no implementation where
454 they do not overlap. */
455 void (*_sa_sigaction
) (int, siginfo_t
*, void *);
458 /* Not all POSIX flags are supported. */
461 # define sa_handler _sa_func._sa_handler
462 # define sa_sigaction _sa_func._sa_sigaction
463 /* Unsupported flags are not present. */
464 # define SA_RESETHAND 1
465 # define SA_NODEFER 2
466 # define SA_RESTART 4
468 # define GNULIB_defined_struct_sigaction 1
471 _GL_FUNCDECL_SYS (sigaction
, int, (int, const struct sigaction
*restrict
,
472 struct sigaction
*restrict
));
474 # elif !@HAVE_STRUCT_SIGACTION_SA_SIGACTION@
476 # define sa_sigaction sa_handler
478 # endif /* !@HAVE_SIGACTION@, !@HAVE_STRUCT_SIGACTION_SA_SIGACTION@ */
480 _GL_CXXALIAS_SYS (sigaction
, int, (int, const struct sigaction
*restrict
,
481 struct sigaction
*restrict
));
482 _GL_CXXALIASWARN (sigaction
);
484 #elif defined GNULIB_POSIXCHECK
486 # if HAVE_RAW_DECL_SIGACTION
487 _GL_WARN_ON_USE (sigaction
, "sigaction is unportable - "
488 "use the gnulib module sigaction for portability");
492 /* Some systems don't have SA_NODEFER. */
494 # define SA_NODEFER 0
498 #endif /* _@GUARD_PREFIX@_SIGNAL_H */
499 #endif /* _@GUARD_PREFIX@_SIGNAL_H */