signalvar.h revision 43208
1221167Sgnn/*
2221167Sgnn * Copyright (c) 1991, 1993
3221167Sgnn *	The Regents of the University of California.  All rights reserved.
4221167Sgnn *
5221167Sgnn * Redistribution and use in source and binary forms, with or without
6221167Sgnn * modification, are permitted provided that the following conditions
7221167Sgnn * are met:
8221167Sgnn * 1. Redistributions of source code must retain the above copyright
9221167Sgnn *    notice, this list of conditions and the following disclaimer.
10221167Sgnn * 2. Redistributions in binary form must reproduce the above copyright
11221167Sgnn *    notice, this list of conditions and the following disclaimer in the
12221167Sgnn *    documentation and/or other materials provided with the distribution.
13221167Sgnn * 3. All advertising materials mentioning features or use of this software
14221167Sgnn *    must display the following acknowledgement:
15221167Sgnn *	This product includes software developed by the University of
16221167Sgnn *	California, Berkeley and its contributors.
17221167Sgnn * 4. Neither the name of the University nor the names of its contributors
18221167Sgnn *    may be used to endorse or promote products derived from this software
19221167Sgnn *    without specific prior written permission.
20221167Sgnn *
21221167Sgnn * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22221167Sgnn * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23221167Sgnn * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24221167Sgnn * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25221167Sgnn * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26221167Sgnn * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27221167Sgnn * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28221167Sgnn * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29221167Sgnn * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30221167Sgnn * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31221167Sgnn * SUCH DAMAGE.
32221167Sgnn *
33221167Sgnn *	@(#)signalvar.h	8.6 (Berkeley) 2/19/95
34221167Sgnn * $Id: signalvar.h,v 1.22 1999/01/07 21:23:46 julian Exp $
35221167Sgnn */
36221167Sgnn
37221167Sgnn#ifndef	_SYS_SIGNALVAR_H_		/* tmp for user.h */
38221167Sgnn#define	_SYS_SIGNALVAR_H_
39221167Sgnn
40221167Sgnn#include <sys/signal.h>
41221167Sgnn
42221167Sgnn/*
43221167Sgnn * Kernel signal definitions and data structures,
44221167Sgnn * not exported to user programs.
45221167Sgnn */
46221167Sgnn
47221167Sgnn/*
48221167Sgnn * Process signal actions and state, needed only within the process
49221167Sgnn * (not necessarily resident).
50221167Sgnn */
51221167Sgnnstruct	sigacts {
52221167Sgnn	sig_t	ps_sigact[NSIG];	/* disposition of signals */
53221167Sgnn	sigset_t ps_catchmask[NSIG];	/* signals to be blocked */
54221167Sgnn	sigset_t ps_sigonstack;		/* signals to take on sigstack */
55221167Sgnn	sigset_t ps_sigintr;		/* signals that interrupt syscalls */
56221167Sgnn	sigset_t ps_sigreset;		/* signals that reset when caught */
57221167Sgnn	sigset_t ps_signodefer;		/* signals not masked while handled */
58221167Sgnn	int	ps_flags;		/* signal flags, below */
59221167Sgnn	struct	sigaltstack ps_sigstk;	/* sp & on stack state variable */
60221167Sgnn	sigset_t ps_usertramp;		/* SunOS compat; libc sigtramp XXX */
61221167Sgnn};
62221167Sgnn
63221167Sgnn/* signal flags */
64221167Sgnn#define	SAS_OLDMASK	0x01		/* need to restore mask before pause */
65221167Sgnn#define	SAS_ALTSTACK	0x02		/* have alternate signal stack */
66221167Sgnn
67221167Sgnn/* additional signal action values, used only temporarily/internally */
68221167Sgnn#define	SIG_CATCH	((__sighandler_t *)2)
69221167Sgnn#define	SIG_HOLD	((__sighandler_t *)3)
70221167Sgnn
71221167Sgnn/*
72221167Sgnn * get signal action for process and signal; currently only for current process
73221167Sgnn */
74221167Sgnn#define SIGACTION(p, sig)	(p->p_sigacts->ps_sigact[(sig)])
75221167Sgnn
76221167Sgnn/*
77221167Sgnn * Determine signal that should be delivered to process p, the current
78221167Sgnn * process, 0 if none.  If there is a pending stop signal with default
79221167Sgnn * action, the process stops in issignal().
80221167Sgnn */
81221167Sgnn#define	CURSIG(p)							\
82221167Sgnn	(((p)->p_siglist == 0 ||					\
83221167Sgnn	    (((p)->p_flag & P_TRACED) == 0 &&				\
84221167Sgnn	     ((p)->p_siglist & ~(p)->p_sigmask) == 0)) ?		\
85221167Sgnn	    0 : issignal(p))
86221167Sgnn
87221167Sgnn/*
88221167Sgnn * Clear a pending signal from a process.
89221167Sgnn */
90221167Sgnn#define	CLRSIG(p, sig)	{ (p)->p_siglist &= ~sigmask(sig); }
91221167Sgnn
92221167Sgnn/*
93221167Sgnn * Signal properties and actions.
94221167Sgnn * The array below categorizes the signals and their default actions
95221167Sgnn * according to the following properties:
96221167Sgnn */
97221167Sgnn#define	SA_KILL		0x01		/* terminates process by default */
98221167Sgnn#define	SA_CORE		0x02		/* ditto and coredumps */
99221167Sgnn#define	SA_STOP		0x04		/* suspend process */
100221167Sgnn#define	SA_TTYSTOP	0x08		/* ditto, from tty */
101221167Sgnn#define	SA_IGNORE	0x10		/* ignore by default */
102221167Sgnn#define	SA_CONT		0x20		/* continue if suspended */
103221167Sgnn#define	SA_CANTMASK	0x40		/* non-maskable, catchable */
104221167Sgnn
105221167Sgnn#ifdef	SIGPROP
106221167Sgnnstatic int sigprop[NSIG + 1] = {
107221167Sgnn	0,			/* unused */
108221167Sgnn	SA_KILL,		/* SIGHUP */
109221167Sgnn	SA_KILL,		/* SIGINT */
110221167Sgnn	SA_KILL|SA_CORE,	/* SIGQUIT */
111221167Sgnn	SA_KILL|SA_CORE,	/* SIGILL */
112221167Sgnn	SA_KILL|SA_CORE,	/* SIGTRAP */
113221167Sgnn	SA_KILL|SA_CORE,	/* SIGABRT */
114221167Sgnn	SA_KILL|SA_CORE,	/* SIGEMT */
115221167Sgnn	SA_KILL|SA_CORE,	/* SIGFPE */
116221167Sgnn	SA_KILL,		/* SIGKILL */
117221167Sgnn	SA_KILL|SA_CORE,	/* SIGBUS */
118221167Sgnn	SA_KILL|SA_CORE,	/* SIGSEGV */
119221167Sgnn	SA_KILL|SA_CORE,	/* SIGSYS */
120221167Sgnn	SA_KILL,		/* SIGPIPE */
121221167Sgnn	SA_KILL,		/* SIGALRM */
122221167Sgnn	SA_KILL,		/* SIGTERM */
123221167Sgnn	SA_IGNORE,		/* SIGURG */
124221167Sgnn	SA_STOP,		/* SIGSTOP */
125221167Sgnn	SA_STOP|SA_TTYSTOP,	/* SIGTSTP */
126221167Sgnn	SA_IGNORE|SA_CONT,	/* SIGCONT */
127221167Sgnn	SA_IGNORE,		/* SIGCHLD */
128221167Sgnn	SA_STOP|SA_TTYSTOP,	/* SIGTTIN */
129221167Sgnn	SA_STOP|SA_TTYSTOP,	/* SIGTTOU */
130221167Sgnn	SA_IGNORE,		/* SIGIO */
131221167Sgnn	SA_KILL,		/* SIGXCPU */
132221167Sgnn	SA_KILL,		/* SIGXFSZ */
133221167Sgnn	SA_KILL,		/* SIGVTALRM */
134221167Sgnn	SA_KILL,		/* SIGPROF */
135221167Sgnn	SA_IGNORE,		/* SIGWINCH  */
136221167Sgnn	SA_IGNORE,		/* SIGINFO */
137221167Sgnn	SA_KILL,		/* SIGUSR1 */
138221167Sgnn	SA_KILL,		/* SIGUSR2 */
139221167Sgnn};
140221167Sgnn
141221167Sgnn#define	contsigmask	(sigmask(SIGCONT))
142221167Sgnn#define	stopsigmask	(sigmask(SIGSTOP) | sigmask(SIGTSTP) | \
143221167Sgnn			    sigmask(SIGTTIN) | sigmask(SIGTTOU))
144221167Sgnn
145221167Sgnn#endif /* SIGPROP */
146221167Sgnn
147221167Sgnn#define	sigcantmask	(sigmask(SIGKILL) | sigmask(SIGSTOP))
148221167Sgnn
149221167Sgnn#ifdef KERNEL
150221167Sgnnstruct pgrp;
151221167Sgnnstruct proc;
152221167Sgnnstruct sigio;
153221167Sgnn
154221167Sgnnextern int sugid_coredump;	/* Sysctl variable kern.sugid_coredump */
155221167Sgnn
156221167Sgnn/*
157221167Sgnn * Machine-independent functions:
158221167Sgnn */
159221167Sgnnvoid	execsigs __P((struct proc *p));
160221167Sgnnchar	*expand_name __P((const char*, int, int));
161221167Sgnnvoid	gsignal __P((int pgid, int sig));
162221167Sgnnint	issignal __P((struct proc *p));
163221167Sgnnvoid	killproc __P((struct proc *p, char *why));
164221167Sgnnvoid	pgsigio __P((struct sigio *, int signum, int checkctty));
165221167Sgnnvoid	pgsignal __P((struct pgrp *pgrp, int sig, int checkctty));
166221167Sgnnvoid	postsig __P((int sig));
167221167Sgnnvoid	psignal __P((struct proc *p, int sig));
168221167Sgnnvoid	sigexit __P((struct proc *p, int signum));
169221167Sgnnvoid	siginit __P((struct proc *p));
170221167Sgnnvoid	trapsignal __P((struct proc *p, int sig, u_long code));
171221167Sgnnvoid check_sigacts (void);
172221167Sgnn/*
173221167Sgnn * Machine-dependent functions:
174221167Sgnn */
175221167Sgnnvoid	sendsig __P((sig_t action, int sig, int returnmask, u_long code));
176221167Sgnn#endif	/* KERNEL */
177221167Sgnn#endif	/* !_SYS_SIGNALVAR_H_ */
178221167Sgnn