This source file includes following definitions.
- copy_siginfo
- clear_siginfo
- sigaddset
- sigdelset
- sigismember
- sigisemptyset
- sigequalsets
- _SIG_SET_OP
- sigfillset
- sigaddsetmask
- sigdelsetmask
- sigtestsetmask
- siginitset
- siginitsetinv
- init_sigpending
- valid_signal
- allow_signal
- allow_kernel_signal
- disallow_signal
1
2 #ifndef _LINUX_SIGNAL_H
3 #define _LINUX_SIGNAL_H
4
5 #include <linux/bug.h>
6 #include <linux/signal_types.h>
7 #include <linux/string.h>
8
9 struct task_struct;
10
11
12 extern int print_fatal_signals;
13
14 static inline void copy_siginfo(kernel_siginfo_t *to,
15 const kernel_siginfo_t *from)
16 {
17 memcpy(to, from, sizeof(*to));
18 }
19
20 static inline void clear_siginfo(kernel_siginfo_t *info)
21 {
22 memset(info, 0, sizeof(*info));
23 }
24
25 #define SI_EXPANSION_SIZE (sizeof(struct siginfo) - sizeof(struct kernel_siginfo))
26
27 int copy_siginfo_to_user(siginfo_t __user *to, const kernel_siginfo_t *from);
28 int copy_siginfo_from_user(kernel_siginfo_t *to, const siginfo_t __user *from);
29
30 enum siginfo_layout {
31 SIL_KILL,
32 SIL_TIMER,
33 SIL_POLL,
34 SIL_FAULT,
35 SIL_FAULT_MCEERR,
36 SIL_FAULT_BNDERR,
37 SIL_FAULT_PKUERR,
38 SIL_CHLD,
39 SIL_RT,
40 SIL_SYS,
41 };
42
43 enum siginfo_layout siginfo_layout(unsigned sig, int si_code);
44
45
46
47
48
49 #ifndef __HAVE_ARCH_SIG_BITOPS
50 #include <linux/bitops.h>
51
52
53
54 static inline void sigaddset(sigset_t *set, int _sig)
55 {
56 unsigned long sig = _sig - 1;
57 if (_NSIG_WORDS == 1)
58 set->sig[0] |= 1UL << sig;
59 else
60 set->sig[sig / _NSIG_BPW] |= 1UL << (sig % _NSIG_BPW);
61 }
62
63 static inline void sigdelset(sigset_t *set, int _sig)
64 {
65 unsigned long sig = _sig - 1;
66 if (_NSIG_WORDS == 1)
67 set->sig[0] &= ~(1UL << sig);
68 else
69 set->sig[sig / _NSIG_BPW] &= ~(1UL << (sig % _NSIG_BPW));
70 }
71
72 static inline int sigismember(sigset_t *set, int _sig)
73 {
74 unsigned long sig = _sig - 1;
75 if (_NSIG_WORDS == 1)
76 return 1 & (set->sig[0] >> sig);
77 else
78 return 1 & (set->sig[sig / _NSIG_BPW] >> (sig % _NSIG_BPW));
79 }
80
81 #endif
82
83 static inline int sigisemptyset(sigset_t *set)
84 {
85 switch (_NSIG_WORDS) {
86 case 4:
87 return (set->sig[3] | set->sig[2] |
88 set->sig[1] | set->sig[0]) == 0;
89 case 2:
90 return (set->sig[1] | set->sig[0]) == 0;
91 case 1:
92 return set->sig[0] == 0;
93 default:
94 BUILD_BUG();
95 return 0;
96 }
97 }
98
99 static inline int sigequalsets(const sigset_t *set1, const sigset_t *set2)
100 {
101 switch (_NSIG_WORDS) {
102 case 4:
103 return (set1->sig[3] == set2->sig[3]) &&
104 (set1->sig[2] == set2->sig[2]) &&
105 (set1->sig[1] == set2->sig[1]) &&
106 (set1->sig[0] == set2->sig[0]);
107 case 2:
108 return (set1->sig[1] == set2->sig[1]) &&
109 (set1->sig[0] == set2->sig[0]);
110 case 1:
111 return set1->sig[0] == set2->sig[0];
112 }
113 return 0;
114 }
115
116 #define sigmask(sig) (1UL << ((sig) - 1))
117
118 #ifndef __HAVE_ARCH_SIG_SETOPS
119 #include <linux/string.h>
120
121 #define _SIG_SET_BINOP(name, op) \
122 static inline void name(sigset_t *r, const sigset_t *a, const sigset_t *b) \
123 { \
124 unsigned long a0, a1, a2, a3, b0, b1, b2, b3; \
125 \
126 switch (_NSIG_WORDS) { \
127 case 4: \
128 a3 = a->sig[3]; a2 = a->sig[2]; \
129 b3 = b->sig[3]; b2 = b->sig[2]; \
130 r->sig[3] = op(a3, b3); \
131 r->sig[2] = op(a2, b2); \
132 \
133 case 2: \
134 a1 = a->sig[1]; b1 = b->sig[1]; \
135 r->sig[1] = op(a1, b1); \
136 \
137 case 1: \
138 a0 = a->sig[0]; b0 = b->sig[0]; \
139 r->sig[0] = op(a0, b0); \
140 break; \
141 default: \
142 BUILD_BUG(); \
143 } \
144 }
145
146 #define _sig_or(x,y) ((x) | (y))
147 _SIG_SET_BINOP(sigorsets, _sig_or)
148
149 #define _sig_and(x,y) ((x) & (y))
150 _SIG_SET_BINOP(sigandsets, _sig_and)
151
152 #define _sig_andn(x,y) ((x) & ~(y))
153 _SIG_SET_BINOP(sigandnsets, _sig_andn)
154
155 #undef _SIG_SET_BINOP
156 #undef _sig_or
157 #undef _sig_and
158 #undef _sig_andn
159
160 #define _SIG_SET_OP(name, op) \
161 static inline void name(sigset_t *set) \
162 { \
163 switch (_NSIG_WORDS) { \
164 case 4: set->sig[3] = op(set->sig[3]); \
165 set->sig[2] = op(set->sig[2]); \
166 \
167 case 2: set->sig[1] = op(set->sig[1]); \
168 \
169 case 1: set->sig[0] = op(set->sig[0]); \
170 break; \
171 default: \
172 BUILD_BUG(); \
173 } \
174 }
175
176 #define _sig_not(x) (~(x))
177 _SIG_SET_OP(signotset, _sig_not)
178
179 #undef _SIG_SET_OP
180 #undef _sig_not
181
182 static inline void sigemptyset(sigset_t *set)
183 {
184 switch (_NSIG_WORDS) {
185 default:
186 memset(set, 0, sizeof(sigset_t));
187 break;
188 case 2: set->sig[1] = 0;
189
190 case 1: set->sig[0] = 0;
191 break;
192 }
193 }
194
195 static inline void sigfillset(sigset_t *set)
196 {
197 switch (_NSIG_WORDS) {
198 default:
199 memset(set, -1, sizeof(sigset_t));
200 break;
201 case 2: set->sig[1] = -1;
202
203 case 1: set->sig[0] = -1;
204 break;
205 }
206 }
207
208
209
210 static inline void sigaddsetmask(sigset_t *set, unsigned long mask)
211 {
212 set->sig[0] |= mask;
213 }
214
215 static inline void sigdelsetmask(sigset_t *set, unsigned long mask)
216 {
217 set->sig[0] &= ~mask;
218 }
219
220 static inline int sigtestsetmask(sigset_t *set, unsigned long mask)
221 {
222 return (set->sig[0] & mask) != 0;
223 }
224
225 static inline void siginitset(sigset_t *set, unsigned long mask)
226 {
227 set->sig[0] = mask;
228 switch (_NSIG_WORDS) {
229 default:
230 memset(&set->sig[1], 0, sizeof(long)*(_NSIG_WORDS-1));
231 break;
232 case 2: set->sig[1] = 0;
233 case 1: ;
234 }
235 }
236
237 static inline void siginitsetinv(sigset_t *set, unsigned long mask)
238 {
239 set->sig[0] = ~mask;
240 switch (_NSIG_WORDS) {
241 default:
242 memset(&set->sig[1], -1, sizeof(long)*(_NSIG_WORDS-1));
243 break;
244 case 2: set->sig[1] = -1;
245 case 1: ;
246 }
247 }
248
249 #endif
250
251 static inline void init_sigpending(struct sigpending *sig)
252 {
253 sigemptyset(&sig->signal);
254 INIT_LIST_HEAD(&sig->list);
255 }
256
257 extern void flush_sigqueue(struct sigpending *queue);
258
259
260 static inline int valid_signal(unsigned long sig)
261 {
262 return sig <= _NSIG ? 1 : 0;
263 }
264
265 struct timespec;
266 struct pt_regs;
267 enum pid_type;
268
269 extern int next_signal(struct sigpending *pending, sigset_t *mask);
270 extern int do_send_sig_info(int sig, struct kernel_siginfo *info,
271 struct task_struct *p, enum pid_type type);
272 extern int group_send_sig_info(int sig, struct kernel_siginfo *info,
273 struct task_struct *p, enum pid_type type);
274 extern int __group_send_sig_info(int, struct kernel_siginfo *, struct task_struct *);
275 extern int sigprocmask(int, sigset_t *, sigset_t *);
276 extern void set_current_blocked(sigset_t *);
277 extern void __set_current_blocked(const sigset_t *);
278 extern int show_unhandled_signals;
279
280 extern bool get_signal(struct ksignal *ksig);
281 extern void signal_setup_done(int failed, struct ksignal *ksig, int stepping);
282 extern void exit_signals(struct task_struct *tsk);
283 extern void kernel_sigaction(int, __sighandler_t);
284
285 #define SIG_KTHREAD ((__force __sighandler_t)2)
286 #define SIG_KTHREAD_KERNEL ((__force __sighandler_t)3)
287
288 static inline void allow_signal(int sig)
289 {
290
291
292
293
294
295 kernel_sigaction(sig, SIG_KTHREAD);
296 }
297
298 static inline void allow_kernel_signal(int sig)
299 {
300
301
302
303
304
305 kernel_sigaction(sig, SIG_KTHREAD_KERNEL);
306 }
307
308 static inline void disallow_signal(int sig)
309 {
310 kernel_sigaction(sig, SIG_IGN);
311 }
312
313 extern struct kmem_cache *sighand_cachep;
314
315 extern bool unhandled_signal(struct task_struct *tsk, int sig);
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391 #ifdef SIGEMT
392 #define SIGEMT_MASK rt_sigmask(SIGEMT)
393 #else
394 #define SIGEMT_MASK 0
395 #endif
396
397 #if SIGRTMIN > BITS_PER_LONG
398 #define rt_sigmask(sig) (1ULL << ((sig)-1))
399 #else
400 #define rt_sigmask(sig) sigmask(sig)
401 #endif
402
403 #define siginmask(sig, mask) \
404 ((sig) > 0 && (sig) < SIGRTMIN && (rt_sigmask(sig) & (mask)))
405
406 #define SIG_KERNEL_ONLY_MASK (\
407 rt_sigmask(SIGKILL) | rt_sigmask(SIGSTOP))
408
409 #define SIG_KERNEL_STOP_MASK (\
410 rt_sigmask(SIGSTOP) | rt_sigmask(SIGTSTP) | \
411 rt_sigmask(SIGTTIN) | rt_sigmask(SIGTTOU) )
412
413 #define SIG_KERNEL_COREDUMP_MASK (\
414 rt_sigmask(SIGQUIT) | rt_sigmask(SIGILL) | \
415 rt_sigmask(SIGTRAP) | rt_sigmask(SIGABRT) | \
416 rt_sigmask(SIGFPE) | rt_sigmask(SIGSEGV) | \
417 rt_sigmask(SIGBUS) | rt_sigmask(SIGSYS) | \
418 rt_sigmask(SIGXCPU) | rt_sigmask(SIGXFSZ) | \
419 SIGEMT_MASK )
420
421 #define SIG_KERNEL_IGNORE_MASK (\
422 rt_sigmask(SIGCONT) | rt_sigmask(SIGCHLD) | \
423 rt_sigmask(SIGWINCH) | rt_sigmask(SIGURG) )
424
425 #define SIG_SPECIFIC_SICODES_MASK (\
426 rt_sigmask(SIGILL) | rt_sigmask(SIGFPE) | \
427 rt_sigmask(SIGSEGV) | rt_sigmask(SIGBUS) | \
428 rt_sigmask(SIGTRAP) | rt_sigmask(SIGCHLD) | \
429 rt_sigmask(SIGPOLL) | rt_sigmask(SIGSYS) | \
430 SIGEMT_MASK )
431
432 #define sig_kernel_only(sig) siginmask(sig, SIG_KERNEL_ONLY_MASK)
433 #define sig_kernel_coredump(sig) siginmask(sig, SIG_KERNEL_COREDUMP_MASK)
434 #define sig_kernel_ignore(sig) siginmask(sig, SIG_KERNEL_IGNORE_MASK)
435 #define sig_kernel_stop(sig) siginmask(sig, SIG_KERNEL_STOP_MASK)
436 #define sig_specific_sicodes(sig) siginmask(sig, SIG_SPECIFIC_SICODES_MASK)
437
438 #define sig_fatal(t, signr) \
439 (!siginmask(signr, SIG_KERNEL_IGNORE_MASK|SIG_KERNEL_STOP_MASK) && \
440 (t)->sighand->action[(signr)-1].sa.sa_handler == SIG_DFL)
441
442 void signals_init(void);
443
444 int restore_altstack(const stack_t __user *);
445 int __save_altstack(stack_t __user *, unsigned long);
446
447 #define save_altstack_ex(uss, sp) do { \
448 stack_t __user *__uss = uss; \
449 struct task_struct *t = current; \
450 put_user_ex((void __user *)t->sas_ss_sp, &__uss->ss_sp); \
451 put_user_ex(t->sas_ss_flags, &__uss->ss_flags); \
452 put_user_ex(t->sas_ss_size, &__uss->ss_size); \
453 if (t->sas_ss_flags & SS_AUTODISARM) \
454 sas_ss_reset(t); \
455 } while (0);
456
457 #ifdef CONFIG_PROC_FS
458 struct seq_file;
459 extern void render_sigset_t(struct seq_file *, const char *, sigset_t *);
460 #endif
461
462 #endif