blob: fcd2b14b19327a9765ff6e9e9a7e45e6cafa0f71 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _LINUX_SIGNAL_H
2#define _LINUX_SIGNAL_H
3
Linus Torvalds1da177e2005-04-16 15:20:36 -07004#include <asm/signal.h>
5#include <asm/siginfo.h>
6
7#ifdef __KERNEL__
David Woodhouse7ab2feb2006-04-25 14:55:46 +01008#include <linux/list.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
Dave Youngd33ed522010-03-10 15:23:59 -080010/* for sysctl */
11extern int print_fatal_signals;
Linus Torvalds1da177e2005-04-16 15:20:36 -070012/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 * Real Time signals may be queued.
14 */
15
16struct sigqueue {
17 struct list_head list;
Linus Torvalds1da177e2005-04-16 15:20:36 -070018 int flags;
19 siginfo_t info;
20 struct user_struct *user;
21};
22
23/* flags values. */
24#define SIGQUEUE_PREALLOC 1
25
26struct sigpending {
27 struct list_head list;
28 sigset_t signal;
29};
30
31/*
32 * Define some primitives to manipulate sigset_t.
33 */
34
35#ifndef __HAVE_ARCH_SIG_BITOPS
36#include <linux/bitops.h>
37
38/* We don't use <linux/bitops.h> for these because there is no need to
39 be atomic. */
40static inline void sigaddset(sigset_t *set, int _sig)
41{
42 unsigned long sig = _sig - 1;
43 if (_NSIG_WORDS == 1)
44 set->sig[0] |= 1UL << sig;
45 else
46 set->sig[sig / _NSIG_BPW] |= 1UL << (sig % _NSIG_BPW);
47}
48
49static inline void sigdelset(sigset_t *set, int _sig)
50{
51 unsigned long sig = _sig - 1;
52 if (_NSIG_WORDS == 1)
53 set->sig[0] &= ~(1UL << sig);
54 else
55 set->sig[sig / _NSIG_BPW] &= ~(1UL << (sig % _NSIG_BPW));
56}
57
58static inline int sigismember(sigset_t *set, int _sig)
59{
60 unsigned long sig = _sig - 1;
61 if (_NSIG_WORDS == 1)
62 return 1 & (set->sig[0] >> sig);
63 else
64 return 1 & (set->sig[sig / _NSIG_BPW] >> (sig % _NSIG_BPW));
65}
66
67static inline int sigfindinword(unsigned long word)
68{
69 return ffz(~word);
70}
71
72#endif /* __HAVE_ARCH_SIG_BITOPS */
73
George Anzinger71fabd52006-01-08 01:02:48 -080074static inline int sigisemptyset(sigset_t *set)
75{
76 extern void _NSIG_WORDS_is_unsupported_size(void);
77 switch (_NSIG_WORDS) {
78 case 4:
79 return (set->sig[3] | set->sig[2] |
80 set->sig[1] | set->sig[0]) == 0;
81 case 2:
82 return (set->sig[1] | set->sig[0]) == 0;
83 case 1:
84 return set->sig[0] == 0;
85 default:
86 _NSIG_WORDS_is_unsupported_size();
87 return 0;
88 }
89}
90
Linus Torvalds1da177e2005-04-16 15:20:36 -070091#define sigmask(sig) (1UL << ((sig) - 1))
92
93#ifndef __HAVE_ARCH_SIG_SETOPS
94#include <linux/string.h>
95
96#define _SIG_SET_BINOP(name, op) \
97static inline void name(sigset_t *r, const sigset_t *a, const sigset_t *b) \
98{ \
99 extern void _NSIG_WORDS_is_unsupported_size(void); \
100 unsigned long a0, a1, a2, a3, b0, b1, b2, b3; \
101 \
102 switch (_NSIG_WORDS) { \
103 case 4: \
104 a3 = a->sig[3]; a2 = a->sig[2]; \
105 b3 = b->sig[3]; b2 = b->sig[2]; \
106 r->sig[3] = op(a3, b3); \
107 r->sig[2] = op(a2, b2); \
108 case 2: \
109 a1 = a->sig[1]; b1 = b->sig[1]; \
110 r->sig[1] = op(a1, b1); \
111 case 1: \
112 a0 = a->sig[0]; b0 = b->sig[0]; \
113 r->sig[0] = op(a0, b0); \
114 break; \
115 default: \
116 _NSIG_WORDS_is_unsupported_size(); \
117 } \
118}
119
120#define _sig_or(x,y) ((x) | (y))
121_SIG_SET_BINOP(sigorsets, _sig_or)
122
123#define _sig_and(x,y) ((x) & (y))
124_SIG_SET_BINOP(sigandsets, _sig_and)
125
126#define _sig_nand(x,y) ((x) & ~(y))
127_SIG_SET_BINOP(signandsets, _sig_nand)
128
129#undef _SIG_SET_BINOP
130#undef _sig_or
131#undef _sig_and
132#undef _sig_nand
133
134#define _SIG_SET_OP(name, op) \
135static inline void name(sigset_t *set) \
136{ \
137 extern void _NSIG_WORDS_is_unsupported_size(void); \
138 \
139 switch (_NSIG_WORDS) { \
140 case 4: set->sig[3] = op(set->sig[3]); \
141 set->sig[2] = op(set->sig[2]); \
142 case 2: set->sig[1] = op(set->sig[1]); \
143 case 1: set->sig[0] = op(set->sig[0]); \
144 break; \
145 default: \
146 _NSIG_WORDS_is_unsupported_size(); \
147 } \
148}
149
150#define _sig_not(x) (~(x))
151_SIG_SET_OP(signotset, _sig_not)
152
153#undef _SIG_SET_OP
154#undef _sig_not
155
156static inline void sigemptyset(sigset_t *set)
157{
158 switch (_NSIG_WORDS) {
159 default:
160 memset(set, 0, sizeof(sigset_t));
161 break;
162 case 2: set->sig[1] = 0;
163 case 1: set->sig[0] = 0;
164 break;
165 }
166}
167
168static inline void sigfillset(sigset_t *set)
169{
170 switch (_NSIG_WORDS) {
171 default:
172 memset(set, -1, sizeof(sigset_t));
173 break;
174 case 2: set->sig[1] = -1;
175 case 1: set->sig[0] = -1;
176 break;
177 }
178}
179
180/* Some extensions for manipulating the low 32 signals in particular. */
181
182static inline void sigaddsetmask(sigset_t *set, unsigned long mask)
183{
184 set->sig[0] |= mask;
185}
186
187static inline void sigdelsetmask(sigset_t *set, unsigned long mask)
188{
189 set->sig[0] &= ~mask;
190}
191
192static inline int sigtestsetmask(sigset_t *set, unsigned long mask)
193{
194 return (set->sig[0] & mask) != 0;
195}
196
197static inline void siginitset(sigset_t *set, unsigned long mask)
198{
199 set->sig[0] = mask;
200 switch (_NSIG_WORDS) {
201 default:
202 memset(&set->sig[1], 0, sizeof(long)*(_NSIG_WORDS-1));
203 break;
204 case 2: set->sig[1] = 0;
205 case 1: ;
206 }
207}
208
209static inline void siginitsetinv(sigset_t *set, unsigned long mask)
210{
211 set->sig[0] = ~mask;
212 switch (_NSIG_WORDS) {
213 default:
214 memset(&set->sig[1], -1, sizeof(long)*(_NSIG_WORDS-1));
215 break;
216 case 2: set->sig[1] = -1;
217 case 1: ;
218 }
219}
220
221#endif /* __HAVE_ARCH_SIG_SETOPS */
222
223static inline void init_sigpending(struct sigpending *sig)
224{
225 sigemptyset(&sig->signal);
226 INIT_LIST_HEAD(&sig->list);
227}
228
Oleg Nesterov6a14c5c2006-03-28 16:11:18 -0800229extern void flush_sigqueue(struct sigpending *queue);
230
Jesper Juhle5bdd882005-05-01 08:59:13 -0700231/* Test if 'sig' is valid signal. Use this instead of testing _NSIG directly */
232static inline int valid_signal(unsigned long sig)
233{
234 return sig <= _NSIG ? 1 : 0;
235}
236
Davide Libenzifba2afa2007-05-10 22:23:13 -0700237extern int next_signal(struct sigpending *pending, sigset_t *mask);
Oleg Nesterov4a30deb2009-09-23 15:57:00 -0700238extern int do_send_sig_info(int sig, struct siginfo *info,
239 struct task_struct *p, bool group);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240extern int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p);
241extern int __group_send_sig_info(int, struct siginfo *, struct task_struct *);
Thomas Gleixner62ab4502009-04-04 21:01:06 +0000242extern long do_rt_tgsigqueueinfo(pid_t tgid, pid_t pid, int sig,
243 siginfo_t *info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244extern long do_sigpending(void __user *, unsigned long);
245extern int sigprocmask(int, sigset_t *, sigset_t *);
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +0200246extern int show_unhandled_signals;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248struct pt_regs;
249extern int get_signal_to_deliver(siginfo_t *info, struct k_sigaction *return_ka, struct pt_regs *regs, void *cookie);
Oleg Nesterovd12619b2008-02-08 04:19:12 -0800250extern void exit_signals(struct task_struct *tsk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
Christoph Lameter298ec1e2006-12-06 20:32:47 -0800252extern struct kmem_cache *sighand_cachep;
253
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +0200254int unhandled_signal(struct task_struct *tsk, int sig);
255
Roland McGrath55c0d1f2007-05-09 02:33:37 -0700256/*
257 * In POSIX a signal is sent either to a specific thread (Linux task)
258 * or to the process as a whole (Linux thread group). How the signal
259 * is sent determines whether it's to one thread or the whole group,
260 * which determines which signal mask(s) are involved in blocking it
261 * from being delivered until later. When the signal is delivered,
262 * either it's caught or ignored by a user handler or it has a default
263 * effect that applies to the whole thread group (POSIX process).
264 *
265 * The possible effects an unblocked signal set to SIG_DFL can have are:
266 * ignore - Nothing Happens
267 * terminate - kill the process, i.e. all threads in the group,
268 * similar to exit_group. The group leader (only) reports
269 * WIFSIGNALED status to its parent.
270 * coredump - write a core dump file describing all threads using
271 * the same mm and then kill all those threads
272 * stop - stop all the threads in the group, i.e. TASK_STOPPED state
273 *
274 * SIGKILL and SIGSTOP cannot be caught, blocked, or ignored.
275 * Other signals when not blocked and set to SIG_DFL behaves as follows.
276 * The job control signals also have other special effects.
277 *
278 * +--------------------+------------------+
279 * | POSIX signal | default action |
280 * +--------------------+------------------+
281 * | SIGHUP | terminate |
282 * | SIGINT | terminate |
283 * | SIGQUIT | coredump |
284 * | SIGILL | coredump |
285 * | SIGTRAP | coredump |
286 * | SIGABRT/SIGIOT | coredump |
287 * | SIGBUS | coredump |
288 * | SIGFPE | coredump |
289 * | SIGKILL | terminate(+) |
290 * | SIGUSR1 | terminate |
291 * | SIGSEGV | coredump |
292 * | SIGUSR2 | terminate |
293 * | SIGPIPE | terminate |
294 * | SIGALRM | terminate |
295 * | SIGTERM | terminate |
296 * | SIGCHLD | ignore |
297 * | SIGCONT | ignore(*) |
298 * | SIGSTOP | stop(*)(+) |
299 * | SIGTSTP | stop(*) |
300 * | SIGTTIN | stop(*) |
301 * | SIGTTOU | stop(*) |
302 * | SIGURG | ignore |
303 * | SIGXCPU | coredump |
304 * | SIGXFSZ | coredump |
305 * | SIGVTALRM | terminate |
306 * | SIGPROF | terminate |
307 * | SIGPOLL/SIGIO | terminate |
308 * | SIGSYS/SIGUNUSED | coredump |
309 * | SIGSTKFLT | terminate |
310 * | SIGWINCH | ignore |
311 * | SIGPWR | terminate |
312 * | SIGRTMIN-SIGRTMAX | terminate |
313 * +--------------------+------------------+
314 * | non-POSIX signal | default action |
315 * +--------------------+------------------+
316 * | SIGEMT | coredump |
317 * +--------------------+------------------+
318 *
319 * (+) For SIGKILL and SIGSTOP the action is "always", not just "default".
320 * (*) Special job control effects:
321 * When SIGCONT is sent, it resumes the process (all threads in the group)
322 * from TASK_STOPPED state and also clears any pending/queued stop signals
323 * (any of those marked with "stop(*)"). This happens regardless of blocking,
324 * catching, or ignoring SIGCONT. When any stop signal is sent, it clears
325 * any pending/queued SIGCONT signals; this happens regardless of blocking,
326 * catching, or ignored the stop signal, though (except for SIGSTOP) the
327 * default action of stopping the process may happen later or never.
328 */
329
330#ifdef SIGEMT
331#define SIGEMT_MASK rt_sigmask(SIGEMT)
332#else
333#define SIGEMT_MASK 0
334#endif
335
336#if SIGRTMIN > BITS_PER_LONG
337#define rt_sigmask(sig) (1ULL << ((sig)-1))
338#else
339#define rt_sigmask(sig) sigmask(sig)
340#endif
341#define siginmask(sig, mask) (rt_sigmask(sig) & (mask))
342
343#define SIG_KERNEL_ONLY_MASK (\
344 rt_sigmask(SIGKILL) | rt_sigmask(SIGSTOP))
345
346#define SIG_KERNEL_STOP_MASK (\
347 rt_sigmask(SIGSTOP) | rt_sigmask(SIGTSTP) | \
348 rt_sigmask(SIGTTIN) | rt_sigmask(SIGTTOU) )
349
350#define SIG_KERNEL_COREDUMP_MASK (\
351 rt_sigmask(SIGQUIT) | rt_sigmask(SIGILL) | \
352 rt_sigmask(SIGTRAP) | rt_sigmask(SIGABRT) | \
353 rt_sigmask(SIGFPE) | rt_sigmask(SIGSEGV) | \
354 rt_sigmask(SIGBUS) | rt_sigmask(SIGSYS) | \
355 rt_sigmask(SIGXCPU) | rt_sigmask(SIGXFSZ) | \
356 SIGEMT_MASK )
357
358#define SIG_KERNEL_IGNORE_MASK (\
359 rt_sigmask(SIGCONT) | rt_sigmask(SIGCHLD) | \
360 rt_sigmask(SIGWINCH) | rt_sigmask(SIGURG) )
361
362#define sig_kernel_only(sig) \
363 (((sig) < SIGRTMIN) && siginmask(sig, SIG_KERNEL_ONLY_MASK))
364#define sig_kernel_coredump(sig) \
365 (((sig) < SIGRTMIN) && siginmask(sig, SIG_KERNEL_COREDUMP_MASK))
366#define sig_kernel_ignore(sig) \
367 (((sig) < SIGRTMIN) && siginmask(sig, SIG_KERNEL_IGNORE_MASK))
368#define sig_kernel_stop(sig) \
369 (((sig) < SIGRTMIN) && siginmask(sig, SIG_KERNEL_STOP_MASK))
370
Roland McGrath55c0d1f2007-05-09 02:33:37 -0700371#define sig_user_defined(t, signr) \
372 (((t)->sighand->action[(signr)-1].sa.sa_handler != SIG_DFL) && \
373 ((t)->sighand->action[(signr)-1].sa.sa_handler != SIG_IGN))
374
375#define sig_fatal(t, signr) \
376 (!siginmask(signr, SIG_KERNEL_IGNORE_MASK|SIG_KERNEL_STOP_MASK) && \
377 (t)->sighand->action[(signr)-1].sa.sa_handler == SIG_DFL)
378
Adrian Bunka1c9eea2008-02-06 01:36:44 -0800379void signals_init(void);
380
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381#endif /* __KERNEL__ */
382
383#endif /* _LINUX_SIGNAL_H */