Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | #ifndef _LINUX_SIGNAL_H |
| 3 | #define _LINUX_SIGNAL_H |
| 4 | |
Oleg Nesterov | 1c3bea0 | 2014-10-13 15:53:33 -0700 | [diff] [blame] | 5 | #include <linux/bug.h> |
Ingo Molnar | e6d930b | 2017-02-03 23:43:50 +0100 | [diff] [blame] | 6 | #include <linux/signal_types.h> |
Christoph Hellwig | 7994200 | 2017-06-03 21:00:59 +0200 | [diff] [blame] | 7 | #include <linux/string.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | |
Stephen Rothwell | 1477fcc | 2011-05-20 11:11:53 +1000 | [diff] [blame] | 9 | struct task_struct; |
| 10 | |
Dave Young | d33ed52 | 2010-03-10 15:23:59 -0800 | [diff] [blame] | 11 | /* for sysctl */ |
| 12 | extern int print_fatal_signals; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | |
Eric W. Biederman | ae7795b | 2018-09-25 11:27:20 +0200 | [diff] [blame] | 14 | static inline void copy_siginfo(kernel_siginfo_t *to, |
| 15 | const kernel_siginfo_t *from) |
James Hogan | ca9eb49 | 2016-02-08 18:43:50 +0000 | [diff] [blame] | 16 | { |
Eric W. Biederman | 8c36fdf | 2017-07-19 21:30:42 -0500 | [diff] [blame] | 17 | memcpy(to, from, sizeof(*to)); |
James Hogan | ca9eb49 | 2016-02-08 18:43:50 +0000 | [diff] [blame] | 18 | } |
| 19 | |
Eric W. Biederman | ae7795b | 2018-09-25 11:27:20 +0200 | [diff] [blame] | 20 | static inline void clear_siginfo(kernel_siginfo_t *info) |
Eric W. Biederman | 8c5dbf2 | 2017-07-24 15:28:56 -0500 | [diff] [blame] | 21 | { |
| 22 | memset(info, 0, sizeof(*info)); |
| 23 | } |
| 24 | |
Eric W. Biederman | 4ce5f9c | 2018-09-25 12:59:31 +0200 | [diff] [blame] | 25 | #define SI_EXPANSION_SIZE (sizeof(struct siginfo) - sizeof(struct kernel_siginfo)) |
| 26 | |
Eric W. Biederman | ae7795b | 2018-09-25 11:27:20 +0200 | [diff] [blame] | 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); |
Christoph Hellwig | b9253a4 | 2017-06-03 21:01:01 +0200 | [diff] [blame] | 29 | |
Eric W. Biederman | cc73152 | 2017-07-16 22:36:59 -0500 | [diff] [blame] | 30 | enum siginfo_layout { |
| 31 | SIL_KILL, |
| 32 | SIL_TIMER, |
| 33 | SIL_POLL, |
| 34 | SIL_FAULT, |
Eric W. Biederman | 31931c9 | 2018-04-24 20:59:47 -0500 | [diff] [blame] | 35 | SIL_FAULT_MCEERR, |
| 36 | SIL_FAULT_BNDERR, |
| 37 | SIL_FAULT_PKUERR, |
Eric W. Biederman | cc73152 | 2017-07-16 22:36:59 -0500 | [diff] [blame] | 38 | SIL_CHLD, |
| 39 | SIL_RT, |
Eric W. Biederman | cc73152 | 2017-07-16 22:36:59 -0500 | [diff] [blame] | 40 | SIL_SYS, |
Eric W. Biederman | cc73152 | 2017-07-16 22:36:59 -0500 | [diff] [blame] | 41 | }; |
| 42 | |
Eric W. Biederman | a367005 | 2018-10-10 20:29:44 -0500 | [diff] [blame] | 43 | enum siginfo_layout siginfo_layout(unsigned sig, int si_code); |
Eric W. Biederman | cc73152 | 2017-07-16 22:36:59 -0500 | [diff] [blame] | 44 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | /* |
| 46 | * Define some primitives to manipulate sigset_t. |
| 47 | */ |
| 48 | |
| 49 | #ifndef __HAVE_ARCH_SIG_BITOPS |
| 50 | #include <linux/bitops.h> |
| 51 | |
| 52 | /* We don't use <linux/bitops.h> for these because there is no need to |
| 53 | be atomic. */ |
| 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | #endif /* __HAVE_ARCH_SIG_BITOPS */ |
| 82 | |
George Anzinger | 71fabd5 | 2006-01-08 01:02:48 -0800 | [diff] [blame] | 83 | static inline int sigisemptyset(sigset_t *set) |
| 84 | { |
George Anzinger | 71fabd5 | 2006-01-08 01:02:48 -0800 | [diff] [blame] | 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: |
Oleg Nesterov | 1c3bea0 | 2014-10-13 15:53:33 -0700 | [diff] [blame] | 94 | BUILD_BUG(); |
George Anzinger | 71fabd5 | 2006-01-08 01:02:48 -0800 | [diff] [blame] | 95 | return 0; |
| 96 | } |
| 97 | } |
| 98 | |
Waiman Long | c7be96a | 2016-12-14 15:04:10 -0800 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | { \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | unsigned long a0, a1, a2, a3, b0, b1, b2, b3; \ |
| 125 | \ |
| 126 | switch (_NSIG_WORDS) { \ |
Oleg Nesterov | 1c3bea0 | 2014-10-13 15:53:33 -0700 | [diff] [blame] | 127 | case 4: \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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); \ |
Gustavo A. R. Silva | 3819dde | 2018-10-30 15:07:10 -0700 | [diff] [blame] | 132 | /* fall through */ \ |
Oleg Nesterov | 1c3bea0 | 2014-10-13 15:53:33 -0700 | [diff] [blame] | 133 | case 2: \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | a1 = a->sig[1]; b1 = b->sig[1]; \ |
| 135 | r->sig[1] = op(a1, b1); \ |
Gustavo A. R. Silva | 3819dde | 2018-10-30 15:07:10 -0700 | [diff] [blame] | 136 | /* fall through */ \ |
Oleg Nesterov | 1c3bea0 | 2014-10-13 15:53:33 -0700 | [diff] [blame] | 137 | case 1: \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | a0 = a->sig[0]; b0 = b->sig[0]; \ |
| 139 | r->sig[0] = op(a0, b0); \ |
| 140 | break; \ |
Oleg Nesterov | 1c3bea0 | 2014-10-13 15:53:33 -0700 | [diff] [blame] | 141 | default: \ |
| 142 | BUILD_BUG(); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Oleg Nesterov | 702a507 | 2011-04-27 22:01:27 +0200 | [diff] [blame] | 152 | #define _sig_andn(x,y) ((x) & ~(y)) |
| 153 | _SIG_SET_BINOP(sigandnsets, _sig_andn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | |
| 155 | #undef _SIG_SET_BINOP |
| 156 | #undef _sig_or |
| 157 | #undef _sig_and |
Oleg Nesterov | 702a507 | 2011-04-27 22:01:27 +0200 | [diff] [blame] | 158 | #undef _sig_andn |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | |
| 160 | #define _SIG_SET_OP(name, op) \ |
| 161 | static inline void name(sigset_t *set) \ |
| 162 | { \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | switch (_NSIG_WORDS) { \ |
Oleg Nesterov | 1c3bea0 | 2014-10-13 15:53:33 -0700 | [diff] [blame] | 164 | case 4: set->sig[3] = op(set->sig[3]); \ |
| 165 | set->sig[2] = op(set->sig[2]); \ |
Gustavo A. R. Silva | 3819dde | 2018-10-30 15:07:10 -0700 | [diff] [blame] | 166 | /* fall through */ \ |
Oleg Nesterov | 1c3bea0 | 2014-10-13 15:53:33 -0700 | [diff] [blame] | 167 | case 2: set->sig[1] = op(set->sig[1]); \ |
Gustavo A. R. Silva | 3819dde | 2018-10-30 15:07:10 -0700 | [diff] [blame] | 168 | /* fall through */ \ |
Oleg Nesterov | 1c3bea0 | 2014-10-13 15:53:33 -0700 | [diff] [blame] | 169 | case 1: set->sig[0] = op(set->sig[0]); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | break; \ |
Oleg Nesterov | 1c3bea0 | 2014-10-13 15:53:33 -0700 | [diff] [blame] | 171 | default: \ |
| 172 | BUILD_BUG(); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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; |
Gustavo A. R. Silva | 3819dde | 2018-10-30 15:07:10 -0700 | [diff] [blame] | 189 | /* fall through */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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; |
Gustavo A. R. Silva | 3819dde | 2018-10-30 15:07:10 -0700 | [diff] [blame] | 202 | /* fall through */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | case 1: set->sig[0] = -1; |
| 204 | break; |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | /* Some extensions for manipulating the low 32 signals in particular. */ |
| 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 /* __HAVE_ARCH_SIG_SETOPS */ |
| 250 | |
| 251 | static inline void init_sigpending(struct sigpending *sig) |
| 252 | { |
| 253 | sigemptyset(&sig->signal); |
| 254 | INIT_LIST_HEAD(&sig->list); |
| 255 | } |
| 256 | |
Oleg Nesterov | 6a14c5c | 2006-03-28 16:11:18 -0800 | [diff] [blame] | 257 | extern void flush_sigqueue(struct sigpending *queue); |
| 258 | |
Jesper Juhl | e5bdd88 | 2005-05-01 08:59:13 -0700 | [diff] [blame] | 259 | /* Test if 'sig' is valid signal. Use this instead of testing _NSIG directly */ |
| 260 | static inline int valid_signal(unsigned long sig) |
| 261 | { |
| 262 | return sig <= _NSIG ? 1 : 0; |
| 263 | } |
| 264 | |
Oleg Nesterov | b2b07e4 | 2011-05-18 15:08:03 +0200 | [diff] [blame] | 265 | struct timespec; |
| 266 | struct pt_regs; |
Eric W. Biederman | 0102498 | 2018-07-13 18:40:57 -0500 | [diff] [blame] | 267 | enum pid_type; |
Oleg Nesterov | b2b07e4 | 2011-05-18 15:08:03 +0200 | [diff] [blame] | 268 | |
Davide Libenzi | fba2afa | 2007-05-10 22:23:13 -0700 | [diff] [blame] | 269 | extern int next_signal(struct sigpending *pending, sigset_t *mask); |
Eric W. Biederman | ae7795b | 2018-09-25 11:27:20 +0200 | [diff] [blame] | 270 | extern int do_send_sig_info(int sig, struct kernel_siginfo *info, |
Eric W. Biederman | 40b3b02 | 2018-07-21 10:45:15 -0500 | [diff] [blame] | 271 | struct task_struct *p, enum pid_type type); |
Eric W. Biederman | ae7795b | 2018-09-25 11:27:20 +0200 | [diff] [blame] | 272 | extern int group_send_sig_info(int sig, struct kernel_siginfo *info, |
Eric W. Biederman | 0102498 | 2018-07-13 18:40:57 -0500 | [diff] [blame] | 273 | struct task_struct *p, enum pid_type type); |
Eric W. Biederman | ae7795b | 2018-09-25 11:27:20 +0200 | [diff] [blame] | 274 | extern int __group_send_sig_info(int, struct kernel_siginfo *, struct task_struct *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | extern int sigprocmask(int, sigset_t *, sigset_t *); |
Al Viro | 77097ae | 2012-04-27 13:58:59 -0400 | [diff] [blame] | 276 | extern void set_current_blocked(sigset_t *); |
| 277 | extern void __set_current_blocked(const sigset_t *); |
Masoud Asgharifard Sharbiani | abd4f75 | 2007-07-22 11:12:28 +0200 | [diff] [blame] | 278 | extern int show_unhandled_signals; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | |
Christian Brauner | 20ab721 | 2018-08-21 22:00:54 -0700 | [diff] [blame] | 280 | extern bool get_signal(struct ksignal *ksig); |
Al Viro | 2ce5da1 | 2012-11-07 15:11:25 -0500 | [diff] [blame] | 281 | extern void signal_setup_done(int failed, struct ksignal *ksig, int stepping); |
Oleg Nesterov | d12619b | 2008-02-08 04:19:12 -0800 | [diff] [blame] | 282 | extern void exit_signals(struct task_struct *tsk); |
Oleg Nesterov | b4e7426 | 2014-06-06 14:37:00 -0700 | [diff] [blame] | 283 | extern void kernel_sigaction(int, __sighandler_t); |
| 284 | |
| 285 | static inline void allow_signal(int sig) |
| 286 | { |
| 287 | /* |
| 288 | * Kernel threads handle their own signals. Let the signal code |
| 289 | * know it'll be handled, so that they don't get converted to |
| 290 | * SIGKILL or just silently dropped. |
| 291 | */ |
| 292 | kernel_sigaction(sig, (__force __sighandler_t)2); |
| 293 | } |
| 294 | |
| 295 | static inline void disallow_signal(int sig) |
| 296 | { |
| 297 | kernel_sigaction(sig, SIG_IGN); |
| 298 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | |
Christoph Lameter | 298ec1e | 2006-12-06 20:32:47 -0800 | [diff] [blame] | 300 | extern struct kmem_cache *sighand_cachep; |
| 301 | |
Christian Brauner | 67a48a2 | 2018-08-21 22:00:34 -0700 | [diff] [blame] | 302 | extern bool unhandled_signal(struct task_struct *tsk, int sig); |
Masoud Asgharifard Sharbiani | abd4f75 | 2007-07-22 11:12:28 +0200 | [diff] [blame] | 303 | |
Roland McGrath | 55c0d1f | 2007-05-09 02:33:37 -0700 | [diff] [blame] | 304 | /* |
| 305 | * In POSIX a signal is sent either to a specific thread (Linux task) |
| 306 | * or to the process as a whole (Linux thread group). How the signal |
| 307 | * is sent determines whether it's to one thread or the whole group, |
| 308 | * which determines which signal mask(s) are involved in blocking it |
| 309 | * from being delivered until later. When the signal is delivered, |
| 310 | * either it's caught or ignored by a user handler or it has a default |
| 311 | * effect that applies to the whole thread group (POSIX process). |
| 312 | * |
| 313 | * The possible effects an unblocked signal set to SIG_DFL can have are: |
| 314 | * ignore - Nothing Happens |
| 315 | * terminate - kill the process, i.e. all threads in the group, |
| 316 | * similar to exit_group. The group leader (only) reports |
| 317 | * WIFSIGNALED status to its parent. |
| 318 | * coredump - write a core dump file describing all threads using |
| 319 | * the same mm and then kill all those threads |
| 320 | * stop - stop all the threads in the group, i.e. TASK_STOPPED state |
| 321 | * |
| 322 | * SIGKILL and SIGSTOP cannot be caught, blocked, or ignored. |
| 323 | * Other signals when not blocked and set to SIG_DFL behaves as follows. |
| 324 | * The job control signals also have other special effects. |
| 325 | * |
| 326 | * +--------------------+------------------+ |
| 327 | * | POSIX signal | default action | |
| 328 | * +--------------------+------------------+ |
| 329 | * | SIGHUP | terminate | |
| 330 | * | SIGINT | terminate | |
| 331 | * | SIGQUIT | coredump | |
| 332 | * | SIGILL | coredump | |
| 333 | * | SIGTRAP | coredump | |
| 334 | * | SIGABRT/SIGIOT | coredump | |
| 335 | * | SIGBUS | coredump | |
| 336 | * | SIGFPE | coredump | |
| 337 | * | SIGKILL | terminate(+) | |
| 338 | * | SIGUSR1 | terminate | |
| 339 | * | SIGSEGV | coredump | |
| 340 | * | SIGUSR2 | terminate | |
| 341 | * | SIGPIPE | terminate | |
| 342 | * | SIGALRM | terminate | |
| 343 | * | SIGTERM | terminate | |
| 344 | * | SIGCHLD | ignore | |
| 345 | * | SIGCONT | ignore(*) | |
| 346 | * | SIGSTOP | stop(*)(+) | |
| 347 | * | SIGTSTP | stop(*) | |
| 348 | * | SIGTTIN | stop(*) | |
| 349 | * | SIGTTOU | stop(*) | |
| 350 | * | SIGURG | ignore | |
| 351 | * | SIGXCPU | coredump | |
| 352 | * | SIGXFSZ | coredump | |
| 353 | * | SIGVTALRM | terminate | |
| 354 | * | SIGPROF | terminate | |
| 355 | * | SIGPOLL/SIGIO | terminate | |
| 356 | * | SIGSYS/SIGUNUSED | coredump | |
| 357 | * | SIGSTKFLT | terminate | |
| 358 | * | SIGWINCH | ignore | |
| 359 | * | SIGPWR | terminate | |
| 360 | * | SIGRTMIN-SIGRTMAX | terminate | |
| 361 | * +--------------------+------------------+ |
| 362 | * | non-POSIX signal | default action | |
| 363 | * +--------------------+------------------+ |
| 364 | * | SIGEMT | coredump | |
| 365 | * +--------------------+------------------+ |
| 366 | * |
| 367 | * (+) For SIGKILL and SIGSTOP the action is "always", not just "default". |
| 368 | * (*) Special job control effects: |
| 369 | * When SIGCONT is sent, it resumes the process (all threads in the group) |
| 370 | * from TASK_STOPPED state and also clears any pending/queued stop signals |
| 371 | * (any of those marked with "stop(*)"). This happens regardless of blocking, |
| 372 | * catching, or ignoring SIGCONT. When any stop signal is sent, it clears |
| 373 | * any pending/queued SIGCONT signals; this happens regardless of blocking, |
| 374 | * catching, or ignored the stop signal, though (except for SIGSTOP) the |
| 375 | * default action of stopping the process may happen later or never. |
| 376 | */ |
| 377 | |
| 378 | #ifdef SIGEMT |
| 379 | #define SIGEMT_MASK rt_sigmask(SIGEMT) |
| 380 | #else |
| 381 | #define SIGEMT_MASK 0 |
| 382 | #endif |
| 383 | |
| 384 | #if SIGRTMIN > BITS_PER_LONG |
| 385 | #define rt_sigmask(sig) (1ULL << ((sig)-1)) |
| 386 | #else |
| 387 | #define rt_sigmask(sig) sigmask(sig) |
| 388 | #endif |
Oleg Nesterov | 5c8ccef | 2016-05-23 16:24:02 -0700 | [diff] [blame] | 389 | |
| 390 | #define siginmask(sig, mask) \ |
| 391 | ((sig) < SIGRTMIN && (rt_sigmask(sig) & (mask))) |
Roland McGrath | 55c0d1f | 2007-05-09 02:33:37 -0700 | [diff] [blame] | 392 | |
| 393 | #define SIG_KERNEL_ONLY_MASK (\ |
| 394 | rt_sigmask(SIGKILL) | rt_sigmask(SIGSTOP)) |
| 395 | |
| 396 | #define SIG_KERNEL_STOP_MASK (\ |
| 397 | rt_sigmask(SIGSTOP) | rt_sigmask(SIGTSTP) | \ |
| 398 | rt_sigmask(SIGTTIN) | rt_sigmask(SIGTTOU) ) |
| 399 | |
| 400 | #define SIG_KERNEL_COREDUMP_MASK (\ |
| 401 | rt_sigmask(SIGQUIT) | rt_sigmask(SIGILL) | \ |
| 402 | rt_sigmask(SIGTRAP) | rt_sigmask(SIGABRT) | \ |
| 403 | rt_sigmask(SIGFPE) | rt_sigmask(SIGSEGV) | \ |
| 404 | rt_sigmask(SIGBUS) | rt_sigmask(SIGSYS) | \ |
| 405 | rt_sigmask(SIGXCPU) | rt_sigmask(SIGXFSZ) | \ |
| 406 | SIGEMT_MASK ) |
| 407 | |
| 408 | #define SIG_KERNEL_IGNORE_MASK (\ |
| 409 | rt_sigmask(SIGCONT) | rt_sigmask(SIGCHLD) | \ |
| 410 | rt_sigmask(SIGWINCH) | rt_sigmask(SIGURG) ) |
| 411 | |
Eric W. Biederman | d08477a | 2017-06-29 09:28:50 -0500 | [diff] [blame] | 412 | #define SIG_SPECIFIC_SICODES_MASK (\ |
| 413 | rt_sigmask(SIGILL) | rt_sigmask(SIGFPE) | \ |
| 414 | rt_sigmask(SIGSEGV) | rt_sigmask(SIGBUS) | \ |
| 415 | rt_sigmask(SIGTRAP) | rt_sigmask(SIGCHLD) | \ |
| 416 | rt_sigmask(SIGPOLL) | rt_sigmask(SIGSYS) | \ |
| 417 | SIGEMT_MASK ) |
| 418 | |
Oleg Nesterov | 5c8ccef | 2016-05-23 16:24:02 -0700 | [diff] [blame] | 419 | #define sig_kernel_only(sig) siginmask(sig, SIG_KERNEL_ONLY_MASK) |
| 420 | #define sig_kernel_coredump(sig) siginmask(sig, SIG_KERNEL_COREDUMP_MASK) |
| 421 | #define sig_kernel_ignore(sig) siginmask(sig, SIG_KERNEL_IGNORE_MASK) |
| 422 | #define sig_kernel_stop(sig) siginmask(sig, SIG_KERNEL_STOP_MASK) |
Eric W. Biederman | d08477a | 2017-06-29 09:28:50 -0500 | [diff] [blame] | 423 | #define sig_specific_sicodes(sig) siginmask(sig, SIG_SPECIFIC_SICODES_MASK) |
Roland McGrath | 55c0d1f | 2007-05-09 02:33:37 -0700 | [diff] [blame] | 424 | |
Roland McGrath | 55c0d1f | 2007-05-09 02:33:37 -0700 | [diff] [blame] | 425 | #define sig_fatal(t, signr) \ |
| 426 | (!siginmask(signr, SIG_KERNEL_IGNORE_MASK|SIG_KERNEL_STOP_MASK) && \ |
| 427 | (t)->sighand->action[(signr)-1].sa.sa_handler == SIG_DFL) |
| 428 | |
Adrian Bunk | a1c9eea | 2008-02-06 01:36:44 -0800 | [diff] [blame] | 429 | void signals_init(void); |
| 430 | |
Al Viro | 5c49574 | 2012-11-18 15:29:16 -0500 | [diff] [blame] | 431 | int restore_altstack(const stack_t __user *); |
Al Viro | c40702c | 2012-11-20 14:24:26 -0500 | [diff] [blame] | 432 | int __save_altstack(stack_t __user *, unsigned long); |
Al Viro | 5c49574 | 2012-11-18 15:29:16 -0500 | [diff] [blame] | 433 | |
Al Viro | bd1c149a | 2013-09-01 20:35:01 +0100 | [diff] [blame] | 434 | #define save_altstack_ex(uss, sp) do { \ |
| 435 | stack_t __user *__uss = uss; \ |
| 436 | struct task_struct *t = current; \ |
| 437 | put_user_ex((void __user *)t->sas_ss_sp, &__uss->ss_sp); \ |
Stas Sergeev | 2a74213 | 2016-04-14 23:20:04 +0300 | [diff] [blame] | 438 | put_user_ex(t->sas_ss_flags, &__uss->ss_flags); \ |
Al Viro | bd1c149a | 2013-09-01 20:35:01 +0100 | [diff] [blame] | 439 | put_user_ex(t->sas_ss_size, &__uss->ss_size); \ |
Stas Sergeev | 2a74213 | 2016-04-14 23:20:04 +0300 | [diff] [blame] | 440 | if (t->sas_ss_flags & SS_AUTODISARM) \ |
| 441 | sas_ss_reset(t); \ |
Al Viro | bd1c149a | 2013-09-01 20:35:01 +0100 | [diff] [blame] | 442 | } while (0); |
| 443 | |
David Howells | 34db8aa | 2013-04-12 02:29:19 +0100 | [diff] [blame] | 444 | #ifdef CONFIG_PROC_FS |
| 445 | struct seq_file; |
| 446 | extern void render_sigset_t(struct seq_file *, const char *, sigset_t *); |
| 447 | #endif |
| 448 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | #endif /* _LINUX_SIGNAL_H */ |