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 | |
Dave Young | d33ed52 | 2010-03-10 15:23:59 -0800 | [diff] [blame] | 10 | /* for sysctl */ |
| 11 | extern int print_fatal_signals; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * Real Time signals may be queued. |
| 14 | */ |
| 15 | |
| 16 | struct sigqueue { |
| 17 | struct list_head list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | int flags; |
| 19 | siginfo_t info; |
| 20 | struct user_struct *user; |
| 21 | }; |
| 22 | |
| 23 | /* flags values. */ |
| 24 | #define SIGQUEUE_PREALLOC 1 |
| 25 | |
| 26 | struct 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. */ |
| 40 | static 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 | |
| 49 | static 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 | |
| 58 | static 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 | |
| 67 | static inline int sigfindinword(unsigned long word) |
| 68 | { |
| 69 | return ffz(~word); |
| 70 | } |
| 71 | |
| 72 | #endif /* __HAVE_ARCH_SIG_BITOPS */ |
| 73 | |
George Anzinger | 71fabd5 | 2006-01-08 01:02:48 -0800 | [diff] [blame] | 74 | static 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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) \ |
| 97 | static 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 | |
| 126 | #define _sig_nand(x,y) ((x) & ~(y)) |
| 127 | _SIG_SET_BINOP(signandsets, _sig_nand) |
| 128 | |
| 129 | #undef _SIG_SET_BINOP |
| 130 | #undef _sig_or |
| 131 | #undef _sig_and |
| 132 | #undef _sig_nand |
| 133 | |
| 134 | #define _SIG_SET_OP(name, op) \ |
| 135 | static 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 | |
| 156 | static 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 | |
| 168 | static 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 | |
| 182 | static inline void sigaddsetmask(sigset_t *set, unsigned long mask) |
| 183 | { |
| 184 | set->sig[0] |= mask; |
| 185 | } |
| 186 | |
| 187 | static inline void sigdelsetmask(sigset_t *set, unsigned long mask) |
| 188 | { |
| 189 | set->sig[0] &= ~mask; |
| 190 | } |
| 191 | |
| 192 | static inline int sigtestsetmask(sigset_t *set, unsigned long mask) |
| 193 | { |
| 194 | return (set->sig[0] & mask) != 0; |
| 195 | } |
| 196 | |
| 197 | static 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 | |
| 209 | static 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 | |
| 223 | static inline void init_sigpending(struct sigpending *sig) |
| 224 | { |
| 225 | sigemptyset(&sig->signal); |
| 226 | INIT_LIST_HEAD(&sig->list); |
| 227 | } |
| 228 | |
Oleg Nesterov | 6a14c5c | 2006-03-28 16:11:18 -0800 | [diff] [blame] | 229 | extern void flush_sigqueue(struct sigpending *queue); |
| 230 | |
Jesper Juhl | e5bdd88 | 2005-05-01 08:59:13 -0700 | [diff] [blame] | 231 | /* Test if 'sig' is valid signal. Use this instead of testing _NSIG directly */ |
| 232 | static inline int valid_signal(unsigned long sig) |
| 233 | { |
| 234 | return sig <= _NSIG ? 1 : 0; |
| 235 | } |
| 236 | |
Davide Libenzi | fba2afa | 2007-05-10 22:23:13 -0700 | [diff] [blame] | 237 | extern int next_signal(struct sigpending *pending, sigset_t *mask); |
Oleg Nesterov | 4a30deb | 2009-09-23 15:57:00 -0700 | [diff] [blame] | 238 | extern int do_send_sig_info(int sig, struct siginfo *info, |
| 239 | struct task_struct *p, bool group); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | extern int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p); |
| 241 | extern int __group_send_sig_info(int, struct siginfo *, struct task_struct *); |
Thomas Gleixner | 62ab450 | 2009-04-04 21:01:06 +0000 | [diff] [blame] | 242 | extern long do_rt_tgsigqueueinfo(pid_t tgid, pid_t pid, int sig, |
| 243 | siginfo_t *info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | extern long do_sigpending(void __user *, unsigned long); |
| 245 | extern int sigprocmask(int, sigset_t *, sigset_t *); |
Oleg Nesterov | e6fa16a | 2011-04-27 20:59:41 +0200 | [diff] [blame^] | 246 | extern void set_current_blocked(const sigset_t *); |
Masoud Asgharifard Sharbiani | abd4f75 | 2007-07-22 11:12:28 +0200 | [diff] [blame] | 247 | extern int show_unhandled_signals; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | struct pt_regs; |
| 250 | extern int get_signal_to_deliver(siginfo_t *info, struct k_sigaction *return_ka, struct pt_regs *regs, void *cookie); |
Oleg Nesterov | d12619b | 2008-02-08 04:19:12 -0800 | [diff] [blame] | 251 | extern void exit_signals(struct task_struct *tsk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | |
Christoph Lameter | 298ec1e | 2006-12-06 20:32:47 -0800 | [diff] [blame] | 253 | extern struct kmem_cache *sighand_cachep; |
| 254 | |
Masoud Asgharifard Sharbiani | abd4f75 | 2007-07-22 11:12:28 +0200 | [diff] [blame] | 255 | int unhandled_signal(struct task_struct *tsk, int sig); |
| 256 | |
Roland McGrath | 55c0d1f | 2007-05-09 02:33:37 -0700 | [diff] [blame] | 257 | /* |
| 258 | * In POSIX a signal is sent either to a specific thread (Linux task) |
| 259 | * or to the process as a whole (Linux thread group). How the signal |
| 260 | * is sent determines whether it's to one thread or the whole group, |
| 261 | * which determines which signal mask(s) are involved in blocking it |
| 262 | * from being delivered until later. When the signal is delivered, |
| 263 | * either it's caught or ignored by a user handler or it has a default |
| 264 | * effect that applies to the whole thread group (POSIX process). |
| 265 | * |
| 266 | * The possible effects an unblocked signal set to SIG_DFL can have are: |
| 267 | * ignore - Nothing Happens |
| 268 | * terminate - kill the process, i.e. all threads in the group, |
| 269 | * similar to exit_group. The group leader (only) reports |
| 270 | * WIFSIGNALED status to its parent. |
| 271 | * coredump - write a core dump file describing all threads using |
| 272 | * the same mm and then kill all those threads |
| 273 | * stop - stop all the threads in the group, i.e. TASK_STOPPED state |
| 274 | * |
| 275 | * SIGKILL and SIGSTOP cannot be caught, blocked, or ignored. |
| 276 | * Other signals when not blocked and set to SIG_DFL behaves as follows. |
| 277 | * The job control signals also have other special effects. |
| 278 | * |
| 279 | * +--------------------+------------------+ |
| 280 | * | POSIX signal | default action | |
| 281 | * +--------------------+------------------+ |
| 282 | * | SIGHUP | terminate | |
| 283 | * | SIGINT | terminate | |
| 284 | * | SIGQUIT | coredump | |
| 285 | * | SIGILL | coredump | |
| 286 | * | SIGTRAP | coredump | |
| 287 | * | SIGABRT/SIGIOT | coredump | |
| 288 | * | SIGBUS | coredump | |
| 289 | * | SIGFPE | coredump | |
| 290 | * | SIGKILL | terminate(+) | |
| 291 | * | SIGUSR1 | terminate | |
| 292 | * | SIGSEGV | coredump | |
| 293 | * | SIGUSR2 | terminate | |
| 294 | * | SIGPIPE | terminate | |
| 295 | * | SIGALRM | terminate | |
| 296 | * | SIGTERM | terminate | |
| 297 | * | SIGCHLD | ignore | |
| 298 | * | SIGCONT | ignore(*) | |
| 299 | * | SIGSTOP | stop(*)(+) | |
| 300 | * | SIGTSTP | stop(*) | |
| 301 | * | SIGTTIN | stop(*) | |
| 302 | * | SIGTTOU | stop(*) | |
| 303 | * | SIGURG | ignore | |
| 304 | * | SIGXCPU | coredump | |
| 305 | * | SIGXFSZ | coredump | |
| 306 | * | SIGVTALRM | terminate | |
| 307 | * | SIGPROF | terminate | |
| 308 | * | SIGPOLL/SIGIO | terminate | |
| 309 | * | SIGSYS/SIGUNUSED | coredump | |
| 310 | * | SIGSTKFLT | terminate | |
| 311 | * | SIGWINCH | ignore | |
| 312 | * | SIGPWR | terminate | |
| 313 | * | SIGRTMIN-SIGRTMAX | terminate | |
| 314 | * +--------------------+------------------+ |
| 315 | * | non-POSIX signal | default action | |
| 316 | * +--------------------+------------------+ |
| 317 | * | SIGEMT | coredump | |
| 318 | * +--------------------+------------------+ |
| 319 | * |
| 320 | * (+) For SIGKILL and SIGSTOP the action is "always", not just "default". |
| 321 | * (*) Special job control effects: |
| 322 | * When SIGCONT is sent, it resumes the process (all threads in the group) |
| 323 | * from TASK_STOPPED state and also clears any pending/queued stop signals |
| 324 | * (any of those marked with "stop(*)"). This happens regardless of blocking, |
| 325 | * catching, or ignoring SIGCONT. When any stop signal is sent, it clears |
| 326 | * any pending/queued SIGCONT signals; this happens regardless of blocking, |
| 327 | * catching, or ignored the stop signal, though (except for SIGSTOP) the |
| 328 | * default action of stopping the process may happen later or never. |
| 329 | */ |
| 330 | |
| 331 | #ifdef SIGEMT |
| 332 | #define SIGEMT_MASK rt_sigmask(SIGEMT) |
| 333 | #else |
| 334 | #define SIGEMT_MASK 0 |
| 335 | #endif |
| 336 | |
| 337 | #if SIGRTMIN > BITS_PER_LONG |
| 338 | #define rt_sigmask(sig) (1ULL << ((sig)-1)) |
| 339 | #else |
| 340 | #define rt_sigmask(sig) sigmask(sig) |
| 341 | #endif |
| 342 | #define siginmask(sig, mask) (rt_sigmask(sig) & (mask)) |
| 343 | |
| 344 | #define SIG_KERNEL_ONLY_MASK (\ |
| 345 | rt_sigmask(SIGKILL) | rt_sigmask(SIGSTOP)) |
| 346 | |
| 347 | #define SIG_KERNEL_STOP_MASK (\ |
| 348 | rt_sigmask(SIGSTOP) | rt_sigmask(SIGTSTP) | \ |
| 349 | rt_sigmask(SIGTTIN) | rt_sigmask(SIGTTOU) ) |
| 350 | |
| 351 | #define SIG_KERNEL_COREDUMP_MASK (\ |
| 352 | rt_sigmask(SIGQUIT) | rt_sigmask(SIGILL) | \ |
| 353 | rt_sigmask(SIGTRAP) | rt_sigmask(SIGABRT) | \ |
| 354 | rt_sigmask(SIGFPE) | rt_sigmask(SIGSEGV) | \ |
| 355 | rt_sigmask(SIGBUS) | rt_sigmask(SIGSYS) | \ |
| 356 | rt_sigmask(SIGXCPU) | rt_sigmask(SIGXFSZ) | \ |
| 357 | SIGEMT_MASK ) |
| 358 | |
| 359 | #define SIG_KERNEL_IGNORE_MASK (\ |
| 360 | rt_sigmask(SIGCONT) | rt_sigmask(SIGCHLD) | \ |
| 361 | rt_sigmask(SIGWINCH) | rt_sigmask(SIGURG) ) |
| 362 | |
| 363 | #define sig_kernel_only(sig) \ |
| 364 | (((sig) < SIGRTMIN) && siginmask(sig, SIG_KERNEL_ONLY_MASK)) |
| 365 | #define sig_kernel_coredump(sig) \ |
| 366 | (((sig) < SIGRTMIN) && siginmask(sig, SIG_KERNEL_COREDUMP_MASK)) |
| 367 | #define sig_kernel_ignore(sig) \ |
| 368 | (((sig) < SIGRTMIN) && siginmask(sig, SIG_KERNEL_IGNORE_MASK)) |
| 369 | #define sig_kernel_stop(sig) \ |
| 370 | (((sig) < SIGRTMIN) && siginmask(sig, SIG_KERNEL_STOP_MASK)) |
| 371 | |
Roland McGrath | 55c0d1f | 2007-05-09 02:33:37 -0700 | [diff] [blame] | 372 | #define sig_user_defined(t, signr) \ |
| 373 | (((t)->sighand->action[(signr)-1].sa.sa_handler != SIG_DFL) && \ |
| 374 | ((t)->sighand->action[(signr)-1].sa.sa_handler != SIG_IGN)) |
| 375 | |
| 376 | #define sig_fatal(t, signr) \ |
| 377 | (!siginmask(signr, SIG_KERNEL_IGNORE_MASK|SIG_KERNEL_STOP_MASK) && \ |
| 378 | (t)->sighand->action[(signr)-1].sa.sa_handler == SIG_DFL) |
| 379 | |
Adrian Bunk | a1c9eea | 2008-02-06 01:36:44 -0800 | [diff] [blame] | 380 | void signals_init(void); |
| 381 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | #endif /* __KERNEL__ */ |
| 383 | |
| 384 | #endif /* _LINUX_SIGNAL_H */ |