xref: /dragonfly/sys/sys/signalvar.h (revision 64b5a8a5)
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. Neither the name of the University nor the names of its contributors
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  *	@(#)signalvar.h	8.6 (Berkeley) 2/19/95
30  * $FreeBSD: src/sys/sys/signalvar.h,v 1.34.2.1 2000/05/16 06:58:05 dillon Exp $
31  */
32 
33 #ifndef	_SYS_SIGNALVAR_H_		/* tmp for user.h */
34 #define	_SYS_SIGNALVAR_H_
35 
36 /*
37  * Don't bring in the entire bleeding include set if we aren't the kernel.
38  * Userland is not allowed to bring in sys/proc.h except under special
39  * circumstances (e.g. sys/user.h)
40  */
41 #include <sys/signal.h>
42 #ifdef _KERNEL
43 #include <sys/proc.h>
44 #include <machine/lock.h>
45 #endif
46 
47 /*
48  * Kernel signal definitions and data structures,
49  * not exported to user programs.
50  */
51 
52 /*
53  * Process signal actions and state, needed only within the process
54  * (not necessarily resident).
55  */
56 struct	sigacts {
57 	sig_t	 ps_sigact[_SIG_MAXSIG];	/* disposition of signals */
58 	sigset_t ps_catchmask[_SIG_MAXSIG];	/* signals to be blocked */
59 	struct {
60 		int	pid;
61 		int	uid;
62 	} ps_frominfo[_SIG_MAXSIG];
63 	sigset_t ps_sigignore;		/* Signals being ignored. */
64 	sigset_t ps_sigcatch;		/* Signals being caught by user. */
65 	sigset_t ps_sigonstack;		/* signals to take on sigstack */
66 	sigset_t ps_sigintr;		/* signals that interrupt syscalls */
67 	sigset_t ps_sigreset;		/* signals that reset when caught */
68 	sigset_t ps_signodefer;		/* signals not masked while handled */
69 	sigset_t ps_siginfo;		/* signals that want SA_SIGINFO args */
70 	sigset_t ps_usertramp;		/* SunOS compat; libc sigtramp XXX */
71 	unsigned int ps_refcnt;
72 	int      ps_flag;
73 };
74 
75 /* additional signal action values, used only temporarily/internally */
76 #define	SIG_CATCH	((__sighandler_t *)2)
77 #define SIG_HOLD        ((__sighandler_t *)3)
78 
79 #ifdef _KERNEL
80 
81 /*
82  * get signal action for process and signal; currently only for current process
83  */
84 #define SIGACTION(p, sig)	(p->p_sigacts->ps_sigact[_SIG_IDX(sig)])
85 
86 #endif
87 
88 /*
89  * sigset_t manipulation macros
90  */
91 #define SIGADDSET(set, signo)						\
92 	(set).__bits[_SIG_WORD(signo)] |= _SIG_BIT(signo)
93 
94 #define SIGADDSET_ATOMIC(set, signo)					\
95 	atomic_set_int(&(set).__bits[_SIG_WORD(signo)], _SIG_BIT(signo))
96 
97 #define SIGDELSET(set, signo)						\
98 	(set).__bits[_SIG_WORD(signo)] &= ~_SIG_BIT(signo)
99 
100 #define SIGDELSET_ATOMIC(set, signo)					\
101 	atomic_clear_int(&(set).__bits[_SIG_WORD(signo)], _SIG_BIT(signo))
102 
103 #define SIGEMPTYSET(set)						\
104 	do {								\
105 		int __i;						\
106 		for (__i = 0; __i < _SIG_WORDS; __i++)			\
107 			(set).__bits[__i] = 0;				\
108 	} while (0)
109 
110 #define SIGFILLSET(set)							\
111 	do {								\
112 		int __i;						\
113 		for (__i = 0; __i < _SIG_WORDS; __i++)			\
114 			(set).__bits[__i] = ~(unsigned int)0;		\
115 	} while (0)
116 
117 #define SIGISMEMBER(set, signo)						\
118 	((set).__bits[_SIG_WORD(signo)] & _SIG_BIT(signo))
119 
120 #define SIGISEMPTY(set)		__sigisempty(&(set))
121 #define SIGNOTEMPTY(set)	(!__sigisempty(&(set)))
122 
123 #define SIGSETEQ(set1, set2)	__sigseteq(&(set1), &(set2))
124 #define SIGSETNEQ(set1, set2)	(!__sigseteq(&(set1), &(set2)))
125 
126 #define SIGSETOR(set1, set2)						\
127 	do {								\
128 		int __i;						\
129 		for (__i = 0; __i < _SIG_WORDS; __i++)			\
130 			(set1).__bits[__i] |= (set2).__bits[__i];	\
131 	} while (0)
132 
133 #define SIGSETAND(set1, set2)						\
134 	do {								\
135 		int __i;						\
136 		for (__i = 0; __i < _SIG_WORDS; __i++)			\
137 			(set1).__bits[__i] &= (set2).__bits[__i];	\
138 	} while (0)
139 
140 #define SIGSETNAND(set1, set2)						\
141 	do {								\
142 		int __i;						\
143 		for (__i = 0; __i < _SIG_WORDS; __i++)			\
144 			(set1).__bits[__i] &= ~(set2).__bits[__i];	\
145 	} while (0)
146 
147 #define SIGSETOR_CANTMASK(set)						\
148 	SIGADDSET(set, SIGKILL), SIGADDSET(set, SIGSTOP)
149 
150 #define SIG_CONDBLOCKALLSIGS(set, lp)					\
151 	__sig_condblockallsigs(&(set), lp)
152 
153 #define SIG_CANTMASK(set)						\
154 	SIGDELSET(set, SIGKILL), SIGDELSET(set, SIGSTOP)
155 
156 #define SIG_STOPSIGMASK(set)						\
157 	SIGDELSET(set, SIGSTOP), SIGDELSET(set, SIGTSTP),		\
158 	SIGDELSET(set, SIGTTIN), SIGDELSET(set, SIGTTOU)
159 
160 #define SIG_STOPSIGMASK_ATOMIC(set)					\
161 	SIGDELSET_ATOMIC(set, SIGSTOP), SIGDELSET_ATOMIC(set, SIGTSTP),	\
162 	SIGDELSET_ATOMIC(set, SIGTTIN), SIGDELSET_ATOMIC(set, SIGTTOU)
163 
164 #define SIG_CONTSIGMASK(set)						\
165 	SIGDELSET(set, SIGCONT)
166 
167 #define SIG_CONTSIGMASK_ATOMIC(set)					\
168 	SIGDELSET_ATOMIC(set, SIGCONT)
169 
170 #define sigcantmask	(sigmask(SIGKILL) | sigmask(SIGSTOP))
171 
172 static __inline int
__sigisempty(sigset_t * set)173 __sigisempty(sigset_t *set)
174 {
175 	int i;
176 
177 	for (i = 0; i < _SIG_WORDS; i++) {
178 		if (set->__bits[i])
179 			return (0);
180 	}
181 	return (1);
182 }
183 
184 static __inline int
__sigseteq(sigset_t * set1,sigset_t * set2)185 __sigseteq(sigset_t *set1, sigset_t *set2)
186 {
187 	int i;
188 
189 	for (i = 0; i < _SIG_WORDS; i++) {
190 		if (set1->__bits[i] != set2->__bits[i])
191 			return (0);
192 	}
193 	return (1);
194 }
195 
196 #ifdef _KERNEL
197 
198 typedef void (*proc_func_t)(struct proc *);
199 
200 struct pgrp;
201 struct proc;
202 struct sigio;
203 
204 extern int sugid_coredump;	/* Sysctl variable kern.sugid_coredump */
205 extern sigset_t sigcantmask_mask;
206 
207 /*
208  * Machine-independent functions:
209  */
210 void	execsigs (struct proc *p);
211 void	gsignal (int pgid, int sig);
212 int	issignal (struct lwp *lp, int maytrace, int *ptokp);
213 int	iscaught (struct lwp *p);
214 void	killproc (struct proc *p, char *why);
215 void	pgsigio (struct sigio *, int signum, int checkctty);
216 void	pgsignal (struct pgrp *pgrp, int sig, int checkctty);
217 void	postsig (int sig, int ptok);
218 void	ksignal (struct proc *p, int sig);
219 void	lwpsignal (struct proc *p, struct lwp *lp, int sig);
220 void	siginit (struct proc *p);
221 void	trapsignal (struct lwp *p, int sig, u_long code);
222 
223 /*
224  * Machine-dependent functions:
225  */
226 void	sendsig (sig_t action, int sig, sigset_t *retmask, u_long code);
227 void	sigexit (struct lwp *lp, int sig) __dead2;
228 int	checkpoint_signal_handler(struct lwp *p);
229 
230 #endif	/* _KERNEL */
231 
232 #endif	/* !_SYS_SIGNALVAR_H_ */
233