FreeBSD/Linux Kernel Cross Reference
sys/sys/signalvar.h
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 * 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.
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: releng/8.4/sys/sys/signalvar.h 235442 2012-05-14 15:05:18Z jhb $
31 */
32
33 #ifndef _SYS_SIGNALVAR_H_
34 #define _SYS_SIGNALVAR_H_
35
36 #include <sys/queue.h>
37 #include <sys/_lock.h>
38 #include <sys/_mutex.h>
39 #include <sys/signal.h>
40
41 /*
42 * Kernel signal definitions and data structures,
43 * not exported to user programs.
44 */
45
46 /*
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.
52 */
53 struct sigacts {
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 */
66 int ps_flag;
67 int ps_refcnt;
68 struct mtx ps_mtx;
69 };
70
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. */
74
75 #if defined(_KERNEL) && defined(COMPAT_43)
76 /*
77 * Compatibility.
78 */
79 typedef struct {
80 struct osigcontext si_sc;
81 int si_signo;
82 int si_code;
83 union sigval si_value;
84 } osiginfo_t;
85
86 struct osigaction {
87 union {
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 */
93 };
94
95 typedef void __osiginfohandler_t(int, osiginfo_t *, void *);
96 #endif /* _KERNEL && COMPAT_43 */
97
98 /* additional signal action values, used only temporarily/internally */
99 #define SIG_CATCH ((__sighandler_t *)2)
100 /* #define SIG_HOLD ((__sighandler_t *)3) See signal.h */
101
102 /*
103 * get signal action for process and signal; currently only for current process
104 */
105 #define SIGACTION(p, sig) (p->p_sigacts->ps_sigact[_SIG_IDX(sig)])
106
107 /*
108 * sigset_t manipulation macros
109 */
110 #define SIGADDSET(set, signo) \
111 ((set).__bits[_SIG_WORD(signo)] |= _SIG_BIT(signo))
112
113 #define SIGDELSET(set, signo) \
114 ((set).__bits[_SIG_WORD(signo)] &= ~_SIG_BIT(signo))
115
116 #define SIGEMPTYSET(set) \
117 do { \
118 int __i; \
119 for (__i = 0; __i < _SIG_WORDS; __i++) \
120 (set).__bits[__i] = 0; \
121 } while (0)
122
123 #define SIGFILLSET(set) \
124 do { \
125 int __i; \
126 for (__i = 0; __i < _SIG_WORDS; __i++) \
127 (set).__bits[__i] = ~0U; \
128 } while (0)
129
130 #define SIGISMEMBER(set, signo) \
131 ((set).__bits[_SIG_WORD(signo)] & _SIG_BIT(signo))
132
133 #define SIGISEMPTY(set) (__sigisempty(&(set)))
134 #define SIGNOTEMPTY(set) (!__sigisempty(&(set)))
135
136 #define SIGSETEQ(set1, set2) (__sigseteq(&(set1), &(set2)))
137 #define SIGSETNEQ(set1, set2) (!__sigseteq(&(set1), &(set2)))
138
139 #define SIGSETOR(set1, set2) \
140 do { \
141 int __i; \
142 for (__i = 0; __i < _SIG_WORDS; __i++) \
143 (set1).__bits[__i] |= (set2).__bits[__i]; \
144 } while (0)
145
146 #define SIGSETAND(set1, set2) \
147 do { \
148 int __i; \
149 for (__i = 0; __i < _SIG_WORDS; __i++) \
150 (set1).__bits[__i] &= (set2).__bits[__i]; \
151 } while (0)
152
153 #define SIGSETNAND(set1, set2) \
154 do { \
155 int __i; \
156 for (__i = 0; __i < _SIG_WORDS; __i++) \
157 (set1).__bits[__i] &= ~(set2).__bits[__i]; \
158 } while (0)
159
160 #define SIGSETLO(set1, set2) ((set1).__bits[0] = (set2).__bits[0])
161 #define SIGSETOLD(set, oset) ((set).__bits[0] = (oset))
162
163 #define SIG_CANTMASK(set) \
164 SIGDELSET(set, SIGKILL), SIGDELSET(set, SIGSTOP)
165
166 #define SIG_STOPSIGMASK(set) \
167 SIGDELSET(set, SIGSTOP), SIGDELSET(set, SIGTSTP), \
168 SIGDELSET(set, SIGTTIN), SIGDELSET(set, SIGTTOU)
169
170 #define SIG_CONTSIGMASK(set) \
171 SIGDELSET(set, SIGCONT)
172
173 #define sigcantmask (sigmask(SIGKILL) | sigmask(SIGSTOP))
174
175 #define SIG2OSIG(sig, osig) (osig = (sig).__bits[0])
176 #define OSIG2SIG(osig, sig) SIGEMPTYSET(sig); (sig).__bits[0] = osig
177
178 static __inline int
179 __sigisempty(sigset_t *set)
180 {
181 int i;
182
183 for (i = 0; i < _SIG_WORDS; i++) {
184 if (set->__bits[i])
185 return (0);
186 }
187 return (1);
188 }
189
190 static __inline int
191 __sigseteq(sigset_t *set1, sigset_t *set2)
192 {
193 int i;
194
195 for (i = 0; i < _SIG_WORDS; i++) {
196 if (set1->__bits[i] != set2->__bits[i])
197 return (0);
198 }
199 return (1);
200 }
201
202 struct osigevent {
203 int sigev_notify; /* Notification type */
204 union {
205 int __sigev_signo; /* Signal number */
206 int __sigev_notify_kqueue;
207 } __sigev_u;
208 union sigval sigev_value; /* Signal value */
209 };
210
211 typedef struct ksiginfo {
212 TAILQ_ENTRY(ksiginfo) ksi_link;
213 siginfo_t ksi_info;
214 int ksi_flags;
215 struct sigqueue *ksi_sigq;
216 } ksiginfo_t;
217
218 #define ksi_signo ksi_info.si_signo
219 #define ksi_errno ksi_info.si_errno
220 #define ksi_code ksi_info.si_code
221 #define ksi_pid ksi_info.si_pid
222 #define ksi_uid ksi_info.si_uid
223 #define ksi_status ksi_info.si_status
224 #define ksi_addr ksi_info.si_addr
225 #define ksi_value ksi_info.si_value
226 #define ksi_band ksi_info.si_band
227 #define ksi_trapno ksi_info.si_trapno
228 #define ksi_overrun ksi_info.si_overrun
229 #define ksi_timerid ksi_info.si_timerid
230 #define ksi_mqd ksi_info.si_mqd
231
232 /* bits for ksi_flags */
233 #define KSI_TRAP 0x01 /* Generated by trap. */
234 #define KSI_EXT 0x02 /* Externally managed ksi. */
235 #define KSI_INS 0x04 /* Directly insert ksi, not the copy */
236 #define KSI_SIGQ 0x08 /* Generated by sigqueue, might ret EGAIN. */
237 #define KSI_HEAD 0x10 /* Insert into head, not tail. */
238 #define KSI_COPYMASK (KSI_TRAP|KSI_SIGQ)
239
240 #define KSI_ONQ(ksi) ((ksi)->ksi_sigq != NULL)
241
242 typedef struct sigqueue {
243 sigset_t sq_signals; /* All pending signals. */
244 sigset_t sq_kill; /* Legacy depth 1 queue. */
245 TAILQ_HEAD(, ksiginfo) sq_list;/* Queued signal info. */
246 struct proc *sq_proc;
247 int sq_flags;
248 } sigqueue_t;
249
250 /* Flags for ksi_flags */
251 #define SQ_INIT 0x01
252
253 #ifdef _KERNEL
254
255 /* Return nonzero if process p has an unmasked pending signal. */
256 #define SIGPENDING(td) \
257 ((!SIGISEMPTY((td)->td_siglist) && \
258 !sigsetmasked(&(td)->td_siglist, &(td)->td_sigmask)) || \
259 (!SIGISEMPTY((td)->td_proc->p_siglist) && \
260 !sigsetmasked(&(td)->td_proc->p_siglist, &(td)->td_sigmask)))
261 /*
262 * Return the value of the pseudo-expression ((*set & ~*mask) != 0). This
263 * is an optimized version of SIGISEMPTY() on a temporary variable
264 * containing SIGSETNAND(*set, *mask).
265 */
266 static __inline int
267 sigsetmasked(sigset_t *set, sigset_t *mask)
268 {
269 int i;
270
271 for (i = 0; i < _SIG_WORDS; i++) {
272 if (set->__bits[i] & ~mask->__bits[i])
273 return (0);
274 }
275 return (1);
276 }
277
278 #define ksiginfo_init(ksi) \
279 do { \
280 bzero(ksi, sizeof(ksiginfo_t)); \
281 } while(0)
282
283 #define ksiginfo_init_trap(ksi) \
284 do { \
285 ksiginfo_t *kp = ksi; \
286 bzero(kp, sizeof(ksiginfo_t)); \
287 kp->ksi_flags |= KSI_TRAP; \
288 } while(0)
289
290 static __inline void
291 ksiginfo_copy(ksiginfo_t *src, ksiginfo_t *dst)
292 {
293 (dst)->ksi_info = src->ksi_info;
294 (dst)->ksi_flags = (src->ksi_flags & KSI_COPYMASK);
295 }
296
297 struct pgrp;
298 struct thread;
299 struct proc;
300 struct sigio;
301 struct mtx;
302
303 extern int sugid_coredump; /* Sysctl variable kern.sugid_coredump */
304 extern struct mtx sigio_lock;
305 extern int kern_logsigexit; /* Sysctl variable kern.logsigexit */
306
307 /*
308 * Lock the pointers for a sigio object in the underlying objects of
309 * a file descriptor.
310 */
311 #define SIGIO_LOCK() mtx_lock(&sigio_lock)
312 #define SIGIO_TRYLOCK() mtx_trylock(&sigio_lock)
313 #define SIGIO_UNLOCK() mtx_unlock(&sigio_lock)
314 #define SIGIO_LOCKED() mtx_owned(&sigio_lock)
315 #define SIGIO_ASSERT(type) mtx_assert(&sigio_lock, type)
316
317 /* stop_allowed parameter for cursig */
318 #define SIG_STOP_ALLOWED 100
319 #define SIG_STOP_NOT_ALLOWED 101
320
321 /* flags for kern_sigprocmask */
322 #define SIGPROCMASK_OLD 0x0001
323 #define SIGPROCMASK_PROC_LOCKED 0x0002
324 #define SIGPROCMASK_PS_LOCKED 0x0004
325
326 /*
327 * Machine-independent functions:
328 */
329 int cursig(struct thread *td, int stop_allowed);
330 void execsigs(struct proc *p);
331 void gsignal(int pgid, int sig, ksiginfo_t *ksi);
332 void killproc(struct proc *p, char *why);
333 void pksignal(struct proc *p, int sig, ksiginfo_t *ksi);
334 void pgsigio(struct sigio **, int signum, int checkctty);
335 void pgsignal(struct pgrp *pgrp, int sig, int checkctty, ksiginfo_t *ksi);
336 int postsig(int sig);
337 void psignal(struct proc *p, int sig);
338 int psignal_event(struct proc *p, struct sigevent *, ksiginfo_t *);
339 struct sigacts *sigacts_alloc(void);
340 void sigacts_copy(struct sigacts *dest, struct sigacts *src);
341 void sigacts_free(struct sigacts *ps);
342 struct sigacts *sigacts_hold(struct sigacts *ps);
343 int sigacts_shared(struct sigacts *ps);
344 void sigexit(struct thread *td, int signum) __dead2;
345 int sig_ffs(sigset_t *set);
346 void siginit(struct proc *p);
347 void signotify(struct thread *td);
348 void tdksignal(struct thread *td, int sig, ksiginfo_t *ksi);
349 void tdsigcleanup(struct thread *td);
350 int tdsignal(struct proc *p, struct thread *td, int sig,
351 ksiginfo_t *ksi);
352 void trapsignal(struct thread *td, ksiginfo_t *);
353 int ptracestop(struct thread *td, int sig);
354 ksiginfo_t * ksiginfo_alloc(int);
355 void ksiginfo_free(ksiginfo_t *);
356 void sigqueue_init(struct sigqueue *queue, struct proc *p);
357 void sigqueue_flush(struct sigqueue *queue);
358 void sigqueue_delete_proc(struct proc *p, int sig);
359 void sigqueue_delete(struct sigqueue *queue, int sig);
360 void sigqueue_take(ksiginfo_t *ksi);
361
362 /*
363 * Machine-dependent functions:
364 */
365 void sendsig(sig_t, ksiginfo_t *, sigset_t *retmask);
366
367 #endif /* _KERNEL */
368
369 #endif /* !_SYS_SIGNALVAR_H_ */
Cache object: e0dc42cf3924687c563bdf0590290a64
|