2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
33 * @(#)signalvar.h 8.6 (Berkeley) 2/19/95
37 #ifndef _SYS_SIGNALVAR_H_ /* tmp for user.h */
38 #define _SYS_SIGNALVAR_H_
40 #include <sys/signal.h>
42 #include <machine/smp.h>
45 * Kernel signal definitions and data structures,
46 * not exported to user programs.
50 * Process signal actions and state, needed only within the process
51 * (not necessarily resident).
54 sig_t ps_sigact[_SIG_MAXSIG]; /* disposition of signals */
55 sigset_t ps_catchmask[_SIG_MAXSIG]; /* signals to be blocked */
56 sigset_t ps_sigonstack; /* signals to take on sigstack */
57 sigset_t ps_sigintr; /* signals that interrupt syscalls */
58 sigset_t ps_sigreset; /* signals that reset when caught */
59 sigset_t ps_signodefer; /* signals not masked while handled */
60 sigset_t ps_siginfo; /* signals that want SA_SIGINFO args */
61 sigset_t ps_osigset; /* signals that use osigset_t */
62 sigset_t ps_usertramp; /* SunOS compat; libc sigtramp XXX */
69 struct osigcontext si_sc;
72 union sigval si_value;
77 void (*__sa_handler) __P((int));
78 void (*__sa_sigaction) __P((int, osiginfo_t *, void *));
79 } __sigaction_u; /* signal handler */
80 osigset_t sa_mask; /* signal mask to apply */
81 int sa_flags; /* see signal options below */
84 typedef void __osiginfohandler_t __P((int, osiginfo_t *, void *));
86 /* additional signal action values, used only temporarily/internally */
87 #define SIG_CATCH ((__sighandler_t *)2)
88 #define SIG_HOLD ((__sighandler_t *)3)
91 * get signal action for process and signal; currently only for current process
93 #define SIGACTION(p, sig) (p->p_sigacts->ps_sigact[_SIG_IDX(sig)])
96 * sigset_t manipulation macros
98 #define SIGADDSET(set, signo) \
99 (set).__bits[_SIG_WORD(signo)] |= _SIG_BIT(signo)
101 #define SIGDELSET(set, signo) \
102 (set).__bits[_SIG_WORD(signo)] &= ~_SIG_BIT(signo)
104 #define SIGEMPTYSET(set) \
107 for (__i = 0; __i < _SIG_WORDS; __i++) \
108 (set).__bits[__i] = 0; \
111 #define SIGFILLSET(set) \
114 for (__i = 0; __i < _SIG_WORDS; __i++) \
115 (set).__bits[__i] = ~(unsigned int)0; \
118 #define SIGISMEMBER(set, signo) \
119 ((set).__bits[_SIG_WORD(signo)] & _SIG_BIT(signo))
121 #define SIGISEMPTY(set) __sigisempty(&(set))
122 #define SIGNOTEMPTY(set) (!__sigisempty(&(set)))
124 #define SIGSETEQ(set1, set2) __sigseteq(&(set1), &(set2))
125 #define SIGSETNEQ(set1, set2) (!__sigseteq(&(set1), &(set2)))
127 #define SIGSETOR(set1, set2) \
130 for (__i = 0; __i < _SIG_WORDS; __i++) \
131 (set1).__bits[__i] |= (set2).__bits[__i]; \
134 #define SIGSETAND(set1, set2) \
137 for (__i = 0; __i < _SIG_WORDS; __i++) \
138 (set1).__bits[__i] &= (set2).__bits[__i]; \
141 #define SIGSETNAND(set1, set2) \
144 for (__i = 0; __i < _SIG_WORDS; __i++) \
145 (set1).__bits[__i] &= ~(set2).__bits[__i]; \
148 #define SIGSETLO(set1, set2) ((set1).__bits[0] = (set2).__bits[0])
149 #define SIGSETOLD(set, oset) ((set).__bits[0] = (oset))
151 #define SIG_CANTMASK(set) \
152 SIGDELSET(set, SIGKILL), SIGDELSET(set, SIGSTOP)
154 #define SIG_STOPSIGMASK(set) \
155 SIGDELSET(set, SIGSTOP), SIGDELSET(set, SIGTSTP), \
156 SIGDELSET(set, SIGTTIN), SIGDELSET(set, SIGTTOU)
158 #define SIG_CONTSIGMASK(set) \
159 SIGDELSET(set, SIGCONT)
161 #define sigcantmask (sigmask(SIGKILL) | sigmask(SIGSTOP))
163 #define SIG2OSIG(sig, osig) osig = (sig).__bits[0]
164 #define OSIG2SIG(osig, sig) SIGEMPTYSET(sig); (sig).__bits[0] = osig
167 __sigisempty(sigset_t *set)
171 for (i = 0; i < _SIG_WORDS; i++) {
179 __sigseteq(sigset_t *set1, sigset_t *set2)
183 for (i = 0; i < _SIG_WORDS; i++) {
184 if (set1->__bits[i] != set2->__bits[i])
193 #include <sys/systm.h>
194 #include <machine/mutex.h>
200 extern int sugid_coredump; /* Sysctl variable kern.sugid_coredump */
203 * Machine-independent functions:
205 void check_sigacts __P((void));
206 void execsigs __P((struct proc *p));
207 void gsignal __P((int pgid, int sig));
208 int issignal __P((struct proc *p));
209 void killproc __P((struct proc *p, char *why));
210 void pgsigio __P((struct sigio *, int signum, int checkctty));
211 void pgsignal __P((struct pgrp *pgrp, int sig, int checkctty));
212 void postsig __P((int sig));
213 void psignal __P((struct proc *p, int sig));
214 void sigexit __P((struct proc *p, int signum));
215 void siginit __P((struct proc *p));
216 void trapsignal __P((struct proc *p, int sig, u_long code));
217 static int __cursig __P((struct proc *p));
220 * Machine-dependent functions:
222 void sendsig __P((sig_t action, int sig, sigset_t *retmask, u_long code));
227 #define CURSIG(p) __cursig(p)
230 * Determine signal that should be delivered to process p, the current
231 * process, 0 if none. If there is a pending stop signal with default
232 * action, the process stops in issignal().
236 static __inline int __cursig(struct proc *p)
241 tmpset = p->p_siglist;
242 SIGSETNAND(tmpset, p->p_sigmask);
243 if (SIGISEMPTY(p->p_siglist) ||
244 (!(p->p_flag & P_TRACED) && SIGISEMPTY(tmpset))) {
247 mtx_enter(&Giant, MTX_DEF);
249 mtx_exit(&Giant, MTX_DEF);
255 #endif /* !_SYS_SIGNALVAR_H_ */