1 /* $NetBSD: signalvar.h,v 1.86 2014/05/15 07:11:30 uebayasi 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 */
49 typedef TAILQ_HEAD(ksiginfoq, ksiginfo) ksiginfoq_t;
50
51 /*
52 * Process signal actions, possibly shared between processes.
53 */
54 struct 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 */
68 typedef struct sigpend {
69 ksiginfoq_t sp_info;
70 sigset_t sp_set;
71 } sigpend_t;
72
73 /*
74 * Process signal state.
75 */
76 struct 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 #if !defined(__minix)
86 /* additional signal action values, used only temporarily/internally */
87 #define SIG_CATCH (void (*)(int))2
88 #endif /* !defined(__minix) */
89
90 /*
91 * get signal action for process and signal; currently only for current process
92 */
93 #define SIGACTION(p, sig) (p->p_sigacts->sa_sigdesc[(sig)].sd_sigact)
94 #define SIGACTION_PS(ps, sig) (ps->sa_sigdesc[(sig)].sd_sigact)
95
96 /*
97 * Signal properties and actions.
98 * The array below categorizes the signals and their default actions
99 * according to the following properties:
100 */
101 #define SA_KILL 0x0001 /* terminates process by default */
102 #define SA_CORE 0x0002 /* ditto and coredumps */
103 #define SA_STOP 0x0004 /* suspend process */
104 #define SA_TTYSTOP 0x0008 /* ditto, from tty */
105 #define SA_IGNORE 0x0010 /* ignore by default */
106 #define SA_CONT 0x0020 /* continue if suspended */
107 #define SA_CANTMASK 0x0040 /* non-maskable, catchable */
108 #define SA_NORESET 0x0080 /* not reset when caught */
109 #define SA_TOLWP 0x0100 /* to LWP that generated, if local */
110 #define SA_TOALL 0x0200 /* always to all LWPs */
111
112 #ifdef _KERNEL
113
114 #include <sys/systm.h> /* for copyin_t/copyout_t */
115
116 extern sigset_t contsigmask, sigcantmask;
117
118 struct vnode;
119 struct coredump_iostate;
120
121 /*
122 * Machine-independent functions:
123 */
124 int coredump_netbsd(struct lwp *, struct coredump_iostate *);
125 void execsigs(struct proc *);
126 int issignal(struct lwp *);
127 void pgsignal(struct pgrp *, int, int);
128 void kpgsignal(struct pgrp *, struct ksiginfo *, void *, int);
129 void postsig(int);
130 void psignal(struct proc *, int);
131 void kpsignal(struct proc *, struct ksiginfo *, void *);
132 void child_psignal(struct proc *, int);
133 void siginit(struct proc *);
134 void trapsignal(struct lwp *, struct ksiginfo *);
135 void sigexit(struct lwp *, int) __dead;
136 void killproc(struct proc *, const char *);
137 void setsigvec(struct proc *, int, struct sigaction *);
138 int killpg1(struct lwp *, struct ksiginfo *, int, int);
139 void proc_unstop(struct proc *p);
140
141 int sigaction1(struct lwp *, int, const struct sigaction *,
142 struct sigaction *, const void *, int);
143 int sigprocmask1(struct lwp *, int, const sigset_t *, sigset_t *);
144 void sigpending1(struct lwp *, sigset_t *);
145 void sigsuspendsetup(struct lwp *, const sigset_t *);
146 void sigsuspendteardown(struct lwp *);
147 int sigsuspend1(struct lwp *, const sigset_t *);
148 int sigaltstack1(struct lwp *, const struct sigaltstack *,
149 struct sigaltstack *);
150 int sigismasked(struct lwp *, int);
151
152 int sigget(sigpend_t *, ksiginfo_t *, int, const sigset_t *);
153 void sigclear(sigpend_t *, const sigset_t *, ksiginfoq_t *);
154 void sigclearall(struct proc *, const sigset_t *, ksiginfoq_t *);
155
156 void kpsignal2(struct proc *, ksiginfo_t *);
157
158 void signal_init(void);
159
160 struct sigacts *sigactsinit(struct proc *, int);
161 void sigactsunshare(struct proc *);
162 void sigactsfree(struct sigacts *);
163
164 void kpsendsig(struct lwp *, const struct ksiginfo *, const sigset_t *);
165 void sendsig_reset(struct lwp *, int);
166 void sendsig(const struct ksiginfo *, const sigset_t *);
167
168 ksiginfo_t *ksiginfo_alloc(struct proc *, ksiginfo_t *, int);
169 void ksiginfo_free(ksiginfo_t *);
170 void ksiginfo_queue_drain0(ksiginfoq_t *);
171
172 struct sys_____sigtimedwait50_args;
173 int sigtimedwait1(struct lwp *, const struct sys_____sigtimedwait50_args *,
174 register_t *, copyin_t, copyout_t, copyin_t, copyout_t);
175
176 void signotify(struct lwp *);
177 int sigispending(struct lwp *, int);
178
179 /*
180 * Machine-dependent functions:
181 */
182 void sendsig_sigcontext(const struct ksiginfo *, const sigset_t *);
183 void sendsig_siginfo(const struct ksiginfo *, const sigset_t *);
184
185 extern struct pool ksiginfo_pool;
186
187 /*
188 * Modularity / compatibility.
189 */
190 extern void (*sendsig_sigcontext_vec)(const struct ksiginfo *,
191 const sigset_t *);
192 extern int (*coredump_vec)(struct lwp *, const char *);
193
194 /*
195 * firstsig:
196 *
197 * Return the first signal in a signal set.
198 */
199 static inline int
firstsig(const sigset_t * ss)200 firstsig(const sigset_t *ss)
201 {
202 int sig;
203
204 sig = ffs(ss->__bits[0]);
205 if (sig != 0)
206 return (sig);
207 #if NSIG > 33
208 sig = ffs(ss->__bits[1]);
209 if (sig != 0)
210 return (sig + 32);
211 #endif
212 #if NSIG > 65
213 sig = ffs(ss->__bits[2]);
214 if (sig != 0)
215 return (sig + 64);
216 #endif
217 #if NSIG > 97
218 sig = ffs(ss->__bits[3]);
219 if (sig != 0)
220 return (sig + 96);
221 #endif
222 return (0);
223 }
224
225 static inline void
ksiginfo_queue_init(ksiginfoq_t * kq)226 ksiginfo_queue_init(ksiginfoq_t *kq)
227 {
228 TAILQ_INIT(kq);
229 }
230
231 static inline void
ksiginfo_queue_drain(ksiginfoq_t * kq)232 ksiginfo_queue_drain(ksiginfoq_t *kq)
233 {
234 if (!TAILQ_EMPTY(kq))
235 ksiginfo_queue_drain0(kq);
236 }
237
238 #endif /* _KERNEL */
239
240 #ifdef _KERNEL
241 #ifdef SIGPROP
242 const int sigprop[NSIG] = {
243 0, /* 0 unused */
244 SA_KILL, /* 1 SIGHUP */
245 SA_KILL, /* 2 SIGINT */
246 SA_KILL|SA_CORE, /* 3 SIGQUIT */
247 SA_KILL|SA_CORE|SA_NORESET|SA_TOLWP, /* 4 SIGILL */
248 SA_KILL|SA_CORE|SA_NORESET|SA_TOLWP, /* 5 SIGTRAP */
249 SA_KILL|SA_CORE, /* 6 SIGABRT */
250 SA_KILL|SA_CORE|SA_TOLWP, /* 7 SIGEMT */
251 SA_KILL|SA_CORE|SA_TOLWP, /* 8 SIGFPE */
252 SA_KILL|SA_CANTMASK|SA_TOALL, /* 9 SIGKILL */
253 SA_KILL|SA_CORE|SA_TOLWP, /* 10 SIGBUS */
254 SA_KILL|SA_CORE|SA_TOLWP, /* 11 SIGSEGV */
255 SA_KILL|SA_CORE|SA_TOLWP, /* 12 SIGSYS */
256 SA_KILL, /* 13 SIGPIPE */
257 SA_KILL, /* 14 SIGALRM */
258 SA_KILL, /* 15 SIGTERM */
259 SA_IGNORE, /* 16 SIGURG */
260 SA_STOP|SA_CANTMASK|SA_TOALL, /* 17 SIGSTOP */
261 SA_STOP|SA_TTYSTOP|SA_TOALL, /* 18 SIGTSTP */
262 SA_IGNORE|SA_CONT|SA_TOALL, /* 19 SIGCONT */
263 SA_IGNORE, /* 20 SIGCHLD */
264 SA_STOP|SA_TTYSTOP|SA_TOALL, /* 21 SIGTTIN */
265 SA_STOP|SA_TTYSTOP|SA_TOALL, /* 22 SIGTTOU */
266 SA_IGNORE, /* 23 SIGIO */
267 SA_KILL, /* 24 SIGXCPU */
268 SA_KILL, /* 25 SIGXFSZ */
269 SA_KILL, /* 26 SIGVTALRM */
270 SA_KILL, /* 27 SIGPROF */
271 SA_IGNORE, /* 28 SIGWINCH */
272 SA_IGNORE, /* 29 SIGINFO */
273 SA_KILL, /* 30 SIGUSR1 */
274 SA_KILL, /* 31 SIGUSR2 */
275 SA_IGNORE|SA_NORESET, /* 32 SIGPWR */
276 SA_KILL, /* 33 SIGRTMIN + 0 */
277 SA_KILL, /* 34 SIGRTMIN + 1 */
278 SA_KILL, /* 35 SIGRTMIN + 2 */
279 SA_KILL, /* 36 SIGRTMIN + 3 */
280 SA_KILL, /* 37 SIGRTMIN + 4 */
281 SA_KILL, /* 38 SIGRTMIN + 5 */
282 SA_KILL, /* 39 SIGRTMIN + 6 */
283 SA_KILL, /* 40 SIGRTMIN + 7 */
284 SA_KILL, /* 41 SIGRTMIN + 8 */
285 SA_KILL, /* 42 SIGRTMIN + 9 */
286 SA_KILL, /* 43 SIGRTMIN + 10 */
287 SA_KILL, /* 44 SIGRTMIN + 11 */
288 SA_KILL, /* 45 SIGRTMIN + 12 */
289 SA_KILL, /* 46 SIGRTMIN + 13 */
290 SA_KILL, /* 47 SIGRTMIN + 14 */
291 SA_KILL, /* 48 SIGRTMIN + 15 */
292 SA_KILL, /* 49 SIGRTMIN + 16 */
293 SA_KILL, /* 50 SIGRTMIN + 17 */
294 SA_KILL, /* 51 SIGRTMIN + 18 */
295 SA_KILL, /* 52 SIGRTMIN + 19 */
296 SA_KILL, /* 53 SIGRTMIN + 20 */
297 SA_KILL, /* 54 SIGRTMIN + 21 */
298 SA_KILL, /* 55 SIGRTMIN + 22 */
299 SA_KILL, /* 56 SIGRTMIN + 23 */
300 SA_KILL, /* 57 SIGRTMIN + 24 */
301 SA_KILL, /* 58 SIGRTMIN + 25 */
302 SA_KILL, /* 59 SIGRTMIN + 26 */
303 SA_KILL, /* 60 SIGRTMIN + 27 */
304 SA_KILL, /* 61 SIGRTMIN + 28 */
305 SA_KILL, /* 62 SIGRTMIN + 29 */
306 SA_KILL, /* 63 SIGRTMIN + 30 */
307 };
308 #undef SIGPROP
309 #else
310 extern const int sigprop[NSIG];
311 #endif /* SIGPROP */
312 #endif /* _KERNEL */
313 #endif /* !_SYS_SIGNALVAR_H_ */
314