Fix sigstack namespace (bug 21511).
[glibc.git] / signal / signal.h
blob947873ea8ec5bdefff01ed08539576a1c51b71f5
1 /* Copyright (C) 1991-2017 Free Software Foundation, Inc.
2 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.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
19 * ISO C99 Standard: 7.14 Signal handling <signal.h>
22 #ifndef _SIGNAL_H
23 #define _SIGNAL_H
25 #include <features.h>
27 __BEGIN_DECLS
29 #include <bits/types.h>
30 #include <bits/signum.h>
32 #include <bits/types/sig_atomic_t.h>
34 #if defined __USE_POSIX
35 #include <bits/types/sigset_t.h>
36 #endif
38 #if defined __USE_XOPEN || defined __USE_XOPEN2K
39 # ifndef __pid_t_defined
40 typedef __pid_t pid_t;
41 # define __pid_t_defined
42 #endif
43 #ifdef __USE_XOPEN
44 # endif
45 # ifndef __uid_t_defined
46 typedef __uid_t uid_t;
47 # define __uid_t_defined
48 # endif
49 #endif /* Unix98 */
51 #ifdef __USE_POSIX199309
52 /* We need `struct timespec' later on. */
53 # include <bits/types/struct_timespec.h>
54 #endif
56 #if defined __USE_POSIX199309 || defined __USE_XOPEN_EXTENDED
57 # include <bits/types/siginfo_t.h>
58 # include <bits/types/sigevent_t.h>
59 # include <bits/siginfo-consts.h>
60 # include <bits/sigevent-consts.h>
61 #endif
64 /* Type of a signal handler. */
65 typedef void (*__sighandler_t) (int);
67 /* The X/Open definition of `signal' specifies the SVID semantic. Use
68 the additional function `sysv_signal' when X/Open compatibility is
69 requested. */
70 extern __sighandler_t __sysv_signal (int __sig, __sighandler_t __handler)
71 __THROW;
72 #ifdef __USE_GNU
73 extern __sighandler_t sysv_signal (int __sig, __sighandler_t __handler)
74 __THROW;
75 #endif
77 /* Set the handler for the signal SIG to HANDLER, returning the old
78 handler, or SIG_ERR on error.
79 By default `signal' has the BSD semantic. */
80 #ifdef __USE_MISC
81 extern __sighandler_t signal (int __sig, __sighandler_t __handler)
82 __THROW;
83 #else
84 /* Make sure the used `signal' implementation is the SVID version. */
85 # ifdef __REDIRECT_NTH
86 extern __sighandler_t __REDIRECT_NTH (signal,
87 (int __sig, __sighandler_t __handler),
88 __sysv_signal);
89 # else
90 # define signal __sysv_signal
91 # endif
92 #endif
94 #if defined __USE_XOPEN && !defined __USE_XOPEN2K8
95 /* The X/Open definition of `signal' conflicts with the BSD version.
96 So they defined another function `bsd_signal'. */
97 extern __sighandler_t bsd_signal (int __sig, __sighandler_t __handler)
98 __THROW;
99 #endif
101 /* Send signal SIG to process number PID. If PID is zero,
102 send SIG to all processes in the current process's process group.
103 If PID is < -1, send SIG to all processes in process group - PID. */
104 #ifdef __USE_POSIX
105 extern int kill (__pid_t __pid, int __sig) __THROW;
106 #endif /* Use POSIX. */
108 #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
109 /* Send SIG to all processes in process group PGRP.
110 If PGRP is zero, send SIG to all processes in
111 the current process's process group. */
112 extern int killpg (__pid_t __pgrp, int __sig) __THROW;
113 #endif /* Use misc || X/Open Unix. */
115 /* Raise signal SIG, i.e., send SIG to yourself. */
116 extern int raise (int __sig) __THROW;
118 #ifdef __USE_MISC
119 /* SVID names for the same things. */
120 extern __sighandler_t ssignal (int __sig, __sighandler_t __handler)
121 __THROW;
122 extern int gsignal (int __sig) __THROW;
123 #endif /* Use misc. */
125 #ifdef __USE_XOPEN2K8
126 /* Print a message describing the meaning of the given signal number. */
127 extern void psignal (int __sig, const char *__s);
129 /* Print a message describing the meaning of the given signal information. */
130 extern void psiginfo (const siginfo_t *__pinfo, const char *__s);
131 #endif /* POSIX 2008. */
135 /* The `sigpause' function in X/Open defines the argument as the
136 signal number. This requires redirecting to another function
137 because the default version in glibc uses an old BSD interface.
139 This function is a cancellation point and therefore not marked with
140 __THROW. */
142 #ifdef __USE_XOPEN
143 # ifdef __GNUC__
144 extern int sigpause (int __sig) __asm__ ("__xpg_sigpause");
145 # else
146 extern int __sigpause (int __sig_or_mask, int __is_sig);
147 /* Remove a signal from the signal mask and suspend the process. */
148 # define sigpause(sig) __sigpause ((sig), 1)
149 # endif
150 #endif
153 #ifdef __USE_MISC
154 /* None of the following functions should be used anymore. They are here
155 only for compatibility. A single word (`int') is not guaranteed to be
156 enough to hold a complete signal mask and therefore these functions
157 simply do not work in many situations. Use `sigprocmask' instead. */
159 /* Compute mask for signal SIG. */
160 # define sigmask(sig) ((int)(1u << ((sig) - 1)))
162 /* Block signals in MASK, returning the old mask. */
163 extern int sigblock (int __mask) __THROW __attribute_deprecated__;
165 /* Set the mask of blocked signals to MASK, returning the old mask. */
166 extern int sigsetmask (int __mask) __THROW __attribute_deprecated__;
168 /* Return currently selected signal mask. */
169 extern int siggetmask (void) __THROW __attribute_deprecated__;
170 #endif /* Use misc. */
173 #ifdef __USE_MISC
174 # define NSIG _NSIG
175 #endif
177 #ifdef __USE_GNU
178 typedef __sighandler_t sighandler_t;
179 #endif
181 /* 4.4 BSD uses the name `sig_t' for this. */
182 #ifdef __USE_MISC
183 typedef __sighandler_t sig_t;
184 #endif
186 #ifdef __USE_POSIX
188 /* Clear all signals from SET. */
189 extern int sigemptyset (sigset_t *__set) __THROW __nonnull ((1));
191 /* Set all signals in SET. */
192 extern int sigfillset (sigset_t *__set) __THROW __nonnull ((1));
194 /* Add SIGNO to SET. */
195 extern int sigaddset (sigset_t *__set, int __signo) __THROW __nonnull ((1));
197 /* Remove SIGNO from SET. */
198 extern int sigdelset (sigset_t *__set, int __signo) __THROW __nonnull ((1));
200 /* Return 1 if SIGNO is in SET, 0 if not. */
201 extern int sigismember (const sigset_t *__set, int __signo)
202 __THROW __nonnull ((1));
204 # ifdef __USE_GNU
205 /* Return non-empty value is SET is not empty. */
206 extern int sigisemptyset (const sigset_t *__set) __THROW __nonnull ((1));
208 /* Build new signal set by combining the two inputs set using logical AND. */
209 extern int sigandset (sigset_t *__set, const sigset_t *__left,
210 const sigset_t *__right) __THROW __nonnull ((1, 2, 3));
212 /* Build new signal set by combining the two inputs set using logical OR. */
213 extern int sigorset (sigset_t *__set, const sigset_t *__left,
214 const sigset_t *__right) __THROW __nonnull ((1, 2, 3));
215 # endif /* GNU */
217 /* Get the system-specific definitions of `struct sigaction'
218 and the `SA_*' and `SIG_*'. constants. */
219 # include <bits/sigaction.h>
221 /* Get and/or change the set of blocked signals. */
222 extern int sigprocmask (int __how, const sigset_t *__restrict __set,
223 sigset_t *__restrict __oset) __THROW;
225 /* Change the set of blocked signals to SET,
226 wait until a signal arrives, and restore the set of blocked signals.
228 This function is a cancellation point and therefore not marked with
229 __THROW. */
230 extern int sigsuspend (const sigset_t *__set) __nonnull ((1));
232 /* Get and/or set the action for signal SIG. */
233 extern int sigaction (int __sig, const struct sigaction *__restrict __act,
234 struct sigaction *__restrict __oact) __THROW;
236 /* Put in SET all signals that are blocked and waiting to be delivered. */
237 extern int sigpending (sigset_t *__set) __THROW __nonnull ((1));
240 /* Select any of pending signals from SET or wait for any to arrive.
242 This function is a cancellation point and therefore not marked with
243 __THROW. */
244 extern int sigwait (const sigset_t *__restrict __set, int *__restrict __sig)
245 __nonnull ((1, 2));
247 # ifdef __USE_POSIX199309
248 /* Select any of pending signals from SET and place information in INFO.
250 This function is a cancellation point and therefore not marked with
251 __THROW. */
252 extern int sigwaitinfo (const sigset_t *__restrict __set,
253 siginfo_t *__restrict __info) __nonnull ((1));
255 /* Select any of pending signals from SET and place information in INFO.
256 Wait the time specified by TIMEOUT if no signal is pending.
258 This function is a cancellation point and therefore not marked with
259 __THROW. */
260 extern int sigtimedwait (const sigset_t *__restrict __set,
261 siginfo_t *__restrict __info,
262 const struct timespec *__restrict __timeout)
263 __nonnull ((1));
265 /* Send signal SIG to the process PID. Associate data in VAL with the
266 signal. */
267 extern int sigqueue (__pid_t __pid, int __sig, const union sigval __val)
268 __THROW;
269 # endif /* Use POSIX 199306. */
271 #endif /* Use POSIX. */
273 #ifdef __USE_MISC
275 /* Names of the signals. This variable exists only for compatibility.
276 Use `strsignal' instead (see <string.h>). */
277 extern const char *const _sys_siglist[_NSIG];
278 extern const char *const sys_siglist[_NSIG];
281 /* Get machine-dependent `struct sigcontext' and signal subcodes. */
282 # include <bits/sigcontext.h>
284 /* Restore the state saved in SCP. */
285 extern int sigreturn (struct sigcontext *__scp) __THROW;
287 #endif /* Use misc. */
290 #if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8
291 # define __need_size_t
292 # include <stddef.h>
294 /* If INTERRUPT is nonzero, make signal SIG interrupt system calls
295 (causing them to fail with EINTR); if INTERRUPT is zero, make system
296 calls be restarted after signal SIG. */
297 extern int siginterrupt (int __sig, int __interrupt) __THROW;
299 # include <bits/sigstack.h>
300 # include <bits/types/stack_t.h>
301 # include <bits/ss_flags.h>
302 # if defined __USE_XOPEN || defined __USE_XOPEN2K8
303 /* This will define `ucontext_t' and `mcontext_t'. */
304 # include <sys/ucontext.h>
305 # endif
307 /* Alternate signal handler stack interface.
308 This interface should always be preferred over `sigstack'. */
309 extern int sigaltstack (const struct sigaltstack *__restrict __ss,
310 struct sigaltstack *__restrict __oss) __THROW;
312 #endif /* Use POSIX.1-2008 or X/Open Unix. */
314 #if ((defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K8) \
315 || defined __USE_MISC)
316 # include <bits/types/struct_sigstack.h>
317 #endif
319 #if ((defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K) \
320 || defined __USE_MISC)
321 /* Run signals handlers on the stack specified by SS (if not NULL).
322 If OSS is not NULL, it is filled in with the old signal stack status.
323 This interface is obsolete and on many platform not implemented. */
324 extern int sigstack (struct sigstack *__ss, struct sigstack *__oss)
325 __THROW __attribute_deprecated__;
326 #endif
328 #ifdef __USE_XOPEN_EXTENDED
329 /* Simplified interface for signal management. */
331 /* Add SIG to the calling process' signal mask. */
332 extern int sighold (int __sig) __THROW;
334 /* Remove SIG from the calling process' signal mask. */
335 extern int sigrelse (int __sig) __THROW;
337 /* Set the disposition of SIG to SIG_IGN. */
338 extern int sigignore (int __sig) __THROW;
340 /* Set the disposition of SIG. */
341 extern __sighandler_t sigset (int __sig, __sighandler_t __disp) __THROW;
342 #endif
344 #if defined __USE_POSIX199506 || defined __USE_UNIX98
345 /* Some of the functions for handling signals in threaded programs must
346 be defined here. */
347 # include <bits/pthreadtypes.h>
348 # include <bits/sigthread.h>
349 #endif /* use Unix98 */
351 /* The following functions are used internally in the C library and in
352 other code which need deep insights. */
354 /* Return number of available real-time signal with highest priority. */
355 extern int __libc_current_sigrtmin (void) __THROW;
356 /* Return number of available real-time signal with lowest priority. */
357 extern int __libc_current_sigrtmax (void) __THROW;
359 __END_DECLS
361 #endif /* not signal.h */