]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - include/linux/signal.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_SIGNAL_H
3 #define _LINUX_SIGNAL_H
6 #include <linux/signal_types.h>
7 #include <linux/string.h>
12 extern int print_fatal_signals
;
14 static inline void copy_siginfo(struct siginfo
*to
, struct siginfo
*from
)
16 if (from
->si_code
< 0)
17 memcpy(to
, from
, sizeof(*to
));
19 /* _sigchld is currently the largest know union member */
20 memcpy(to
, from
, __ARCH_SI_PREAMBLE_SIZE
+ sizeof(from
->_sifields
._sigchld
));
23 int copy_siginfo_to_user(struct siginfo __user
*to
, const struct siginfo
*from
);
37 enum siginfo_layout
siginfo_layout(int sig
, int si_code
);
40 * Define some primitives to manipulate sigset_t.
43 #ifndef __HAVE_ARCH_SIG_BITOPS
44 #include <linux/bitops.h>
46 /* We don't use <linux/bitops.h> for these because there is no need to
48 static inline void sigaddset(sigset_t
*set
, int _sig
)
50 unsigned long sig
= _sig
- 1;
52 set
->sig
[0] |= 1UL << sig
;
54 set
->sig
[sig
/ _NSIG_BPW
] |= 1UL << (sig
% _NSIG_BPW
);
57 static inline void sigdelset(sigset_t
*set
, int _sig
)
59 unsigned long sig
= _sig
- 1;
61 set
->sig
[0] &= ~(1UL << sig
);
63 set
->sig
[sig
/ _NSIG_BPW
] &= ~(1UL << (sig
% _NSIG_BPW
));
66 static inline int sigismember(sigset_t
*set
, int _sig
)
68 unsigned long sig
= _sig
- 1;
70 return 1 & (set
->sig
[0] >> sig
);
72 return 1 & (set
->sig
[sig
/ _NSIG_BPW
] >> (sig
% _NSIG_BPW
));
75 #endif /* __HAVE_ARCH_SIG_BITOPS */
77 static inline int sigisemptyset(sigset_t
*set
)
79 switch (_NSIG_WORDS
) {
81 return (set
->sig
[3] | set
->sig
[2] |
82 set
->sig
[1] | set
->sig
[0]) == 0;
84 return (set
->sig
[1] | set
->sig
[0]) == 0;
86 return set
->sig
[0] == 0;
93 static inline int sigequalsets(const sigset_t
*set1
, const sigset_t
*set2
)
95 switch (_NSIG_WORDS
) {
97 return (set1
->sig
[3] == set2
->sig
[3]) &&
98 (set1
->sig
[2] == set2
->sig
[2]) &&
99 (set1
->sig
[1] == set2
->sig
[1]) &&
100 (set1
->sig
[0] == set2
->sig
[0]);
102 return (set1
->sig
[1] == set2
->sig
[1]) &&
103 (set1
->sig
[0] == set2
->sig
[0]);
105 return set1
->sig
[0] == set2
->sig
[0];
110 #define sigmask(sig) (1UL << ((sig) - 1))
112 #ifndef __HAVE_ARCH_SIG_SETOPS
113 #include <linux/string.h>
115 #define _SIG_SET_BINOP(name, op) \
116 static inline void name(sigset_t *r, const sigset_t *a, const sigset_t *b) \
118 unsigned long a0, a1, a2, a3, b0, b1, b2, b3; \
120 switch (_NSIG_WORDS) { \
122 a3 = a->sig[3]; a2 = a->sig[2]; \
123 b3 = b->sig[3]; b2 = b->sig[2]; \
124 r->sig[3] = op(a3, b3); \
125 r->sig[2] = op(a2, b2); \
127 a1 = a->sig[1]; b1 = b->sig[1]; \
128 r->sig[1] = op(a1, b1); \
130 a0 = a->sig[0]; b0 = b->sig[0]; \
131 r->sig[0] = op(a0, b0); \
138 #define _sig_or(x,y) ((x) | (y))
139 _SIG_SET_BINOP(sigorsets
, _sig_or
)
141 #define _sig_and(x,y) ((x) & (y))
142 _SIG_SET_BINOP(sigandsets
, _sig_and
)
144 #define _sig_andn(x,y) ((x) & ~(y))
145 _SIG_SET_BINOP(sigandnsets
, _sig_andn
)
147 #undef _SIG_SET_BINOP
152 #define _SIG_SET_OP(name, op) \
153 static inline void name(sigset_t *set) \
155 switch (_NSIG_WORDS) { \
156 case 4: set->sig[3] = op(set->sig[3]); \
157 set->sig[2] = op(set->sig[2]); \
158 case 2: set->sig[1] = op(set->sig[1]); \
159 case 1: set->sig[0] = op(set->sig[0]); \
166 #define _sig_not(x) (~(x))
167 _SIG_SET_OP(signotset
, _sig_not
)
172 static inline void sigemptyset(sigset_t
*set
)
174 switch (_NSIG_WORDS
) {
176 memset(set
, 0, sizeof(sigset_t
));
178 case 2: set
->sig
[1] = 0;
179 case 1: set
->sig
[0] = 0;
184 static inline void sigfillset(sigset_t
*set
)
186 switch (_NSIG_WORDS
) {
188 memset(set
, -1, sizeof(sigset_t
));
190 case 2: set
->sig
[1] = -1;
191 case 1: set
->sig
[0] = -1;
196 /* Some extensions for manipulating the low 32 signals in particular. */
198 static inline void sigaddsetmask(sigset_t
*set
, unsigned long mask
)
203 static inline void sigdelsetmask(sigset_t
*set
, unsigned long mask
)
205 set
->sig
[0] &= ~mask
;
208 static inline int sigtestsetmask(sigset_t
*set
, unsigned long mask
)
210 return (set
->sig
[0] & mask
) != 0;
213 static inline void siginitset(sigset_t
*set
, unsigned long mask
)
216 switch (_NSIG_WORDS
) {
218 memset(&set
->sig
[1], 0, sizeof(long)*(_NSIG_WORDS
-1));
220 case 2: set
->sig
[1] = 0;
225 static inline void siginitsetinv(sigset_t
*set
, unsigned long mask
)
228 switch (_NSIG_WORDS
) {
230 memset(&set
->sig
[1], -1, sizeof(long)*(_NSIG_WORDS
-1));
232 case 2: set
->sig
[1] = -1;
237 #endif /* __HAVE_ARCH_SIG_SETOPS */
239 static inline void init_sigpending(struct sigpending
*sig
)
241 sigemptyset(&sig
->signal
);
242 INIT_LIST_HEAD(&sig
->list
);
245 extern void flush_sigqueue(struct sigpending
*queue
);
247 /* Test if 'sig' is valid signal. Use this instead of testing _NSIG directly */
248 static inline int valid_signal(unsigned long sig
)
250 return sig
<= _NSIG
? 1 : 0;
256 extern int next_signal(struct sigpending
*pending
, sigset_t
*mask
);
257 extern int do_send_sig_info(int sig
, struct siginfo
*info
,
258 struct task_struct
*p
, bool group
);
259 extern int group_send_sig_info(int sig
, struct siginfo
*info
, struct task_struct
*p
);
260 extern int __group_send_sig_info(int, struct siginfo
*, struct task_struct
*);
261 extern int sigprocmask(int, sigset_t
*, sigset_t
*);
262 extern void set_current_blocked(sigset_t
*);
263 extern void __set_current_blocked(const sigset_t
*);
264 extern int show_unhandled_signals
;
266 extern int get_signal(struct ksignal
*ksig
);
267 extern void signal_setup_done(int failed
, struct ksignal
*ksig
, int stepping
);
268 extern void exit_signals(struct task_struct
*tsk
);
269 extern void kernel_sigaction(int, __sighandler_t
);
271 static inline void allow_signal(int sig
)
274 * Kernel threads handle their own signals. Let the signal code
275 * know it'll be handled, so that they don't get converted to
276 * SIGKILL or just silently dropped.
278 kernel_sigaction(sig
, (__force __sighandler_t
)2);
281 static inline void disallow_signal(int sig
)
283 kernel_sigaction(sig
, SIG_IGN
);
286 extern struct kmem_cache
*sighand_cachep
;
288 int unhandled_signal(struct task_struct
*tsk
, int sig
);
291 * In POSIX a signal is sent either to a specific thread (Linux task)
292 * or to the process as a whole (Linux thread group). How the signal
293 * is sent determines whether it's to one thread or the whole group,
294 * which determines which signal mask(s) are involved in blocking it
295 * from being delivered until later. When the signal is delivered,
296 * either it's caught or ignored by a user handler or it has a default
297 * effect that applies to the whole thread group (POSIX process).
299 * The possible effects an unblocked signal set to SIG_DFL can have are:
300 * ignore - Nothing Happens
301 * terminate - kill the process, i.e. all threads in the group,
302 * similar to exit_group. The group leader (only) reports
303 * WIFSIGNALED status to its parent.
304 * coredump - write a core dump file describing all threads using
305 * the same mm and then kill all those threads
306 * stop - stop all the threads in the group, i.e. TASK_STOPPED state
308 * SIGKILL and SIGSTOP cannot be caught, blocked, or ignored.
309 * Other signals when not blocked and set to SIG_DFL behaves as follows.
310 * The job control signals also have other special effects.
312 * +--------------------+------------------+
313 * | POSIX signal | default action |
314 * +--------------------+------------------+
315 * | SIGHUP | terminate |
316 * | SIGINT | terminate |
317 * | SIGQUIT | coredump |
318 * | SIGILL | coredump |
319 * | SIGTRAP | coredump |
320 * | SIGABRT/SIGIOT | coredump |
321 * | SIGBUS | coredump |
322 * | SIGFPE | coredump |
323 * | SIGKILL | terminate(+) |
324 * | SIGUSR1 | terminate |
325 * | SIGSEGV | coredump |
326 * | SIGUSR2 | terminate |
327 * | SIGPIPE | terminate |
328 * | SIGALRM | terminate |
329 * | SIGTERM | terminate |
330 * | SIGCHLD | ignore |
331 * | SIGCONT | ignore(*) |
332 * | SIGSTOP | stop(*)(+) |
333 * | SIGTSTP | stop(*) |
334 * | SIGTTIN | stop(*) |
335 * | SIGTTOU | stop(*) |
336 * | SIGURG | ignore |
337 * | SIGXCPU | coredump |
338 * | SIGXFSZ | coredump |
339 * | SIGVTALRM | terminate |
340 * | SIGPROF | terminate |
341 * | SIGPOLL/SIGIO | terminate |
342 * | SIGSYS/SIGUNUSED | coredump |
343 * | SIGSTKFLT | terminate |
344 * | SIGWINCH | ignore |
345 * | SIGPWR | terminate |
346 * | SIGRTMIN-SIGRTMAX | terminate |
347 * +--------------------+------------------+
348 * | non-POSIX signal | default action |
349 * +--------------------+------------------+
350 * | SIGEMT | coredump |
351 * +--------------------+------------------+
353 * (+) For SIGKILL and SIGSTOP the action is "always", not just "default".
354 * (*) Special job control effects:
355 * When SIGCONT is sent, it resumes the process (all threads in the group)
356 * from TASK_STOPPED state and also clears any pending/queued stop signals
357 * (any of those marked with "stop(*)"). This happens regardless of blocking,
358 * catching, or ignoring SIGCONT. When any stop signal is sent, it clears
359 * any pending/queued SIGCONT signals; this happens regardless of blocking,
360 * catching, or ignored the stop signal, though (except for SIGSTOP) the
361 * default action of stopping the process may happen later or never.
365 #define SIGEMT_MASK rt_sigmask(SIGEMT)
367 #define SIGEMT_MASK 0
370 #if SIGRTMIN > BITS_PER_LONG
371 #define rt_sigmask(sig) (1ULL << ((sig)-1))
373 #define rt_sigmask(sig) sigmask(sig)
376 #define siginmask(sig, mask) \
377 ((sig) < SIGRTMIN && (rt_sigmask(sig) & (mask)))
379 #define SIG_KERNEL_ONLY_MASK (\
380 rt_sigmask(SIGKILL) | rt_sigmask(SIGSTOP))
382 #define SIG_KERNEL_STOP_MASK (\
383 rt_sigmask(SIGSTOP) | rt_sigmask(SIGTSTP) | \
384 rt_sigmask(SIGTTIN) | rt_sigmask(SIGTTOU) )
386 #define SIG_KERNEL_COREDUMP_MASK (\
387 rt_sigmask(SIGQUIT) | rt_sigmask(SIGILL) | \
388 rt_sigmask(SIGTRAP) | rt_sigmask(SIGABRT) | \
389 rt_sigmask(SIGFPE) | rt_sigmask(SIGSEGV) | \
390 rt_sigmask(SIGBUS) | rt_sigmask(SIGSYS) | \
391 rt_sigmask(SIGXCPU) | rt_sigmask(SIGXFSZ) | \
394 #define SIG_KERNEL_IGNORE_MASK (\
395 rt_sigmask(SIGCONT) | rt_sigmask(SIGCHLD) | \
396 rt_sigmask(SIGWINCH) | rt_sigmask(SIGURG) )
398 #define SIG_SPECIFIC_SICODES_MASK (\
399 rt_sigmask(SIGILL) | rt_sigmask(SIGFPE) | \
400 rt_sigmask(SIGSEGV) | rt_sigmask(SIGBUS) | \
401 rt_sigmask(SIGTRAP) | rt_sigmask(SIGCHLD) | \
402 rt_sigmask(SIGPOLL) | rt_sigmask(SIGSYS) | \
405 #define sig_kernel_only(sig) siginmask(sig, SIG_KERNEL_ONLY_MASK)
406 #define sig_kernel_coredump(sig) siginmask(sig, SIG_KERNEL_COREDUMP_MASK)
407 #define sig_kernel_ignore(sig) siginmask(sig, SIG_KERNEL_IGNORE_MASK)
408 #define sig_kernel_stop(sig) siginmask(sig, SIG_KERNEL_STOP_MASK)
409 #define sig_specific_sicodes(sig) siginmask(sig, SIG_SPECIFIC_SICODES_MASK)
411 #define sig_fatal(t, signr) \
412 (!siginmask(signr, SIG_KERNEL_IGNORE_MASK|SIG_KERNEL_STOP_MASK) && \
413 (t)->sighand->action[(signr)-1].sa.sa_handler == SIG_DFL)
415 void signals_init(void);
417 int restore_altstack(const stack_t __user
*);
418 int __save_altstack(stack_t __user
*, unsigned long);
420 #define save_altstack_ex(uss, sp) do { \
421 stack_t __user *__uss = uss; \
422 struct task_struct *t = current; \
423 put_user_ex((void __user *)t->sas_ss_sp, &__uss->ss_sp); \
424 put_user_ex(t->sas_ss_flags, &__uss->ss_flags); \
425 put_user_ex(t->sas_ss_size, &__uss->ss_size); \
426 if (t->sas_ss_flags & SS_AUTODISARM) \
430 #ifdef CONFIG_PROC_FS
432 extern void render_sigset_t(struct seq_file
*, const char *, sigset_t
*);
435 #endif /* _LINUX_SIGNAL_H */