signalvar.h revision 51791
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 51791 1999-09-29 15:03:48Z marcel $
35 */
36
37#ifndef	_SYS_SIGNALVAR_H_		/* tmp for user.h */
38#define	_SYS_SIGNALVAR_H_
39
40#include <sys/signal.h>
41#include <sys/proc.h>
42
43/*
44 * Kernel signal definitions and data structures,
45 * not exported to user programs.
46 */
47int	__sigisempty	__P((sigset_t *set));
48int	__sigseteq	__P((sigset_t *set1, sigset_t *set2));
49
50/*
51 * Process signal actions and state, needed only within the process
52 * (not necessarily resident).
53 */
54struct	sigacts {
55	sig_t	ps_sigact[_SIG_MAXSIG];	/* disposition of signals */
56	sigset_t ps_catchmask[_SIG_MAXSIG];	/* signals to be blocked */
57	sigset_t ps_sigonstack;		/* signals to take on sigstack */
58	sigset_t ps_sigintr;		/* signals that interrupt syscalls */
59	sigset_t ps_sigreset;		/* signals that reset when caught */
60	sigset_t ps_signodefer;		/* signals not masked while handled */
61	sigset_t ps_siginfo;		/* signals that want SA_SIGINFO args */
62	int	ps_flags;		/* signal flags, below */
63	stack_t	ps_sigstk;		/* sp & on stack state variable */
64	sigset_t ps_usertramp;		/* SunOS compat; libc sigtramp XXX */
65};
66
67/* signal flags */
68#define	SAS_OLDMASK	0x01		/* need to restore mask before pause */
69#define	SAS_ALTSTACK	0x02		/* have alternate signal stack */
70
71/*
72 * Compatibility
73 */
74typedef struct {
75	struct osigcontext si_sc;
76	int		si_signo;
77	int		si_code;
78	union sigval	si_value;
79} osiginfo_t;
80
81struct	osigaction {
82	union {
83		void    (*__sa_handler) __P((int));
84		void    (*__sa_sigaction) __P((int, osiginfo_t *, void *));
85	} __sigaction_u;		/* signal handler */
86	osigset_t	sa_mask;	/* signal mask to apply */
87	int		sa_flags;	/* see signal options below */
88};
89
90typedef void __osiginfohandler_t __P((int, osiginfo_t *, void *));
91
92/*
93 * additional signal action values, used only temporarily/internally
94 * NOTE: SIG_HOLD was previously internal only, but has been moved to
95 *       sys/signal.h
96 */
97#define	SIG_CATCH	((__sighandler_t *)3)
98
99/*
100 * get signal action for process and signal; currently only for current process
101 */
102#define SIGACTION(p, sig)	(p->p_sigacts->ps_sigact[_SIG_IDX(sig)])
103
104/*
105 * sigset_t manipulation macros
106 */
107#define SIGADDSET(set, signo)						\
108	(set).__bits[_SIG_WORD(signo)] |= _SIG_BIT(signo)
109
110#define SIGDELSET(set, signo)						\
111	(set).__bits[_SIG_WORD(signo)] &= ~_SIG_BIT(signo)
112
113#define SIGEMPTYSET(set)						\
114	do {								\
115		int __i;						\
116		for (__i = 0; __i < _SIG_WORDS; __i++)			\
117			(set).__bits[__i] = 0;				\
118	} while (0)
119
120#define SIGFILLSET(set)							\
121	do {								\
122		int __i;						\
123		for (__i = 0; __i < _SIG_WORDS; __i++)			\
124			(set).__bits[__i] = ~(unsigned int)0;		\
125	} while (0)
126
127#define SIGISMEMBER(set, signo)						\
128	((set).__bits[_SIG_WORD(signo)] & _SIG_BIT(signo))
129
130#define SIGISEMPTY(set)		__sigisempty(&(set))
131#define SIGNOTEMPTY(set)	(!__sigisempty(&(set)))
132
133#define SIGSETEQ(set1, set2)	__sigseteq(&(set1), &(set2))
134#define SIGSETNEQ(set1, set2)	(!__sigseteq(&(set1), &(set2)))
135
136#define SIGSETOR(set1, set2)						\
137	do {								\
138		int __i;						\
139		for (__i = 0; __i < _SIG_WORDS; __i++)			\
140			(set1).__bits[__i] |= (set2).__bits[__i];	\
141	} while (0)
142
143#define SIGSETAND(set1, set2)						\
144	do {								\
145		int __i;						\
146		for (__i = 0; __i < _SIG_WORDS; __i++)			\
147			(set1).__bits[__i] &= (set2).__bits[__i];	\
148	} while (0)
149
150#define SIGSETNAND(set1, set2)						\
151	do {								\
152		int __i;						\
153		for (__i = 0; __i < _SIG_WORDS; __i++)			\
154			(set1).__bits[__i] &= ~(set2).__bits[__i];	\
155	} while (0)
156
157#define SIG_CANTMASK(set)						\
158	SIGDELSET(set, SIGKILL), SIGDELSET(set, SIGSTOP)
159
160#define SIG_STOPSIGMASK(set)						\
161	SIGDELSET(set, SIGSTOP), SIGDELSET(set, SIGTSTP),		\
162	SIGDELSET(set, SIGTTIN), SIGDELSET(set, SIGTTOU)
163
164#define SIG_CONTSIGMASK(set)						\
165	SIGDELSET(set, SIGCONT)
166
167#define sigcantmask	(sigmask(SIGKILL) | sigmask(SIGSTOP))
168
169#define SIG2OSIG(sig, osig)	osig = (sig).__bits[0]
170#define OSIG2SIG(osig, sig)	SIGEMPTYSET(sig); (sig).__bits[0] = osig
171
172extern __inline int __sigisempty(sigset_t *set)
173{
174	int i;
175
176	for (i = 0; i < _SIG_WORDS; i++) {
177		if (set->__bits[i])
178			return (0);
179	}
180	return (1);
181}
182
183extern __inline int __sigseteq(sigset_t *set1, sigset_t *set2)
184{
185	int i;
186
187	for (i = 0; i < _SIG_WORDS; i++) {
188		if (set1->__bits[i] != set2->__bits[i])
189			return (0);
190	}
191	return (1);
192}
193
194#ifdef KERNEL
195
196struct pgrp;
197struct proc;
198struct sigio;
199
200extern int sugid_coredump;	/* Sysctl variable kern.sugid_coredump */
201
202/*
203 * Machine-independent functions:
204 */
205void	execsigs __P((struct proc *p));
206void	gsignal __P((int pgid, int sig));
207int	issignal __P((struct proc *p));
208void	killproc __P((struct proc *p, char *why));
209void	pgsigio __P((struct sigio *, int signum, int checkctty));
210void	pgsignal __P((struct pgrp *pgrp, int sig, int checkctty));
211void	postsig __P((int sig));
212void	psignal __P((struct proc *p, int sig));
213void	sigexit __P((struct proc *p, int signum));
214void	siginit __P((struct proc *p));
215void	trapsignal __P((struct proc *p, int sig, u_long code));
216void	check_sigacts __P((void));
217int	__sig_ffs __P((sigset_t *set));
218int	__cursig __P((struct proc *p));
219
220/*
221 * Machine-dependent functions:
222 */
223void	sendsig __P((sig_t action, int sig, sigset_t *retmask, u_long code));
224int	md_sigreturn __P((struct proc *p, void *sigcntxp, sigset_t *mask));
225
226/*
227 * Inline functions:
228 */
229#define	CURSIG(p)	__cursig(p)
230
231/*
232 * Determine signal that should be delivered to process p, the current
233 * process, 0 if none.  If there is a pending stop signal with default
234 * action, the process stops in issignal().
235 */
236extern __inline int __cursig(struct proc *p)
237{
238	sigset_t tmpset;
239
240	tmpset = p->p_siglist;
241	SIGSETNAND(tmpset, p->p_sigmask);
242	return ((SIGISEMPTY(p->p_siglist) ||
243		 (!(p->p_flag & P_TRACED) && SIGISEMPTY(tmpset)))
244		? 0 : issignal(p));
245}
246
247#endif	/* KERNEL */
248
249#endif	/* !_SYS_SIGNALVAR_H_ */
250