xref: /illumos-gate/usr/src/ucbhead/sys/signal.h (revision bdf0047c)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 /*
31  * University Copyright- Copyright (c) 1982, 1986, 1988
32  * The Regents of the University of California
33  * All Rights Reserved
34  *
35  * University Acknowledgment- Portions of this document are derived from
36  * software developed by the University of California, Berkeley, and its
37  * contributors.
38  */
39 
40 #ifndef _UCB_SYS_SIGNAL_H
41 #define	_UCB_SYS_SIGNAL_H
42 
43 /*
44  * 4.3BSD signal compatibility header
45  *
46  * this file includes all standard SVR4 header info, plus the 4.3BSD
47  * structures  - 4.3BSD signal codes are translated to SVR4 generic
48  * signal codes where applicable
49  */
50 
51 #ifdef	__cplusplus
52 extern "C" {
53 #endif
54 
55 /*
56  * SysV <signal.h>
57  */
58 
59 /* ---- <signal.h> ---- */
60 
61 /*	Copyright (c) 1988 AT&T	*/
62 /*	  All Rights Reserved  	*/
63 
64 
65 #ifndef _SIGNAL_H
66 #define	_SIGNAL_H
67 
68 /* ---- <sys/signal.h> ---- */
69 
70 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
71 /*	  All Rights Reserved  	*/
72 
73 
74 #ifndef _SYS_SIGNAL_H
75 #define	_SYS_SIGNAL_H
76 
77 #define	SIGHUP	1	/* hangup */
78 #define	SIGINT	2	/* interrupt (rubout) */
79 #define	SIGQUIT	3	/* quit (ASCII FS) */
80 #define	SIGILL	4	/* illegal instruction (not reset when caught) */
81 #define	SIGTRAP	5	/* trace trap (not reset when caught) */
82 #define	SIGIOT	6	/* IOT instruction */
83 #define	SIGABRT 6	/* used by abort, replace SIGIOT in the future */
84 #define	SIGEMT	7	/* EMT instruction */
85 #define	SIGFPE	8	/* floating point exception */
86 #define	SIGKILL	9	/* kill (cannot be caught or ignored) */
87 #define	SIGBUS	10	/* bus error */
88 #define	SIGSEGV	11	/* segmentation violation */
89 #define	SIGSYS	12	/* bad argument to system call */
90 #define	SIGPIPE	13	/* write on a pipe with no one to read it */
91 #define	SIGALRM	14	/* alarm clock */
92 #define	SIGTERM	15	/* software termination signal from kill */
93 #define	SIGUSR1	16	/* user defined signal 1 */
94 #define	SIGUSR2	17	/* user defined signal 2 */
95 #define	SIGCLD	18	/* child status change */
96 #define	SIGCHLD	18	/* child status change alias (POSIX) */
97 #define	SIGPWR	19	/* power-fail restart */
98 #define	SIGWINCH 20	/* window size change */
99 #define	SIGURG	21	/* urgent socket condition */
100 #define	SIGPOLL 22	/* pollable event occured */
101 #define	SIGIO	SIGPOLL	/* socket I/O possible (SIGPOLL alias) */
102 #define	SIGSTOP 23	/* stop (cannot be caught or ignored) */
103 #define	SIGTSTP 24	/* user stop requested from tty */
104 #define	SIGCONT 25	/* stopped process has been continued */
105 #define	SIGTTIN 26	/* background tty read attempted */
106 #define	SIGTTOU 27	/* background tty write attempted */
107 #define	SIGVTALRM 28	/* virtual timer expired */
108 #define	SIGPROF 29	/* profiling timer expired */
109 #define	SIGXCPU 30	/* exceeded cpu limit */
110 #define	SIGXFSZ 31	/* exceeded file size limit */
111 #define	SIGWAITING 32	/* process's lwps are blocked */
112 #define	SIGLWP	33	/* special signal used by thread library */
113 
114 #if	defined(__cplusplus)
115 
116 typedef	void SIG_FUNC_TYP(int);
117 typedef	SIG_FUNC_TYP *SIG_TYP;
118 #define	SIG_PF SIG_TYP
119 
120 #define	SIG_DFL	(SIG_PF)0
121 #define	SIG_ERR (SIG_PF)-1
122 #define	SIG_IGN	(SIG_PF)1
123 #define	SIG_HOLD (SIG_PF)2
124 
125 #elif	defined(lint)
126 
127 #define	SIG_DFL	(void(*)(int))0
128 #define	SIG_ERR (void(*)(int))0
129 #define	SIG_IGN	(void (*)(int))0
130 #define	SIG_HOLD (void(*)(int))0
131 
132 #else
133 
134 #define	SIG_DFL	(void(*)())0
135 #define	SIG_ERR	(void(*)())-1
136 #define	SIG_IGN	(void (*)())1
137 #define	SIG_HOLD (void(*)())2
138 
139 #endif
140 
141 #define	SIG_BLOCK	1
142 #define	SIG_UNBLOCK	2
143 #define	SIG_SETMASK	3
144 
145 #define	SIGNO_MASK	0xFF
146 #define	SIGDEFER	0x100
147 #define	SIGHOLD		0x200
148 #define	SIGRELSE	0x400
149 #define	SIGIGNORE	0x800
150 #define	SIGPAUSE	0x1000
151 
152 #if !defined(_STRICT_STDC) || defined(_POSIX_SOURCE)
153 
154 #ifndef	_SIGSET_T
155 #define	_SIGSET_T
156 typedef struct {		/* signal set type */
157 	unsigned int	__sigbits[4];
158 } sigset_t;
159 #endif	/* _SIGSET_T */
160 
161 struct sigaction {
162 	int sa_flags;
163 #if defined(__cplusplus)
164 	void (*sa_handler)(int);
165 #else
166 	void (*sa_handler)();
167 #endif
168 	sigset_t sa_mask;
169 	int sa_resv[2];
170 };
171 
172 /* this is only valid for SIGCLD */
173 #define	SA_NOCLDSTOP	0x00020000	/* don't send job control SIGCLD's */
174 #endif
175 
176 #if !defined(_STRICT_STDC) && !defined(_POSIX_SOURCE)
177 			/* non-comformant ANSI compilation	*/
178 
179 /* definitions for the sa_flags field */
180 #define	SA_ONSTACK	0x00000001
181 #define	SA_RESETHAND	0x00000002
182 #define	SA_RESTART	0x00000004
183 #define	SA_SIGINFO	0x00000008
184 #define	SA_NODEFER	0x00000010
185 
186 /* this is only valid for SIGCLD */
187 #define	SA_NOCLDWAIT	0x00010000	/* don't save zombie children	 */
188 
189 #define	NSIG	34	/* valid signals range from 1 to NSIG-1 */
190 #define	MAXSIG	33	/* size of u_signal[], NSIG-1 <= MAXSIG */
191 
192 #define	MINSIGSTKSZ	2048
193 #define	SIGSTKSZ	8192
194 
195 #define	SS_ONSTACK	0x00000001
196 #define	SS_DISABLE	0x00000002
197 
198 struct sigaltstack {
199 	char	*ss_sp;
200 	int	ss_size;
201 	int	ss_flags;
202 };
203 
204 typedef struct sigaltstack stack_t;
205 
206 #endif /* __STDC__ && !POSIX */
207 
208 
209 #endif /* _SYS_SIGNAL_H */
210 
211 /* ---- end of SysV <sys/signal.h> ---- */
212 
213 typedef int	sig_atomic_t;
214 
215 #if defined(__STDC__)
216 
217 extern const char *_sys_siglist[];
218 extern const int _sys_nsig;
219 
220 #ifdef __cplusplus
221 extern "C" SIG_PF signal(int, SIG_PF);
222 #else
223 extern void (*signal(int, void (*)(int)))(int);
224 #endif
225 extern int raise(int);
226 
227 #if !defined(_STRICT_STDC) || defined(_POSIX_SOURCE) || \
228 	defined(_XOPEN_SOURCE)
229 extern int kill(pid_t, int);
230 extern int sigaction(int, const struct sigaction *, struct sigaction *);
231 extern int sigaddset(sigset_t *, int);
232 extern int sigdelset(sigset_t *, int);
233 extern int sigemptyset(sigset_t *);
234 extern int sigfillset(sigset_t *);
235 extern int sigismember(const sigset_t *, int);
236 extern int sigpending(sigset_t *);
237 extern int sigprocmask(int, const sigset_t *, sigset_t *);
238 extern int sigsuspend(const sigset_t *);
239 #endif
240 
241 #if !defined(_STRICT_STDC) && !defined(_POSIX_SOURCE)
242 extern int gsignal(int);
243 extern void (*sigset(int, void (*)(int)))(int);
244 extern int sighold(int);
245 extern int sigrelse(int);
246 extern int sigignore(int);
247 extern int sigpause(int);
248 extern int (*ssignal(int, int (*)(int)))(int);
249 extern int sigaltstack(const stack_t *, stack_t *);
250 /* extern int sigsend(idtype_t, id_t, int); */
251 /* extern int sigsendset(const procset_t *, int); */
252 #endif
253 
254 #else
255 
256 extern char *_sys_siglist[];
257 extern int _sys_nsig;
258 
259 extern	void(*signal())();
260 extern  void(*sigset())();
261 
262 #endif	/* __STDC__ */
263 
264 #endif	/* _SIGNAL_H */
265 /* ---- end of SysV <signal.h> ---- */
266 
267 #define	sigmask(m)	(m > 32 ? 0 : (1 << ((m)-1)))
268 
269 /*
270  * 4.3BSD structure used in sigstack call.
271  */
272 
273 struct  sigstack {
274 	char	*ss_sp;			/* signal stack pointer */
275 	int	ss_onstack;		/* current status */
276 };
277 
278 #define	SV_ONSTACK	0x0001  /* take signal on signal stack */
279 #define	SV_INTERRUPT    0x0002  /* do not restart system on signal return */
280 #define	SV_RESETHAND    0x0004  /* reset handler to SIG_DFL when signal taken */
281 
282 #define	sv_onstack sv_flags
283 
284 struct  sigcontext {
285 	int	sc_onstack;		/* sigstack state to restore */
286 	int	sc_mask;		/* signal mask to restore */
287 #ifdef u3b2
288 	int	sc_sp;			/* sp to restore */
289 	int	sc_fp;			/* fp to restore */
290 	int	sc_ap;			/* ap to restore */
291 	int	sc_pc;			/* pc to restore */
292 	int	sc_ps;			/* psw to restore */
293 #endif
294 #ifdef vax
295 	int	sc_sp;			/* sp to restore */
296 	int	sc_fp;			/* fp to restore */
297 	int	sc_ap;			/* ap to restore */
298 	int	sc_pc;			/* pc to restore */
299 	int	sc_ps;			/* psl to restore */
300 #endif /* vax */
301 #ifdef mc68000
302 	int	sc_sp;			/* sp to restore */
303 	int	sc_pc;			/* pc to retore */
304 	int	sc_ps;			/* psl to restore */
305 #endif /* mc68000 */
306 #ifdef __sparc
307 #define	MAXWINDOW	31		/* max usable windows in sparc */
308 	long	sc_sp;			/* sp to restore */
309 	long	sc_pc;			/* pc to retore */
310 	long	sc_npc;			/* next pc to restore */
311 	long	sc_psr;			/* psr to restore */
312 					/* aliased to REG_CCR for sparcv9 */
313 	long	sc_g1;			/* register that must be restored */
314 	long	sc_o0;
315 	int	sc_wbcnt;		/* number of outstanding windows */
316 	char	*sc_spbuf[MAXWINDOW];	/* sp's for each wbuf */
317 	long	sc_wbuf[MAXWINDOW][16];	/* outstanding window save buffer */
318 #endif /* __sparc */
319 #if defined(__amd64)
320 	long	sc_sp;			/* sp to restore */
321 	long	sc_pc;			/* pc to retore */
322 	long	sc_ps;			/* psl to restore */
323 	long	sc_rax;			/* rax to restore */
324 	long	sc_rdx;			/* rdx to restore */
325 #define	sc_r0	sc_rax
326 #define	sc_r1	sc_rdx
327 #elif defined(__i386)
328 	int	sc_sp;			/* sp to restore */
329 	int	sc_pc;			/* pc to retore */
330 	int	sc_ps;			/* psl to restore */
331 	int	sc_eax;			/* eax to restore */
332 	int	sc_edx;			/* edx to restore */
333 #define	sc_r0	sc_eax
334 #define	sc_r1	sc_edx
335 #endif
336 };
337 
338 /*
339  * 4.3BSD signal vector structure used in sigvec call.
340  */
341 struct  sigvec {
342 #if defined(__cplusplus)
343 	void	(*sv_handler)(int, int, struct sigcontext *, char *);
344 #else
345 	void	(*sv_handler)();	/* signal handler */
346 #endif
347 	int	sv_mask;		/* signal mask to apply */
348 	int	sv_flags;		/* see signal options below */
349 };
350 
351 #if defined(__STDC__)
352 extern int sigvec(int, struct sigvec *, struct sigvec *);
353 extern int sigblock(int);
354 extern int sigsetmask(int);
355 #endif
356 
357 /*
358  * Signal codes taken verbatim from SunOS4.1
359  */
360 #ifdef	vax
361 #define	    ILL_RESAD_FAULT	0x0	/* reserved addressing fault */
362 #define	    ILL_PRIVIN_FAULT	0x1	/* privileged instruction fault */
363 #define	    ILL_RESOP_FAULT	0x2	/* reserved operand fault */
364 #endif	/* vax */
365 #ifdef	mc68000
366 #define	    ILL_ILLINSTR_FAULT	0x10	/* illegal instruction fault */
367 #define	    ILL_PRIVVIO_FAULT	0x20	/* privilege violation fault */
368 #define	    ILL_COPROCERR_FAULT	0x34	/* [coprocessor protocol error fault] */
369 #define	    ILL_TRAP1_FAULT	0x84	/* trap #1 fault */
370 #define	    ILL_TRAP2_FAULT	0x88	/* trap #2 fault */
371 #define	    ILL_TRAP3_FAULT	0x8c	/* trap #3 fault */
372 #define	    ILL_TRAP4_FAULT	0x90	/* trap #4 fault */
373 #define	    ILL_TRAP5_FAULT	0x94	/* trap #5 fault */
374 #define	    ILL_TRAP6_FAULT	0x98	/* trap #6 fault */
375 #define	    ILL_TRAP7_FAULT	0x9c	/* trap #7 fault */
376 #define	    ILL_TRAP8_FAULT	0xa0	/* trap #8 fault */
377 #define	    ILL_TRAP9_FAULT	0xa4	/* trap #9 fault */
378 #define	    ILL_TRAP10_FAULT	0xa8	/* trap #10 fault */
379 #define	    ILL_TRAP11_FAULT	0xac	/* trap #11 fault */
380 #define	    ILL_TRAP12_FAULT	0xb0	/* trap #12 fault */
381 #define	    ILL_TRAP13_FAULT	0xb4	/* trap #13 fault */
382 #define	    ILL_TRAP14_FAULT	0xb8	/* trap #14 fault */
383 #endif	/* mc68000 */
384 #ifdef	sparc
385 #define	    ILL_STACK		0x00	/* bad stack */
386 #define	    ILL_ILLINSTR_FAULT	0x02	/* illegal instruction fault */
387 #define	    ILL_PRIVINSTR_FAULT	0x03	/* privileged instruction fault */
388 /* codes from 0x80 to 0xff are software traps */
389 #define	    ILL_TRAP_FAULT(n)	((n)+0x80) /* trap n fault */
390 #endif	/* sparc */
391 #if defined(__i386) || defined(__amd64)
392 #define	    ILL_ILLINSTR_FAULT	0x02	/* illegal instruction fault */
393 #endif
394 
395 #ifdef	mc68000
396 #define	    EMT_EMU1010		0x28	/* line 1010 emulator trap */
397 #define	    EMT_EMU1111		0x2c	/* line 1111 emulator trap */
398 #endif	/* mc68000 */
399 #ifdef	sparc
400 #define	    EMT_TAG		0x0a	/* tag overflow */
401 #endif	/* sparc */
402 
403 #ifdef	vax
404 #define	    FPE_INTOVF_TRAP	0x1	/* integer overflow */
405 #define	    FPE_INTDIV_TRAP	0x2	/* integer divide by zero */
406 #define	    FPE_FLTOVF_TRAP	0x3	/* floating overflow */
407 #define	    FPE_FLTDIV_TRAP	0x4	/* floating/decimal divide by zero */
408 #define	    FPE_FLTUND_TRAP	0x5	/* floating underflow */
409 #define	    FPE_DECOVF_TRAP	0x6	/* decimal overflow */
410 #define	    FPE_SUBRNG_TRAP	0x7	/* subscript out of range */
411 #define	    FPE_FLTOVF_FAULT	0x8	/* floating overflow fault */
412 #define	    FPE_FLTDIV_FAULT	0x9	/* divide by zero floating fault */
413 #define	    FPE_FLTUND_FAULT	0xa	/* floating underflow fault */
414 #endif	/* vax */
415 #ifdef	mc68000
416 #define	    FPE_INTDIV_TRAP	0x14	/* integer divide by zero */
417 #define	    FPE_CHKINST_TRAP	0x18	/* CHK [CHK2] instruction */
418 #define	    FPE_TRAPV_TRAP	0x1c	/* TRAPV [cpTRAPcc TRAPcc] instr */
419 #define	    FPE_FLTBSUN_TRAP	0xc0	/* [branch or set on unordered cond] */
420 #define	    FPE_FLTINEX_TRAP	0xc4	/* [floating inexact result] */
421 #define	    FPE_FLTDIV_TRAP	0xc8	/* [floating divide by zero] */
422 #define	    FPE_FLTUND_TRAP	0xcc	/* [floating underflow] */
423 #define	    FPE_FLTOPERR_TRAP	0xd0	/* [floating operand error] */
424 #define	    FPE_FLTOVF_TRAP	0xd4	/* [floating overflow] */
425 #define	    FPE_FLTNAN_TRAP	0xd8	/* [floating Not-A-Number] */
426 #ifdef	sun
427 #define	    FPE_FPA_ENABLE	0x400	/* [FPA not enabled] */
428 #define	    FPE_FPA_ERROR	0x404	/* [FPA arithmetic exception] */
429 #endif	/* sun */
430 #endif	/* mc68000 */
431 #ifdef	sparc
432 #define	    FPE_INTOVF_TRAP	0x1	/* integer overflow */
433 #define	    FPE_STARTSIG_TRAP	0x2	/* process using fp */
434 #define	    FPE_INTDIV_TRAP	0x14	/* integer divide by zero */
435 #define	    FPE_FLTINEX_TRAP	0xc4	/* [floating inexact result] */
436 #define	    FPE_FLTDIV_TRAP	0xc8	/* [floating divide by zero] */
437 #define	    FPE_FLTUND_TRAP	0xcc	/* [floating underflow] */
438 #define	    FPE_FLTOPERR_TRAP	0xd0	/* [floating operand error] */
439 #define	    FPE_FLTOVF_TRAP	0xd4	/* [floating overflow] */
440 #endif	/* sparc */
441 
442 /*
443  * The codes for SIGBUS and SIGSEGV are described in <vm/faultcode.h>
444  * These are the same between SunOS4.1 and SunOS5.0
445  */
446 
447 #include <vm/faultcode.h>
448 
449 #define	    BUS_HWERR	FC_HWERR	/* misc hardware error (e.g. timeout) */
450 #define	    BUS_ALIGN	FC_ALIGN	/* hardware alignment error */
451 #ifdef	BUS_OBJERR	/* namespace conflict with SysV */
452 #undef	BUS_OBJERR
453 #endif
454 #define	    BUS_OBJERR	FC_OBJERR	/* object returned errno value */
455 /*
456  * The BUS_CODE(code) will be one of the above.  In the BUS_OBJERR case,
457  * doing a BUS_ERRNO(code) gives an errno value reported by the underlying
458  * file object mapped at the fault address.  Note that this appears to be
459  * duplicated with the segmentation fault case below -- unfortunate, since
460  * the specification has always claimed that such errors produce SIGBUS.
461  * The segmentation cases are left defined as a transition aid.
462  */
463 #define	    BUS_CODE(C)		FC_CODE(C)
464 #define	    BUS_ERRNO(C)	FC_ERRNO(C)
465 
466 #define	    SEGV_NOMAP	FC_NOMAP	/* no mapping at the fault address */
467 #define	    SEGV_PROT	FC_PROT		/* access exceeded protections */
468 #define	    SEGV_OBJERR	FC_OBJERR	/* object returned errno value */
469 /*
470  * The SEGV_CODE(code) will be SEGV_NOMAP, SEGV_PROT, or SEGV_OBJERR.
471  * In the SEGV_OBJERR case, doing a SEGV_ERRNO(code) gives an errno value
472  * reported by the underlying file object mapped at the fault address.
473  */
474 #define	    SEGV_CODE(C)	FC_CODE(C)
475 #define	    SEGV_ERRNO(C)	FC_ERRNO(C)
476 #define	    SEGV_MAKE_ERR(e)	FC_MAKE_ERR(e)
477 
478 #define	SIG_NOADDR	((char *)~0)
479 
480 #if defined(lint)
481 #define	BADSIG (void(*)())0
482 #else
483 #define	BADSIG (void(*)())-1
484 #endif
485 
486 #ifdef	__cplusplus
487 }
488 #endif
489 
490 #endif /* _UCB_SYS_SIGNAL_H */
491