xref: /netbsd/sys/sys/signal.h (revision bf9ec67e)
1 /*	$NetBSD: signal.h,v 1.47 2002/04/12 17:37:30 manu Exp $	*/
2 
3 /*
4  * Copyright (c) 1982, 1986, 1989, 1991, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  * (c) UNIX System Laboratories, Inc.
7  * All or some portions of this file are derived from material licensed
8  * to the University of California by American Telephone and Telegraph
9  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10  * the permission of UNIX System Laboratories, Inc.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  * 3. All advertising materials mentioning features or use of this software
21  *    must display the following acknowledgement:
22  *	This product includes software developed by the University of
23  *	California, Berkeley and its contributors.
24  * 4. Neither the name of the University nor the names of its contributors
25  *    may be used to endorse or promote products derived from this software
26  *    without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38  * SUCH DAMAGE.
39  *
40  *	@(#)signal.h	8.4 (Berkeley) 5/4/95
41  */
42 
43 #ifndef	_SYS_SIGNAL_H_
44 #define	_SYS_SIGNAL_H_
45 
46 #include <sys/featuretest.h>
47 
48 #define _NSIG		64
49 
50 #if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE) && \
51     !defined(_XOPEN_SOURCE)
52 #define NSIG _NSIG
53 
54 #if defined(__LIBC12_SOURCE__) || defined(_KERNEL)
55 /* Number of signals supported by old style signal mask. */
56 #define	NSIG13		32
57 #endif
58 
59 #endif /* !_ANSI_SOURCE && !_POSIX_C_SOURCE && !_XOPEN_SOURCE */
60 
61 #define	SIGHUP		1	/* hangup */
62 #define	SIGINT		2	/* interrupt */
63 #define	SIGQUIT		3	/* quit */
64 #define	SIGILL		4	/* illegal instruction (not reset when caught) */
65 #ifndef _POSIX_SOURCE
66 #define	SIGTRAP		5	/* trace trap (not reset when caught) */
67 #endif
68 #define	SIGABRT		6	/* abort() */
69 #ifndef _POSIX_SOURCE
70 #define	SIGIOT		SIGABRT	/* compatibility */
71 #define	SIGEMT		7	/* EMT instruction */
72 #endif
73 #define	SIGFPE		8	/* floating point exception */
74 #define	SIGKILL		9	/* kill (cannot be caught or ignored) */
75 #ifndef _POSIX_SOURCE
76 #define	SIGBUS		10	/* bus error */
77 #endif
78 #define	SIGSEGV		11	/* segmentation violation */
79 #ifndef _POSIX_SOURCE
80 #define	SIGSYS		12	/* bad argument to system call */
81 #endif
82 #define	SIGPIPE		13	/* write on a pipe with no one to read it */
83 #define	SIGALRM		14	/* alarm clock */
84 #define	SIGTERM		15	/* software termination signal from kill */
85 #ifndef _POSIX_SOURCE
86 #define	SIGURG		16	/* urgent condition on IO channel */
87 #endif
88 #define	SIGSTOP		17	/* sendable stop signal not from tty */
89 #define	SIGTSTP		18	/* stop signal from tty */
90 #define	SIGCONT		19	/* continue a stopped process */
91 #define	SIGCHLD		20	/* to parent on child stop or exit */
92 #define	SIGTTIN		21	/* to readers pgrp upon background tty read */
93 #define	SIGTTOU		22	/* like TTIN for output if (tp->t_local&LTOSTOP) */
94 #ifndef _POSIX_SOURCE
95 #define	SIGIO		23	/* input/output possible signal */
96 #define	SIGXCPU		24	/* exceeded CPU time limit */
97 #define	SIGXFSZ		25	/* exceeded file size limit */
98 #define	SIGVTALRM	26	/* virtual time alarm */
99 #define	SIGPROF		27	/* profiling time alarm */
100 #define SIGWINCH	28	/* window size changes */
101 #define SIGINFO		29	/* information request */
102 #endif
103 #define SIGUSR1		30	/* user defined signal 1 */
104 #define SIGUSR2		31	/* user defined signal 2 */
105 #ifndef _POSIX_SOURCE
106 #define	SIGPWR		32	/* power fail/restart (not reset when caught) */
107 #endif
108 #ifdef _KERNEL
109 #define SIGRTMIN	33	/* Kernel only; not exposed to userland yet */
110 #define SIGRTMAX	63	/* Kernel only; not exposed to userland yet */
111 #endif
112 
113 #ifndef _KERNEL
114 #include <sys/cdefs.h>
115 #endif
116 
117 #define	SIG_DFL		((void (*) __P((int)))  0)
118 #define	SIG_IGN		((void (*) __P((int)))  1)
119 #define	SIG_ERR		((void (*) __P((int))) -1)
120 
121 #ifndef _ANSI_SOURCE
122 #if defined(__LIBC12_SOURCE__) || defined(_KERNEL)
123 typedef unsigned int sigset13_t;
124 
125 /*
126  * Macro for manipulating signal masks.
127  */
128 #define __sigmask13(n)		(1 << ((n) - 1))
129 #define	__sigaddset13(s, n)	(*(s) |= __sigmask13(n))
130 #define	__sigdelset13(s, n)	(*(s) &= ~__sigmask13(n))
131 #define	__sigismember13(s, n)	(*(s) & __sigmask13(n))
132 #define	__sigemptyset13(s)	(*(s) = 0)
133 #define	__sigfillset13(s)	(*(s) = ~(sigset13_t)0)
134 
135 /*
136  * Signal vector "template" used in sigaction call.
137  */
138 struct	sigaction13 {
139 	void	(*sa_handler)		/* signal handler */
140 			    __P((int));
141 	sigset13_t sa_mask;		/* signal mask to apply */
142 	int	sa_flags;		/* see signal options below */
143 };
144 #endif
145 
146 typedef struct {
147 	u_int32_t	__bits[4];
148 } sigset_t;
149 
150 /*
151  * Macro for manipulating signal masks.
152  */
153 #define __sigmask(n)		(1 << (((unsigned int)(n) - 1) & 31))
154 #define	__sigword(n)		(((unsigned int)(n) - 1) >> 5)
155 #define	__sigaddset(s, n)	((s)->__bits[__sigword(n)] |= __sigmask(n))
156 #define	__sigdelset(s, n)	((s)->__bits[__sigword(n)] &= ~__sigmask(n))
157 #define	__sigismember(s, n)	(((s)->__bits[__sigword(n)] & __sigmask(n)) != 0)
158 #define	__sigemptyset(s)	((s)->__bits[0] = 0x00000000, \
159 				 (s)->__bits[1] = 0x00000000, \
160 				 (s)->__bits[2] = 0x00000000, \
161 				 (s)->__bits[3] = 0x00000000)
162 #define	__sigfillset(s)		((s)->__bits[0] = 0xffffffff, \
163 				 (s)->__bits[1] = 0xffffffff, \
164 				 (s)->__bits[2] = 0xffffffff, \
165 				 (s)->__bits[3] = 0xffffffff)
166 
167 #ifdef _KERNEL
168 #define	sigaddset(s, n)		__sigaddset(s, n)
169 #define	sigdelset(s, n)		__sigdelset(s, n)
170 #define	sigismember(s, n)	__sigismember(s, n)
171 #define	sigemptyset(s)		__sigemptyset(s)
172 #define	sigfillset(s)		__sigfillset(s)
173 #define	sigplusset(s, t) \
174 	do {						\
175 		(t)->__bits[0] |= (s)->__bits[0];	\
176 		(t)->__bits[1] |= (s)->__bits[1];	\
177 		(t)->__bits[2] |= (s)->__bits[2];	\
178 		(t)->__bits[3] |= (s)->__bits[3];	\
179 	} while (/* CONSTCOND */ 0)
180 #define	sigminusset(s, t) \
181 	do {						\
182 		(t)->__bits[0] &= ~(s)->__bits[0];	\
183 		(t)->__bits[1] &= ~(s)->__bits[1];	\
184 		(t)->__bits[2] &= ~(s)->__bits[2];	\
185 		(t)->__bits[3] &= ~(s)->__bits[3];	\
186 	} while (/* CONSTCOND */ 0)
187 #endif /* _KERNEL */
188 
189 /*
190  * Signal vector "template" used in sigaction call.
191  */
192 struct	sigaction {
193 	void	(*sa_handler)		/* signal handler */
194 			    __P((int));
195 	sigset_t sa_mask;		/* signal mask to apply */
196 	int	sa_flags;		/* see signal options below */
197 };
198 
199 #if (!defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)) || \
200     (defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) || \
201     (_XOPEN_SOURCE - 0) >= 500
202 #define SA_ONSTACK	0x0001	/* take signal on signal stack */
203 #define SA_RESTART	0x0002	/* restart system on signal return */
204 #define SA_RESETHAND	0x0004	/* reset to SIG_DFL when taking signal */
205 #define SA_NODEFER	0x0010	/* don't mask the signal we're delivering */
206 #if defined(_KERNEL)
207 #define SA_SIGINFO	0x0040
208 #endif /* _KERNEL */
209 #endif /* (!_POSIX_C_SOURCE && !_XOPEN_SOURCE) || ... */
210 /* Only valid for SIGCHLD. */
211 #define SA_NOCLDSTOP	0x0008	/* do not generate SIGCHLD on child stop */
212 #define SA_NOCLDWAIT	0x0020	/* do not generate zombies on unwaited child */
213 #ifdef _KERNEL
214 #define	SA_ALLBITS	0x007f
215 #endif
216 
217 /*
218  * Flags for sigprocmask():
219  */
220 #define	SIG_BLOCK	1	/* block specified signal set */
221 #define	SIG_UNBLOCK	2	/* unblock specified signal set */
222 #define	SIG_SETMASK	3	/* set specified signal set */
223 
224 #if !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)
225 typedef	void (*sig_t) __P((int));	/* type of signal function */
226 #endif
227 
228 /*
229  * Structure used in sigaltstack call.
230  */
231 #if defined(__LIBC12_SOURCE__) || defined(_KERNEL)
232 struct sigaltstack13 {
233 	char	*ss_sp;			/* signal stack base */
234 	int	ss_size;		/* signal stack length */
235 	int	ss_flags;		/* SS_DISABLE and/or SS_ONSTACK */
236 };
237 #endif /* defined(__LIBC12_SOURCE__) || defined(_KERNEL) */
238 
239 #if (!defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)) || \
240     (defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) || \
241     (_XOPEN_SOURCE - 0) >= 500
242 typedef struct
243 #ifndef _XOPEN_SOURCE
244                sigaltstack
245 #endif /* !_XOPEN_SOURCE */
246 			   {
247 	void	*ss_sp;			/* signal stack base */
248 	size_t	ss_size;		/* signal stack length */
249 	int	ss_flags;		/* SS_DISABLE and/or SS_ONSTACK */
250 } stack_t;
251 
252 #define SS_ONSTACK	0x0001	/* take signals on alternate stack */
253 #define SS_DISABLE	0x0004	/* disable taking signals on alternate stack */
254 #ifdef _KERNEL
255 #define	SS_ALLBITS	0x0005
256 #endif
257 #define	MINSIGSTKSZ	8192			/* minimum allowable stack */
258 #define	SIGSTKSZ	(MINSIGSTKSZ + 32768)	/* recommended stack size */
259 #endif /* (!_POSIX_C_SOURCE && !_XOPEN_SOURCE) || ... */
260 
261 #if !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)
262 /*
263  * 4.3 compatibility:
264  * Signal vector "template" used in sigvec call.
265  */
266 struct	sigvec {
267 	void	(*sv_handler)		/* signal handler */
268 			    __P((int));
269 	int	sv_mask;		/* signal mask to apply */
270 	int	sv_flags;		/* see signal options below */
271 };
272 #define SV_ONSTACK	SA_ONSTACK
273 #define SV_INTERRUPT	SA_RESTART	/* same bit, opposite sense */
274 #define SV_RESETHAND	SA_RESETHAND
275 #define sv_onstack sv_flags	/* isn't compatibility wonderful! */
276 #endif /* !_POSIX_C_SOURCE && !_XOPEN_SOURCE */
277 
278 #if (!defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)) || \
279     (defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) || \
280     (_XOPEN_SOURCE - 0) >= 500
281 /*
282  * Structure used in sigstack call.
283  */
284 struct	sigstack {
285 	void	*ss_sp;			/* signal stack pointer */
286 	int	ss_onstack;		/* current status */
287 };
288 #endif /* (!_POSIX_C_SOURCE && !_XOPEN_SOURCE) || ... */
289 
290 #include <machine/signal.h>	/* sigcontext; codes for SIGILL, SIGFPE */
291 
292 #if !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE) && !defined(_KERNEL)
293 /*
294  * Macro for converting signal number to a mask suitable for
295  * sigblock().
296  */
297 #define sigmask(n)	__sigmask(n)
298 
299 #define	BADSIG		SIG_ERR
300 #endif /* !_POSIX_C_SOURCE && !_XOPEN_SOURCE */
301 
302 #endif	/* !_ANSI_SOURCE */
303 
304 /*
305  * For historical reasons; programs expect signal's return value to be
306  * defined by <sys/signal.h>.
307  */
308 __BEGIN_DECLS
309 void	(*signal __P((int, void (*) __P((int))))) __P((int));
310 __END_DECLS
311 #endif	/* !_SYS_SIGNAL_H_ */
312