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