signal.h revision 83045
1254885Sdumbbell/*
2254885Sdumbbell * Copyright (c) 1982, 1986, 1989, 1991, 1993
3254885Sdumbbell *	The Regents of the University of California.  All rights reserved.
4254885Sdumbbell * (c) UNIX System Laboratories, Inc.
5254885Sdumbbell * All or some portions of this file are derived from material licensed
6254885Sdumbbell * to the University of California by American Telephone and Telegraph
7254885Sdumbbell * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8254885Sdumbbell * the permission of UNIX System Laboratories, Inc.
9254885Sdumbbell *
10254885Sdumbbell * Redistribution and use in source and binary forms, with or without
11254885Sdumbbell * modification, are permitted provided that the following conditions
12254885Sdumbbell * are met:
13254885Sdumbbell * 1. Redistributions of source code must retain the above copyright
14254885Sdumbbell *    notice, this list of conditions and the following disclaimer.
15254885Sdumbbell * 2. Redistributions in binary form must reproduce the above copyright
16254885Sdumbbell *    notice, this list of conditions and the following disclaimer in the
17254885Sdumbbell *    documentation and/or other materials provided with the distribution.
18254885Sdumbbell * 3. All advertising materials mentioning features or use of this software
19254885Sdumbbell *    must display the following acknowledgement:
20254885Sdumbbell *	This product includes software developed by the University of
21254885Sdumbbell *	California, Berkeley and its contributors.
22254885Sdumbbell * 4. Neither the name of the University nor the names of its contributors
23254885Sdumbbell *    may be used to endorse or promote products derived from this software
24254885Sdumbbell *    without specific prior written permission.
25254885Sdumbbell *
26254885Sdumbbell * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27254885Sdumbbell * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28254885Sdumbbell * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29254885Sdumbbell * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30254885Sdumbbell * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31254885Sdumbbell * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32254885Sdumbbell * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33254885Sdumbbell * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34254885Sdumbbell * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35254885Sdumbbell * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36254885Sdumbbell * SUCH DAMAGE.
37254885Sdumbbell *
38254885Sdumbbell *	@(#)signal.h	8.4 (Berkeley) 5/4/95
39254885Sdumbbell * $FreeBSD: head/sys/sys/signal.h 83045 2001-09-05 01:22:14Z obrien $
40254885Sdumbbell */
41254885Sdumbbell
42254885Sdumbbell#ifndef	_SYS_SIGNAL_H_
43254885Sdumbbell#define	_SYS_SIGNAL_H_
44254885Sdumbbell
45254885Sdumbbell#include <sys/cdefs.h>
46254885Sdumbbell#include <sys/_posix.h>
47254885Sdumbbell
48254885Sdumbbell/*
49254885Sdumbbell * sigset_t macros.
50254885Sdumbbell */
51254885Sdumbbell#define	_SIG_WORDS	4
52254885Sdumbbell#define	_SIG_MAXSIG	128
53254885Sdumbbell#define	_SIG_IDX(sig)	((sig) - 1)
54254885Sdumbbell#define	_SIG_WORD(sig)	(_SIG_IDX(sig) >> 5)
55254885Sdumbbell#define	_SIG_BIT(sig)	(1 << (_SIG_IDX(sig) & 31))
56254885Sdumbbell#define	_SIG_VALID(sig)	((sig) < _SIG_MAXSIG && (sig) > 0)
57254885Sdumbbell
58254885Sdumbbell/*
59254885Sdumbbell * System defined signals.
60254885Sdumbbell */
61254885Sdumbbell#define	SIGHUP		1	/* hangup */
62254885Sdumbbell#define	SIGINT		2	/* interrupt */
63254885Sdumbbell#define	SIGQUIT		3	/* quit */
64254885Sdumbbell#define	SIGILL		4	/* illegal instr. (not reset when caught) */
65254885Sdumbbell#ifndef _POSIX_SOURCE
66254885Sdumbbell#define	SIGTRAP		5	/* trace trap (not reset when caught) */
67254885Sdumbbell#endif
68254885Sdumbbell#define	SIGABRT		6	/* abort() */
69254885Sdumbbell#ifndef _POSIX_SOURCE
70254885Sdumbbell#define	SIGIOT		SIGABRT	/* compatibility */
71254885Sdumbbell#define	SIGEMT		7	/* EMT instruction */
72254885Sdumbbell#endif
73254885Sdumbbell#define	SIGFPE		8	/* floating point exception */
74254885Sdumbbell#define	SIGKILL		9	/* kill (cannot be caught or ignored) */
75254885Sdumbbell#ifndef _POSIX_SOURCE
76254885Sdumbbell#define	SIGBUS		10	/* bus error */
77254885Sdumbbell#endif
78254885Sdumbbell#define	SIGSEGV		11	/* segmentation violation */
79254885Sdumbbell#ifndef _POSIX_SOURCE
80254885Sdumbbell#define	SIGSYS		12	/* non-existent system call invoked */
81254885Sdumbbell#endif
82254885Sdumbbell#define	SIGPIPE		13	/* write on a pipe with no one to read it */
83254885Sdumbbell#define	SIGALRM		14	/* alarm clock */
84254885Sdumbbell#define	SIGTERM		15	/* software termination signal from kill */
85254885Sdumbbell#ifndef _POSIX_SOURCE
86254885Sdumbbell#define	SIGURG		16	/* urgent condition on IO channel */
87254885Sdumbbell#endif
88254885Sdumbbell#define	SIGSTOP		17	/* sendable stop signal not from tty */
89254885Sdumbbell#define	SIGTSTP		18	/* stop signal from tty */
90254885Sdumbbell#define	SIGCONT		19	/* continue a stopped process */
91254885Sdumbbell#define	SIGCHLD		20	/* to parent on child stop or exit */
92280183Sdumbbell#define	SIGTTIN		21	/* to readers pgrp upon background tty read */
93254885Sdumbbell#define	SIGTTOU		22	/* like TTIN if (tp->t_local&LTOSTOP) */
94254885Sdumbbell#ifndef _POSIX_SOURCE
95254885Sdumbbell#define	SIGIO		23	/* input/output possible signal */
96254885Sdumbbell#define	SIGXCPU		24	/* exceeded CPU time limit */
97254885Sdumbbell#define	SIGXFSZ		25	/* exceeded file size limit */
98254885Sdumbbell#define	SIGVTALRM	26	/* virtual time alarm */
99254885Sdumbbell#define	SIGPROF		27	/* profiling time alarm */
100254885Sdumbbell#define	SIGWINCH	28	/* window size changes */
101254885Sdumbbell#define	SIGINFO		29	/* information request */
102254885Sdumbbell#endif
103254885Sdumbbell#define	SIGUSR1		30	/* user defined signal 1 */
104254885Sdumbbell#define	SIGUSR2		31	/* user defined signal 2 */
105280183Sdumbbell
106254885Sdumbbell/*-
107254885Sdumbbell * Type of a signal handling function.
108254885Sdumbbell *
109254885Sdumbbell * Language spec sez signal handlers take exactly one arg, even though we
110254885Sdumbbell * actually supply three.  Ugh!
111254885Sdumbbell *
112254885Sdumbbell * We don't try to hide the difference by leaving out the args because
113254885Sdumbbell * that would cause warnings about conformant programs.  Nonconformant
114254885Sdumbbell * programs can avoid the warnings by casting to (__sighandler_t *) or
115254885Sdumbbell * sig_t before calling signal() or assigning to sa_handler or sv_handler.
116254885Sdumbbell *
117254885Sdumbbell * The kernel should reverse the cast before calling the function.  It
118254885Sdumbbell * has no way to do this, but on most machines 1-arg and 3-arg functions
119254885Sdumbbell * have the same calling protocol so there is no problem in practice.
120254885Sdumbbell * A bit in sa_flags could be used to specify the number of args.
121254885Sdumbbell */
122280183Sdumbbelltypedef void __sighandler_t __P((int));
123254885Sdumbbell
124254885Sdumbbell#define	SIG_DFL		((__sighandler_t *)0)
125280183Sdumbbell#define	SIG_IGN		((__sighandler_t *)1)
126254885Sdumbbell#define	SIG_ERR		((__sighandler_t *)-1)
127254885Sdumbbell
128254885Sdumbbell#if defined(_P1003_1B_VISIBLE) || defined(_KERNEL)
129254885Sdumbbellunion sigval {
130254885Sdumbbell	/* Members as suggested by Annex C of POSIX 1003.1b. */
131254885Sdumbbell	int	sigval_int;
132254885Sdumbbell	void	*sigval_ptr;
133254885Sdumbbell};
134254885Sdumbbell
135254885Sdumbbellstruct sigevent {
136254885Sdumbbell	int	sigev_notify;		/* Notification type */
137254885Sdumbbell	union {
138254885Sdumbbell		int	__sigev_signo;	/* Signal number */
139254885Sdumbbell		int	__sigev_notify_kqueue;
140254885Sdumbbell	} __sigev_u;
141254885Sdumbbell	union sigval sigev_value;	/* Signal value */
142254885Sdumbbell};
143254885Sdumbbell#define sigev_signo		__sigev_u.__sigev_signo
144254885Sdumbbell#define sigev_notify_kqueue	__sigev_u.__sigev_notify_kqueue
145254885Sdumbbell
146254885Sdumbbell#define	SIGEV_NONE	0		/* No async notification */
147254885Sdumbbell#define	SIGEV_SIGNAL	1		/* Generate a queued signal */
148254885Sdumbbell#define SIGEV_KEVENT	3		/* Generate a kevent */
149254885Sdumbbell
150254885Sdumbbelltypedef struct __siginfo {
151254885Sdumbbell	int	si_signo;		/* signal number */
152254885Sdumbbell	int	si_errno;		/* errno association */
153254885Sdumbbell	/*
154254885Sdumbbell	 * Cause of signal, one of the SI_ macros or signal-specific
155254885Sdumbbell	 * values, i.e. one of the FPE_... values for SIGFPE. This
156254885Sdumbbell	 * value is equivalent to the second argument to an old-style
157254885Sdumbbell	 * FreeBSD signal handler.
158254885Sdumbbell	 */
159254885Sdumbbell	int	si_code;		/* signal code */
160254885Sdumbbell	int	si_pid;			/* sending process */
161254885Sdumbbell	unsigned int si_uid;		/* sender's ruid */
162254885Sdumbbell	int	si_status;		/* exit value */
163254885Sdumbbell	void	*si_addr;		/* faulting instruction */
164254885Sdumbbell	union sigval si_value;		/* signal value */
165254885Sdumbbell	long	si_band;		/* band event for SIGPOLL */
166254885Sdumbbell	int	__spare__[7];		/* gimme some slack */
167254885Sdumbbell} siginfo_t;
168254885Sdumbbell#endif /* _P1003_1B_VISIBLE */
169254885Sdumbbell
170254885Sdumbbelltypedef struct __sigset {
171254885Sdumbbell	unsigned int	__bits[_SIG_WORDS];
172254885Sdumbbell} sigset_t;
173254885Sdumbbell
174254885Sdumbbell/*
175254885Sdumbbell * XXX - there are some nasty dependencies on include file order. Now that
176254885Sdumbbell * sigset_t has been defined we can include the MD header.
177254885Sdumbbell */
178254885Sdumbbell#include <machine/signal.h>     /* sig_atomic_t; trap codes; sigcontext */
179254885Sdumbbell
180254885Sdumbbell#if !defined(_ANSI_SOURCE)
181254885Sdumbbell
182254885Sdumbbellstruct __siginfo;
183254885Sdumbbell
184254885Sdumbbell/*
185254885Sdumbbell * Signal vector "template" used in sigaction call.
186254885Sdumbbell */
187254885Sdumbbellstruct sigaction {
188254885Sdumbbell	union {
189254885Sdumbbell		void    (*__sa_handler) __P((int));
190254885Sdumbbell		void    (*__sa_sigaction) __P((int, struct __siginfo *,
191254885Sdumbbell					       void *));
192254885Sdumbbell	} __sigaction_u;		/* signal handler */
193254885Sdumbbell	int	sa_flags;		/* see signal options below */
194254885Sdumbbell	sigset_t sa_mask;		/* signal mask to apply */
195254885Sdumbbell};
196254885Sdumbbell
197254885Sdumbbell/* if SA_SIGINFO is set, sa_sigaction is to be used instead of sa_handler. */
198254885Sdumbbell#define	sa_handler	__sigaction_u.__sa_handler
199254885Sdumbbell
200254885Sdumbbell#define SA_NOCLDSTOP	0x0008	/* do not generate SIGCHLD on child stop */
201254885Sdumbbell
202254885Sdumbbell#if !defined(_POSIX_SOURCE)
203254885Sdumbbell
204254885Sdumbbell#define	sa_sigaction	__sigaction_u.__sa_sigaction
205254885Sdumbbell
206254885Sdumbbell#define SA_ONSTACK	0x0001	/* take signal on signal stack */
207254885Sdumbbell#define SA_RESTART	0x0002	/* restart system call on signal return */
208254885Sdumbbell#define	SA_RESETHAND	0x0004	/* reset to SIG_DFL when taking signal */
209254885Sdumbbell#define	SA_NODEFER	0x0010	/* don't mask the signal we're delivering */
210254885Sdumbbell#define	SA_NOCLDWAIT	0x0020	/* don't keep zombies around */
211254885Sdumbbell#define	SA_SIGINFO	0x0040	/* signal handler with SA_SIGINFO args */
212254885Sdumbbell#ifdef COMPAT_SUNOS
213254885Sdumbbell#define	SA_USERTRAMP	0x0100	/* do not bounce off kernel's sigtramp */
214254885Sdumbbell#endif
215254885Sdumbbell
216254885Sdumbbell#define NSIG		32	/* number of old signals (counting 0) */
217254885Sdumbbell
218254885Sdumbbell/* POSIX 1003.1b required values. */
219254885Sdumbbell#define SI_USER		0x10001
220254885Sdumbbell#define SI_QUEUE	0x10002
221254885Sdumbbell#define SI_TIMER	0x10003
222254885Sdumbbell#define SI_ASYNCIO	0x10004
223254885Sdumbbell#define SI_MESGQ	0x10005
224254885Sdumbbell
225254885Sdumbbell/* Additional FreeBSD values. */
226254885Sdumbbell#define SI_UNDEFINED	0
227254885Sdumbbell
228254885Sdumbbelltypedef void __siginfohandler_t __P((int, struct __siginfo *, void *));
229254885Sdumbbell
230254885Sdumbbelltypedef	__sighandler_t	*sig_t;	/* type of pointer to a signal function */
231254885Sdumbbell
232254885Sdumbbell#ifdef	_BSD_SIZE_T_
233254885Sdumbbelltypedef	_BSD_SIZE_T_	size_t;
234254885Sdumbbell#undef	_BSD_SIZE_T_
235254885Sdumbbell#endif
236254885Sdumbbell
237254885Sdumbbell/*
238254885Sdumbbell * Structure used in sigaltstack call.
239254885Sdumbbell */
240254885Sdumbbelltypedef struct sigaltstack {
241254885Sdumbbell	char	*ss_sp;			/* signal stack base */
242254885Sdumbbell	size_t	ss_size;		/* signal stack length */
243254885Sdumbbell	int	ss_flags;		/* SS_DISABLE and/or SS_ONSTACK */
244254885Sdumbbell} stack_t;
245254885Sdumbbell
246254885Sdumbbell#define	SS_ONSTACK	0x0001	/* take signal on alternate stack */
247254885Sdumbbell#define	SS_DISABLE	0x0004	/* disable taking signals on alternate stack */
248280183Sdumbbell#define	SIGSTKSZ	(MINSIGSTKSZ + 32768)	/* recommended stack size */
249254885Sdumbbell
250254885Sdumbbell/* Have enough typedefs for this now.  XXX */
251254885Sdumbbell#include <sys/ucontext.h>
252254885Sdumbbell
253254885Sdumbbell/*
254254885Sdumbbell * 4.3 compatibility:
255254885Sdumbbell * Signal vector "template" used in sigvec call.
256254885Sdumbbell */
257254885Sdumbbellstruct sigvec {
258254885Sdumbbell	__sighandler_t *sv_handler;	/* signal handler */
259254885Sdumbbell	int	sv_mask;		/* signal mask to apply */
260254885Sdumbbell	int	sv_flags;		/* see signal options below */
261254885Sdumbbell};
262254885Sdumbbell
263254885Sdumbbell#define SV_ONSTACK	SA_ONSTACK
264254885Sdumbbell#define SV_INTERRUPT	SA_RESTART	/* same bit, opposite sense */
265254885Sdumbbell#define SV_RESETHAND	SA_RESETHAND
266254885Sdumbbell#define SV_NODEFER	SA_NODEFER
267254885Sdumbbell#define SV_NOCLDSTOP	SA_NOCLDSTOP
268254885Sdumbbell#define SV_SIGINFO	SA_SIGINFO
269254885Sdumbbell#define sv_onstack sv_flags	/* isn't compatibility wonderful! */
270254885Sdumbbell
271254885Sdumbbell/*
272254885Sdumbbell * Structure used in sigstack call.
273254885Sdumbbell */
274254885Sdumbbellstruct sigstack {
275254885Sdumbbell	char	*ss_sp;			/* signal stack pointer */
276254885Sdumbbell	int	ss_onstack;		/* current status */
277254885Sdumbbell};
278254885Sdumbbell
279254885Sdumbbell/*
280254885Sdumbbell * Macro for converting signal number to a mask suitable for
281254885Sdumbbell * sigblock().
282254885Sdumbbell */
283254885Sdumbbell#define sigmask(m)	(1 << ((m)-1))
284254885Sdumbbell
285254885Sdumbbell#define	BADSIG		SIG_ERR
286254885Sdumbbell
287254885Sdumbbell#endif /* !_POSIX_SOURCE */
288254885Sdumbbell
289254885Sdumbbell/*
290254885Sdumbbell * Flags for sigprocmask:
291254885Sdumbbell */
292254885Sdumbbell#define	SIG_BLOCK	1	/* block specified signal set */
293254885Sdumbbell#define	SIG_UNBLOCK	2	/* unblock specified signal set */
294254885Sdumbbell#define	SIG_SETMASK	3	/* set specified signal set */
295254885Sdumbbell
296254885Sdumbbell#endif /* !_ANSI_SOURCE */
297254885Sdumbbell
298254885Sdumbbell/*
299254885Sdumbbell * For historical reasons; programs expect signal's return value to be
300254885Sdumbbell * defined by <sys/signal.h>.
301254885Sdumbbell */
302254885Sdumbbell__BEGIN_DECLS
303254885Sdumbbell__sighandler_t *signal __P((int, __sighandler_t *));
304254885Sdumbbell__END_DECLS
305254885Sdumbbell
306254885Sdumbbell#endif	/* !_SYS_SIGNAL_H_ */
307254885Sdumbbell