signal.h revision 48621
11541Srgrimes/*
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 * 3. All advertising materials mentioning features or use of this software
191541Srgrimes *    must display the following acknowledgement:
201541Srgrimes *	This product includes software developed by the University of
211541Srgrimes *	California, Berkeley and its contributors.
221541Srgrimes * 4. Neither the name of the University nor the names of its contributors
231541Srgrimes *    may be used to endorse or promote products derived from this software
241541Srgrimes *    without specific prior written permission.
251541Srgrimes *
261541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
271541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
281541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
291541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
301541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
311541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
321541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
331541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
341541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
351541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
361541Srgrimes * SUCH DAMAGE.
371541Srgrimes *
3814486Shsu *	@(#)signal.h	8.4 (Berkeley) 5/4/95
3948621Scracauer * $Id: signal.h,v 1.14 1998/08/05 09:04:36 dfr Exp $
401541Srgrimes */
411541Srgrimes
421541Srgrimes#ifndef	_SYS_SIGNAL_H_
431541Srgrimes#define	_SYS_SIGNAL_H_
441541Srgrimes
459343Sbde#include <sys/cdefs.h>
4634925Sdufault#include <sys/_posix.h>
479343Sbde#include <machine/signal.h>	/* sig_atomic_t; trap codes; sigcontext */
489343Sbde
499343Sbde#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
501541Srgrimes#define NSIG	32		/* counting 0; could be 33 (mask is 1-32) */
511541Srgrimes#endif
521541Srgrimes
531541Srgrimes#define	SIGHUP	1	/* hangup */
541541Srgrimes#define	SIGINT	2	/* interrupt */
551541Srgrimes#define	SIGQUIT	3	/* quit */
561541Srgrimes#define	SIGILL	4	/* illegal instruction (not reset when caught) */
571541Srgrimes#ifndef _POSIX_SOURCE
581541Srgrimes#define	SIGTRAP	5	/* trace trap (not reset when caught) */
591541Srgrimes#endif
601541Srgrimes#define	SIGABRT	6	/* abort() */
611541Srgrimes#ifndef _POSIX_SOURCE
621541Srgrimes#define	SIGIOT	SIGABRT	/* compatibility */
631541Srgrimes#define	SIGEMT	7	/* EMT instruction */
641541Srgrimes#endif
651541Srgrimes#define	SIGFPE	8	/* floating point exception */
661541Srgrimes#define	SIGKILL	9	/* kill (cannot be caught or ignored) */
671541Srgrimes#ifndef _POSIX_SOURCE
681541Srgrimes#define	SIGBUS	10	/* bus error */
691541Srgrimes#endif
701541Srgrimes#define	SIGSEGV	11	/* segmentation violation */
711541Srgrimes#ifndef _POSIX_SOURCE
7213561Smpp#define	SIGSYS	12	/* non-existent system call invoked */
731541Srgrimes#endif
741541Srgrimes#define	SIGPIPE	13	/* write on a pipe with no one to read it */
751541Srgrimes#define	SIGALRM	14	/* alarm clock */
761541Srgrimes#define	SIGTERM	15	/* software termination signal from kill */
771541Srgrimes#ifndef _POSIX_SOURCE
781541Srgrimes#define	SIGURG	16	/* urgent condition on IO channel */
791541Srgrimes#endif
801541Srgrimes#define	SIGSTOP	17	/* sendable stop signal not from tty */
811541Srgrimes#define	SIGTSTP	18	/* stop signal from tty */
821541Srgrimes#define	SIGCONT	19	/* continue a stopped process */
831541Srgrimes#define	SIGCHLD	20	/* to parent on child stop or exit */
841541Srgrimes#define	SIGTTIN	21	/* to readers pgrp upon background tty read */
851541Srgrimes#define	SIGTTOU	22	/* like TTIN for output if (tp->t_local&LTOSTOP) */
861541Srgrimes#ifndef _POSIX_SOURCE
871541Srgrimes#define	SIGIO	23	/* input/output possible signal */
881541Srgrimes#define	SIGXCPU	24	/* exceeded CPU time limit */
891541Srgrimes#define	SIGXFSZ	25	/* exceeded file size limit */
901541Srgrimes#define	SIGVTALRM 26	/* virtual time alarm */
911541Srgrimes#define	SIGPROF	27	/* profiling time alarm */
921541Srgrimes#define SIGWINCH 28	/* window size changes */
931541Srgrimes#define SIGINFO	29	/* information request */
941541Srgrimes#endif
951541Srgrimes#define SIGUSR1 30	/* user defined signal 1 */
961541Srgrimes#define SIGUSR2 31	/* user defined signal 2 */
971541Srgrimes
989343Sbde/*-
999343Sbde * Type of a signal handling function.
1009343Sbde *
1019343Sbde * Language spec sez signal handlers take exactly one arg, even though we
1021541Srgrimes * actually supply three.  Ugh!
1039343Sbde *
1049343Sbde * We don't try to hide the difference by leaving out the args because
1059343Sbde * that would cause warnings about conformant programs.  Nonconformant
1069343Sbde * programs can avoid the warnings by casting to (__sighandler_t *) or
1079343Sbde * sig_t before calling signal() or assigning to sa_handler or sv_handler.
1089343Sbde *
1099343Sbde * The kernel should reverse the cast before calling the function.  It
1109343Sbde * has no way to do this, but on most machines 1-arg and 3-arg functions
1119343Sbde * have the same calling protocol so there is no problem in practice.
1129343Sbde * A bit in sa_flags could be used to specify the number of args.
1131541Srgrimes */
1149343Sbdetypedef void __sighandler_t __P((int));
1151541Srgrimes
11648621Scracauer#if defined(_P1003_1B_VISIBLE_HISTORICALLY) || \
11748621Scracauer	(!defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE))
11848621Scracauerunion sigval {
11948621Scracauer	/* Members as suggested by Annex C of POSIX 1003.1b. */
12048621Scracauer	int   sigval_int;
12148621Scracauer	void *sigval_ptr;
12248621Scracauer};
12348621Scracauer#endif /* !_ANSI_SOURCE && _P1003_1B_VISIBLE_HISTORICALLY */
12448621Scracauer
12548621Scracauer#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
12648621Scracauer/* POSIX 1003.1b required values. */
12748621Scracauer#define SI_USER       0x10001
12848621Scracauer#define SI_QUEUE      0x10002
12948621Scracauer#define SI_TIMER      0x10003
13048621Scracauer#define SI_ASYNCIO    0x10004
13148621Scracauer#define SI_MESGQ      0x10005
13248621Scracauer
13348621Scracauer/* Additional FreeBSD values. */
13448621Scracauer#define SI_UNDEFINED  0
13548621Scracauer
13648621Scracauerstruct __siginfo {
13748621Scracauer	struct sigcontext si_sc;
13848621Scracauer	int               si_signo;              /* signal number */
13948621Scracauer
14048621Scracauer	/*
14148621Scracauer	 * Cause of signal, one of the SI_ macros or signal-specific
14248621Scracauer	 * values, i.e. one of the FPE_... values for SIGFPE. This
14348621Scracauer	 * value is equivalent to the second argument to an old-style
14448621Scracauer	 * FreeBSD signal handler.
14548621Scracauer	 */
14648621Scracauer	int               si_code;
14748621Scracauer
14848621Scracauer	union sigval      si_value;
14948621Scracauer};
15048621Scracauer#else /* ! _ANSI_SOURCE && ! _POSIX_SOURCE */
15148621Scracauerstruct __siginfo;
15248621Scracauer#endif /* ! _ANSI_SOURCE && ! _POSIX_SOURCE */
15348621Scracauer
15448621Scracauertypedef struct __siginfo siginfo_t;
15548621Scracauer
15648621Scracauer#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
15748621Scracauertypedef void __siginfohandler_t __P((int, siginfo_t *, void *));
15848621Scracauer#endif /* ! _ANSI_SOURCE && ! _POSIX_SOURCE */
15948621Scracauer
1609343Sbde#define	SIG_DFL		((__sighandler_t *)0)
1619343Sbde#define	SIG_IGN		((__sighandler_t *)1)
1629343Sbde#define	SIG_ERR		((__sighandler_t *)-1)
1639343Sbde
1641541Srgrimes#ifndef _ANSI_SOURCE
1651541Srgrimestypedef unsigned int sigset_t;
1661541Srgrimes
1671541Srgrimes/*
1681541Srgrimes * Signal vector "template" used in sigaction call.
1691541Srgrimes */
1701541Srgrimesstruct	sigaction {
17148621Scracauer	union {
17248621Scracauer		void    (*__sa_handler) __P((int));
17348621Scracauer		void    (*__sa_sigaction) __P((int, siginfo_t *, void *));
17448621Scracauer	} __sigaction_u;		/* signal handler */
1751541Srgrimes	sigset_t sa_mask;		/* signal mask to apply */
1761541Srgrimes	int	sa_flags;		/* see signal options below */
1771541Srgrimes};
17848621Scracauer/* if SA_SIGINFO is set, sa_sigaction is to be used instead of sa_handler. */
17948621Scracauer#define	sa_handler	__sigaction_u.__sa_handler
1801541Srgrimes#ifndef _POSIX_SOURCE
18148621Scracauer#define	sa_sigaction	__sigaction_u.__sa_sigaction
18248621Scracauer#endif
18348621Scracauer
18448621Scracauer#ifndef _POSIX_SOURCE
1851541Srgrimes#define SA_ONSTACK	0x0001	/* take signal on signal stack */
1869343Sbde#define SA_RESTART	0x0002	/* restart system call on signal return */
18714331Speter#define	SA_RESETHAND	0x0004	/* reset to SIG_DFL when taking signal */
18814331Speter#define	SA_NODEFER	0x0010	/* don't mask the signal we're delivering */
18929340Sjoerg#define	SA_NOCLDWAIT	0x0020	/* don't keep zombies around */
19048621Scracauer#define	SA_SIGINFO	0x0040	/* signal handler with SA_SIGINFO args */
1911541Srgrimes#ifdef COMPAT_SUNOS
1921541Srgrimes#define	SA_USERTRAMP	0x0100	/* do not bounce off kernel's sigtramp */
1931541Srgrimes#endif
19414331Speter#endif	/* _POSIX_SOURCE */
1951541Srgrimes#define SA_NOCLDSTOP	0x0008	/* do not generate SIGCHLD on child stop */
1961541Srgrimes
1971541Srgrimes/*
1981541Srgrimes * Flags for sigprocmask:
1991541Srgrimes */
2001541Srgrimes#define	SIG_BLOCK	1	/* block specified signal set */
2011541Srgrimes#define	SIG_UNBLOCK	2	/* unblock specified signal set */
2021541Srgrimes#define	SIG_SETMASK	3	/* set specified signal set */
2031541Srgrimes
2041541Srgrimes#ifndef _POSIX_SOURCE
2059343Sbdetypedef	__sighandler_t	*sig_t;	/* type of pointer to a signal function */
2061541Srgrimes
20738121Sdfr#ifdef	_BSD_SIZE_T_
20838121Sdfrtypedef	_BSD_SIZE_T_	size_t;
20938121Sdfr#undef	_BSD_SIZE_T_
21038121Sdfr#endif
21138121Sdfr
2121541Srgrimes/*
2131541Srgrimes * Structure used in sigaltstack call.
2141541Srgrimes */
2151541Srgrimesstruct	sigaltstack {
2165999Sats	char	*ss_sp;			/* signal stack base */
21738121Sdfr	size_t	ss_size;		/* signal stack length */
21814331Speter	int	ss_flags;		/* SS_DISABLE and/or SS_ONSTACK */
2191541Srgrimes};
22014331Speter#define	SS_ONSTACK	0x0001	/* take signal on alternate stack */
22114331Speter#define	SS_DISABLE	0x0004	/* disable taking signals on alternate stack */
2221541Srgrimes#define	MINSIGSTKSZ	8192			/* minimum allowable stack */
2231541Srgrimes#define	SIGSTKSZ	(MINSIGSTKSZ + 32768)	/* recommended stack size */
2241541Srgrimes
2251541Srgrimes/*
2261541Srgrimes * 4.3 compatibility:
2271541Srgrimes * Signal vector "template" used in sigvec call.
2281541Srgrimes */
2291541Srgrimesstruct	sigvec {
2309343Sbde	__sighandler_t *sv_handler;	/* signal handler */
2311541Srgrimes	int	sv_mask;		/* signal mask to apply */
2321541Srgrimes	int	sv_flags;		/* see signal options below */
2331541Srgrimes};
2341541Srgrimes
2351541Srgrimes#define SV_ONSTACK	SA_ONSTACK
2361541Srgrimes#define SV_INTERRUPT	SA_RESTART	/* same bit, opposite sense */
23714331Speter#define SV_RESETHAND	SA_RESETHAND
23814927Speter#define SV_NODEFER	SA_NODEFER
23914927Speter#define SV_NOCLDSTOP	SA_NOCLDSTOP
24048621Scracauer#define SV_SIGINFO	SA_SIGINFO
2411541Srgrimes#define sv_onstack sv_flags	/* isn't compatibility wonderful! */
2421541Srgrimes
2431541Srgrimes/*
2441541Srgrimes * Structure used in sigstack call.
2451541Srgrimes */
2461541Srgrimesstruct	sigstack {
2471541Srgrimes	char	*ss_sp;			/* signal stack pointer */
2481541Srgrimes	int	ss_onstack;		/* current status */
2491541Srgrimes};
2501541Srgrimes
2511541Srgrimes/*
2521541Srgrimes * Macro for converting signal number to a mask suitable for
2531541Srgrimes * sigblock().
2541541Srgrimes */
2551541Srgrimes#define sigmask(m)	(1 << ((m)-1))
2561541Srgrimes
2571541Srgrimes#define	BADSIG		SIG_ERR
2581541Srgrimes
2591541Srgrimes#endif	/* !_POSIX_SOURCE */
2601541Srgrimes#endif	/* !_ANSI_SOURCE */
2611541Srgrimes
26248621Scracauer#if !defined(_ANSI_SOURCE) && defined(_P1003_1B_VISIBLE_HISTORICALLY)
26334925Sdufault
26434925Sdufaultstruct sigevent {
26534925Sdufault	int	sigev_notify;		/* Notification type */
26634925Sdufault	int	sigev_signo;		/* Signal number */
26734925Sdufault	union sigval sigev_value;	/* Signal value */
26834925Sdufault};
26934925Sdufault
27034925Sdufault#define	SIGEV_NONE	0		/* No async notification */
27134925Sdufault#define	SIGEV_SIGNAL	1		/* Generate a queued signal */
27234925Sdufault
27348621Scracauer#endif /* ! _ANSI_SOURCE && _P1003_1B_VISIBLE_HISTORICALLY */
27434925Sdufault
2751541Srgrimes/*
2761541Srgrimes * For historical reasons; programs expect signal's return value to be
2771541Srgrimes * defined by <sys/signal.h>.
2781541Srgrimes */
2791541Srgrimes__BEGIN_DECLS
2809343Sbde__sighandler_t *signal __P((int, __sighandler_t *));
2811541Srgrimes__END_DECLS
2829343Sbde
2831541Srgrimes#endif	/* !_SYS_SIGNAL_H_ */
284