]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - include/linux/signal.h
signal: sys_sigprocmask() needs retarget_shared_pending()
[mirror_ubuntu-zesty-kernel.git] / include / linux / signal.h
CommitLineData
1da177e4
LT
1#ifndef _LINUX_SIGNAL_H
2#define _LINUX_SIGNAL_H
3
1da177e4
LT
4#include <asm/signal.h>
5#include <asm/siginfo.h>
6
7#ifdef __KERNEL__
7ab2febd 8#include <linux/list.h>
1da177e4 9
d33ed52d
DY
10/* for sysctl */
11extern int print_fatal_signals;
1da177e4
LT
12/*
13 * Real Time signals may be queued.
14 */
15
16struct sigqueue {
17 struct list_head list;
1da177e4
LT
18 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
71fabd5e
GA
74static 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
1da177e4
LT
91#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
702a5073
ON
126#define _sig_andn(x,y) ((x) & ~(y))
127_SIG_SET_BINOP(sigandnsets, _sig_andn)
1da177e4
LT
128
129#undef _SIG_SET_BINOP
130#undef _sig_or
131#undef _sig_and
702a5073 132#undef _sig_andn
1da177e4
LT
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
6a14c5c9
ON
229extern void flush_sigqueue(struct sigpending *queue);
230
e5bdd883
JJ
231/* 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
fba2afaa 237extern int next_signal(struct sigpending *pending, sigset_t *mask);
4a30debf
ON
238extern int do_send_sig_info(int sig, struct siginfo *info,
239 struct task_struct *p, bool group);
1da177e4
LT
240extern 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 *);
62ab4505
TG
242extern long do_rt_tgsigqueueinfo(pid_t tgid, pid_t pid, int sig,
243 siginfo_t *info);
1da177e4 244extern long do_sigpending(void __user *, unsigned long);
943df148
ON
245extern int do_sigtimedwait(const sigset_t *, siginfo_t *,
246 const struct timespec *);
1da177e4 247extern int sigprocmask(int, sigset_t *, sigset_t *);
e6fa16ab 248extern void set_current_blocked(const sigset_t *);
abd4f750 249extern int show_unhandled_signals;
1da177e4 250
1da177e4
LT
251struct pt_regs;
252extern int get_signal_to_deliver(siginfo_t *info, struct k_sigaction *return_ka, struct pt_regs *regs, void *cookie);
d12619b5 253extern void exit_signals(struct task_struct *tsk);
1da177e4 254
298ec1e2
CL
255extern struct kmem_cache *sighand_cachep;
256
abd4f750
MAS
257int unhandled_signal(struct task_struct *tsk, int sig);
258
55c0d1f8
RM
259/*
260 * In POSIX a signal is sent either to a specific thread (Linux task)
261 * or to the process as a whole (Linux thread group). How the signal
262 * is sent determines whether it's to one thread or the whole group,
263 * which determines which signal mask(s) are involved in blocking it
264 * from being delivered until later. When the signal is delivered,
265 * either it's caught or ignored by a user handler or it has a default
266 * effect that applies to the whole thread group (POSIX process).
267 *
268 * The possible effects an unblocked signal set to SIG_DFL can have are:
269 * ignore - Nothing Happens
270 * terminate - kill the process, i.e. all threads in the group,
271 * similar to exit_group. The group leader (only) reports
272 * WIFSIGNALED status to its parent.
273 * coredump - write a core dump file describing all threads using
274 * the same mm and then kill all those threads
275 * stop - stop all the threads in the group, i.e. TASK_STOPPED state
276 *
277 * SIGKILL and SIGSTOP cannot be caught, blocked, or ignored.
278 * Other signals when not blocked and set to SIG_DFL behaves as follows.
279 * The job control signals also have other special effects.
280 *
281 * +--------------------+------------------+
282 * | POSIX signal | default action |
283 * +--------------------+------------------+
284 * | SIGHUP | terminate |
285 * | SIGINT | terminate |
286 * | SIGQUIT | coredump |
287 * | SIGILL | coredump |
288 * | SIGTRAP | coredump |
289 * | SIGABRT/SIGIOT | coredump |
290 * | SIGBUS | coredump |
291 * | SIGFPE | coredump |
292 * | SIGKILL | terminate(+) |
293 * | SIGUSR1 | terminate |
294 * | SIGSEGV | coredump |
295 * | SIGUSR2 | terminate |
296 * | SIGPIPE | terminate |
297 * | SIGALRM | terminate |
298 * | SIGTERM | terminate |
299 * | SIGCHLD | ignore |
300 * | SIGCONT | ignore(*) |
301 * | SIGSTOP | stop(*)(+) |
302 * | SIGTSTP | stop(*) |
303 * | SIGTTIN | stop(*) |
304 * | SIGTTOU | stop(*) |
305 * | SIGURG | ignore |
306 * | SIGXCPU | coredump |
307 * | SIGXFSZ | coredump |
308 * | SIGVTALRM | terminate |
309 * | SIGPROF | terminate |
310 * | SIGPOLL/SIGIO | terminate |
311 * | SIGSYS/SIGUNUSED | coredump |
312 * | SIGSTKFLT | terminate |
313 * | SIGWINCH | ignore |
314 * | SIGPWR | terminate |
315 * | SIGRTMIN-SIGRTMAX | terminate |
316 * +--------------------+------------------+
317 * | non-POSIX signal | default action |
318 * +--------------------+------------------+
319 * | SIGEMT | coredump |
320 * +--------------------+------------------+
321 *
322 * (+) For SIGKILL and SIGSTOP the action is "always", not just "default".
323 * (*) Special job control effects:
324 * When SIGCONT is sent, it resumes the process (all threads in the group)
325 * from TASK_STOPPED state and also clears any pending/queued stop signals
326 * (any of those marked with "stop(*)"). This happens regardless of blocking,
327 * catching, or ignoring SIGCONT. When any stop signal is sent, it clears
328 * any pending/queued SIGCONT signals; this happens regardless of blocking,
329 * catching, or ignored the stop signal, though (except for SIGSTOP) the
330 * default action of stopping the process may happen later or never.
331 */
332
333#ifdef SIGEMT
334#define SIGEMT_MASK rt_sigmask(SIGEMT)
335#else
336#define SIGEMT_MASK 0
337#endif
338
339#if SIGRTMIN > BITS_PER_LONG
340#define rt_sigmask(sig) (1ULL << ((sig)-1))
341#else
342#define rt_sigmask(sig) sigmask(sig)
343#endif
344#define siginmask(sig, mask) (rt_sigmask(sig) & (mask))
345
346#define SIG_KERNEL_ONLY_MASK (\
347 rt_sigmask(SIGKILL) | rt_sigmask(SIGSTOP))
348
349#define SIG_KERNEL_STOP_MASK (\
350 rt_sigmask(SIGSTOP) | rt_sigmask(SIGTSTP) | \
351 rt_sigmask(SIGTTIN) | rt_sigmask(SIGTTOU) )
352
353#define SIG_KERNEL_COREDUMP_MASK (\
354 rt_sigmask(SIGQUIT) | rt_sigmask(SIGILL) | \
355 rt_sigmask(SIGTRAP) | rt_sigmask(SIGABRT) | \
356 rt_sigmask(SIGFPE) | rt_sigmask(SIGSEGV) | \
357 rt_sigmask(SIGBUS) | rt_sigmask(SIGSYS) | \
358 rt_sigmask(SIGXCPU) | rt_sigmask(SIGXFSZ) | \
359 SIGEMT_MASK )
360
361#define SIG_KERNEL_IGNORE_MASK (\
362 rt_sigmask(SIGCONT) | rt_sigmask(SIGCHLD) | \
363 rt_sigmask(SIGWINCH) | rt_sigmask(SIGURG) )
364
365#define sig_kernel_only(sig) \
366 (((sig) < SIGRTMIN) && siginmask(sig, SIG_KERNEL_ONLY_MASK))
367#define sig_kernel_coredump(sig) \
368 (((sig) < SIGRTMIN) && siginmask(sig, SIG_KERNEL_COREDUMP_MASK))
369#define sig_kernel_ignore(sig) \
370 (((sig) < SIGRTMIN) && siginmask(sig, SIG_KERNEL_IGNORE_MASK))
371#define sig_kernel_stop(sig) \
372 (((sig) < SIGRTMIN) && siginmask(sig, SIG_KERNEL_STOP_MASK))
373
55c0d1f8
RM
374#define sig_user_defined(t, signr) \
375 (((t)->sighand->action[(signr)-1].sa.sa_handler != SIG_DFL) && \
376 ((t)->sighand->action[(signr)-1].sa.sa_handler != SIG_IGN))
377
378#define sig_fatal(t, signr) \
379 (!siginmask(signr, SIG_KERNEL_IGNORE_MASK|SIG_KERNEL_STOP_MASK) && \
380 (t)->sighand->action[(signr)-1].sa.sa_handler == SIG_DFL)
381
a1c9eea9
AB
382void signals_init(void);
383
1da177e4
LT
384#endif /* __KERNEL__ */
385
386#endif /* _LINUX_SIGNAL_H */