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 * 4. 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.
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
29 * @(#)signalvar.h 8.6 (Berkeley) 2/19/95
33 #ifndef _SYS_SIGNALVAR_H_
34 #define _SYS_SIGNALVAR_H_
36 #include <sys/queue.h>
37 #include <sys/_lock.h>
38 #include <sys/_mutex.h>
39 #include <sys/signal.h>
42 * Kernel signal definitions and data structures,
43 * not exported to user programs.
47 * Logical process signal actions and state, needed only within the process
48 * The mapping between sigacts and proc structures is 1:1 except for rfork()
49 * processes masquerading as threads which use one structure for the whole
50 * group. All members are locked by the included mutex. The reference count
51 * and mutex must be last for the bcopy in sigacts_copy() to work.
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_sigignore; /* Signals being ignored. */
62 sigset_t ps_sigcatch; /* Signals being caught by user. */
63 sigset_t ps_freebsd4; /* signals using freebsd4 ucontext. */
64 sigset_t ps_osigset; /* Signals using <= 3.x osigset_t. */
65 sigset_t ps_usertramp; /* SunOS compat; libc sigtramp. XXX */
71 #define PS_NOCLDWAIT 0x0001 /* No zombies if child dies */
72 #define PS_NOCLDSTOP 0x0002 /* No SIGCHLD when children stop. */
73 #define PS_CLDSIGIGN 0x0004 /* The SIGCHLD handler is SIG_IGN. */
75 #if defined(_KERNEL) && defined(COMPAT_43)
80 struct osigcontext si_sc;
83 union sigval si_value;
88 void (*__sa_handler)(int);
89 void (*__sa_sigaction)(int, osiginfo_t *, void *);
90 } __sigaction_u; /* signal handler */
91 osigset_t sa_mask; /* signal mask to apply */
92 int sa_flags; /* see signal options below */
95 typedef void __osiginfohandler_t(int, osiginfo_t *, void *);
96 #endif /* _KERNEL && COMPAT_43 */
98 /* additional signal action values, used only temporarily/internally */
99 #define SIG_CATCH ((__sighandler_t *)2)
100 #define SIG_HOLD ((__sighandler_t *)3)
103 * get signal action for process and signal; currently only for current process
105 #define SIGACTION(p, sig) (p->p_sigacts->ps_sigact[_SIG_IDX(sig)])
108 * sigset_t manipulation macros
110 #define SIGADDSET(set, signo) \
111 ((set).__bits[_SIG_WORD(signo)] |= _SIG_BIT(signo))
113 #define SIGDELSET(set, signo) \
114 ((set).__bits[_SIG_WORD(signo)] &= ~_SIG_BIT(signo))
116 #define SIGEMPTYSET(set) \
119 for (__i = 0; __i < _SIG_WORDS; __i++) \
120 (set).__bits[__i] = 0; \
123 #define SIGFILLSET(set) \
126 for (__i = 0; __i < _SIG_WORDS; __i++) \
127 (set).__bits[__i] = ~0U; \
130 #define SIGISMEMBER(set, signo) \
131 ((set).__bits[_SIG_WORD(signo)] & _SIG_BIT(signo))
133 #define SIGISEMPTY(set) (__sigisempty(&(set)))
134 #define SIGNOTEMPTY(set) (!__sigisempty(&(set)))
136 #define SIGSETEQ(set1, set2) (__sigseteq(&(set1), &(set2)))
137 #define SIGSETNEQ(set1, set2) (!__sigseteq(&(set1), &(set2)))
139 #define SIGSETOR(set1, set2) \
142 for (__i = 0; __i < _SIG_WORDS; __i++) \
143 (set1).__bits[__i] |= (set2).__bits[__i]; \
146 #define SIGSETAND(set1, set2) \
149 for (__i = 0; __i < _SIG_WORDS; __i++) \
150 (set1).__bits[__i] &= (set2).__bits[__i]; \
153 #define SIGSETNAND(set1, set2) \
156 for (__i = 0; __i < _SIG_WORDS; __i++) \
157 (set1).__bits[__i] &= ~(set2).__bits[__i]; \
160 #define SIGSETLO(set1, set2) ((set1).__bits[0] = (set2).__bits[0])
161 #define SIGSETOLD(set, oset) ((set).__bits[0] = (oset))
163 #define SIG_CANTMASK(set) \
164 SIGDELSET(set, SIGKILL), SIGDELSET(set, SIGSTOP)
166 #define SIG_STOPSIGMASK(set) \
167 SIGDELSET(set, SIGSTOP), SIGDELSET(set, SIGTSTP), \
168 SIGDELSET(set, SIGTTIN), SIGDELSET(set, SIGTTOU)
170 #define SIG_CONTSIGMASK(set) \
171 SIGDELSET(set, SIGCONT)
173 #define sigcantmask (sigmask(SIGKILL) | sigmask(SIGSTOP))
175 #define SIG2OSIG(sig, osig) (osig = (sig).__bits[0])
176 #define OSIG2SIG(osig, sig) SIGEMPTYSET(sig); (sig).__bits[0] = osig
179 __sigisempty(sigset_t *set)
183 for (i = 0; i < _SIG_WORDS; i++) {
191 __sigseteq(sigset_t *set1, sigset_t *set2)
195 for (i = 0; i < _SIG_WORDS; i++) {
196 if (set1->__bits[i] != set2->__bits[i])
205 * Specifies the target of a signal.
206 * P - Doesn't matter which thread it gets delivered to.
207 * TD - Must be delivered to a specific thread.
209 typedef enum sigtarget_enum { SIGTARGET_P, SIGTARGET_TD } sigtarget_t;
211 /* Return nonzero if process p has an unmasked pending signal. */
212 #define SIGPENDING(td) \
213 (!SIGISEMPTY((td)->td_siglist) && \
214 !sigsetmasked(&(td)->td_siglist, &(td)->td_sigmask))
217 * Return the value of the pseudo-expression ((*set & ~*mask) != 0). This
218 * is an optimized version of SIGISEMPTY() on a temporary variable
219 * containing SIGSETNAND(*set, *mask).
222 sigsetmasked(sigset_t *set, sigset_t *mask)
226 for (i = 0; i < _SIG_WORDS; i++) {
227 if (set->__bits[i] & ~mask->__bits[i])
239 extern int sugid_coredump; /* Sysctl variable kern.sugid_coredump */
240 extern struct mtx sigio_lock;
243 * Lock the pointers for a sigio object in the underlying objects of
246 #define SIGIO_LOCK() mtx_lock(&sigio_lock)
247 #define SIGIO_TRYLOCK() mtx_trylock(&sigio_lock)
248 #define SIGIO_UNLOCK() mtx_unlock(&sigio_lock)
249 #define SIGIO_LOCKED() mtx_owned(&sigio_lock)
250 #define SIGIO_ASSERT(type) mtx_assert(&sigio_lock, type)
253 * Machine-independent functions:
255 int cursig(struct thread *td);
256 void execsigs(struct proc *p);
257 void gsignal(int pgid, int sig);
258 void killproc(struct proc *p, char *why);
259 void pgsigio(struct sigio **, int signum, int checkctty);
260 void pgsignal(struct pgrp *pgrp, int sig, int checkctty);
261 void postsig(int sig);
262 void psignal(struct proc *p, int sig);
263 struct sigacts *sigacts_alloc(void);
264 void sigacts_copy(struct sigacts *dest, struct sigacts *src);
265 void sigacts_free(struct sigacts *ps);
266 struct sigacts *sigacts_hold(struct sigacts *ps);
267 int sigacts_shared(struct sigacts *ps);
268 void sigexit(struct thread *td, int signum) __dead2;
269 int sig_ffs(sigset_t *set);
270 void siginit(struct proc *p);
271 void signotify(struct thread *td);
272 void tdsignal(struct thread *td, int sig, sigtarget_t target);
273 void trapsignal(struct thread *td, int sig, u_long code);
274 int ptracestop(struct thread *td, int sig);
277 * Machine-dependent functions:
279 void sendsig(sig_t action, int sig, sigset_t *retmask, u_long code);
283 #endif /* !_SYS_SIGNALVAR_H_ */