OSDN Git Service

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