signal.h revision 151306
1105109Smike/*-
21541Srgrimes * Copyright (c) 1982, 1986, 1989, 1991, 1993
31541Srgrimes *	The Regents of the University of California.  All rights reserved.
41541Srgrimes * (c) UNIX System Laboratories, Inc.
51541Srgrimes * All or some portions of this file are derived from material licensed
61541Srgrimes * to the University of California by American Telephone and Telegraph
71541Srgrimes * Co. or Unix System Laboratories, Inc. and are reproduced herein with
81541Srgrimes * the permission of UNIX System Laboratories, Inc.
91541Srgrimes *
101541Srgrimes * Redistribution and use in source and binary forms, with or without
111541Srgrimes * modification, are permitted provided that the following conditions
121541Srgrimes * are met:
131541Srgrimes * 1. Redistributions of source code must retain the above copyright
141541Srgrimes *    notice, this list of conditions and the following disclaimer.
151541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
161541Srgrimes *    notice, this list of conditions and the following disclaimer in the
171541Srgrimes *    documentation and/or other materials provided with the distribution.
181541Srgrimes * 4. Neither the name of the University nor the names of its contributors
191541Srgrimes *    may be used to endorse or promote products derived from this software
201541Srgrimes *    without specific prior written permission.
211541Srgrimes *
221541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
231541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
241541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
251541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
261541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
271541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
281541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
291541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
301541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
311541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
321541Srgrimes * SUCH DAMAGE.
331541Srgrimes *
3414486Shsu *	@(#)signal.h	8.4 (Berkeley) 5/4/95
3550477Speter * $FreeBSD: head/sys/sys/signal.h 151306 2005-10-14 03:01:14Z davidxu $
361541Srgrimes */
371541Srgrimes
38105109Smike#ifndef _SYS_SIGNAL_H_
391541Srgrimes#define	_SYS_SIGNAL_H_
401541Srgrimes
419343Sbde#include <sys/cdefs.h>
42107376Smike#include <sys/_types.h>
4398301Swollman#include <sys/_sigset.h>
449343Sbde
45149337Sstefanf#include <machine/_limits.h>	/* __MINSIGSTKSZ */
46105109Smike#include <machine/signal.h>	/* sig_atomic_t; trap codes; sigcontext */
47105109Smike
4851791Smarcel/*
4951942Smarcel * System defined signals.
5051791Smarcel */
51105106Smike#if __POSIX_VISIBLE || __XSI_VISIBLE
5251942Smarcel#define	SIGHUP		1	/* hangup */
53105106Smike#endif
5451791Smarcel#define	SIGINT		2	/* interrupt */
55105106Smike#if __POSIX_VISIBLE || __XSI_VISIBLE
5651791Smarcel#define	SIGQUIT		3	/* quit */
57105106Smike#endif
5851791Smarcel#define	SIGILL		4	/* illegal instr. (not reset when caught) */
59105106Smike#if __XSI_VISIBLE
6051791Smarcel#define	SIGTRAP		5	/* trace trap (not reset when caught) */
61105106Smike#endif
6251791Smarcel#define	SIGABRT		6	/* abort() */
63105106Smike#if __BSD_VISIBLE
6451791Smarcel#define	SIGIOT		SIGABRT	/* compatibility */
6551791Smarcel#define	SIGEMT		7	/* EMT instruction */
66105106Smike#endif
6751791Smarcel#define	SIGFPE		8	/* floating point exception */
68105106Smike#if __POSIX_VISIBLE || __XSI_VISIBLE
6951791Smarcel#define	SIGKILL		9	/* kill (cannot be caught or ignored) */
70105106Smike#endif
71105106Smike#if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE
7251791Smarcel#define	SIGBUS		10	/* bus error */
73105106Smike#endif
7451791Smarcel#define	SIGSEGV		11	/* segmentation violation */
75105106Smike#if __BSD_VISIBLE
7651791Smarcel#define	SIGSYS		12	/* non-existent system call invoked */
77105106Smike#endif
78105106Smike#if __POSIX_VISIBLE || __XSI_VISIBLE
7951791Smarcel#define	SIGPIPE		13	/* write on a pipe with no one to read it */
8051791Smarcel#define	SIGALRM		14	/* alarm clock */
81105106Smike#endif
8251791Smarcel#define	SIGTERM		15	/* software termination signal from kill */
83105106Smike#if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE
8451791Smarcel#define	SIGURG		16	/* urgent condition on IO channel */
85105106Smike#endif
86105106Smike#if __POSIX_VISIBLE || __XSI_VISIBLE
8751791Smarcel#define	SIGSTOP		17	/* sendable stop signal not from tty */
8851791Smarcel#define	SIGTSTP		18	/* stop signal from tty */
8951791Smarcel#define	SIGCONT		19	/* continue a stopped process */
9051791Smarcel#define	SIGCHLD		20	/* to parent on child stop or exit */
9151791Smarcel#define	SIGTTIN		21	/* to readers pgrp upon background tty read */
9251791Smarcel#define	SIGTTOU		22	/* like TTIN if (tp->t_local&LTOSTOP) */
93105106Smike#endif
94105106Smike#if __BSD_VISIBLE
9551791Smarcel#define	SIGIO		23	/* input/output possible signal */
96105106Smike#endif
97105106Smike#if __XSI_VISIBLE
9851791Smarcel#define	SIGXCPU		24	/* exceeded CPU time limit */
9951791Smarcel#define	SIGXFSZ		25	/* exceeded file size limit */
10051791Smarcel#define	SIGVTALRM	26	/* virtual time alarm */
10151791Smarcel#define	SIGPROF		27	/* profiling time alarm */
102105106Smike#endif
103105106Smike#if __BSD_VISIBLE
10451942Smarcel#define	SIGWINCH	28	/* window size changes */
10551942Smarcel#define	SIGINFO		29	/* information request */
106105106Smike#endif
107105106Smike#if __POSIX_VISIBLE || __XSI_VISIBLE
10851942Smarcel#define	SIGUSR1		30	/* user defined signal 1 */
10951942Smarcel#define	SIGUSR2		31	/* user defined signal 2 */
110105106Smike#endif
111112894Sjeff#if __BSD_VISIBLE
112112885Sjeff#define	SIGTHR		32	/* Thread interrupt. */
113112894Sjeff#endif
1141541Srgrimes
115151306Sdavidxu#define	SIGRTMIN	65
116151306Sdavidxu#define	SIGRTMAX	128
117151306Sdavidxu
118105106Smike#define	SIG_DFL		((__sighandler_t *)0)
119105106Smike#define	SIG_IGN		((__sighandler_t *)1)
120105106Smike#define	SIG_ERR		((__sighandler_t *)-1)
121105106Smike/*
122105106Smike * XXX missing SIG_HOLD.
123105106Smike */
124105106Smike
1259343Sbde/*-
1269343Sbde * Type of a signal handling function.
1279343Sbde *
1289343Sbde * Language spec sez signal handlers take exactly one arg, even though we
1291541Srgrimes * actually supply three.  Ugh!
1309343Sbde *
1319343Sbde * We don't try to hide the difference by leaving out the args because
1329343Sbde * that would cause warnings about conformant programs.  Nonconformant
1339343Sbde * programs can avoid the warnings by casting to (__sighandler_t *) or
1349343Sbde * sig_t before calling signal() or assigning to sa_handler or sv_handler.
1359343Sbde *
1369343Sbde * The kernel should reverse the cast before calling the function.  It
1379343Sbde * has no way to do this, but on most machines 1-arg and 3-arg functions
1389343Sbde * have the same calling protocol so there is no problem in practice.
1399343Sbde * A bit in sa_flags could be used to specify the number of args.
1401541Srgrimes */
141105109Smiketypedef	void __sighandler_t(int);
1421541Srgrimes
143105015Smike#if __POSIX_VISIBLE || __XSI_VISIBLE
144105015Smike#ifndef _SIGSET_T_DECLARED
145105015Smike#define	_SIGSET_T_DECLARED
146105015Smiketypedef	__sigset_t	sigset_t;
147105015Smike#endif
148105015Smike#endif
149105015Smike
150105015Smike#if __POSIX_VISIBLE >= 199309 || __XSI_VISIBLE >= 500
15148621Scracauerunion sigval {
15248621Scracauer	/* Members as suggested by Annex C of POSIX 1003.1b. */
15351942Smarcel	int	sigval_int;
15451942Smarcel	void	*sigval_ptr;
15548621Scracauer};
156105015Smike#endif
15748621Scracauer
158105015Smike#if __POSIX_VISIBLE >= 199309
15952308Smarcelstruct sigevent {
16052308Smarcel	int	sigev_notify;		/* Notification type */
16169002Salc	union {
16269002Salc		int	__sigev_signo;	/* Signal number */
16369002Salc		int	__sigev_notify_kqueue;
16469002Salc	} __sigev_u;
16552308Smarcel	union sigval sigev_value;	/* Signal value */
166105015Smike/*
167105015Smike * XXX missing sigev_notify_function, sigev_notify_attributes.
168105015Smike */
16952308Smarcel};
170105109Smike#define	sigev_signo		__sigev_u.__sigev_signo
171105015Smike#if __BSD_VISIBLE
172105109Smike#define	sigev_notify_kqueue	__sigev_u.__sigev_notify_kqueue
173105015Smike#endif
17452308Smarcel
17552308Smarcel#define	SIGEV_NONE	0		/* No async notification */
17652308Smarcel#define	SIGEV_SIGNAL	1		/* Generate a queued signal */
177105015Smike#if __BSD_VISIBLE
178105109Smike#define	SIGEV_KEVENT	3		/* Generate a kevent */
179105015Smike#endif
180105015Smike/*
181105015Smike * XXX missing SIGEV_THREAD.
182105015Smike */
183105015Smike#endif /* __POSIX_VISIBLE >= 199309 */
18452308Smarcel
185105015Smike#if __POSIX_VISIBLE >= 199309 || __XSI_VISIBLE
186105109Smiketypedef	struct __siginfo {
18751942Smarcel	int	si_signo;		/* signal number */
18851942Smarcel	int	si_errno;		/* errno association */
18952160Smarcel	/*
19048621Scracauer	 * Cause of signal, one of the SI_ macros or signal-specific
191105109Smike	 * values, i.e. one of the FPE_... values for SIGFPE.  This
19248621Scracauer	 * value is equivalent to the second argument to an old-style
19348621Scracauer	 * FreeBSD signal handler.
19448621Scracauer	 */
19551942Smarcel	int	si_code;		/* signal code */
196105015Smike	__pid_t	si_pid;			/* sending process */
197105015Smike	__uid_t	si_uid;			/* sender's ruid */
19851942Smarcel	int	si_status;		/* exit value */
19951942Smarcel	void	*si_addr;		/* faulting instruction */
20051942Smarcel	union sigval si_value;		/* signal value */
20151942Smarcel	long	si_band;		/* band event for SIGPOLL */
202151306Sdavidxu	union	{
203151306Sdavidxu		struct {
204151306Sdavidxu			int	_trapno;/* machine specific trap code */
205151306Sdavidxu		} _fault;
206151306Sdavidxu		int	__spare__[7];	/* gimme some slack */
207151306Sdavidxu	} _reason;
20851791Smarcel} siginfo_t;
209151306Sdavidxu
210151306Sdavidxu#define si_trapno	_reason._fault._trapno
211151306Sdavidxu
212151306Sdavidxu/** si_code **/
213151306Sdavidxu/* codes for SIGILL */
214151306Sdavidxu#define ILL_ILLOPC 	1	/* Illegal opcode.			*/
215151306Sdavidxu#define ILL_ILLOPN 	2	/* Illegal operand.			*/
216151306Sdavidxu#define ILL_ILLADR 	3	/* Illegal addressing mode.		*/
217151306Sdavidxu#define ILL_ILLTRP 	4	/* Illegal trap.			*/
218151306Sdavidxu#define ILL_PRVOPC 	5	/* Privileged opcode.			*/
219151306Sdavidxu#define ILL_PRVREG 	6	/* Privileged register.			*/
220151306Sdavidxu#define ILL_COPROC 	7	/* Coprocessor error.			*/
221151306Sdavidxu#define ILL_BADSTK 	8	/* Internal stack error.		*/
222151306Sdavidxu
223151306Sdavidxu/* codes for SIGBUS */
224151306Sdavidxu#define BUS_ADRALN	1	/* Invalid address alignment.		*/
225151306Sdavidxu#define BUS_ADRERR	2	/* Nonexistent physical address.	*/
226151306Sdavidxu#define BUS_OBJERR	3	/* Object-specific hardware error.	*/
227151306Sdavidxu
228151306Sdavidxu/* codes for SIGSEGV */
229151306Sdavidxu#define SEGV_MAPERR	1	/* Address not mapped to object.	*/
230151306Sdavidxu#define SEGV_ACCERR	2	/* Invalid permissions for mapped	*/
231151306Sdavidxu				/* object.				*/
232151306Sdavidxu
233151306Sdavidxu/* codes for SIGFPE */
234151306Sdavidxu#define FPE_INTOVF	1	/* Integer overflow.			*/
235151306Sdavidxu#define FPE_INTDIV	2	/* Integer divide by zero.		*/
236151306Sdavidxu#define FPE_FLTDIV	3	/* Floating point divide by zero.	*/
237151306Sdavidxu#define FPE_FLTOVF	4	/* Floating point overflow.		*/
238151306Sdavidxu#define FPE_FLTUND	5	/* Floating point underflow.		*/
239151306Sdavidxu#define FPE_FLTRES	6	/* Floating point inexact result.	*/
240151306Sdavidxu#define FPE_FLTINV	7	/* Invalid floating point operation.	*/
241151306Sdavidxu#define FPE_FLTSUB	8	/* Subscript out of range.		*/
242151306Sdavidxu
243151306Sdavidxu/* codes for SIGTRAP */
244151306Sdavidxu#define TRAP_BRKPT	1	/* Process breakpoint.			*/
245151306Sdavidxu#define TRAP_TRACE	2	/* Process trace trap.			*/
246151306Sdavidxu
247151306Sdavidxu/* codes for SIGCHLD */
248151306Sdavidxu#define CLD_EXITED	1	/* Child has exited			*/
249151306Sdavidxu#define CLD_KILLED	2	/* Child has terminated abnormally but	*/
250151306Sdavidxu				/* did not create a core file		*/
251151306Sdavidxu#define CLD_DUMPED	3	/* Child has terminated abnormally and	*/
252151306Sdavidxu				/* created a core file			*/
253151306Sdavidxu#define CLD_TRAPPED	4	/* Traced child has trapped		*/
254151306Sdavidxu#define CLD_STOPPED	5	/* Child has stopped			*/
255151306Sdavidxu#define CLD_CONTINUED	6	/* Stopped child has continued		*/
256151306Sdavidxu
257151306Sdavidxu/* codes for SIGPOLL */
258151306Sdavidxu#define POLL_IN		1	/* Data input available			*/
259151306Sdavidxu#define POLL_OUT	2	/* Output buffers available		*/
260151306Sdavidxu#define POLL_MSG	3	/* Input message available		*/
261151306Sdavidxu#define POLL_ERR	4	/* I/O Error				*/
262151306Sdavidxu#define POLL_PRI	5	/* High priority input available	*/
263151306Sdavidxu#define POLL_HUP	4	/* Device disconnected			*/
264151306Sdavidxu
265105015Smike#endif
26648621Scracauer
267105106Smike#if __POSIX_VISIBLE || __XSI_VISIBLE
26851942Smarcelstruct __siginfo;
26951942Smarcel
2701541Srgrimes/*
2711541Srgrimes * Signal vector "template" used in sigaction call.
2721541Srgrimes */
27383045Sobrienstruct sigaction {
27448621Scracauer	union {
27592719Salfred		void    (*__sa_handler)(int);
27692719Salfred		void    (*__sa_sigaction)(int, struct __siginfo *, void *);
27748621Scracauer	} __sigaction_u;		/* signal handler */
27851942Smarcel	int	sa_flags;		/* see signal options below */
27951942Smarcel	sigset_t sa_mask;		/* signal mask to apply */
2801541Srgrimes};
281108382Smike
282108382Smike#define	sa_handler	__sigaction_u.__sa_handler
283105015Smike#endif
28451791Smarcel
285105015Smike#if __XSI_VISIBLE
286108402Smike/* If SA_SIGINFO is set, sa_sigaction must be used instead of sa_handler. */
287105015Smike#define	sa_sigaction	__sigaction_u.__sa_sigaction
288105015Smike#endif
28951791Smarcel
290105015Smike#if __POSIX_VISIBLE || __XSI_VISIBLE
291105109Smike#define	SA_NOCLDSTOP	0x0008	/* do not generate SIGCHLD on child stop */
292105015Smike#endif /* __POSIX_VISIBLE || __XSI_VISIBLE */
29351791Smarcel
294105015Smike#if __XSI_VISIBLE
295105109Smike#define	SA_ONSTACK	0x0001	/* take signal on signal stack */
296105109Smike#define	SA_RESTART	0x0002	/* restart system call on signal return */
29714331Speter#define	SA_RESETHAND	0x0004	/* reset to SIG_DFL when taking signal */
29814331Speter#define	SA_NODEFER	0x0010	/* don't mask the signal we're delivering */
29929340Sjoerg#define	SA_NOCLDWAIT	0x0020	/* don't keep zombies around */
30048621Scracauer#define	SA_SIGINFO	0x0040	/* signal handler with SA_SIGINFO args */
301105015Smike#endif
3021541Srgrimes
303105015Smike#if __BSD_VISIBLE
304105109Smike#define	NSIG		32	/* number of old signals (counting 0) */
305105015Smike#endif
3061541Srgrimes
307105015Smike#if __POSIX_VISIBLE || __XSI_VISIBLE
308151306Sdavidxu#define	SI_USER		0x10001		/* Signal sent by kill(). */
309151306Sdavidxu#define	SI_QUEUE	0x10002		/* Signal sent by the sigqueue(). */
310151306Sdavidxu#define	SI_TIMER	0x10003		/* Signal generated by expiration of */
311151306Sdavidxu					/* a timer set by timer_settime(). */
312151306Sdavidxu#define	SI_ASYNCIO	0x10004		/* Signal generated by completion of */
313151306Sdavidxu					/* an asynchronous I/O request.*/
314151306Sdavidxu#define	SI_MESGQ	0x10005		/* Signal generated by arrival of a */
315151306Sdavidxu					/* message on an empty message queue. */
316105015Smike#endif
317105015Smike#if __BSD_VISIBLE
318105109Smike#define	SI_UNDEFINED	0
319105015Smike#endif
32051791Smarcel
321105106Smike#if __BSD_VISIBLE
3229343Sbdetypedef	__sighandler_t	*sig_t;	/* type of pointer to a signal function */
323105106Smiketypedef	void __siginfohandler_t(int, struct __siginfo *, void *);
324105106Smike#endif
3251541Srgrimes
326105015Smike#if __XSI_VISIBLE
3271541Srgrimes/*
32851942Smarcel * Structure used in sigaltstack call.
3291541Srgrimes */
330105015Smike#if __BSD_VISIBLE
331105015Smiketypedef	struct sigaltstack {
332105015Smike#else
333105015Smiketypedef	struct {
334105015Smike#endif
33551942Smarcel	char	*ss_sp;			/* signal stack base */
336105015Smike	__size_t ss_size;		/* signal stack length */
33751942Smarcel	int	ss_flags;		/* SS_DISABLE and/or SS_ONSTACK */
33851791Smarcel} stack_t;
33951791Smarcel
34014331Speter#define	SS_ONSTACK	0x0001	/* take signal on alternate stack */
34114331Speter#define	SS_DISABLE	0x0004	/* disable taking signals on alternate stack */
342149337Sstefanf#define	MINSIGSTKSZ	__MINSIGSTKSZ		/* minimum stack size */
3431541Srgrimes#define	SIGSTKSZ	(MINSIGSTKSZ + 32768)	/* recommended stack size */
344105015Smike#endif
3451541Srgrimes
346105015Smike#if __BSD_VISIBLE
34751791Smarcel/*
3481541Srgrimes * 4.3 compatibility:
3491541Srgrimes * Signal vector "template" used in sigvec call.
3501541Srgrimes */
35183045Sobrienstruct sigvec {
35251942Smarcel	__sighandler_t *sv_handler;	/* signal handler */
35351942Smarcel	int	sv_mask;		/* signal mask to apply */
35451942Smarcel	int	sv_flags;		/* see signal options below */
3551541Srgrimes};
3561541Srgrimes
357105109Smike#define	SV_ONSTACK	SA_ONSTACK
358105109Smike#define	SV_INTERRUPT	SA_RESTART	/* same bit, opposite sense */
359105109Smike#define	SV_RESETHAND	SA_RESETHAND
360105109Smike#define	SV_NODEFER	SA_NODEFER
361105109Smike#define	SV_NOCLDSTOP	SA_NOCLDSTOP
362105109Smike#define	SV_SIGINFO	SA_SIGINFO
363105109Smike#define	sv_onstack	sv_flags	/* isn't compatibility wonderful! */
364105015Smike#endif
3651541Srgrimes
366105950Speter/* Keep this in one place only */
367105950Speter#if defined(_KERNEL) && defined(COMPAT_43) && \
368105950Speter    !defined(__i386__) && !defined(__alpha__)
369105950Speterstruct osigcontext {
370105950Speter	int _not_used;
371105950Speter};
372105950Speter#endif
373105950Speter
374105015Smike#if __XSI_VISIBLE
3751541Srgrimes/*
3761541Srgrimes * Structure used in sigstack call.
3771541Srgrimes */
37883045Sobrienstruct sigstack {
379105015Smike	/* XXX ss_sp's type should be `void *'. */
38051942Smarcel	char	*ss_sp;			/* signal stack pointer */
38151942Smarcel	int	ss_onstack;		/* current status */
3821541Srgrimes};
383105015Smike#endif
3841541Srgrimes
385105015Smike#if __BSD_VISIBLE || __POSIX_VISIBLE > 0 && __POSIX_VISIBLE <= 200112
3861541Srgrimes/*
3871541Srgrimes * Macro for converting signal number to a mask suitable for
3881541Srgrimes * sigblock().
3891541Srgrimes */
390105109Smike#define	sigmask(m)	(1 << ((m)-1))
391105015Smike#endif
3921541Srgrimes
393105015Smike#if __BSD_VISIBLE
3941541Srgrimes#define	BADSIG		SIG_ERR
395105015Smike#endif
3961541Srgrimes
397105015Smike#if __POSIX_VISIBLE || __XSI_VISIBLE
39851791Smarcel/*
39951791Smarcel * Flags for sigprocmask:
40051791Smarcel */
40151791Smarcel#define	SIG_BLOCK	1	/* block specified signal set */
40251791Smarcel#define	SIG_UNBLOCK	2	/* unblock specified signal set */
40351791Smarcel#define	SIG_SETMASK	3	/* set specified signal set */
404105015Smike#endif
40534925Sdufault
4061541Srgrimes/*
4071541Srgrimes * For historical reasons; programs expect signal's return value to be
4081541Srgrimes * defined by <sys/signal.h>.
4091541Srgrimes */
4101541Srgrimes__BEGIN_DECLS
41192719Salfred__sighandler_t *signal(int, __sighandler_t *);
4121541Srgrimes__END_DECLS
4139343Sbde
414105109Smike#endif /* !_SYS_SIGNAL_H_ */
415