]>
git.proxmox.com Git - mirror_ubuntu-eoan-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(kernel_siginfo_t
*to
,
15 const kernel_siginfo_t
*from
)
17 memcpy(to
, from
, sizeof(*to
));
20 static inline void clear_siginfo(kernel_siginfo_t
*info
)
22 memset(info
, 0, sizeof(*info
));
25 #define SI_EXPANSION_SIZE (sizeof(struct siginfo) - sizeof(struct kernel_siginfo))
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
);
43 enum siginfo_layout
siginfo_layout(unsigned sig
, int si_code
);
46 * Define some primitives to manipulate sigset_t.
49 #ifndef __HAVE_ARCH_SIG_BITOPS
50 #include <linux/bitops.h>
52 /* We don't use <linux/bitops.h> for these because there is no need to
54 static inline void sigaddset(sigset_t
*set
, int _sig
)
56 unsigned long sig
= _sig
- 1;
58 set
->sig
[0] |= 1UL << sig
;
60 set
->sig
[sig
/ _NSIG_BPW
] |= 1UL << (sig
% _NSIG_BPW
);
63 static inline void sigdelset(sigset_t
*set
, int _sig
)
65 unsigned long sig
= _sig
- 1;
67 set
->sig
[0] &= ~(1UL << sig
);
69 set
->sig
[sig
/ _NSIG_BPW
] &= ~(1UL << (sig
% _NSIG_BPW
));
72 static inline int sigismember(sigset_t
*set
, int _sig
)
74 unsigned long sig
= _sig
- 1;
76 return 1 & (set
->sig
[0] >> sig
);
78 return 1 & (set
->sig
[sig
/ _NSIG_BPW
] >> (sig
% _NSIG_BPW
));
81 #endif /* __HAVE_ARCH_SIG_BITOPS */
83 static inline int sigisemptyset(sigset_t
*set
)
85 switch (_NSIG_WORDS
) {
87 return (set
->sig
[3] | set
->sig
[2] |
88 set
->sig
[1] | set
->sig
[0]) == 0;
90 return (set
->sig
[1] | set
->sig
[0]) == 0;
92 return set
->sig
[0] == 0;
99 static inline int sigequalsets(const sigset_t
*set1
, const sigset_t
*set2
)
101 switch (_NSIG_WORDS
) {
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]);
108 return (set1
->sig
[1] == set2
->sig
[1]) &&
109 (set1
->sig
[0] == set2
->sig
[0]);
111 return set1
->sig
[0] == set2
->sig
[0];
116 #define sigmask(sig) (1UL << ((sig) - 1))
118 #ifndef __HAVE_ARCH_SIG_SETOPS
119 #include <linux/string.h>
121 #define _SIG_SET_BINOP(name, op) \
122 static inline void name(sigset_t *r, const sigset_t *a, const sigset_t *b) \
124 unsigned long a0, a1, a2, a3, b0, b1, b2, b3; \
126 switch (_NSIG_WORDS) { \
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); \
134 a1 = a->sig[1]; b1 = b->sig[1]; \
135 r->sig[1] = op(a1, b1); \
138 a0 = a->sig[0]; b0 = b->sig[0]; \
139 r->sig[0] = op(a0, b0); \
146 #define _sig_or(x,y) ((x) | (y))
147 _SIG_SET_BINOP(sigorsets
, _sig_or
)
149 #define _sig_and(x,y) ((x) & (y))
150 _SIG_SET_BINOP(sigandsets
, _sig_and
)
152 #define _sig_andn(x,y) ((x) & ~(y))
153 _SIG_SET_BINOP(sigandnsets
, _sig_andn
)
155 #undef _SIG_SET_BINOP
160 #define _SIG_SET_OP(name, op) \
161 static inline void name(sigset_t *set) \
163 switch (_NSIG_WORDS) { \
164 case 4: set->sig[3] = op(set->sig[3]); \
165 set->sig[2] = op(set->sig[2]); \
167 case 2: set->sig[1] = op(set->sig[1]); \
169 case 1: set->sig[0] = op(set->sig[0]); \
176 #define _sig_not(x) (~(x))
177 _SIG_SET_OP(signotset
, _sig_not
)
182 static inline void sigemptyset(sigset_t
*set
)
184 switch (_NSIG_WORDS
) {
186 memset(set
, 0, sizeof(sigset_t
));
188 case 2: set
->sig
[1] = 0;
190 case 1: set
->sig
[0] = 0;
195 static inline void sigfillset(sigset_t
*set
)
197 switch (_NSIG_WORDS
) {
199 memset(set
, -1, sizeof(sigset_t
));
201 case 2: set
->sig
[1] = -1;
203 case 1: set
->sig
[0] = -1;
208 /* Some extensions for manipulating the low 32 signals in particular. */
210 static inline void sigaddsetmask(sigset_t
*set
, unsigned long mask
)
215 static inline void sigdelsetmask(sigset_t
*set
, unsigned long mask
)
217 set
->sig
[0] &= ~mask
;
220 static inline int sigtestsetmask(sigset_t
*set
, unsigned long mask
)
222 return (set
->sig
[0] & mask
) != 0;
225 static inline void siginitset(sigset_t
*set
, unsigned long mask
)
228 switch (_NSIG_WORDS
) {
230 memset(&set
->sig
[1], 0, sizeof(long)*(_NSIG_WORDS
-1));
232 case 2: set
->sig
[1] = 0;
237 static inline void siginitsetinv(sigset_t
*set
, unsigned long mask
)
240 switch (_NSIG_WORDS
) {
242 memset(&set
->sig
[1], -1, sizeof(long)*(_NSIG_WORDS
-1));
244 case 2: set
->sig
[1] = -1;
249 #endif /* __HAVE_ARCH_SIG_SETOPS */
251 static inline void init_sigpending(struct sigpending
*sig
)
253 sigemptyset(&sig
->signal
);
254 INIT_LIST_HEAD(&sig
->list
);
257 extern void flush_sigqueue(struct sigpending
*queue
);
259 /* Test if 'sig' is valid signal. Use this instead of testing _NSIG directly */
260 static inline int valid_signal(unsigned long sig
)
262 return sig
<= _NSIG
? 1 : 0;
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 int set_user_sigmask(const sigset_t __user
*usigmask
, sigset_t
*set
,
277 sigset_t
*oldset
, size_t sigsetsize
);
278 extern void restore_user_sigmask(const void __user
*usigmask
,
280 extern void set_current_blocked(sigset_t
*);
281 extern void __set_current_blocked(const sigset_t
*);
282 extern int show_unhandled_signals
;
284 extern bool get_signal(struct ksignal
*ksig
);
285 extern void signal_setup_done(int failed
, struct ksignal
*ksig
, int stepping
);
286 extern void exit_signals(struct task_struct
*tsk
);
287 extern void kernel_sigaction(int, __sighandler_t
);
289 static inline void allow_signal(int sig
)
292 * Kernel threads handle their own signals. Let the signal code
293 * know it'll be handled, so that they don't get converted to
294 * SIGKILL or just silently dropped.
296 kernel_sigaction(sig
, (__force __sighandler_t
)2);
299 static inline void disallow_signal(int sig
)
301 kernel_sigaction(sig
, SIG_IGN
);
304 extern struct kmem_cache
*sighand_cachep
;
306 extern bool unhandled_signal(struct task_struct
*tsk
, int sig
);
309 * In POSIX a signal is sent either to a specific thread (Linux task)
310 * or to the process as a whole (Linux thread group). How the signal
311 * is sent determines whether it's to one thread or the whole group,
312 * which determines which signal mask(s) are involved in blocking it
313 * from being delivered until later. When the signal is delivered,
314 * either it's caught or ignored by a user handler or it has a default
315 * effect that applies to the whole thread group (POSIX process).
317 * The possible effects an unblocked signal set to SIG_DFL can have are:
318 * ignore - Nothing Happens
319 * terminate - kill the process, i.e. all threads in the group,
320 * similar to exit_group. The group leader (only) reports
321 * WIFSIGNALED status to its parent.
322 * coredump - write a core dump file describing all threads using
323 * the same mm and then kill all those threads
324 * stop - stop all the threads in the group, i.e. TASK_STOPPED state
326 * SIGKILL and SIGSTOP cannot be caught, blocked, or ignored.
327 * Other signals when not blocked and set to SIG_DFL behaves as follows.
328 * The job control signals also have other special effects.
330 * +--------------------+------------------+
331 * | POSIX signal | default action |
332 * +--------------------+------------------+
333 * | SIGHUP | terminate |
334 * | SIGINT | terminate |
335 * | SIGQUIT | coredump |
336 * | SIGILL | coredump |
337 * | SIGTRAP | coredump |
338 * | SIGABRT/SIGIOT | coredump |
339 * | SIGBUS | coredump |
340 * | SIGFPE | coredump |
341 * | SIGKILL | terminate(+) |
342 * | SIGUSR1 | terminate |
343 * | SIGSEGV | coredump |
344 * | SIGUSR2 | terminate |
345 * | SIGPIPE | terminate |
346 * | SIGALRM | terminate |
347 * | SIGTERM | terminate |
348 * | SIGCHLD | ignore |
349 * | SIGCONT | ignore(*) |
350 * | SIGSTOP | stop(*)(+) |
351 * | SIGTSTP | stop(*) |
352 * | SIGTTIN | stop(*) |
353 * | SIGTTOU | stop(*) |
354 * | SIGURG | ignore |
355 * | SIGXCPU | coredump |
356 * | SIGXFSZ | coredump |
357 * | SIGVTALRM | terminate |
358 * | SIGPROF | terminate |
359 * | SIGPOLL/SIGIO | terminate |
360 * | SIGSYS/SIGUNUSED | coredump |
361 * | SIGSTKFLT | terminate |
362 * | SIGWINCH | ignore |
363 * | SIGPWR | terminate |
364 * | SIGRTMIN-SIGRTMAX | terminate |
365 * +--------------------+------------------+
366 * | non-POSIX signal | default action |
367 * +--------------------+------------------+
368 * | SIGEMT | coredump |
369 * +--------------------+------------------+
371 * (+) For SIGKILL and SIGSTOP the action is "always", not just "default".
372 * (*) Special job control effects:
373 * When SIGCONT is sent, it resumes the process (all threads in the group)
374 * from TASK_STOPPED state and also clears any pending/queued stop signals
375 * (any of those marked with "stop(*)"). This happens regardless of blocking,
376 * catching, or ignoring SIGCONT. When any stop signal is sent, it clears
377 * any pending/queued SIGCONT signals; this happens regardless of blocking,
378 * catching, or ignored the stop signal, though (except for SIGSTOP) the
379 * default action of stopping the process may happen later or never.
383 #define SIGEMT_MASK rt_sigmask(SIGEMT)
385 #define SIGEMT_MASK 0
388 #if SIGRTMIN > BITS_PER_LONG
389 #define rt_sigmask(sig) (1ULL << ((sig)-1))
391 #define rt_sigmask(sig) sigmask(sig)
394 #define siginmask(sig, mask) \
395 ((sig) > 0 && (sig) < SIGRTMIN && (rt_sigmask(sig) & (mask)))
397 #define SIG_KERNEL_ONLY_MASK (\
398 rt_sigmask(SIGKILL) | rt_sigmask(SIGSTOP))
400 #define SIG_KERNEL_STOP_MASK (\
401 rt_sigmask(SIGSTOP) | rt_sigmask(SIGTSTP) | \
402 rt_sigmask(SIGTTIN) | rt_sigmask(SIGTTOU) )
404 #define SIG_KERNEL_COREDUMP_MASK (\
405 rt_sigmask(SIGQUIT) | rt_sigmask(SIGILL) | \
406 rt_sigmask(SIGTRAP) | rt_sigmask(SIGABRT) | \
407 rt_sigmask(SIGFPE) | rt_sigmask(SIGSEGV) | \
408 rt_sigmask(SIGBUS) | rt_sigmask(SIGSYS) | \
409 rt_sigmask(SIGXCPU) | rt_sigmask(SIGXFSZ) | \
412 #define SIG_KERNEL_IGNORE_MASK (\
413 rt_sigmask(SIGCONT) | rt_sigmask(SIGCHLD) | \
414 rt_sigmask(SIGWINCH) | rt_sigmask(SIGURG) )
416 #define SIG_SPECIFIC_SICODES_MASK (\
417 rt_sigmask(SIGILL) | rt_sigmask(SIGFPE) | \
418 rt_sigmask(SIGSEGV) | rt_sigmask(SIGBUS) | \
419 rt_sigmask(SIGTRAP) | rt_sigmask(SIGCHLD) | \
420 rt_sigmask(SIGPOLL) | rt_sigmask(SIGSYS) | \
423 #define sig_kernel_only(sig) siginmask(sig, SIG_KERNEL_ONLY_MASK)
424 #define sig_kernel_coredump(sig) siginmask(sig, SIG_KERNEL_COREDUMP_MASK)
425 #define sig_kernel_ignore(sig) siginmask(sig, SIG_KERNEL_IGNORE_MASK)
426 #define sig_kernel_stop(sig) siginmask(sig, SIG_KERNEL_STOP_MASK)
427 #define sig_specific_sicodes(sig) siginmask(sig, SIG_SPECIFIC_SICODES_MASK)
429 #define sig_fatal(t, signr) \
430 (!siginmask(signr, SIG_KERNEL_IGNORE_MASK|SIG_KERNEL_STOP_MASK) && \
431 (t)->sighand->action[(signr)-1].sa.sa_handler == SIG_DFL)
433 void signals_init(void);
435 int restore_altstack(const stack_t __user
*);
436 int __save_altstack(stack_t __user
*, unsigned long);
438 #define save_altstack_ex(uss, sp) do { \
439 stack_t __user *__uss = uss; \
440 struct task_struct *t = current; \
441 put_user_ex((void __user *)t->sas_ss_sp, &__uss->ss_sp); \
442 put_user_ex(t->sas_ss_flags, &__uss->ss_flags); \
443 put_user_ex(t->sas_ss_size, &__uss->ss_size); \
444 if (t->sas_ss_flags & SS_AUTODISARM) \
448 #ifdef CONFIG_PROC_FS
450 extern void render_sigset_t(struct seq_file
*, const char *, sigset_t
*);
453 #endif /* _LINUX_SIGNAL_H */