OSDN Git Service

Sync up w/ glibc
[uclinux-h8/uClibc.git] / include / signal.h
1 /* Copyright (C) 1991-2003, 2004 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 #if defined __USE_XOPEN || defined __USE_XOPEN2K
61 # ifndef __pid_t_defined
62 typedef __pid_t pid_t;
63 #  define __pid_t_defined
64 #endif
65 #ifdef __USE_XOPEN
66 # endif
67 # ifndef __uid_t_defined
68 typedef __uid_t uid_t;
69 #  define __uid_t_defined
70 # endif
71 #endif  /* Unix98 */
72
73
74 /* Type of a signal handler.  */
75 typedef void (*__sighandler_t) (int);
76
77 /* The X/Open definition of `signal' specifies the SVID semantic.  Use
78    the additional function `sysv_signal' when X/Open compatibility is
79    requested.  */
80 extern __sighandler_t __sysv_signal (int __sig, __sighandler_t __handler)
81      __THROW;
82 #ifdef __USE_GNU
83 extern __sighandler_t sysv_signal (int __sig, __sighandler_t __handler)
84      __THROW;
85 #endif
86
87 /* Set the handler for the signal SIG to HANDLER, returning the old
88    handler, or SIG_ERR on error.
89    By default `signal' has the BSD semantic.  */
90 __BEGIN_NAMESPACE_STD
91 #ifdef __USE_BSD
92 extern __sighandler_t signal (int __sig, __sighandler_t __handler)
93      __THROW;
94 #else
95 /* Make sure the used `signal' implementation is the SVID version. */
96 # ifdef __REDIRECT
97 extern __sighandler_t __REDIRECT (signal,
98                                       (int __sig, __sighandler_t __handler),
99                                       __sysv_signal);
100 # else
101 #  define signal __sysv_signal
102 # endif
103 #endif
104 __END_NAMESPACE_STD
105
106 #ifdef __USE_XOPEN
107 /* The X/Open definition of `signal' conflicts with the BSD version.
108    So they defined another function `bsd_signal'.  */
109 extern __sighandler_t bsd_signal (int __sig, __sighandler_t __handler)
110      __THROW;
111 #endif
112
113 /* Send signal SIG to process number PID.  If PID is zero,
114    send SIG to all processes in the current process's process group.
115    If PID is < -1, send SIG to all processes in process group - PID.  */
116 #ifdef __USE_POSIX
117 extern int kill (__pid_t __pid, int __sig) __THROW;
118 #endif /* Use POSIX.  */
119
120 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
121 /* Send SIG to all processes in process group PGRP.
122    If PGRP is zero, send SIG to all processes in
123    the current process's process group.  */
124 extern int killpg (__pid_t __pgrp, int __sig) __THROW;
125 #endif /* Use BSD || X/Open Unix.  */
126
127 __BEGIN_NAMESPACE_STD
128 /* Raise signal SIG, i.e., send SIG to yourself.  */
129 extern int raise (int __sig) __THROW;
130 __END_NAMESPACE_STD
131
132 #ifdef __USE_SVID
133 /* SVID names for the same things.  */
134 extern __sighandler_t ssignal (int __sig, __sighandler_t __handler)
135      __THROW;
136 extern int gsignal (int __sig) __THROW;
137 #endif /* Use SVID.  */
138
139 #ifdef __USE_MISC
140 /* Print a message describing the meaning of the given signal number.  */
141 extern void psignal (int __sig, __const char *__s);
142 #endif /* Use misc.  */
143
144
145 /* The `sigpause' function has two different interfaces.  The original
146    BSD definition defines the argument as a mask of the signal, while
147    the more modern interface in X/Open defines it as the signal
148    number.  We go with the BSD version unless the user explicitly
149    selects the X/Open version.
150
151    This function is a cancellation point and therefore not marked with
152    __THROW.  */
153 extern int __sigpause (int __sig_or_mask, int __is_sig);
154
155 #ifdef __FAVOR_BSD
156 /* Set the mask of blocked signals to MASK,
157    wait for a signal to arrive, and then restore the mask.  */
158 # define sigpause(mask) __sigpause ((mask), 0)
159 extern int sigpause (int __mask) __THROW __attribute_deprecated__;
160 #else
161 # ifdef __USE_XOPEN
162 #  ifdef __GNUC__
163 extern int sigpause (int __sig) __asm__ ("__xpg_sigpause");
164 #  else
165 /* Remove a signal from the signal mask and suspend the process.  */
166 #   define sigpause(sig) __sigpause ((sig), 1)
167 #  endif
168 # endif
169 #endif
170
171
172 #ifdef __USE_BSD
173 /* None of the following functions should be used anymore.  They are here
174    only for compatibility.  A single word (`int') is not guaranteed to be
175    enough to hold a complete signal mask and therefore these functions
176    simply do not work in many situations.  Use `sigprocmask' instead.  */
177
178 /* Compute mask for signal SIG.  */
179 # define sigmask(sig)   __sigmask(sig)
180
181 /* Block signals in MASK, returning the old mask.  */
182 extern int sigblock (int __mask) __THROW __attribute_deprecated__;
183
184 /* Set the mask of blocked signals to MASK, returning the old mask.  */
185 extern int sigsetmask (int __mask) __THROW __attribute_deprecated__;
186
187 /* Return currently selected signal mask.  */
188 extern int siggetmask (void) __THROW __attribute_deprecated__;
189 #endif /* Use BSD.  */
190
191
192 #ifdef __USE_MISC
193 # define NSIG   _NSIG
194 #endif
195
196 #ifdef __USE_GNU
197 typedef __sighandler_t sighandler_t;
198 #endif
199
200 /* 4.4 BSD uses the name `sig_t' for this.  */
201 #ifdef __USE_BSD
202 typedef __sighandler_t sig_t;
203 #endif
204
205 #ifdef __USE_POSIX
206
207 # ifdef __USE_POSIX199309
208 /* We need `struct timespec' later on.  */
209 #  define __need_timespec
210 #  include <time.h>
211
212 /* Get the `siginfo_t' type plus the needed symbols.  */
213 #  include <bits/siginfo.h>
214 # endif
215
216 /* Clear all signals from SET.  */
217 extern int sigemptyset (sigset_t *__set) __THROW __nonnull ((1));
218
219 /* Set all signals in SET.  */
220 extern int sigfillset (sigset_t *__set) __THROW __nonnull ((1));
221
222 /* Add SIGNO to SET.  */
223 extern int sigaddset (sigset_t *__set, int __signo) __THROW __nonnull ((1));
224
225 /* Remove SIGNO from SET.  */
226 extern int sigdelset (sigset_t *__set, int __signo) __THROW __nonnull ((1));
227
228 /* Return 1 if SIGNO is in SET, 0 if not.  */
229 extern int sigismember (__const sigset_t *__set, int __signo)
230      __THROW __nonnull ((1));
231
232 # ifdef __USE_GNU
233 /* Return non-empty value is SET is not empty.  */
234 extern int sigisemptyset (__const sigset_t *__set) __THROW __nonnull ((1));
235
236 /* Build new signal set by combining the two inputs set using logical AND.  */
237 extern int sigandset (sigset_t *__set, __const sigset_t *__left,
238                       __const sigset_t *__right) __THROW __nonnull ((1, 2, 3));
239
240 /* Build new signal set by combining the two inputs set using logical OR.  */
241 extern int sigorset (sigset_t *__set, __const sigset_t *__left,
242                      __const sigset_t *__right) __THROW __nonnull ((1, 2, 3));
243 # endif /* GNU */
244
245 /* Get the system-specific definitions of `struct sigaction'
246    and the `SA_*' and `SIG_*'. constants.  */
247 # include <bits/sigaction.h>
248
249 /* Get and/or change the set of blocked signals.  */
250 extern int sigprocmask (int __how, __const sigset_t *__restrict __set,
251                         sigset_t *__restrict __oset) __THROW;
252
253 /* Change the set of blocked signals to SET,
254    wait until a signal arrives, and restore the set of blocked signals.
255
256    This function is a cancellation point and therefore not marked with
257    __THROW.  */
258 extern int sigsuspend (__const sigset_t *__set) __nonnull ((1));
259
260 /* Get and/or set the action for signal SIG.  */
261 extern int sigaction (int __sig, __const struct sigaction *__restrict __act,
262                       struct sigaction *__restrict __oact) __THROW;
263
264 /* Put in SET all signals that are blocked and waiting to be delivered.  */
265 extern int sigpending (sigset_t *__set) __THROW __nonnull ((1));
266
267
268 /* Select any of pending signals from SET or wait for any to arrive.
269
270    This function is a cancellation point and therefore not marked with
271    __THROW.  */
272 extern int sigwait (__const sigset_t *__restrict __set, int *__restrict __sig)
273      __nonnull ((1, 2));
274
275 # ifdef __USE_POSIX199309
276 /* Select any of pending signals from SET and place information in INFO.
277
278    This function is a cancellation point and therefore not marked with
279    __THROW.  */
280 extern int sigwaitinfo (__const sigset_t *__restrict __set,
281                         siginfo_t *__restrict __info) __nonnull ((1));
282
283 /* Select any of pending signals from SET and place information in INFO.
284    Wait the time specified by TIMEOUT if no signal is pending.
285
286    This function is a cancellation point and therefore not marked with
287    __THROW.  */
288 extern int sigtimedwait (__const sigset_t *__restrict __set,
289                          siginfo_t *__restrict __info,
290                          __const struct timespec *__restrict __timeout)
291      __nonnull ((1));
292
293 /* Send signal SIG to the process PID.  Associate data in VAL with the
294    signal.  */
295 extern int sigqueue (__pid_t __pid, int __sig, __const union sigval __val)
296      __THROW;
297 # endif /* Use POSIX 199306.  */
298
299 #endif /* Use POSIX.  */
300
301 #ifdef __USE_BSD
302
303 #ifdef __UCLIBC_HAS_SYS_SIGLIST__
304 /* Names of the signals.  This variable exists only for compatibility.
305    Use `strsignal' instead (see <string.h>).  */
306 #define _sys_siglist sys_siglist
307 extern __const char *__const sys_siglist[_NSIG];
308 #endif /* __UCLIBC_HAS_SYS_SIGLIST__ */
309
310 /* Structure passed to `sigvec'.  */
311 struct sigvec
312   {
313     __sighandler_t sv_handler;  /* Signal handler.  */
314     int sv_mask;                /* Mask of signals to be blocked.  */
315
316     int sv_flags;               /* Flags (see below).  */
317 # define sv_onstack     sv_flags /* 4.2 BSD compatibility.  */
318   };
319
320 /* Bits in `sv_flags'.  */
321 # define SV_ONSTACK     (1 << 0)/* Take the signal on the signal stack.  */
322 # define SV_INTERRUPT   (1 << 1)/* Do not restart system calls.  */
323 # define SV_RESETHAND   (1 << 2)/* Reset handler to SIG_DFL on receipt.  */
324
325
326 /* If VEC is non-NULL, set the handler for SIG to the `sv_handler' member
327    of VEC.  The signals in `sv_mask' will be blocked while the handler runs.
328    If the SV_RESETHAND bit is set in `sv_flags', the handler for SIG will be
329    reset to SIG_DFL before `sv_handler' is entered.  If OVEC is non-NULL,
330    it is filled in with the old information for SIG.  */
331 extern int sigvec (int __sig, __const struct sigvec *__vec,
332                    struct sigvec *__ovec) __THROW;
333
334
335 /* Get machine-dependent `struct sigcontext' and signal subcodes.  */
336 # include <bits/sigcontext.h>
337
338 /* Restore the state saved in SCP.  */
339 extern int sigreturn (struct sigcontext *__scp) __THROW;
340
341 #endif /*  use BSD.  */
342
343
344 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
345
346 /* If INTERRUPT is nonzero, make signal SIG interrupt system calls
347    (causing them to fail with EINTR); if INTERRUPT is zero, make system
348    calls be restarted after signal SIG.  */
349 extern int siginterrupt (int __sig, int __interrupt) __THROW;
350
351 # include <bits/sigstack.h>
352 # ifdef __USE_XOPEN
353 /* This will define `ucontext_t' and `mcontext_t'.  */
354 #  include <ucontext.h>
355 # endif
356
357 /* Run signals handlers on the stack specified by SS (if not NULL).
358    If OSS is not NULL, it is filled in with the old signal stack status.
359    This interface is obsolete and on many platform not implemented.  */
360 extern int sigstack (struct sigstack *__ss, struct sigstack *__oss)
361      __THROW __attribute_deprecated__;
362
363 /* Alternate signal handler stack interface.
364    This interface should always be preferred over `sigstack'.  */
365 extern int sigaltstack (__const struct sigaltstack *__restrict __ss,
366                         struct sigaltstack *__restrict __oss) __THROW;
367
368 #endif /* use BSD or X/Open Unix.  */
369
370 #ifdef __USE_XOPEN_EXTENDED
371 /* Simplified interface for signal management.  */
372
373 /* Add SIG to the calling process' signal mask.  */
374 extern int sighold (int __sig) __THROW;
375
376 /* Remove SIG from the calling process' signal mask.  */
377 extern int sigrelse (int __sig) __THROW;
378
379 /* Set the disposition of SIG to SIG_IGN.  */
380 extern int sigignore (int __sig) __THROW;
381
382 /* Set the disposition of SIG.  */
383 extern __sighandler_t sigset (int __sig, __sighandler_t __disp) __THROW;
384 #endif
385
386 #if defined __UCLIBC_HAS_THREADS__ && (defined __USE_POSIX199506 || defined __USE_UNIX98)
387 /* Some of the functions for handling signals in threaded programs must
388    be defined here.  */
389 # include <bits/pthreadtypes.h>
390 # include <bits/sigthread.h>
391 #endif /* use Unix98 */
392
393 /* The following functions are used internally in the C library and in
394    other code which need deep insights.  */
395
396 /* Return number of available real-time signal with highest priority.  */
397 extern int __libc_current_sigrtmin (void) __THROW;
398 /* Return number of available real-time signal with lowest priority.  */
399 extern int __libc_current_sigrtmax (void) __THROW;
400
401 #endif /* signal.h  */
402
403 __END_DECLS
404
405 #endif /* not signal.h */