signalvar.h revision 95759
1/*
2 * Copyright (c) 1991, 1993
3 *	The Regents of the University of California.  All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 *    must display the following acknowledgement:
15 *	This product includes software developed by the University of
16 *	California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 *    may be used to endorse or promote products derived from this software
19 *    without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 *	@(#)signalvar.h	8.6 (Berkeley) 2/19/95
34 * $FreeBSD: head/sys/sys/signalvar.h 95759 2002-04-30 01:54:54Z tanimura $
35 */
36
37#ifndef _SYS_SIGNALVAR_H_
38#define	_SYS_SIGNALVAR_H_
39
40#include <sys/signal.h>
41
42/*
43 * Kernel signal definitions and data structures,
44 * not exported to user programs.
45 */
46
47/*
48 * Process signal actions and state, needed only within the process
49 * (not necessarily resident).
50 */
51struct sigacts {
52	sig_t	ps_sigact[_SIG_MAXSIG];	/* disposition of signals */
53	sigset_t ps_catchmask[_SIG_MAXSIG];	/* signals to be blocked */
54	sigset_t ps_sigonstack;		/* signals to take on sigstack */
55	sigset_t ps_sigintr;		/* signals that interrupt syscalls */
56	sigset_t ps_sigreset;		/* signals that reset when caught */
57	sigset_t ps_signodefer;		/* signals not masked while handled */
58	sigset_t ps_siginfo;		/* signals that want SA_SIGINFO args */
59	sigset_t ps_osigset;		/* signals that use osigset_t */
60	sigset_t ps_usertramp;		/* SunOS compat; libc sigtramp XXX */
61};
62
63#ifdef _KERNEL
64/*
65 * Compatibility.
66 */
67typedef struct {
68	struct osigcontext si_sc;
69	int		si_signo;
70	int		si_code;
71	union sigval	si_value;
72} osiginfo_t;
73
74struct osigaction {
75	union {
76		void    (*__sa_handler)(int);
77		void    (*__sa_sigaction)(int, osiginfo_t *, void *);
78	} __sigaction_u;		/* signal handler */
79	osigset_t	sa_mask;	/* signal mask to apply */
80	int		sa_flags;	/* see signal options below */
81};
82
83typedef void __osiginfohandler_t(int, osiginfo_t *, void *);
84#endif /* _KERNEL */
85
86/* additional signal action values, used only temporarily/internally */
87#define	SIG_CATCH	((__sighandler_t *)2)
88#define SIG_HOLD        ((__sighandler_t *)3)
89
90/*
91 * get signal action for process and signal; currently only for current process
92 */
93#define SIGACTION(p, sig)	(p->p_sigacts->ps_sigact[_SIG_IDX(sig)])
94
95/*
96 * sigset_t manipulation macros
97 */
98#define SIGADDSET(set, signo)						\
99	(set).__bits[_SIG_WORD(signo)] |= _SIG_BIT(signo)
100
101#define SIGDELSET(set, signo)						\
102	(set).__bits[_SIG_WORD(signo)] &= ~_SIG_BIT(signo)
103
104#define SIGEMPTYSET(set)						\
105	do {								\
106		int __i;						\
107		for (__i = 0; __i < _SIG_WORDS; __i++)			\
108			(set).__bits[__i] = 0;				\
109	} while (0)
110
111#define SIGFILLSET(set)							\
112	do {								\
113		int __i;						\
114		for (__i = 0; __i < _SIG_WORDS; __i++)			\
115			(set).__bits[__i] = ~0U;			\
116	} while (0)
117
118#define SIGISMEMBER(set, signo)						\
119	((set).__bits[_SIG_WORD(signo)] & _SIG_BIT(signo))
120
121#define SIGISEMPTY(set)		__sigisempty(&(set))
122#define SIGNOTEMPTY(set)	(!__sigisempty(&(set)))
123
124#define SIGSETEQ(set1, set2)	__sigseteq(&(set1), &(set2))
125#define SIGSETNEQ(set1, set2)	(!__sigseteq(&(set1), &(set2)))
126
127#define SIGSETOR(set1, set2)						\
128	do {								\
129		int __i;						\
130		for (__i = 0; __i < _SIG_WORDS; __i++)			\
131			(set1).__bits[__i] |= (set2).__bits[__i];	\
132	} while (0)
133
134#define SIGSETAND(set1, set2)						\
135	do {								\
136		int __i;						\
137		for (__i = 0; __i < _SIG_WORDS; __i++)			\
138			(set1).__bits[__i] &= (set2).__bits[__i];	\
139	} while (0)
140
141#define SIGSETNAND(set1, set2)						\
142	do {								\
143		int __i;						\
144		for (__i = 0; __i < _SIG_WORDS; __i++)			\
145			(set1).__bits[__i] &= ~(set2).__bits[__i];	\
146	} while (0)
147
148#define SIGSETLO(set1, set2)	((set1).__bits[0] = (set2).__bits[0])
149#define SIGSETOLD(set, oset)	((set).__bits[0] = (oset))
150
151#define SIG_CANTMASK(set)						\
152	SIGDELSET(set, SIGKILL), SIGDELSET(set, SIGSTOP)
153
154#define SIG_STOPSIGMASK(set)						\
155	SIGDELSET(set, SIGSTOP), SIGDELSET(set, SIGTSTP),		\
156	SIGDELSET(set, SIGTTIN), SIGDELSET(set, SIGTTOU)
157
158#define SIG_CONTSIGMASK(set)						\
159	SIGDELSET(set, SIGCONT)
160
161#define sigcantmask	(sigmask(SIGKILL) | sigmask(SIGSTOP))
162
163#define SIG2OSIG(sig, osig)	osig = (sig).__bits[0]
164#define OSIG2SIG(osig, sig)	SIGEMPTYSET(sig); (sig).__bits[0] = osig
165
166static __inline int
167__sigisempty(sigset_t *set)
168{
169	int i;
170
171	for (i = 0; i < _SIG_WORDS; i++) {
172		if (set->__bits[i])
173			return (0);
174	}
175	return (1);
176}
177
178static __inline int
179__sigseteq(sigset_t *set1, sigset_t *set2)
180{
181	int i;
182
183	for (i = 0; i < _SIG_WORDS; i++) {
184		if (set1->__bits[i] != set2->__bits[i])
185			return (0);
186	}
187	return (1);
188}
189
190#ifdef _KERNEL
191
192/* Return nonzero if process p has an unmasked pending signal. */
193#define	SIGPENDING(p)							\
194	(!SIGISEMPTY((p)->p_siglist) &&					\
195	    (!sigsetmasked(&(p)->p_siglist, &(p)->p_sigmask) ||		\
196	    (p)->p_flag & P_TRACED))
197
198/*
199 * Return the value of the pseudo-expression ((*set & ~*mask) != 0).  This
200 * is an optimized version of SIGISEMPTY() on a temporary variable
201 * containing SIGSETNAND(*set, *mask).
202 */
203static __inline int
204sigsetmasked(sigset_t *set, sigset_t *mask)
205{
206	int i;
207
208	for (i = 0; i < _SIG_WORDS; i++) {
209		if (set->__bits[i] & ~mask->__bits[i])
210			return (0);
211	}
212	return (1);
213}
214
215struct pgrp;
216struct thread;
217struct proc;
218struct sigio;
219struct sx;
220
221extern int sugid_coredump;	/* Sysctl variable kern.sugid_coredump */
222extern struct sx	sigio_lock;
223
224/*
225 * Lock the pointers for a sigio object in the underlying objects of
226 * a file descriptor.
227 */
228#define SIGIO_SLOCK()	sx_slock(&sigio_lock)
229#define SIGIO_XLOCK()	sx_xlock(&sigio_lock)
230#define SIGIO_SUNLOCK()	sx_sunlock(&sigio_lock)
231#define SIGIO_XUNLOCK()	sx_xunlock(&sigio_lock)
232#define SIGIO_ASSERT(what)	sx_assert(&sigio_lock, what)
233
234/*
235 * Machine-independent functions:
236 */
237int	CURSIG(struct proc *p);
238void	execsigs(struct proc *p);
239void	gsignal(int pgid, int sig);
240int	issignal(struct proc *p);
241void	killproc(struct proc *p, char *why);
242void	pgsigio(struct sigio *, int signum, int checkctty);
243void	pgsignal(struct pgrp *pgrp, int sig, int checkctty);
244void	postsig(int sig);
245void	psignal(struct proc *p, int sig);
246void	sigexit(struct thread *td, int signum) __dead2;
247void	siginit(struct proc *p);
248void	signotify(struct proc *p);
249void	trapsignal(struct proc *p, int sig, u_long code);
250
251/*
252 * Machine-dependent functions:
253 */
254void	sendsig(sig_t action, int sig, sigset_t *retmask, u_long code);
255
256#endif /* _KERNEL */
257
258#endif /* !_SYS_SIGNALVAR_H_ */
259