1 /* Copyright (C) 1991-2003, 2004, 2007, 2009 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>
24 #if !defined __need_sig_atomic_t && !defined __need_sigset_t
32 #include <bits/sigset.h> /* __sigset_t, __sig_atomic_t. */
34 /* An integral type that can be modified atomically, without the
35 possibility of a signal arriving in the middle of the operation. */
36 #if defined __need_sig_atomic_t || defined _SIGNAL_H
37 # ifndef __sig_atomic_t_defined
38 # define __sig_atomic_t_defined
40 typedef __sig_atomic_t sig_atomic_t;
43 # undef __need_sig_atomic_t
46 #if defined __need_sigset_t || (defined _SIGNAL_H && defined __USE_POSIX)
47 # ifndef __sigset_t_defined
48 # define __sigset_t_defined
49 typedef __sigset_t sigset_t;
51 # undef __need_sigset_t
56 #include <bits/types.h>
57 #include <bits/signum.h>
59 /* Fake signal functions. */
60 #define SIG_ERR ((__sighandler_t) -1) /* Error return. */
61 #define SIG_DFL ((__sighandler_t) 0) /* Default action. */
62 #define SIG_IGN ((__sighandler_t) 1) /* Ignore signal. */
64 # define SIG_HOLD ((__sighandler_t) 2) /* Add signal to hold mask. */
66 /* Biggest signal number + 1 (including real-time signals). */
67 #ifndef _NSIG /* if arch has not defined it in bits/signum.h... */
73 /* Real-time signal range */
74 #define SIGRTMIN (__libc_current_sigrtmin())
75 #define SIGRTMAX (__libc_current_sigrtmax())
76 /* These are the hard limits of the kernel. These values should not be
77 used directly at user level. */
78 #ifndef __SIGRTMIN /* if arch has not defined it in bits/signum.h... */
79 # define __SIGRTMIN 32
81 #define __SIGRTMAX (_NSIG - 1)
84 #if defined __USE_XOPEN || defined __USE_XOPEN2K
85 # ifndef __pid_t_defined
86 typedef __pid_t pid_t;
87 # define __pid_t_defined
91 # ifndef __uid_t_defined
92 typedef __uid_t uid_t;
93 # define __uid_t_defined
97 #if defined __USE_POSIX199309 && defined __UCLIBC_HAS_REALTIME__
98 /* We need `struct timespec' later on. */
99 # define __need_timespec
102 /* Get the `siginfo_t' type plus the needed symbols. */
103 # include <bits/siginfo.h>
107 /* Type of a signal handler. */
108 typedef void (*__sighandler_t) (int);
110 #if defined __UCLIBC_HAS_OBSOLETE_SYSV_SIGNAL__
111 /* The X/Open definition of `signal' specifies the SVID semantic. Use
112 the additional function `sysv_signal' when X/Open compatibility is
114 extern __sighandler_t __sysv_signal (int __sig, __sighandler_t __handler)
117 extern __sighandler_t sysv_signal (int __sig, __sighandler_t __handler)
120 #endif /* __UCLIBC_HAS_OBSOLETE_SYSV_SIGNAL__ */
122 /* Set the handler for the signal SIG to HANDLER, returning the old
123 handler, or SIG_ERR on error.
124 By default `signal' has the BSD semantic. */
125 __BEGIN_NAMESPACE_STD
126 #if defined __USE_BSD || !defined __UCLIBC_HAS_OBSOLETE_SYSV_SIGNAL__
127 extern __sighandler_t signal (int __sig, __sighandler_t __handler)
129 libc_hidden_proto(signal)
131 /* Make sure the used `signal' implementation is the SVID version. */
132 # ifdef __REDIRECT_NTH
133 extern __sighandler_t __REDIRECT_NTH (signal,
134 (int __sig, __sighandler_t __handler),
137 # define signal __sysv_signal
142 #if defined __USE_XOPEN && defined __UCLIBC_SUSV3_LEGACY__
143 /* The X/Open definition of `signal' conflicts with the BSD version.
144 So they defined another function `bsd_signal'. */
145 extern __sighandler_t bsd_signal (int __sig, __sighandler_t __handler)
149 /* Send signal SIG to process number PID. If PID is zero,
150 send SIG to all processes in the current process's process group.
151 If PID is < -1, send SIG to all processes in process group - PID. */
153 extern int kill (__pid_t __pid, int __sig) __THROW;
154 libc_hidden_proto(kill)
157 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
158 /* Send SIG to all processes in process group PGRP.
159 If PGRP is zero, send SIG to all processes in
160 the current process's process group. */
161 extern int killpg (__pid_t __pgrp, int __sig) __THROW;
164 __BEGIN_NAMESPACE_STD
165 /* Raise signal SIG, i.e., send SIG to yourself. */
166 extern int raise (int __sig) __THROW;
167 libc_hidden_proto(raise)
170 #if 0 /*def __USE_SVID*/
171 /* SVID names for the same things. */
172 extern __sighandler_t ssignal (int __sig, __sighandler_t __handler)
174 extern int gsignal (int __sig) __THROW;
175 #endif /* Use SVID. */
177 /* glibc guards the next two wrong with __USE_XOPEN2K */
178 #if defined __USE_MISC || defined __USE_XOPEN2K8
179 /* Print a message describing the meaning of the given signal number. */
180 extern void psignal (int __sig, const char *__s);
181 #endif /* Use misc or POSIX 2008. */
183 #if 0 /*def __USE_XOPEN2K8*/
184 /* Print a message describing the meaning of the given signal information. */
185 extern void psiginfo (const siginfo_t *__pinfo, const char *__s);
186 #endif /* POSIX 2008. */
188 #ifdef __UCLIBC_SUSV4_LEGACY__
189 /* The `sigpause' function has two different interfaces. The original
190 BSD definition defines the argument as a mask of the signal, while
191 the more modern interface in X/Open defines it as the signal
192 number. We go with the BSD version unless the user explicitly
193 selects the X/Open version.
195 This function is a cancellation point and therefore not marked with
197 /*extern int __sigpause (int __sig_or_mask, int __is_sig);*/
200 /* Set the mask of blocked signals to MASK,
201 wait for a signal to arrive, and then restore the mask. */
202 /*extern int sigpause (int __mask) __THROW __attribute_deprecated__;
203 # define sigpause(mask) __sigpause ((mask), 0)*/
204 /* uClibc note: BSD sigpause is available as __bsd_sigpause.
205 * It is intentionally not prototyped */
208 /* Remove a signal from the signal mask and suspend the process. */
209 extern int sigpause(int __sig);
210 /*# define sigpause(sig) __sigpause ((sig), 1)*/
213 #endif /* __UCLIBC_SUSV4_LEGACY__ */
215 #if 0 /*def __USE_BSD*/
216 /* None of the following functions should be used anymore. They are here
217 only for compatibility. A single word (`int') is not guaranteed to be
218 enough to hold a complete signal mask and therefore these functions
219 simply do not work in many situations. Use `sigprocmask' instead. */
221 /* Compute mask for signal SIG. */
222 # define sigmask(sig) __sigmask(sig)
224 /* Block signals in MASK, returning the old mask. */
225 extern int sigblock (int __mask) __THROW __attribute_deprecated__;
227 /* Set the mask of blocked signals to MASK, returning the old mask. */
228 extern int sigsetmask (int __mask) __THROW __attribute_deprecated__;
230 /* Return currently selected signal mask. */
231 extern int siggetmask (void) __THROW __attribute_deprecated__;
232 #endif /* Use BSD. */
236 typedef __sighandler_t sighandler_t;
239 /* 4.4 BSD uses the name `sig_t' for this. */
241 typedef __sighandler_t sig_t;
246 /* Clear all signals from SET. */
247 extern int sigemptyset (sigset_t *__set) __THROW __nonnull ((1));
249 /* Set all signals in SET. */
250 extern int sigfillset (sigset_t *__set) __THROW __nonnull ((1));
252 /* Add SIGNO to SET. */
253 extern int sigaddset (sigset_t *__set, int __signo) __THROW __nonnull ((1));
254 libc_hidden_proto(sigaddset)
256 /* Remove SIGNO from SET. */
257 extern int sigdelset (sigset_t *__set, int __signo) __THROW __nonnull ((1));
258 libc_hidden_proto(sigdelset)
260 /* Return 1 if SIGNO is in SET, 0 if not. */
261 extern int sigismember (const sigset_t *__set, int __signo)
262 __THROW __nonnull ((1));
265 /* Return non-empty value is SET is not empty. */
266 extern int sigisemptyset (const sigset_t *__set) __THROW __nonnull ((1));
268 /* Build new signal set by combining the two inputs set using logical AND. */
269 extern int sigandset (sigset_t *__set, const sigset_t *__left,
270 const sigset_t *__right) __THROW __nonnull ((1, 2, 3));
272 /* Build new signal set by combining the two inputs set using logical OR. */
273 extern int sigorset (sigset_t *__set, const sigset_t *__left,
274 const sigset_t *__right) __THROW __nonnull ((1, 2, 3));
277 /* Get the system-specific definitions of `struct sigaction'
278 and the `SA_*' and `SIG_*'. constants. */
279 # include <bits/sigaction.h>
281 /* Get and/or change the set of blocked signals. */
282 extern int sigprocmask (int __how, const sigset_t *__restrict __set,
283 sigset_t *__restrict __oset) __THROW;
284 libc_hidden_proto(sigprocmask)
286 /* Change the set of blocked signals to SET,
287 wait until a signal arrives, and restore the set of blocked signals.
289 This function is a cancellation point and therefore not marked with
291 extern int sigsuspend (const sigset_t *__set) __nonnull ((1));
293 extern __typeof(sigsuspend) __sigsuspend_nocancel attribute_hidden;
294 libc_hidden_proto(sigsuspend)
297 /* Get and/or set the action for signal SIG. */
298 extern int sigaction (int __sig, const struct sigaction *__restrict __act,
299 struct sigaction *__restrict __oact) __THROW;
301 # if 0 /* this is in headers */
302 /* In uclibc, userspace struct sigaction is identical to
303 * "new" struct kernel_sigaction (one from the Linux 2.1.68 kernel).
306 struct old_kernel_sigaction;
307 extern int __syscall_sigaction(int, const struct old_kernel_sigaction *,
308 struct old_kernel_sigaction *) attribute_hidden;
309 # else /* this is how the function is built */
310 extern __typeof(sigaction) __syscall_sigaction attribute_hidden;
312 # define __need_size_t
314 /* candidate for attribute_hidden, if NPTL would behave */
315 extern int __syscall_rt_sigaction(int, const struct sigaction *,
316 struct sigaction *, size_t)
317 # ifndef __UCLIBC_HAS_THREADS_NATIVE__
321 extern __typeof(sigaction) __libc_sigaction;
322 libc_hidden_proto(sigaction)
325 # define _KERNEL_NSIG_WORDS (_NSIG / _MIPS_SZLONG)
327 unsigned long sig[_KERNEL_NSIG_WORDS];
329 # define __SYSCALL_SIGSET_T_SIZE (sizeof(kernel_sigset_t))
331 # define __SYSCALL_SIGSET_T_SIZE (_NSIG / 8)
335 /* Put in SET all signals that are blocked and waiting to be delivered. */
336 extern int sigpending (sigset_t *__set) __THROW __nonnull ((1));
339 /* Select any of pending signals from SET or wait for any to arrive.
341 This function is a cancellation point and therefore not marked with
343 extern int sigwait (const sigset_t *__restrict __set, int *__restrict __sig)
346 # if defined __USE_POSIX199309 && defined __UCLIBC_HAS_REALTIME__
347 /* Select any of pending signals from SET and place information in INFO.
349 This function is a cancellation point and therefore not marked with
351 extern int sigwaitinfo (const sigset_t *__restrict __set,
352 siginfo_t *__restrict __info) __nonnull ((1));
354 extern __typeof(sigwaitinfo) __sigwaitinfo attribute_hidden;
357 /* Select any of pending signals from SET and place information in INFO.
358 Wait the time specified by TIMEOUT if no signal is pending.
360 This function is a cancellation point and therefore not marked with
362 extern int sigtimedwait (const sigset_t *__restrict __set,
363 siginfo_t *__restrict __info,
364 const struct timespec *__restrict __timeout)
367 extern __typeof(sigtimedwait) __sigtimedwait_nocancel attribute_hidden;
368 libc_hidden_proto(sigtimedwait)
371 /* Send signal SIG to the process PID. Associate data in VAL with the
373 extern int sigqueue (__pid_t __pid, int __sig, const union sigval __val)
375 # endif /* Use POSIX 199306. */
377 #endif /* Use POSIX. */
381 # ifdef __UCLIBC_HAS_SYS_SIGLIST__
382 /* Names of the signals. This variable exists only for compatibility.
383 Use `strsignal' instead (see <string.h>). */
384 # define _sys_siglist sys_siglist
385 extern const char *const sys_siglist[_NSIG];
388 #ifndef __UCLIBC_STRICT_HEADERS__
389 /* Structure passed to `sigvec'. */
392 __sighandler_t sv_handler; /* Signal handler. */
393 int sv_mask; /* Mask of signals to be blocked. */
395 int sv_flags; /* Flags (see below). */
396 # define sv_onstack sv_flags /* 4.2 BSD compatibility. */
399 /* Bits in `sv_flags'. */
400 # define SV_ONSTACK (1 << 0)/* Take the signal on the signal stack. */
401 # define SV_INTERRUPT (1 << 1)/* Do not restart system calls. */
402 # define SV_RESETHAND (1 << 2)/* Reset handler to SIG_DFL on receipt. */
407 /* If VEC is non-NULL, set the handler for SIG to the `sv_handler' member
408 of VEC. The signals in `sv_mask' will be blocked while the handler runs.
409 If the SV_RESETHAND bit is set in `sv_flags', the handler for SIG will be
410 reset to SIG_DFL before `sv_handler' is entered. If OVEC is non-NULL,
411 it is filled in with the old information for SIG. */
412 extern int sigvec (int __sig, const struct sigvec *__vec,
413 struct sigvec *__ovec) __THROW;
417 /* Get machine-dependent `struct sigcontext' and signal subcodes. */
418 # include <bits/sigcontext.h>
421 /* Restore the state saved in SCP. */
422 extern int sigreturn (struct sigcontext *__scp) __THROW;
425 #endif /* use BSD. */
428 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
429 # define __need_size_t
432 # ifdef __UCLIBC_SUSV4_LEGACY__
433 /* If INTERRUPT is nonzero, make signal SIG interrupt system calls
434 (causing them to fail with EINTR); if INTERRUPT is zero, make system
435 calls be restarted after signal SIG. */
436 extern int siginterrupt (int __sig, int __interrupt) __THROW;
439 # include <bits/sigstack.h>
441 /* This will define `ucontext_t' and `mcontext_t'. */
442 /* SuSv4 obsoleted include/ucontext.h */
443 # include <sys/ucontext.h>
447 /* Run signals handlers on the stack specified by SS (if not NULL).
448 If OSS is not NULL, it is filled in with the old signal stack status.
449 This interface is obsolete and on many platform not implemented. */
450 extern int sigstack (struct sigstack *__ss, struct sigstack *__oss)
451 __THROW __attribute_deprecated__;
454 /* Alternate signal handler stack interface.
455 This interface should always be preferred over `sigstack'. */
456 extern int sigaltstack (const struct sigaltstack *__restrict __ss,
457 struct sigaltstack *__restrict __oss) __THROW;
459 #endif /* use BSD or X/Open Unix. */
461 #if defined __USE_XOPEN_EXTENDED && defined __UCLIBC_HAS_OBSOLETE_BSD_SIGNAL__
462 /* Simplified interface for signal management. */
464 /* Add SIG to the calling process' signal mask. */
465 extern int sighold (int __sig) __THROW;
467 /* Remove SIG from the calling process' signal mask. */
468 extern int sigrelse (int __sig) __THROW;
470 /* Set the disposition of SIG to SIG_IGN. */
471 extern int sigignore (int __sig) __THROW;
473 /* Set the disposition of SIG. */
474 extern __sighandler_t sigset (int __sig, __sighandler_t __disp) __THROW;
477 #if defined __UCLIBC_HAS_THREADS__ && (defined __USE_POSIX199506 || defined __USE_UNIX98)
478 /* Some of the functions for handling signals in threaded programs must
480 # include <bits/pthreadtypes.h>
481 # include <bits/sigthread.h>
484 /* The following functions are used internally in the C library and in
485 other code which need deep insights. */
487 /* Return number of available real-time signal with highest priority. */
488 extern int __libc_current_sigrtmin (void) __THROW;
489 /* Return number of available real-time signal with lowest priority. */
490 extern int __libc_current_sigrtmax (void) __THROW;
493 extern sigset_t _sigintr attribute_hidden;
494 /* simplified version without parameter checking */
496 # undef __sigemptyset
497 # define __sigemptyset(ss) (memset(ss, '\0', sizeof(sigset_t)), 0)
499 #endif /* signal.h */
503 #endif /* not signal.h */