1/* $NetBSD: signalvar.h,v 1.87 2016/08/04 06:43:43 christos Exp $ */
2
3/*
4 * Copyright (c) 1991, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
31 * @(#)signalvar.h 8.6 (Berkeley) 2/19/95
32 */
33
34#ifndef _SYS_SIGNALVAR_H_
35#define _SYS_SIGNALVAR_H_
36
37#include <sys/siginfo.h>
38#include <sys/queue.h>
39#include <sys/mutex.h>
40
41/*
42 * Kernel signal definitions and data structures,
43 * not exported to user programs.
44 */
45
46/*
47 * Queue of signals.
48 */
49typedef TAILQ_HEAD(ksiginfoq, ksiginfo) ksiginfoq_t;
50
51/*
52 * Process signal actions, possibly shared between processes.
53 */
54struct sigacts {
55 struct sigact_sigdesc {
56 struct sigaction sd_sigact;
57 const void *sd_tramp;
58 int sd_vers;
59 } sa_sigdesc[NSIG]; /* disposition of signals */
60
61 int sa_refcnt; /* reference count */
62 kmutex_t sa_mutex; /* lock on sa_refcnt */
63};
64
65/*
66 * Pending signals, per LWP and per process.
67 */
68typedef struct sigpend {
69 ksiginfoq_t sp_info;
70 sigset_t sp_set;
71} sigpend_t;
72
73/*
74 * Process signal state.
75 */
76struct sigctx {
77 int ps_signo; /* for core dump/debugger XXX */
78 int ps_code; /* for core dump/debugger XXX */
79 int ps_lwp; /* for core dump/debugger XXX */
80 void *ps_sigcode; /* address of signal trampoline */
81 sigset_t ps_sigignore; /* Signals being ignored. */
82 sigset_t ps_sigcatch; /* Signals being caught by user. */
83};
84
85/* additional signal action values, used only temporarily/internally */
86#define SIG_CATCH (void (*)(int))2
87
88/*
89 * get signal action for process and signal; currently only for current process
90 */
91#define SIGACTION(p, sig) (p->p_sigacts->sa_sigdesc[(sig)].sd_sigact)
92#define SIGACTION_PS(ps, sig) (ps->sa_sigdesc[(sig)].sd_sigact)
93
94/*
95 * Signal properties and actions.
96 * The array below categorizes the signals and their default actions
97 * according to the following properties:
98 */
99#define SA_KILL 0x0001 /* terminates process by default */
100#define SA_CORE 0x0002 /* ditto and coredumps */
101#define SA_STOP 0x0004 /* suspend process */
102#define SA_TTYSTOP 0x0008 /* ditto, from tty */
103#define SA_IGNORE 0x0010 /* ignore by default */
104#define SA_CONT 0x0020 /* continue if suspended */
105#define SA_CANTMASK 0x0040 /* non-maskable, catchable */
106#define SA_NORESET 0x0080 /* not reset when caught */
107#define SA_TOLWP 0x0100 /* to LWP that generated, if local */
108#define SA_TOALL 0x0200 /* always to all LWPs */
109
110#ifdef _KERNEL
111
112#include <sys/systm.h> /* for copyin_t/copyout_t */
113
114extern sigset_t contsigmask, sigcantmask;
115
116struct vnode;
117struct coredump_iostate;
118
119/*
120 * Machine-independent functions:
121 */
122int coredump_netbsd(struct lwp *, struct coredump_iostate *);
123void execsigs(struct proc *);
124int issignal(struct lwp *);
125void pgsignal(struct pgrp *, int, int);
126void kpgsignal(struct pgrp *, struct ksiginfo *, void *, int);
127void postsig(int);
128void psignal(struct proc *, int);
129void kpsignal(struct proc *, struct ksiginfo *, void *);
130void child_psignal(struct proc *, int);
131void siginit(struct proc *);
132void trapsignal(struct lwp *, struct ksiginfo *);
133void sigexit(struct lwp *, int) __dead;
134void killproc(struct proc *, const char *);
135void setsigvec(struct proc *, int, struct sigaction *);
136int killpg1(struct lwp *, struct ksiginfo *, int, int);
137void proc_unstop(struct proc *p);
138
139int sigaction1(struct lwp *, int, const struct sigaction *,
140 struct sigaction *, const void *, int);
141int sigprocmask1(struct lwp *, int, const sigset_t *, sigset_t *);
142void sigpending1(struct lwp *, sigset_t *);
143void sigsuspendsetup(struct lwp *, const sigset_t *);
144void sigsuspendteardown(struct lwp *);
145int sigsuspend1(struct lwp *, const sigset_t *);
146int sigaltstack1(struct lwp *, const struct sigaltstack *,
147 struct sigaltstack *);
148int sigismasked(struct lwp *, int);
149
150int sigget(sigpend_t *, ksiginfo_t *, int, const sigset_t *);
151void sigclear(sigpend_t *, const sigset_t *, ksiginfoq_t *);
152void sigclearall(struct proc *, const sigset_t *, ksiginfoq_t *);
153
154int kpsignal2(struct proc *, ksiginfo_t *);
155
156void signal_init(void);
157
158struct sigacts *sigactsinit(struct proc *, int);
159void sigactsunshare(struct proc *);
160void sigactsfree(struct sigacts *);
161
162void kpsendsig(struct lwp *, const struct ksiginfo *, const sigset_t *);
163void sendsig_reset(struct lwp *, int);
164void sendsig(const struct ksiginfo *, const sigset_t *);
165
166ksiginfo_t *ksiginfo_alloc(struct proc *, ksiginfo_t *, int);
167void ksiginfo_free(ksiginfo_t *);
168void ksiginfo_queue_drain0(ksiginfoq_t *);
169
170struct sys_____sigtimedwait50_args;
171int sigtimedwait1(struct lwp *, const struct sys_____sigtimedwait50_args *,
172 register_t *, copyin_t, copyout_t, copyin_t, copyout_t);
173
174void signotify(struct lwp *);
175int sigispending(struct lwp *, int);
176
177/*
178 * Machine-dependent functions:
179 */
180void sendsig_sigcontext(const struct ksiginfo *, const sigset_t *);
181void sendsig_siginfo(const struct ksiginfo *, const sigset_t *);
182
183extern struct pool ksiginfo_pool;
184
185/*
186 * Modularity / compatibility.
187 */
188extern void (*sendsig_sigcontext_vec)(const struct ksiginfo *,
189 const sigset_t *);
190extern int (*coredump_vec)(struct lwp *, const char *);
191
192/*
193 * firstsig:
194 *
195 * Return the first signal in a signal set.
196 */
197static inline int
198firstsig(const sigset_t *ss)
199{
200 int sig;
201
202 sig = ffs(ss->__bits[0]);
203 if (sig != 0)
204 return (sig);
205#if NSIG > 33
206 sig = ffs(ss->__bits[1]);
207 if (sig != 0)
208 return (sig + 32);
209#endif
210#if NSIG > 65
211 sig = ffs(ss->__bits[2]);
212 if (sig != 0)
213 return (sig + 64);
214#endif
215#if NSIG > 97
216 sig = ffs(ss->__bits[3]);
217 if (sig != 0)
218 return (sig + 96);
219#endif
220 return (0);
221}
222
223static inline void
224ksiginfo_queue_init(ksiginfoq_t *kq)
225{
226 TAILQ_INIT(kq);
227}
228
229static inline void
230ksiginfo_queue_drain(ksiginfoq_t *kq)
231{
232 if (!TAILQ_EMPTY(kq))
233 ksiginfo_queue_drain0(kq);
234}
235
236#endif /* _KERNEL */
237
238#ifdef _KERNEL
239#ifdef SIGPROP
240const int sigprop[NSIG] = {
241 0, /* 0 unused */
242 SA_KILL, /* 1 SIGHUP */
243 SA_KILL, /* 2 SIGINT */
244 SA_KILL|SA_CORE, /* 3 SIGQUIT */
245 SA_KILL|SA_CORE|SA_NORESET|SA_TOLWP, /* 4 SIGILL */
246 SA_KILL|SA_CORE|SA_NORESET|SA_TOLWP, /* 5 SIGTRAP */
247 SA_KILL|SA_CORE, /* 6 SIGABRT */
248 SA_KILL|SA_CORE|SA_TOLWP, /* 7 SIGEMT */
249 SA_KILL|SA_CORE|SA_TOLWP, /* 8 SIGFPE */
250 SA_KILL|SA_CANTMASK|SA_TOALL, /* 9 SIGKILL */
251 SA_KILL|SA_CORE|SA_TOLWP, /* 10 SIGBUS */
252 SA_KILL|SA_CORE|SA_TOLWP, /* 11 SIGSEGV */
253 SA_KILL|SA_CORE|SA_TOLWP, /* 12 SIGSYS */
254 SA_KILL, /* 13 SIGPIPE */
255 SA_KILL, /* 14 SIGALRM */
256 SA_KILL, /* 15 SIGTERM */
257 SA_IGNORE, /* 16 SIGURG */
258 SA_STOP|SA_CANTMASK|SA_TOALL, /* 17 SIGSTOP */
259 SA_STOP|SA_TTYSTOP|SA_TOALL, /* 18 SIGTSTP */
260 SA_IGNORE|SA_CONT|SA_TOALL, /* 19 SIGCONT */
261 SA_IGNORE, /* 20 SIGCHLD */
262 SA_STOP|SA_TTYSTOP|SA_TOALL, /* 21 SIGTTIN */
263 SA_STOP|SA_TTYSTOP|SA_TOALL, /* 22 SIGTTOU */
264 SA_IGNORE, /* 23 SIGIO */
265 SA_KILL, /* 24 SIGXCPU */
266 SA_KILL, /* 25 SIGXFSZ */
267 SA_KILL, /* 26 SIGVTALRM */
268 SA_KILL, /* 27 SIGPROF */
269 SA_IGNORE, /* 28 SIGWINCH */
270 SA_IGNORE, /* 29 SIGINFO */
271 SA_KILL, /* 30 SIGUSR1 */
272 SA_KILL, /* 31 SIGUSR2 */
273 SA_IGNORE|SA_NORESET, /* 32 SIGPWR */
274 SA_KILL, /* 33 SIGRTMIN + 0 */
275 SA_KILL, /* 34 SIGRTMIN + 1 */
276 SA_KILL, /* 35 SIGRTMIN + 2 */
277 SA_KILL, /* 36 SIGRTMIN + 3 */
278 SA_KILL, /* 37 SIGRTMIN + 4 */
279 SA_KILL, /* 38 SIGRTMIN + 5 */
280 SA_KILL, /* 39 SIGRTMIN + 6 */
281 SA_KILL, /* 40 SIGRTMIN + 7 */
282 SA_KILL, /* 41 SIGRTMIN + 8 */
283 SA_KILL, /* 42 SIGRTMIN + 9 */
284 SA_KILL, /* 43 SIGRTMIN + 10 */
285 SA_KILL, /* 44 SIGRTMIN + 11 */
286 SA_KILL, /* 45 SIGRTMIN + 12 */
287 SA_KILL, /* 46 SIGRTMIN + 13 */
288 SA_KILL, /* 47 SIGRTMIN + 14 */
289 SA_KILL, /* 48 SIGRTMIN + 15 */
290 SA_KILL, /* 49 SIGRTMIN + 16 */
291 SA_KILL, /* 50 SIGRTMIN + 17 */
292 SA_KILL, /* 51 SIGRTMIN + 18 */
293 SA_KILL, /* 52 SIGRTMIN + 19 */
294 SA_KILL, /* 53 SIGRTMIN + 20 */
295 SA_KILL, /* 54 SIGRTMIN + 21 */
296 SA_KILL, /* 55 SIGRTMIN + 22 */
297 SA_KILL, /* 56 SIGRTMIN + 23 */
298 SA_KILL, /* 57 SIGRTMIN + 24 */
299 SA_KILL, /* 58 SIGRTMIN + 25 */
300 SA_KILL, /* 59 SIGRTMIN + 26 */
301 SA_KILL, /* 60 SIGRTMIN + 27 */
302 SA_KILL, /* 61 SIGRTMIN + 28 */
303 SA_KILL, /* 62 SIGRTMIN + 29 */
304 SA_KILL, /* 63 SIGRTMIN + 30 */
305};
306#undef SIGPROP
307#else
308extern const int sigprop[NSIG];
309#endif /* SIGPROP */
310#endif /* _KERNEL */
311#endif /* !_SYS_SIGNALVAR_H_ */
312