ubacktrace/uargp: remove unneeded and false linker scripts
[uclibc-ng.git] / include / signal.h
blob38baaccfbc610fa18b8a1a5888556003b3558ce0
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>
22 #ifndef _SIGNAL_H
24 #if !defined __need_sig_atomic_t && !defined __need_sigset_t
25 # define _SIGNAL_H
26 #endif
28 #include <features.h>
30 __BEGIN_DECLS
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
39 __BEGIN_NAMESPACE_STD
40 typedef __sig_atomic_t sig_atomic_t;
41 __END_NAMESPACE_STD
42 # endif
43 # undef __need_sig_atomic_t
44 #endif
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;
50 # endif
51 # undef __need_sigset_t
52 #endif
54 #ifdef _SIGNAL_H
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. */
63 #ifdef __USE_UNIX98
64 # define SIG_HOLD ((__sighandler_t) 2) /* Add signal to hold mask. */
65 #endif
66 /* Biggest signal number + 1 (including real-time signals). */
67 #ifndef _NSIG /* if arch has not defined it in bits/signum.h... */
68 # define _NSIG 65
69 #endif
70 #ifdef __USE_MISC
71 # define NSIG _NSIG
72 #endif
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
80 #endif
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
88 # endif
89 #endif
90 #ifdef __USE_XOPEN
91 # ifndef __uid_t_defined
92 typedef __uid_t uid_t;
93 # define __uid_t_defined
94 # endif
95 #endif /* Unix98 */
97 #if defined __USE_POSIX199309 && defined __UCLIBC_HAS_REALTIME__
98 /* We need `struct timespec' later on. */
99 # define __need_timespec
100 # include <time.h>
101 #endif
103 #if defined __USE_POSIX199309 || defined __USE_XOPEN_EXTENDED
104 /* Get the `siginfo_t' type plus the needed symbols. */
105 # include <bits/siginfo.h>
106 #endif
109 /* Type of a signal handler. */
110 typedef void (*__sighandler_t) (int);
112 #if defined __UCLIBC_HAS_OBSOLETE_SYSV_SIGNAL__
113 /* The X/Open definition of `signal' specifies the SVID semantic. Use
114 the additional function `sysv_signal' when X/Open compatibility is
115 requested. */
116 extern __sighandler_t __sysv_signal (int __sig, __sighandler_t __handler)
117 __THROW;
118 # ifdef __USE_GNU
119 extern __sighandler_t sysv_signal (int __sig, __sighandler_t __handler)
120 __THROW;
121 # endif
122 #endif /* __UCLIBC_HAS_OBSOLETE_SYSV_SIGNAL__ */
124 /* Set the handler for the signal SIG to HANDLER, returning the old
125 handler, or SIG_ERR on error.
126 By default `signal' has the BSD semantic. */
127 __BEGIN_NAMESPACE_STD
128 #if defined __USE_BSD || !defined __UCLIBC_HAS_OBSOLETE_SYSV_SIGNAL__
129 extern __sighandler_t signal (int __sig, __sighandler_t __handler)
130 __THROW;
131 libc_hidden_proto(signal)
132 #else
133 /* Make sure the used `signal' implementation is the SVID version. */
134 # ifdef __REDIRECT_NTH
135 extern __sighandler_t __REDIRECT_NTH (signal,
136 (int __sig, __sighandler_t __handler),
137 __sysv_signal);
138 # else
139 # define signal __sysv_signal
140 # endif
141 #endif
142 __END_NAMESPACE_STD
144 #if defined __USE_XOPEN && defined __UCLIBC_SUSV3_LEGACY__
145 /* The X/Open definition of `signal' conflicts with the BSD version.
146 So they defined another function `bsd_signal'. */
147 extern __sighandler_t bsd_signal (int __sig, __sighandler_t __handler)
148 __THROW;
149 #endif
151 /* Send signal SIG to process number PID. If PID is zero,
152 send SIG to all processes in the current process's process group.
153 If PID is < -1, send SIG to all processes in process group - PID. */
154 #ifdef __USE_POSIX
155 extern int kill (__pid_t __pid, int __sig) __THROW;
156 libc_hidden_proto(kill)
157 #endif
159 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
160 /* Send SIG to all processes in process group PGRP.
161 If PGRP is zero, send SIG to all processes in
162 the current process's process group. */
163 extern int killpg (__pid_t __pgrp, int __sig) __THROW;
164 #endif
166 __BEGIN_NAMESPACE_STD
167 /* Raise signal SIG, i.e., send SIG to yourself. */
168 extern int raise (int __sig) __THROW;
169 libc_hidden_proto(raise)
170 __END_NAMESPACE_STD
172 #if 0 /*def __USE_SVID*/
173 /* SVID names for the same things. */
174 extern __sighandler_t ssignal (int __sig, __sighandler_t __handler)
175 __THROW;
176 extern int gsignal (int __sig) __THROW;
177 #endif /* Use SVID. */
179 /* glibc guards the next two wrong with __USE_XOPEN2K */
180 #if defined __USE_MISC || defined __USE_XOPEN2K8
181 /* Print a message describing the meaning of the given signal number. */
182 extern void psignal (int __sig, const char *__s);
183 #endif /* Use misc or POSIX 2008. */
185 #if 0 /*def __USE_XOPEN2K8*/
186 /* Print a message describing the meaning of the given signal information. */
187 extern void psiginfo (const siginfo_t *__pinfo, const char *__s);
188 #endif /* POSIX 2008. */
190 #ifdef __UCLIBC_SUSV4_LEGACY__
191 /* The `sigpause' function has two different interfaces. The original
192 BSD definition defines the argument as a mask of the signal, while
193 the more modern interface in X/Open defines it as the signal
194 number. We go with the BSD version unless the user explicitly
195 selects the X/Open version.
197 This function is a cancellation point and therefore not marked with
198 __THROW. */
199 /*extern int __sigpause (int __sig_or_mask, int __is_sig);*/
201 #ifdef __FAVOR_BSD
202 /* Set the mask of blocked signals to MASK,
203 wait for a signal to arrive, and then restore the mask. */
204 /*extern int sigpause (int __mask) __THROW __attribute_deprecated__;
205 # define sigpause(mask) __sigpause ((mask), 0)*/
206 /* uClibc note: BSD sigpause is available as __bsd_sigpause.
207 * It is intentionally not prototyped */
208 #else
209 # ifdef __USE_XOPEN
210 /* Remove a signal from the signal mask and suspend the process. */
211 extern int sigpause(int __sig);
212 /*# define sigpause(sig) __sigpause ((sig), 1)*/
213 # endif
214 #endif
215 #endif /* __UCLIBC_SUSV4_LEGACY__ */
217 #if 0 /*def __USE_BSD*/
218 /* None of the following functions should be used anymore. They are here
219 only for compatibility. A single word (`int') is not guaranteed to be
220 enough to hold a complete signal mask and therefore these functions
221 simply do not work in many situations. Use `sigprocmask' instead. */
223 /* Compute mask for signal SIG. */
224 # define sigmask(sig) __sigmask(sig)
226 /* Block signals in MASK, returning the old mask. */
227 extern int sigblock (int __mask) __THROW __attribute_deprecated__;
229 /* Set the mask of blocked signals to MASK, returning the old mask. */
230 extern int sigsetmask (int __mask) __THROW __attribute_deprecated__;
232 /* Return currently selected signal mask. */
233 extern int siggetmask (void) __THROW __attribute_deprecated__;
234 #endif /* Use BSD. */
237 #ifdef __USE_GNU
238 typedef __sighandler_t sighandler_t;
239 #endif
241 /* 4.4 BSD uses the name `sig_t' for this. */
242 #ifdef __USE_BSD
243 typedef __sighandler_t sig_t;
244 #endif
246 #ifdef __USE_POSIX
248 /* Clear all signals from SET. */
249 extern int sigemptyset (sigset_t *__set) __THROW __nonnull ((1));
251 /* Set all signals in SET. */
252 extern int sigfillset (sigset_t *__set) __THROW __nonnull ((1));
254 /* Add SIGNO to SET. */
255 extern int sigaddset (sigset_t *__set, int __signo) __THROW __nonnull ((1));
256 libc_hidden_proto(sigaddset)
258 /* Remove SIGNO from SET. */
259 extern int sigdelset (sigset_t *__set, int __signo) __THROW __nonnull ((1));
260 libc_hidden_proto(sigdelset)
262 /* Return 1 if SIGNO is in SET, 0 if not. */
263 extern int sigismember (const sigset_t *__set, int __signo)
264 __THROW __nonnull ((1));
266 # ifdef __USE_GNU
267 /* Return non-empty value is SET is not empty. */
268 extern int sigisemptyset (const sigset_t *__set) __THROW __nonnull ((1));
270 /* Build new signal set by combining the two inputs set using logical AND. */
271 extern int sigandset (sigset_t *__set, const sigset_t *__left,
272 const sigset_t *__right) __THROW __nonnull ((1, 2, 3));
274 /* Build new signal set by combining the two inputs set using logical OR. */
275 extern int sigorset (sigset_t *__set, const sigset_t *__left,
276 const sigset_t *__right) __THROW __nonnull ((1, 2, 3));
277 # endif /* GNU */
279 /* Get the system-specific definitions of `struct sigaction'
280 and the `SA_*' and `SIG_*'. constants. */
281 # include <bits/sigaction.h>
283 /* Get and/or change the set of blocked signals. */
284 extern int sigprocmask (int __how, const sigset_t *__restrict __set,
285 sigset_t *__restrict __oset) __THROW;
286 libc_hidden_proto(sigprocmask)
288 /* Change the set of blocked signals to SET,
289 wait until a signal arrives, and restore the set of blocked signals.
291 This function is a cancellation point and therefore not marked with
292 __THROW. */
293 extern int sigsuspend (const sigset_t *__set) __nonnull ((1));
294 #ifdef _LIBC
295 extern __typeof(sigsuspend) __sigsuspend_nocancel attribute_hidden;
296 libc_hidden_proto(sigsuspend)
297 #endif
299 /* Get and/or set the action for signal SIG. */
300 extern int sigaction (int __sig, const struct sigaction *__restrict __act,
301 struct sigaction *__restrict __oact) __THROW;
302 #ifdef _LIBC
303 # if 0 /* this is in headers */
304 /* In uclibc, userspace struct sigaction is identical to
305 * "new" struct kernel_sigaction (one from the Linux 2.1.68 kernel).
306 * See sigaction.h
308 struct old_kernel_sigaction;
309 extern int __syscall_sigaction(int, const struct old_kernel_sigaction *,
310 struct old_kernel_sigaction *) attribute_hidden;
311 # else /* this is how the function is built */
312 extern __typeof(sigaction) __syscall_sigaction attribute_hidden;
313 # endif
314 # define __need_size_t
315 # include <stddef.h>
316 /* candidate for attribute_hidden, if NPTL would behave */
317 extern int __syscall_rt_sigaction(int, const struct sigaction *,
318 struct sigaction *, size_t)
319 # ifndef __UCLIBC_HAS_THREADS_NATIVE__
320 attribute_hidden
321 # endif
323 extern __typeof(sigaction) __libc_sigaction;
324 libc_hidden_proto(sigaction)
326 # ifdef __mips__
327 # define _KERNEL_NSIG_WORDS (_NSIG / _MIPS_SZLONG)
328 typedef struct {
329 unsigned long sig[_KERNEL_NSIG_WORDS];
330 } kernel_sigset_t;
331 # define __SYSCALL_SIGSET_T_SIZE (sizeof(kernel_sigset_t))
332 # else
333 # define __SYSCALL_SIGSET_T_SIZE (_NSIG / 8)
334 # endif
335 #endif
337 /* Put in SET all signals that are blocked and waiting to be delivered. */
338 extern int sigpending (sigset_t *__set) __THROW __nonnull ((1));
341 /* Select any of pending signals from SET or wait for any to arrive.
343 This function is a cancellation point and therefore not marked with
344 __THROW. */
345 extern int sigwait (const sigset_t *__restrict __set, int *__restrict __sig)
346 __nonnull ((1, 2));
348 # if defined __USE_POSIX199309 && defined __UCLIBC_HAS_REALTIME__
349 /* Select any of pending signals from SET and place information in INFO.
351 This function is a cancellation point and therefore not marked with
352 __THROW. */
353 extern int sigwaitinfo (const sigset_t *__restrict __set,
354 siginfo_t *__restrict __info) __nonnull ((1));
355 #ifdef _LIBC
356 extern __typeof(sigwaitinfo) __sigwaitinfo attribute_hidden;
357 #endif
359 /* Select any of pending signals from SET and place information in INFO.
360 Wait the time specified by TIMEOUT if no signal is pending.
362 This function is a cancellation point and therefore not marked with
363 __THROW. */
364 extern int sigtimedwait (const sigset_t *__restrict __set,
365 siginfo_t *__restrict __info,
366 const struct timespec *__restrict __timeout)
367 __nonnull ((1));
368 #ifdef _LIBC
369 extern __typeof(sigtimedwait) __sigtimedwait_nocancel attribute_hidden;
370 libc_hidden_proto(sigtimedwait)
371 #endif
373 /* Send signal SIG to the process PID. Associate data in VAL with the
374 signal. */
375 extern int sigqueue (__pid_t __pid, int __sig, const union sigval __val)
376 __THROW;
377 # endif /* Use POSIX 199306. */
379 #endif /* Use POSIX. */
381 #ifdef __USE_BSD
383 # ifdef __UCLIBC_HAS_SYS_SIGLIST__
384 /* Names of the signals. This variable exists only for compatibility.
385 Use `strsignal' instead (see <string.h>). */
386 # define _sys_siglist sys_siglist
387 extern const char *const sys_siglist[_NSIG];
388 # endif
390 #ifndef __UCLIBC_STRICT_HEADERS__
391 /* Structure passed to `sigvec'. */
392 struct sigvec
394 __sighandler_t sv_handler; /* Signal handler. */
395 int sv_mask; /* Mask of signals to be blocked. */
397 int sv_flags; /* Flags (see below). */
398 # define sv_onstack sv_flags /* 4.2 BSD compatibility. */
401 /* Bits in `sv_flags'. */
402 # define SV_ONSTACK (1 << 0)/* Take the signal on the signal stack. */
403 # define SV_INTERRUPT (1 << 1)/* Do not restart system calls. */
404 # define SV_RESETHAND (1 << 2)/* Reset handler to SIG_DFL on receipt. */
405 #endif
408 #if 0
409 /* If VEC is non-NULL, set the handler for SIG to the `sv_handler' member
410 of VEC. The signals in `sv_mask' will be blocked while the handler runs.
411 If the SV_RESETHAND bit is set in `sv_flags', the handler for SIG will be
412 reset to SIG_DFL before `sv_handler' is entered. If OVEC is non-NULL,
413 it is filled in with the old information for SIG. */
414 extern int sigvec (int __sig, const struct sigvec *__vec,
415 struct sigvec *__ovec) __THROW;
416 #endif
419 /* Get machine-dependent `struct sigcontext' and signal subcodes. */
420 # include <bits/sigcontext.h>
422 #if 0
423 /* Restore the state saved in SCP. */
424 extern int sigreturn (struct sigcontext *__scp) __THROW;
425 #endif
427 #endif /* use BSD. */
430 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
431 # define __need_size_t
432 # include <stddef.h>
434 # ifdef __UCLIBC_SUSV4_LEGACY__
435 /* If INTERRUPT is nonzero, make signal SIG interrupt system calls
436 (causing them to fail with EINTR); if INTERRUPT is zero, make system
437 calls be restarted after signal SIG. */
438 extern int siginterrupt (int __sig, int __interrupt) __THROW;
439 # endif
441 # include <bits/sigstack.h>
442 # ifdef __USE_XOPEN
443 /* This will define `ucontext_t' and `mcontext_t'. */
444 /* SuSv4 obsoleted include/ucontext.h */
445 # include <sys/ucontext.h>
446 # endif
448 # if 0
449 /* Run signals handlers on the stack specified by SS (if not NULL).
450 If OSS is not NULL, it is filled in with the old signal stack status.
451 This interface is obsolete and on many platform not implemented. */
452 extern int sigstack (struct sigstack *__ss, struct sigstack *__oss)
453 __THROW __attribute_deprecated__;
454 # endif
456 /* Alternate signal handler stack interface.
457 This interface should always be preferred over `sigstack'. */
458 extern int sigaltstack (const struct sigaltstack *__restrict __ss,
459 struct sigaltstack *__restrict __oss) __THROW;
461 #endif /* use BSD or X/Open Unix. */
463 #if defined __USE_XOPEN_EXTENDED && defined __UCLIBC_HAS_OBSOLETE_BSD_SIGNAL__
464 /* Simplified interface for signal management. */
466 /* Add SIG to the calling process' signal mask. */
467 extern int sighold (int __sig) __THROW;
469 /* Remove SIG from the calling process' signal mask. */
470 extern int sigrelse (int __sig) __THROW;
472 /* Set the disposition of SIG to SIG_IGN. */
473 extern int sigignore (int __sig) __THROW;
475 /* Set the disposition of SIG. */
476 extern __sighandler_t sigset (int __sig, __sighandler_t __disp) __THROW;
477 #endif
479 #if defined __UCLIBC_HAS_THREADS__ && (defined __USE_POSIX199506 || defined __USE_UNIX98)
480 /* Some of the functions for handling signals in threaded programs must
481 be defined here. */
482 # include <bits/pthreadtypes.h>
483 # include <bits/sigthread.h>
484 #endif
486 /* The following functions are used internally in the C library and in
487 other code which need deep insights. */
489 /* Return number of available real-time signal with highest priority. */
490 extern int __libc_current_sigrtmin (void) __THROW;
491 /* Return number of available real-time signal with lowest priority. */
492 extern int __libc_current_sigrtmax (void) __THROW;
494 #ifdef _LIBC
495 extern sigset_t _sigintr attribute_hidden;
496 # include <string.h>
497 #endif
498 #endif /* signal.h */
500 __END_DECLS
502 #endif /* not signal.h */