OSDN Git Service

sigsuspend.c: add cancellation support independently of rt_sigsuspend
[uclinux-h8/uClibc.git] / include / signal.h
1 /* Copyright (C) 1991-2003, 2004, 2007, 2009 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3
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.
8
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.
13
14    You should have received a copy of the GNU Lesser General Public
15    License along with the GNU C Library; if not, write to the Free
16    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17    02111-1307 USA.  */
18
19 /*
20  *      ISO C99 Standard: 7.14 Signal handling <signal.h>
21  */
22
23 #ifndef _SIGNAL_H
24
25 #if !defined __need_sig_atomic_t && !defined __need_sigset_t
26 # define _SIGNAL_H
27 #endif
28
29 #include <features.h>
30
31 __BEGIN_DECLS
32
33 #include <bits/sigset.h>                /* __sigset_t, __sig_atomic_t.  */
34
35 /* An integral type that can be modified atomically, without the
36    possibility of a signal arriving in the middle of the operation.  */
37 #if defined __need_sig_atomic_t || defined _SIGNAL_H
38 # ifndef __sig_atomic_t_defined
39 #  define __sig_atomic_t_defined
40 __BEGIN_NAMESPACE_STD
41 typedef __sig_atomic_t sig_atomic_t;
42 __END_NAMESPACE_STD
43 # endif
44 # undef __need_sig_atomic_t
45 #endif
46
47 #if defined __need_sigset_t || (defined _SIGNAL_H && defined __USE_POSIX)
48 # ifndef __sigset_t_defined
49 #  define __sigset_t_defined
50 typedef __sigset_t sigset_t;
51 # endif
52 # undef __need_sigset_t
53 #endif
54
55 #ifdef _SIGNAL_H
56
57 #include <bits/types.h>
58 #include <bits/signum.h>
59
60 /* Fake signal functions.  */
61 #define SIG_ERR    ((__sighandler_t) -1) /* Error return.  */
62 #define SIG_DFL    ((__sighandler_t) 0)  /* Default action.  */
63 #define SIG_IGN    ((__sighandler_t) 1)  /* Ignore signal.  */
64 #ifdef __USE_UNIX98
65 # define SIG_HOLD  ((__sighandler_t) 2)  /* Add signal to hold mask.  */
66 #endif
67 /* Biggest signal number + 1 (including real-time signals).  */
68 #ifndef _NSIG /* if arch has not defined it in bits/signum.h... */
69 # define _NSIG 65
70 #endif
71 #ifdef __USE_MISC
72 # define NSIG _NSIG
73 #endif
74 /* Real-time signal range */
75 #define SIGRTMIN   (__libc_current_sigrtmin())
76 #define SIGRTMAX   (__libc_current_sigrtmax())
77 /* These are the hard limits of the kernel.  These values should not be
78    used directly at user level.  */
79 #ifndef __SIGRTMIN /* if arch has not defined it in bits/signum.h... */
80 # define __SIGRTMIN 32
81 #endif
82 #define __SIGRTMAX (_NSIG - 1)
83
84
85 #if defined __USE_XOPEN || defined __USE_XOPEN2K
86 # ifndef __pid_t_defined
87 typedef __pid_t pid_t;
88 #  define __pid_t_defined
89 # endif
90 #endif
91 #ifdef __USE_XOPEN
92 # ifndef __uid_t_defined
93 typedef __uid_t uid_t;
94 #  define __uid_t_defined
95 # endif
96 #endif  /* Unix98 */
97
98 #if defined __USE_POSIX199309 && defined __UCLIBC_HAS_REALTIME__
99 /* We need `struct timespec' later on.  */
100 # define __need_timespec
101 # include <time.h>
102
103 /* Get the `siginfo_t' type plus the needed symbols.  */
104 # include <bits/siginfo.h>
105 #endif
106
107
108 /* Type of a signal handler.  */
109 typedef void (*__sighandler_t) (int);
110
111 #if defined __UCLIBC_HAS_OBSOLETE_SYSV_SIGNAL__
112 /* The X/Open definition of `signal' specifies the SVID semantic.  Use
113    the additional function `sysv_signal' when X/Open compatibility is
114    requested.  */
115 extern __sighandler_t __sysv_signal (int __sig, __sighandler_t __handler)
116      __THROW;
117 # ifdef __USE_GNU
118 extern __sighandler_t sysv_signal (int __sig, __sighandler_t __handler)
119      __THROW;
120 # endif
121 #endif /* __UCLIBC_HAS_OBSOLETE_SYSV_SIGNAL__ */
122
123 /* Set the handler for the signal SIG to HANDLER, returning the old
124    handler, or SIG_ERR on error.
125    By default `signal' has the BSD semantic.  */
126 __BEGIN_NAMESPACE_STD
127 #if defined __USE_BSD || !defined __UCLIBC_HAS_OBSOLETE_SYSV_SIGNAL__
128 extern __sighandler_t signal (int __sig, __sighandler_t __handler)
129      __THROW;
130 libc_hidden_proto(signal)
131 #else
132 /* Make sure the used `signal' implementation is the SVID version. */
133 # ifdef __REDIRECT_NTH
134 extern __sighandler_t __REDIRECT_NTH (signal,
135                                       (int __sig, __sighandler_t __handler),
136                                       __sysv_signal);
137 # else
138 #  define signal __sysv_signal
139 # endif
140 #endif
141 __END_NAMESPACE_STD
142
143 #if defined __USE_XOPEN && defined __UCLIBC_SUSV3_LEGACY__
144 /* The X/Open definition of `signal' conflicts with the BSD version.
145    So they defined another function `bsd_signal'.  */
146 extern __sighandler_t bsd_signal (int __sig, __sighandler_t __handler)
147      __THROW;
148 #endif
149
150 /* Send signal SIG to process number PID.  If PID is zero,
151    send SIG to all processes in the current process's process group.
152    If PID is < -1, send SIG to all processes in process group - PID.  */
153 #ifdef __USE_POSIX
154 extern int kill (__pid_t __pid, int __sig) __THROW;
155 libc_hidden_proto(kill)
156 #endif
157
158 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
159 /* Send SIG to all processes in process group PGRP.
160    If PGRP is zero, send SIG to all processes in
161    the current process's process group.  */
162 extern int killpg (__pid_t __pgrp, int __sig) __THROW;
163 #endif
164
165 __BEGIN_NAMESPACE_STD
166 /* Raise signal SIG, i.e., send SIG to yourself.  */
167 extern int raise (int __sig) __THROW;
168 libc_hidden_proto(raise)
169 __END_NAMESPACE_STD
170
171 #if 0 /*def __USE_SVID*/
172 /* SVID names for the same things.  */
173 extern __sighandler_t ssignal (int __sig, __sighandler_t __handler)
174      __THROW;
175 extern int gsignal (int __sig) __THROW;
176 #endif /* Use SVID.  */
177
178 /* glibc guards the next two wrong with __USE_XOPEN2K */
179 #if defined __USE_MISC || defined __USE_XOPEN2K8
180 /* Print a message describing the meaning of the given signal number.  */
181 extern void psignal (int __sig, __const char *__s);
182 #endif /* Use misc or POSIX 2008.  */
183
184 #if 0 /*def __USE_XOPEN2K8*/
185 /* Print a message describing the meaning of the given signal information.  */
186 extern void psiginfo (__const siginfo_t *__pinfo, __const char *__s);
187 #endif /* POSIX 2008.  */
188
189 #ifdef __UCLIBC_SUSV4_LEGACY__
190 /* The `sigpause' function has two different interfaces.  The original
191    BSD definition defines the argument as a mask of the signal, while
192    the more modern interface in X/Open defines it as the signal
193    number.  We go with the BSD version unless the user explicitly
194    selects the X/Open version.
195
196    This function is a cancellation point and therefore not marked with
197    __THROW.  */
198 extern int __sigpause (int __sig_or_mask, int __is_sig);
199
200 #ifdef __FAVOR_BSD
201 /* Set the mask of blocked signals to MASK,
202    wait for a signal to arrive, and then restore the mask.  */
203 extern int sigpause (int __mask) __THROW __attribute_deprecated__;
204 # define sigpause(mask) __sigpause ((mask), 0)
205 #else
206 # ifdef __USE_XOPEN
207 /* Remove a signal from the signal mask and suspend the process.  */
208 #  define sigpause(sig) __sigpause ((sig), 1)
209 # endif
210 #endif
211 #endif /* __UCLIBC_SUSV4_LEGACY__ */
212
213 #ifdef __USE_BSD
214 /* None of the following functions should be used anymore.  They are here
215    only for compatibility.  A single word (`int') is not guaranteed to be
216    enough to hold a complete signal mask and therefore these functions
217    simply do not work in many situations.  Use `sigprocmask' instead.  */
218
219 /* Compute mask for signal SIG.  */
220 # define sigmask(sig)   __sigmask(sig)
221
222 /* Block signals in MASK, returning the old mask.  */
223 # ifdef _LIBC
224 extern int sigblock (int __mask) __THROW;
225 /* collides with libc_hidden_proto: __attribute_deprecated__; */
226 libc_hidden_proto(sigblock)
227 # else
228 extern int sigblock (int __mask) __THROW __attribute_deprecated__;
229 # endif
230
231 /* Set the mask of blocked signals to MASK, returning the old mask.  */
232 # ifdef _LIBC
233 extern int sigsetmask (int __mask) __THROW;
234 /* collides with libc_hidden_proto: __attribute_deprecated__; */
235 libc_hidden_proto(sigsetmask)
236 # else
237 extern int sigsetmask (int __mask) __THROW __attribute_deprecated__;
238 # endif
239
240 /* Return currently selected signal mask.  */
241 extern int siggetmask (void) __THROW __attribute_deprecated__;
242 #endif /* Use BSD.  */
243
244
245 #ifdef __USE_GNU
246 typedef __sighandler_t sighandler_t;
247 #endif
248
249 /* 4.4 BSD uses the name `sig_t' for this.  */
250 #ifdef __USE_BSD
251 typedef __sighandler_t sig_t;
252 #endif
253
254 #ifdef __USE_POSIX
255
256 /* Clear all signals from SET.  */
257 extern int sigemptyset (sigset_t *__set) __THROW __nonnull ((1));
258
259 /* Set all signals in SET.  */
260 extern int sigfillset (sigset_t *__set) __THROW __nonnull ((1));
261
262 /* Add SIGNO to SET.  */
263 extern int sigaddset (sigset_t *__set, int __signo) __THROW __nonnull ((1));
264 libc_hidden_proto(sigaddset)
265
266 /* Remove SIGNO from SET.  */
267 extern int sigdelset (sigset_t *__set, int __signo) __THROW __nonnull ((1));
268 libc_hidden_proto(sigdelset)
269
270 /* Return 1 if SIGNO is in SET, 0 if not.  */
271 extern int sigismember (__const sigset_t *__set, int __signo)
272      __THROW __nonnull ((1));
273
274 # ifdef __USE_GNU
275 /* Return non-empty value is SET is not empty.  */
276 extern int sigisemptyset (__const sigset_t *__set) __THROW __nonnull ((1));
277
278 /* Build new signal set by combining the two inputs set using logical AND.  */
279 extern int sigandset (sigset_t *__set, __const sigset_t *__left,
280                       __const sigset_t *__right) __THROW __nonnull ((1, 2, 3));
281
282 /* Build new signal set by combining the two inputs set using logical OR.  */
283 extern int sigorset (sigset_t *__set, __const sigset_t *__left,
284                      __const sigset_t *__right) __THROW __nonnull ((1, 2, 3));
285 # endif /* GNU */
286
287 /* Get the system-specific definitions of `struct sigaction'
288    and the `SA_*' and `SIG_*'. constants.  */
289 # include <bits/sigaction.h>
290
291 /* Get and/or change the set of blocked signals.  */
292 extern int sigprocmask (int __how, __const sigset_t *__restrict __set,
293                         sigset_t *__restrict __oset) __THROW;
294 libc_hidden_proto(sigprocmask)
295
296 /* Change the set of blocked signals to SET,
297    wait until a signal arrives, and restore the set of blocked signals.
298
299    This function is a cancellation point and therefore not marked with
300    __THROW.  */
301 extern int sigsuspend (__const sigset_t *__set) __nonnull ((1));
302 #ifdef _LIBC
303 extern __typeof(sigsuspend) __sigsuspend_nocancel attribute_hidden;
304 libc_hidden_proto(sigsuspend)
305 #endif
306
307 /* Get and/or set the action for signal SIG.  */
308 extern int sigaction (int __sig, __const struct sigaction *__restrict __act,
309                       struct sigaction *__restrict __oact) __THROW;
310 #ifdef _LIBC
311 # if 0 /* this is in headers */
312 /* In uclibc, userspace struct sigaction is identical to
313  * "new" struct kernel_sigaction (one from the Linux 2.1.68 kernel).
314  * See sigaction.h
315  */
316 struct old_kernel_sigaction;
317 extern int __syscall_sigaction(int, __const struct old_kernel_sigaction *,
318         struct old_kernel_sigaction *) attribute_hidden;
319 # else /* this is how the function is built */
320 extern __typeof(sigaction) __syscall_sigaction attribute_hidden;
321 # endif
322 /* candidate for attribute_hidden, if NPTL would behave */
323 extern int __syscall_rt_sigaction(int, __const struct sigaction *,
324         struct sigaction *, size_t)
325 # ifndef __UCLIBC_HAS_THREADS_NATIVE__
326                 attribute_hidden
327 # endif
328         ;
329 extern __typeof(sigaction) __libc_sigaction;
330 libc_hidden_proto(sigaction)
331
332 # ifdef __mips__
333 #  define _KERNEL_NSIG_WORDS (_NSIG / _MIPS_SZLONG)
334 typedef struct {
335         unsigned long sig[_KERNEL_NSIG_WORDS];
336 } kernel_sigset_t;
337 #  define __SYSCALL_SIGSET_T_SIZE (sizeof(kernel_sigset_t))
338 # else
339 #  define __SYSCALL_SIGSET_T_SIZE (_NSIG / 8)
340 # endif
341 #endif
342
343 /* Put in SET all signals that are blocked and waiting to be delivered.  */
344 extern int sigpending (sigset_t *__set) __THROW __nonnull ((1));
345
346
347 /* Select any of pending signals from SET or wait for any to arrive.
348
349    This function is a cancellation point and therefore not marked with
350    __THROW.  */
351 extern int sigwait (__const sigset_t *__restrict __set, int *__restrict __sig)
352      __nonnull ((1, 2));
353
354 # if defined __USE_POSIX199309 && defined __UCLIBC_HAS_REALTIME__
355 /* Select any of pending signals from SET and place information in INFO.
356
357    This function is a cancellation point and therefore not marked with
358    __THROW.  */
359 extern int sigwaitinfo (__const sigset_t *__restrict __set,
360                         siginfo_t *__restrict __info) __nonnull ((1));
361 #ifdef _LIBC
362 extern __typeof(sigwaitinfo) __sigwaitinfo attribute_hidden;
363 #endif
364
365 /* Select any of pending signals from SET and place information in INFO.
366    Wait the time specified by TIMEOUT if no signal is pending.
367
368    This function is a cancellation point and therefore not marked with
369    __THROW.  */
370 extern int sigtimedwait (__const sigset_t *__restrict __set,
371                          siginfo_t *__restrict __info,
372                          __const struct timespec *__restrict __timeout)
373      __nonnull ((1));
374 #ifdef _LIBC
375 extern __typeof(sigtimedwait) __sigtimedwait attribute_hidden;
376 #endif
377
378 /* Send signal SIG to the process PID.  Associate data in VAL with the
379    signal.  */
380 extern int sigqueue (__pid_t __pid, int __sig, __const union sigval __val)
381      __THROW;
382 # endif /* Use POSIX 199306.  */
383
384 #endif /* Use POSIX.  */
385
386 #ifdef __USE_BSD
387
388 # ifdef __UCLIBC_HAS_SYS_SIGLIST__
389 /* Names of the signals.  This variable exists only for compatibility.
390    Use `strsignal' instead (see <string.h>).  */
391 #  define _sys_siglist sys_siglist
392 extern __const char *__const sys_siglist[_NSIG];
393 # endif
394
395 #ifndef __UCLIBC_STRICT_HEADERS__
396 /* Structure passed to `sigvec'.  */
397 struct sigvec
398   {
399     __sighandler_t sv_handler;  /* Signal handler.  */
400     int sv_mask;                /* Mask of signals to be blocked.  */
401
402     int sv_flags;               /* Flags (see below).  */
403 # define sv_onstack     sv_flags /* 4.2 BSD compatibility.  */
404   };
405
406 /* Bits in `sv_flags'.  */
407 # define SV_ONSTACK     (1 << 0)/* Take the signal on the signal stack.  */
408 # define SV_INTERRUPT   (1 << 1)/* Do not restart system calls.  */
409 # define SV_RESETHAND   (1 << 2)/* Reset handler to SIG_DFL on receipt.  */
410 #endif
411
412
413 #if 0
414 /* If VEC is non-NULL, set the handler for SIG to the `sv_handler' member
415    of VEC.  The signals in `sv_mask' will be blocked while the handler runs.
416    If the SV_RESETHAND bit is set in `sv_flags', the handler for SIG will be
417    reset to SIG_DFL before `sv_handler' is entered.  If OVEC is non-NULL,
418    it is filled in with the old information for SIG.  */
419 extern int sigvec (int __sig, __const struct sigvec *__vec,
420                    struct sigvec *__ovec) __THROW;
421 #endif
422
423
424 /* Get machine-dependent `struct sigcontext' and signal subcodes.  */
425 # include <bits/sigcontext.h>
426
427 #if 0
428 /* Restore the state saved in SCP.  */
429 extern int sigreturn (struct sigcontext *__scp) __THROW;
430 #endif
431
432 #endif /*  use BSD.  */
433
434
435 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
436
437 # ifdef __UCLIBC_SUSV4_LEGACY__
438 /* If INTERRUPT is nonzero, make signal SIG interrupt system calls
439    (causing them to fail with EINTR); if INTERRUPT is zero, make system
440    calls be restarted after signal SIG.  */
441 extern int siginterrupt (int __sig, int __interrupt) __THROW;
442 # endif
443
444 # include <bits/sigstack.h>
445 # ifdef __USE_XOPEN
446 /* This will define `ucontext_t' and `mcontext_t'.  */
447 /* SuSv4 obsoleted include/ucontext.h */
448 #  include <sys/ucontext.h>
449 # endif
450
451 # if 0
452 /* Run signals handlers on the stack specified by SS (if not NULL).
453    If OSS is not NULL, it is filled in with the old signal stack status.
454    This interface is obsolete and on many platform not implemented.  */
455 extern int sigstack (struct sigstack *__ss, struct sigstack *__oss)
456      __THROW __attribute_deprecated__;
457 # endif
458
459 /* Alternate signal handler stack interface.
460    This interface should always be preferred over `sigstack'.  */
461 extern int sigaltstack (__const struct sigaltstack *__restrict __ss,
462                         struct sigaltstack *__restrict __oss) __THROW;
463
464 #endif /* use BSD or X/Open Unix.  */
465
466 #if defined __USE_XOPEN_EXTENDED && defined __UCLIBC_HAS_OBSOLETE_BSD_SIGNAL__
467 /* Simplified interface for signal management.  */
468
469 /* Add SIG to the calling process' signal mask.  */
470 extern int sighold (int __sig) __THROW;
471
472 /* Remove SIG from the calling process' signal mask.  */
473 extern int sigrelse (int __sig) __THROW;
474
475 /* Set the disposition of SIG to SIG_IGN.  */
476 extern int sigignore (int __sig) __THROW;
477
478 /* Set the disposition of SIG.  */
479 extern __sighandler_t sigset (int __sig, __sighandler_t __disp) __THROW;
480 #endif
481
482 #if defined __UCLIBC_HAS_THREADS__ && (defined __USE_POSIX199506 || defined __USE_UNIX98)
483 /* Some of the functions for handling signals in threaded programs must
484    be defined here.  */
485 # include <bits/pthreadtypes.h>
486 # include <bits/sigthread.h>
487 #endif
488
489 /* The following functions are used internally in the C library and in
490    other code which need deep insights.  */
491
492 /* Return number of available real-time signal with highest priority.  */
493 extern int __libc_current_sigrtmin (void) __THROW;
494 /* Return number of available real-time signal with lowest priority.  */
495 extern int __libc_current_sigrtmax (void) __THROW;
496
497 #ifdef _LIBC
498 extern sigset_t _sigintr attribute_hidden;
499 /* simplified version without parameter checking */
500 # include <string.h>
501 # undef __sigemptyset
502 # define __sigemptyset(ss) (memset(ss, '\0', sizeof(sigset_t)), 0)
503 #endif
504 #endif /* signal.h  */
505
506 __END_DECLS
507
508 #endif /* not signal.h */