1 #ifndef _LINUX_SIGNAL_H
2 #define _LINUX_SIGNAL_H
5 #include <linux/signal_types.h>
6 #include <linux/string.h>
11 extern int print_fatal_signals
;
13 static inline void copy_siginfo(struct siginfo
*to
, struct siginfo
*from
)
15 if (from
->si_code
< 0)
16 memcpy(to
, from
, sizeof(*to
));
18 /* _sigchld is currently the largest know union member */
19 memcpy(to
, from
, __ARCH_SI_PREAMBLE_SIZE
+ sizeof(from
->_sifields
._sigchld
));
22 int copy_siginfo_to_user(struct siginfo __user
*to
, const struct siginfo
*from
);
25 * Define some primitives to manipulate sigset_t.
28 #ifndef __HAVE_ARCH_SIG_BITOPS
29 #include <linux/bitops.h>
31 /* We don't use <linux/bitops.h> for these because there is no need to
33 static inline void sigaddset(sigset_t
*set
, int _sig
)
35 unsigned long sig
= _sig
- 1;
37 set
->sig
[0] |= 1UL << sig
;
39 set
->sig
[sig
/ _NSIG_BPW
] |= 1UL << (sig
% _NSIG_BPW
);
42 static inline void sigdelset(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 int sigismember(sigset_t
*set
, int _sig
)
53 unsigned long sig
= _sig
- 1;
55 return 1 & (set
->sig
[0] >> sig
);
57 return 1 & (set
->sig
[sig
/ _NSIG_BPW
] >> (sig
% _NSIG_BPW
));
60 #endif /* __HAVE_ARCH_SIG_BITOPS */
62 static inline int sigisemptyset(sigset_t
*set
)
64 switch (_NSIG_WORDS
) {
66 return (set
->sig
[3] | set
->sig
[2] |
67 set
->sig
[1] | set
->sig
[0]) == 0;
69 return (set
->sig
[1] | set
->sig
[0]) == 0;
71 return set
->sig
[0] == 0;
78 static inline int sigequalsets(const sigset_t
*set1
, const sigset_t
*set2
)
80 switch (_NSIG_WORDS
) {
82 return (set1
->sig
[3] == set2
->sig
[3]) &&
83 (set1
->sig
[2] == set2
->sig
[2]) &&
84 (set1
->sig
[1] == set2
->sig
[1]) &&
85 (set1
->sig
[0] == set2
->sig
[0]);
87 return (set1
->sig
[1] == set2
->sig
[1]) &&
88 (set1
->sig
[0] == set2
->sig
[0]);
90 return set1
->sig
[0] == set2
->sig
[0];
95 #define sigmask(sig) (1UL << ((sig) - 1))
97 #ifndef __HAVE_ARCH_SIG_SETOPS
98 #include <linux/string.h>
100 #define _SIG_SET_BINOP(name, op) \
101 static inline void name(sigset_t *r, const sigset_t *a, const sigset_t *b) \
103 unsigned long a0, a1, a2, a3, b0, b1, b2, b3; \
105 switch (_NSIG_WORDS) { \
107 a3 = a->sig[3]; a2 = a->sig[2]; \
108 b3 = b->sig[3]; b2 = b->sig[2]; \
109 r->sig[3] = op(a3, b3); \
110 r->sig[2] = op(a2, b2); \
112 a1 = a->sig[1]; b1 = b->sig[1]; \
113 r->sig[1] = op(a1, b1); \
115 a0 = a->sig[0]; b0 = b->sig[0]; \
116 r->sig[0] = op(a0, b0); \
123 #define _sig_or(x,y) ((x) | (y))
124 _SIG_SET_BINOP(sigorsets
, _sig_or
)
126 #define _sig_and(x,y) ((x) & (y))
127 _SIG_SET_BINOP(sigandsets
, _sig_and
)
129 #define _sig_andn(x,y) ((x) & ~(y))
130 _SIG_SET_BINOP(sigandnsets
, _sig_andn
)
132 #undef _SIG_SET_BINOP
137 #define _SIG_SET_OP(name, op) \
138 static inline void name(sigset_t *set) \
140 switch (_NSIG_WORDS) { \
141 case 4: set->sig[3] = op(set->sig[3]); \
142 set->sig[2] = op(set->sig[2]); \
143 case 2: set->sig[1] = op(set->sig[1]); \
144 case 1: set->sig[0] = op(set->sig[0]); \
151 #define _sig_not(x) (~(x))
152 _SIG_SET_OP(signotset
, _sig_not
)
157 static inline void sigemptyset(sigset_t
*set
)
159 switch (_NSIG_WORDS
) {
161 memset(set
, 0, sizeof(sigset_t
));
163 case 2: set
->sig
[1] = 0;
164 case 1: set
->sig
[0] = 0;
169 static inline void sigfillset(sigset_t
*set
)
171 switch (_NSIG_WORDS
) {
173 memset(set
, -1, sizeof(sigset_t
));
175 case 2: set
->sig
[1] = -1;
176 case 1: set
->sig
[0] = -1;
181 /* Some extensions for manipulating the low 32 signals in particular. */
183 static inline void sigaddsetmask(sigset_t
*set
, unsigned long mask
)
188 static inline void sigdelsetmask(sigset_t
*set
, unsigned long mask
)
190 set
->sig
[0] &= ~mask
;
193 static inline int sigtestsetmask(sigset_t
*set
, unsigned long mask
)
195 return (set
->sig
[0] & mask
) != 0;
198 static inline void siginitset(sigset_t
*set
, unsigned long mask
)
201 switch (_NSIG_WORDS
) {
203 memset(&set
->sig
[1], 0, sizeof(long)*(_NSIG_WORDS
-1));
205 case 2: set
->sig
[1] = 0;
210 static inline void siginitsetinv(sigset_t
*set
, unsigned long mask
)
213 switch (_NSIG_WORDS
) {
215 memset(&set
->sig
[1], -1, sizeof(long)*(_NSIG_WORDS
-1));
217 case 2: set
->sig
[1] = -1;
222 #endif /* __HAVE_ARCH_SIG_SETOPS */
224 static inline void init_sigpending(struct sigpending
*sig
)
226 sigemptyset(&sig
->signal
);
227 INIT_LIST_HEAD(&sig
->list
);
230 extern void flush_sigqueue(struct sigpending
*queue
);
232 /* Test if 'sig' is valid signal. Use this instead of testing _NSIG directly */
233 static inline int valid_signal(unsigned long sig
)
235 return sig
<= _NSIG
? 1 : 0;
241 extern int next_signal(struct sigpending
*pending
, sigset_t
*mask
);
242 extern int do_send_sig_info(int sig
, struct siginfo
*info
,
243 struct task_struct
*p
, bool group
);
244 extern int group_send_sig_info(int sig
, struct siginfo
*info
, struct task_struct
*p
);
245 extern int __group_send_sig_info(int, struct siginfo
*, struct task_struct
*);
246 extern int sigprocmask(int, sigset_t
*, sigset_t
*);
247 extern void set_current_blocked(sigset_t
*);
248 extern void __set_current_blocked(const sigset_t
*);
249 extern int show_unhandled_signals
;
251 extern int get_signal(struct ksignal
*ksig
);
252 extern void signal_setup_done(int failed
, struct ksignal
*ksig
, int stepping
);
253 extern void exit_signals(struct task_struct
*tsk
);
254 extern void kernel_sigaction(int, __sighandler_t
);
256 static inline void allow_signal(int sig
)
259 * Kernel threads handle their own signals. Let the signal code
260 * know it'll be handled, so that they don't get converted to
261 * SIGKILL or just silently dropped.
263 kernel_sigaction(sig
, (__force __sighandler_t
)2);
266 static inline void disallow_signal(int sig
)
268 kernel_sigaction(sig
, SIG_IGN
);
271 extern struct kmem_cache
*sighand_cachep
;
273 int unhandled_signal(struct task_struct
*tsk
, int sig
);
276 * In POSIX a signal is sent either to a specific thread (Linux task)
277 * or to the process as a whole (Linux thread group). How the signal
278 * is sent determines whether it's to one thread or the whole group,
279 * which determines which signal mask(s) are involved in blocking it
280 * from being delivered until later. When the signal is delivered,
281 * either it's caught or ignored by a user handler or it has a default
282 * effect that applies to the whole thread group (POSIX process).
284 * The possible effects an unblocked signal set to SIG_DFL can have are:
285 * ignore - Nothing Happens
286 * terminate - kill the process, i.e. all threads in the group,
287 * similar to exit_group. The group leader (only) reports
288 * WIFSIGNALED status to its parent.
289 * coredump - write a core dump file describing all threads using
290 * the same mm and then kill all those threads
291 * stop - stop all the threads in the group, i.e. TASK_STOPPED state
293 * SIGKILL and SIGSTOP cannot be caught, blocked, or ignored.
294 * Other signals when not blocked and set to SIG_DFL behaves as follows.
295 * The job control signals also have other special effects.
297 * +--------------------+------------------+
298 * | POSIX signal | default action |
299 * +--------------------+------------------+
300 * | SIGHUP | terminate |
301 * | SIGINT | terminate |
302 * | SIGQUIT | coredump |
303 * | SIGILL | coredump |
304 * | SIGTRAP | coredump |
305 * | SIGABRT/SIGIOT | coredump |
306 * | SIGBUS | coredump |
307 * | SIGFPE | coredump |
308 * | SIGKILL | terminate(+) |
309 * | SIGUSR1 | terminate |
310 * | SIGSEGV | coredump |
311 * | SIGUSR2 | terminate |
312 * | SIGPIPE | terminate |
313 * | SIGALRM | terminate |
314 * | SIGTERM | terminate |
315 * | SIGCHLD | ignore |
316 * | SIGCONT | ignore(*) |
317 * | SIGSTOP | stop(*)(+) |
318 * | SIGTSTP | stop(*) |
319 * | SIGTTIN | stop(*) |
320 * | SIGTTOU | stop(*) |
321 * | SIGURG | ignore |
322 * | SIGXCPU | coredump |
323 * | SIGXFSZ | coredump |
324 * | SIGVTALRM | terminate |
325 * | SIGPROF | terminate |
326 * | SIGPOLL/SIGIO | terminate |
327 * | SIGSYS/SIGUNUSED | coredump |
328 * | SIGSTKFLT | terminate |
329 * | SIGWINCH | ignore |
330 * | SIGPWR | terminate |
331 * | SIGRTMIN-SIGRTMAX | terminate |
332 * +--------------------+------------------+
333 * | non-POSIX signal | default action |
334 * +--------------------+------------------+
335 * | SIGEMT | coredump |
336 * +--------------------+------------------+
338 * (+) For SIGKILL and SIGSTOP the action is "always", not just "default".
339 * (*) Special job control effects:
340 * When SIGCONT is sent, it resumes the process (all threads in the group)
341 * from TASK_STOPPED state and also clears any pending/queued stop signals
342 * (any of those marked with "stop(*)"). This happens regardless of blocking,
343 * catching, or ignoring SIGCONT. When any stop signal is sent, it clears
344 * any pending/queued SIGCONT signals; this happens regardless of blocking,
345 * catching, or ignored the stop signal, though (except for SIGSTOP) the
346 * default action of stopping the process may happen later or never.
350 #define SIGEMT_MASK rt_sigmask(SIGEMT)
352 #define SIGEMT_MASK 0
355 #if SIGRTMIN > BITS_PER_LONG
356 #define rt_sigmask(sig) (1ULL << ((sig)-1))
358 #define rt_sigmask(sig) sigmask(sig)
361 #define siginmask(sig, mask) \
362 ((sig) < SIGRTMIN && (rt_sigmask(sig) & (mask)))
364 #define SIG_KERNEL_ONLY_MASK (\
365 rt_sigmask(SIGKILL) | rt_sigmask(SIGSTOP))
367 #define SIG_KERNEL_STOP_MASK (\
368 rt_sigmask(SIGSTOP) | rt_sigmask(SIGTSTP) | \
369 rt_sigmask(SIGTTIN) | rt_sigmask(SIGTTOU) )
371 #define SIG_KERNEL_COREDUMP_MASK (\
372 rt_sigmask(SIGQUIT) | rt_sigmask(SIGILL) | \
373 rt_sigmask(SIGTRAP) | rt_sigmask(SIGABRT) | \
374 rt_sigmask(SIGFPE) | rt_sigmask(SIGSEGV) | \
375 rt_sigmask(SIGBUS) | rt_sigmask(SIGSYS) | \
376 rt_sigmask(SIGXCPU) | rt_sigmask(SIGXFSZ) | \
379 #define SIG_KERNEL_IGNORE_MASK (\
380 rt_sigmask(SIGCONT) | rt_sigmask(SIGCHLD) | \
381 rt_sigmask(SIGWINCH) | rt_sigmask(SIGURG) )
383 #define sig_kernel_only(sig) siginmask(sig, SIG_KERNEL_ONLY_MASK)
384 #define sig_kernel_coredump(sig) siginmask(sig, SIG_KERNEL_COREDUMP_MASK)
385 #define sig_kernel_ignore(sig) siginmask(sig, SIG_KERNEL_IGNORE_MASK)
386 #define sig_kernel_stop(sig) siginmask(sig, SIG_KERNEL_STOP_MASK)
388 #define sig_fatal(t, signr) \
389 (!siginmask(signr, SIG_KERNEL_IGNORE_MASK|SIG_KERNEL_STOP_MASK) && \
390 (t)->sighand->action[(signr)-1].sa.sa_handler == SIG_DFL)
392 void signals_init(void);
394 int restore_altstack(const stack_t __user
*);
395 int __save_altstack(stack_t __user
*, unsigned long);
397 #define save_altstack_ex(uss, sp) do { \
398 stack_t __user *__uss = uss; \
399 struct task_struct *t = current; \
400 put_user_ex((void __user *)t->sas_ss_sp, &__uss->ss_sp); \
401 put_user_ex(t->sas_ss_flags, &__uss->ss_flags); \
402 put_user_ex(t->sas_ss_size, &__uss->ss_size); \
403 if (t->sas_ss_flags & SS_AUTODISARM) \
407 #ifdef CONFIG_PROC_FS
409 extern void render_sigset_t(struct seq_file
*, const char *, sigset_t
*);
412 #endif /* _LINUX_SIGNAL_H */