1 #ifndef _LINUX_SIGNAL_H
2 #define _LINUX_SIGNAL_H
4 #include <asm/signal.h>
5 #include <asm/siginfo.h>
8 #include <linux/list.h>
13 extern int print_fatal_signals;
15 * Real Time signals may be queued.
19 struct list_head list;
22 struct user_struct *user;
26 #define SIGQUEUE_PREALLOC 1
29 struct list_head list;
34 * Define some primitives to manipulate sigset_t.
37 #ifndef __HAVE_ARCH_SIG_BITOPS
38 #include <linux/bitops.h>
40 /* We don't use <linux/bitops.h> for these because there is no need to
42 static inline void sigaddset(sigset_t *set, int _sig)
44 unsigned long sig = _sig - 1;
46 set->sig[0] |= 1UL << sig;
48 set->sig[sig / _NSIG_BPW] |= 1UL << (sig % _NSIG_BPW);
51 static inline void sigdelset(sigset_t *set, int _sig)
53 unsigned long sig = _sig - 1;
55 set->sig[0] &= ~(1UL << sig);
57 set->sig[sig / _NSIG_BPW] &= ~(1UL << (sig % _NSIG_BPW));
60 static inline int sigismember(sigset_t *set, int _sig)
62 unsigned long sig = _sig - 1;
64 return 1 & (set->sig[0] >> sig);
66 return 1 & (set->sig[sig / _NSIG_BPW] >> (sig % _NSIG_BPW));
69 static inline int sigfindinword(unsigned long word)
74 #endif /* __HAVE_ARCH_SIG_BITOPS */
76 static inline int sigisemptyset(sigset_t *set)
78 extern void _NSIG_WORDS_is_unsupported_size(void);
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;
88 _NSIG_WORDS_is_unsupported_size();
93 #define sigmask(sig) (1UL << ((sig) - 1))
95 #ifndef __HAVE_ARCH_SIG_SETOPS
96 #include <linux/string.h>
98 #define _SIG_SET_BINOP(name, op) \
99 static inline void name(sigset_t *r, const sigset_t *a, const sigset_t *b) \
101 extern void _NSIG_WORDS_is_unsupported_size(void); \
102 unsigned long a0, a1, a2, a3, b0, b1, b2, b3; \
104 switch (_NSIG_WORDS) { \
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); \
111 a1 = a->sig[1]; b1 = b->sig[1]; \
112 r->sig[1] = op(a1, b1); \
114 a0 = a->sig[0]; b0 = b->sig[0]; \
115 r->sig[0] = op(a0, b0); \
118 _NSIG_WORDS_is_unsupported_size(); \
122 #define _sig_or(x,y) ((x) | (y))
123 _SIG_SET_BINOP(sigorsets, _sig_or)
125 #define _sig_and(x,y) ((x) & (y))
126 _SIG_SET_BINOP(sigandsets, _sig_and)
128 #define _sig_andn(x,y) ((x) & ~(y))
129 _SIG_SET_BINOP(sigandnsets, _sig_andn)
131 #undef _SIG_SET_BINOP
136 #define _SIG_SET_OP(name, op) \
137 static inline void name(sigset_t *set) \
139 extern void _NSIG_WORDS_is_unsupported_size(void); \
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]); \
148 _NSIG_WORDS_is_unsupported_size(); \
152 #define _sig_not(x) (~(x))
153 _SIG_SET_OP(signotset, _sig_not)
158 static inline void sigemptyset(sigset_t *set)
160 switch (_NSIG_WORDS) {
162 memset(set, 0, sizeof(sigset_t));
164 case 2: set->sig[1] = 0;
165 case 1: set->sig[0] = 0;
170 static inline void sigfillset(sigset_t *set)
172 switch (_NSIG_WORDS) {
174 memset(set, -1, sizeof(sigset_t));
176 case 2: set->sig[1] = -1;
177 case 1: set->sig[0] = -1;
182 /* Some extensions for manipulating the low 32 signals in particular. */
184 static inline void sigaddsetmask(sigset_t *set, unsigned long mask)
189 static inline void sigdelsetmask(sigset_t *set, unsigned long mask)
191 set->sig[0] &= ~mask;
194 static inline int sigtestsetmask(sigset_t *set, unsigned long mask)
196 return (set->sig[0] & mask) != 0;
199 static inline void siginitset(sigset_t *set, unsigned long mask)
202 switch (_NSIG_WORDS) {
204 memset(&set->sig[1], 0, sizeof(long)*(_NSIG_WORDS-1));
206 case 2: set->sig[1] = 0;
211 static inline void siginitsetinv(sigset_t *set, unsigned long mask)
214 switch (_NSIG_WORDS) {
216 memset(&set->sig[1], -1, sizeof(long)*(_NSIG_WORDS-1));
218 case 2: set->sig[1] = -1;
223 #endif /* __HAVE_ARCH_SIG_SETOPS */
225 static inline void init_sigpending(struct sigpending *sig)
227 sigemptyset(&sig->signal);
228 INIT_LIST_HEAD(&sig->list);
231 extern void flush_sigqueue(struct sigpending *queue);
233 /* Test if 'sig' is valid signal. Use this instead of testing _NSIG directly */
234 static inline int valid_signal(unsigned long sig)
236 return sig <= _NSIG ? 1 : 0;
242 extern int next_signal(struct sigpending *pending, sigset_t *mask);
243 extern int do_send_sig_info(int sig, struct siginfo *info,
244 struct task_struct *p, bool group);
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 *);
247 extern long do_rt_tgsigqueueinfo(pid_t tgid, pid_t pid, int sig,
249 extern long do_sigpending(void __user *, unsigned long);
250 extern int do_sigtimedwait(const sigset_t *, siginfo_t *,
251 const struct timespec *);
252 extern int sigprocmask(int, sigset_t *, sigset_t *);
253 extern void set_current_blocked(const sigset_t *);
254 extern int show_unhandled_signals;
256 extern int get_signal_to_deliver(siginfo_t *info, struct k_sigaction *return_ka, struct pt_regs *regs, void *cookie);
257 extern void block_sigmask(struct k_sigaction *ka, int signr);
258 extern void exit_signals(struct task_struct *tsk);
260 extern struct kmem_cache *sighand_cachep;
262 int unhandled_signal(struct task_struct *tsk, int sig);
265 * In POSIX a signal is sent either to a specific thread (Linux task)
266 * or to the process as a whole (Linux thread group). How the signal
267 * is sent determines whether it's to one thread or the whole group,
268 * which determines which signal mask(s) are involved in blocking it
269 * from being delivered until later. When the signal is delivered,
270 * either it's caught or ignored by a user handler or it has a default
271 * effect that applies to the whole thread group (POSIX process).
273 * The possible effects an unblocked signal set to SIG_DFL can have are:
274 * ignore - Nothing Happens
275 * terminate - kill the process, i.e. all threads in the group,
276 * similar to exit_group. The group leader (only) reports
277 * WIFSIGNALED status to its parent.
278 * coredump - write a core dump file describing all threads using
279 * the same mm and then kill all those threads
280 * stop - stop all the threads in the group, i.e. TASK_STOPPED state
282 * SIGKILL and SIGSTOP cannot be caught, blocked, or ignored.
283 * Other signals when not blocked and set to SIG_DFL behaves as follows.
284 * The job control signals also have other special effects.
286 * +--------------------+------------------+
287 * | POSIX signal | default action |
288 * +--------------------+------------------+
289 * | SIGHUP | terminate |
290 * | SIGINT | terminate |
291 * | SIGQUIT | coredump |
292 * | SIGILL | coredump |
293 * | SIGTRAP | coredump |
294 * | SIGABRT/SIGIOT | coredump |
295 * | SIGBUS | coredump |
296 * | SIGFPE | coredump |
297 * | SIGKILL | terminate(+) |
298 * | SIGUSR1 | terminate |
299 * | SIGSEGV | coredump |
300 * | SIGUSR2 | terminate |
301 * | SIGPIPE | terminate |
302 * | SIGALRM | terminate |
303 * | SIGTERM | terminate |
304 * | SIGCHLD | ignore |
305 * | SIGCONT | ignore(*) |
306 * | SIGSTOP | stop(*)(+) |
307 * | SIGTSTP | stop(*) |
308 * | SIGTTIN | stop(*) |
309 * | SIGTTOU | stop(*) |
310 * | SIGURG | ignore |
311 * | SIGXCPU | coredump |
312 * | SIGXFSZ | coredump |
313 * | SIGVTALRM | terminate |
314 * | SIGPROF | terminate |
315 * | SIGPOLL/SIGIO | terminate |
316 * | SIGSYS/SIGUNUSED | coredump |
317 * | SIGSTKFLT | terminate |
318 * | SIGWINCH | ignore |
319 * | SIGPWR | terminate |
320 * | SIGRTMIN-SIGRTMAX | terminate |
321 * +--------------------+------------------+
322 * | non-POSIX signal | default action |
323 * +--------------------+------------------+
324 * | SIGEMT | coredump |
325 * +--------------------+------------------+
327 * (+) For SIGKILL and SIGSTOP the action is "always", not just "default".
328 * (*) Special job control effects:
329 * When SIGCONT is sent, it resumes the process (all threads in the group)
330 * from TASK_STOPPED state and also clears any pending/queued stop signals
331 * (any of those marked with "stop(*)"). This happens regardless of blocking,
332 * catching, or ignoring SIGCONT. When any stop signal is sent, it clears
333 * any pending/queued SIGCONT signals; this happens regardless of blocking,
334 * catching, or ignored the stop signal, though (except for SIGSTOP) the
335 * default action of stopping the process may happen later or never.
339 #define SIGEMT_MASK rt_sigmask(SIGEMT)
341 #define SIGEMT_MASK 0
344 #if SIGRTMIN > BITS_PER_LONG
345 #define rt_sigmask(sig) (1ULL << ((sig)-1))
347 #define rt_sigmask(sig) sigmask(sig)
349 #define siginmask(sig, mask) (rt_sigmask(sig) & (mask))
351 #define SIG_KERNEL_ONLY_MASK (\
352 rt_sigmask(SIGKILL) | rt_sigmask(SIGSTOP))
354 #define SIG_KERNEL_STOP_MASK (\
355 rt_sigmask(SIGSTOP) | rt_sigmask(SIGTSTP) | \
356 rt_sigmask(SIGTTIN) | rt_sigmask(SIGTTOU) )
358 #define SIG_KERNEL_COREDUMP_MASK (\
359 rt_sigmask(SIGQUIT) | rt_sigmask(SIGILL) | \
360 rt_sigmask(SIGTRAP) | rt_sigmask(SIGABRT) | \
361 rt_sigmask(SIGFPE) | rt_sigmask(SIGSEGV) | \
362 rt_sigmask(SIGBUS) | rt_sigmask(SIGSYS) | \
363 rt_sigmask(SIGXCPU) | rt_sigmask(SIGXFSZ) | \
366 #define SIG_KERNEL_IGNORE_MASK (\
367 rt_sigmask(SIGCONT) | rt_sigmask(SIGCHLD) | \
368 rt_sigmask(SIGWINCH) | rt_sigmask(SIGURG) )
370 #define sig_kernel_only(sig) \
371 (((sig) < SIGRTMIN) && siginmask(sig, SIG_KERNEL_ONLY_MASK))
372 #define sig_kernel_coredump(sig) \
373 (((sig) < SIGRTMIN) && siginmask(sig, SIG_KERNEL_COREDUMP_MASK))
374 #define sig_kernel_ignore(sig) \
375 (((sig) < SIGRTMIN) && siginmask(sig, SIG_KERNEL_IGNORE_MASK))
376 #define sig_kernel_stop(sig) \
377 (((sig) < SIGRTMIN) && siginmask(sig, SIG_KERNEL_STOP_MASK))
379 #define sig_user_defined(t, signr) \
380 (((t)->sighand->action[(signr)-1].sa.sa_handler != SIG_DFL) && \
381 ((t)->sighand->action[(signr)-1].sa.sa_handler != SIG_IGN))
383 #define sig_fatal(t, signr) \
384 (!siginmask(signr, SIG_KERNEL_IGNORE_MASK|SIG_KERNEL_STOP_MASK) && \
385 (t)->sighand->action[(signr)-1].sa.sa_handler == SIG_DFL)
387 void signals_init(void);
389 #endif /* __KERNEL__ */
391 #endif /* _LINUX_SIGNAL_H */