Remove extra semicolons in struct pthread_mutex (bug 21804)
[glibc.git] / signal / signal.h
blobc8f6100ac479ef57144598001b0b28df4fc69424
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/siginfo-consts.h>
59 #endif
61 #ifdef __USE_POSIX199309
62 # include <bits/types/sigevent_t.h>
63 # include <bits/sigevent-consts.h>
64 #endif
67 /* Type of a signal handler. */
68 typedef void (*__sighandler_t) (int);
70 /* The X/Open definition of `signal' specifies the SVID semantic. Use
71 the additional function `sysv_signal' when X/Open compatibility is
72 requested. */
73 extern __sighandler_t __sysv_signal (int __sig, __sighandler_t __handler)
74 __THROW;
75 #ifdef __USE_GNU
76 extern __sighandler_t sysv_signal (int __sig, __sighandler_t __handler)
77 __THROW;
78 #endif
80 /* Set the handler for the signal SIG to HANDLER, returning the old
81 handler, or SIG_ERR on error.
82 By default `signal' has the BSD semantic. */
83 #ifdef __USE_MISC
84 extern __sighandler_t signal (int __sig, __sighandler_t __handler)
85 __THROW;
86 #else
87 /* Make sure the used `signal' implementation is the SVID version. */
88 # ifdef __REDIRECT_NTH
89 extern __sighandler_t __REDIRECT_NTH (signal,
90 (int __sig, __sighandler_t __handler),
91 __sysv_signal);
92 # else
93 # define signal __sysv_signal
94 # endif
95 #endif
97 #if defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K8
98 /* The X/Open definition of `signal' conflicts with the BSD version.
99 So they defined another function `bsd_signal'. */
100 extern __sighandler_t bsd_signal (int __sig, __sighandler_t __handler)
101 __THROW;
102 #endif
104 /* Send signal SIG to process number PID. If PID is zero,
105 send SIG to all processes in the current process's process group.
106 If PID is < -1, send SIG to all processes in process group - PID. */
107 #ifdef __USE_POSIX
108 extern int kill (__pid_t __pid, int __sig) __THROW;
109 #endif /* Use POSIX. */
111 #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
112 /* Send SIG to all processes in process group PGRP.
113 If PGRP is zero, send SIG to all processes in
114 the current process's process group. */
115 extern int killpg (__pid_t __pgrp, int __sig) __THROW;
116 #endif /* Use misc || X/Open Unix. */
118 /* Raise signal SIG, i.e., send SIG to yourself. */
119 extern int raise (int __sig) __THROW;
121 #ifdef __USE_MISC
122 /* SVID names for the same things. */
123 extern __sighandler_t ssignal (int __sig, __sighandler_t __handler)
124 __THROW;
125 extern int gsignal (int __sig) __THROW;
126 #endif /* Use misc. */
128 #ifdef __USE_XOPEN2K8
129 /* Print a message describing the meaning of the given signal number. */
130 extern void psignal (int __sig, const char *__s);
132 /* Print a message describing the meaning of the given signal information. */
133 extern void psiginfo (const siginfo_t *__pinfo, const char *__s);
134 #endif /* POSIX 2008. */
138 /* The `sigpause' function in X/Open defines the argument as the
139 signal number. This requires redirecting to another function
140 because the default version in glibc uses an old BSD interface.
142 This function is a cancellation point and therefore not marked with
143 __THROW. */
145 #ifdef __USE_XOPEN_EXTENDED
146 # ifdef __GNUC__
147 extern int sigpause (int __sig) __asm__ ("__xpg_sigpause");
148 # else
149 extern int __sigpause (int __sig_or_mask, int __is_sig);
150 /* Remove a signal from the signal mask and suspend the process. */
151 # define sigpause(sig) __sigpause ((sig), 1)
152 # endif
153 #endif
156 #ifdef __USE_MISC
157 /* None of the following functions should be used anymore. They are here
158 only for compatibility. A single word (`int') is not guaranteed to be
159 enough to hold a complete signal mask and therefore these functions
160 simply do not work in many situations. Use `sigprocmask' instead. */
162 /* Compute mask for signal SIG. */
163 # define sigmask(sig) ((int)(1u << ((sig) - 1)))
165 /* Block signals in MASK, returning the old mask. */
166 extern int sigblock (int __mask) __THROW __attribute_deprecated__;
168 /* Set the mask of blocked signals to MASK, returning the old mask. */
169 extern int sigsetmask (int __mask) __THROW __attribute_deprecated__;
171 /* Return currently selected signal mask. */
172 extern int siggetmask (void) __THROW __attribute_deprecated__;
173 #endif /* Use misc. */
176 #ifdef __USE_MISC
177 # define NSIG _NSIG
178 #endif
180 #ifdef __USE_GNU
181 typedef __sighandler_t sighandler_t;
182 #endif
184 /* 4.4 BSD uses the name `sig_t' for this. */
185 #ifdef __USE_MISC
186 typedef __sighandler_t sig_t;
187 #endif
189 #ifdef __USE_POSIX
191 /* Clear all signals from SET. */
192 extern int sigemptyset (sigset_t *__set) __THROW __nonnull ((1));
194 /* Set all signals in SET. */
195 extern int sigfillset (sigset_t *__set) __THROW __nonnull ((1));
197 /* Add SIGNO to SET. */
198 extern int sigaddset (sigset_t *__set, int __signo) __THROW __nonnull ((1));
200 /* Remove SIGNO from SET. */
201 extern int sigdelset (sigset_t *__set, int __signo) __THROW __nonnull ((1));
203 /* Return 1 if SIGNO is in SET, 0 if not. */
204 extern int sigismember (const sigset_t *__set, int __signo)
205 __THROW __nonnull ((1));
207 # ifdef __USE_GNU
208 /* Return non-empty value is SET is not empty. */
209 extern int sigisemptyset (const sigset_t *__set) __THROW __nonnull ((1));
211 /* Build new signal set by combining the two inputs set using logical AND. */
212 extern int sigandset (sigset_t *__set, const sigset_t *__left,
213 const sigset_t *__right) __THROW __nonnull ((1, 2, 3));
215 /* Build new signal set by combining the two inputs set using logical OR. */
216 extern int sigorset (sigset_t *__set, const sigset_t *__left,
217 const sigset_t *__right) __THROW __nonnull ((1, 2, 3));
218 # endif /* GNU */
220 /* Get the system-specific definitions of `struct sigaction'
221 and the `SA_*' and `SIG_*'. constants. */
222 # include <bits/sigaction.h>
224 /* Get and/or change the set of blocked signals. */
225 extern int sigprocmask (int __how, const sigset_t *__restrict __set,
226 sigset_t *__restrict __oset) __THROW;
228 /* Change the set of blocked signals to SET,
229 wait until a signal arrives, and restore the set of blocked signals.
231 This function is a cancellation point and therefore not marked with
232 __THROW. */
233 extern int sigsuspend (const sigset_t *__set) __nonnull ((1));
235 /* Get and/or set the action for signal SIG. */
236 extern int sigaction (int __sig, const struct sigaction *__restrict __act,
237 struct sigaction *__restrict __oact) __THROW;
239 /* Put in SET all signals that are blocked and waiting to be delivered. */
240 extern int sigpending (sigset_t *__set) __THROW __nonnull ((1));
243 # ifdef __USE_POSIX199506
244 /* Select any of pending signals from SET or wait for any to arrive.
246 This function is a cancellation point and therefore not marked with
247 __THROW. */
248 extern int sigwait (const sigset_t *__restrict __set, int *__restrict __sig)
249 __nonnull ((1, 2));
250 # endif /* Use POSIX 1995. */
252 # ifdef __USE_POSIX199309
253 /* Select any of pending signals from SET and place information in INFO.
255 This function is a cancellation point and therefore not marked with
256 __THROW. */
257 extern int sigwaitinfo (const sigset_t *__restrict __set,
258 siginfo_t *__restrict __info) __nonnull ((1));
260 /* Select any of pending signals from SET and place information in INFO.
261 Wait the time specified by TIMEOUT if no signal is pending.
263 This function is a cancellation point and therefore not marked with
264 __THROW. */
265 extern int sigtimedwait (const sigset_t *__restrict __set,
266 siginfo_t *__restrict __info,
267 const struct timespec *__restrict __timeout)
268 __nonnull ((1));
270 /* Send signal SIG to the process PID. Associate data in VAL with the
271 signal. */
272 extern int sigqueue (__pid_t __pid, int __sig, const union sigval __val)
273 __THROW;
274 # endif /* Use POSIX 199306. */
276 #endif /* Use POSIX. */
278 #ifdef __USE_MISC
280 /* Names of the signals. This variable exists only for compatibility.
281 Use `strsignal' instead (see <string.h>). */
282 extern const char *const _sys_siglist[_NSIG];
283 extern const char *const sys_siglist[_NSIG];
286 /* Get machine-dependent `struct sigcontext' and signal subcodes. */
287 # include <bits/sigcontext.h>
289 /* Restore the state saved in SCP. */
290 extern int sigreturn (struct sigcontext *__scp) __THROW;
292 #endif /* Use misc. */
295 #if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8
296 # define __need_size_t
297 # include <stddef.h>
299 # include <bits/types/stack_t.h>
300 # if defined __USE_XOPEN || defined __USE_XOPEN2K8
301 /* This will define `ucontext_t' and `mcontext_t'. */
302 # include <sys/ucontext.h>
303 # endif
304 #endif /* Use POSIX.1-2008 or X/Open Unix. */
306 #if defined __USE_XOPEN_EXTENDED || defined __USE_MISC
307 /* If INTERRUPT is nonzero, make signal SIG interrupt system calls
308 (causing them to fail with EINTR); if INTERRUPT is zero, make system
309 calls be restarted after signal SIG. */
310 extern int siginterrupt (int __sig, int __interrupt) __THROW;
312 # include <bits/sigstack.h>
313 # include <bits/ss_flags.h>
315 /* Alternate signal handler stack interface.
316 This interface should always be preferred over `sigstack'. */
317 extern int sigaltstack (const stack_t *__restrict __ss,
318 stack_t *__restrict __oss) __THROW;
319 #endif /* __USE_XOPEN_EXTENDED || __USE_MISC */
321 #if ((defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K8) \
322 || defined __USE_MISC)
323 # include <bits/types/struct_sigstack.h>
324 #endif
326 #if ((defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K) \
327 || defined __USE_MISC)
328 /* Run signals handlers on the stack specified by SS (if not NULL).
329 If OSS is not NULL, it is filled in with the old signal stack status.
330 This interface is obsolete and on many platform not implemented. */
331 extern int sigstack (struct sigstack *__ss, struct sigstack *__oss)
332 __THROW __attribute_deprecated__;
333 #endif
335 #ifdef __USE_XOPEN_EXTENDED
336 /* Simplified interface for signal management. */
338 /* Add SIG to the calling process' signal mask. */
339 extern int sighold (int __sig) __THROW;
341 /* Remove SIG from the calling process' signal mask. */
342 extern int sigrelse (int __sig) __THROW;
344 /* Set the disposition of SIG to SIG_IGN. */
345 extern int sigignore (int __sig) __THROW;
347 /* Set the disposition of SIG. */
348 extern __sighandler_t sigset (int __sig, __sighandler_t __disp) __THROW;
349 #endif
351 #if defined __USE_POSIX199506 || defined __USE_UNIX98
352 /* Some of the functions for handling signals in threaded programs must
353 be defined here. */
354 # include <bits/pthreadtypes.h>
355 # include <bits/sigthread.h>
356 #endif /* use Unix98 */
358 /* The following functions are used internally in the C library and in
359 other code which need deep insights. */
361 /* Return number of available real-time signal with highest priority. */
362 extern int __libc_current_sigrtmin (void) __THROW;
363 /* Return number of available real-time signal with lowest priority. */
364 extern int __libc_current_sigrtmax (void) __THROW;
366 #define SIGRTMIN (__libc_current_sigrtmin ())
367 #define SIGRTMAX (__libc_current_sigrtmax ())
369 __END_DECLS
371 #endif /* not signal.h */