OSDN Git Service

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