]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - include/linux/signal.h
1 #ifndef _LINUX_SIGNAL_H
2 #define _LINUX_SIGNAL_H
4 #include <linux/list.h>
5 #include <uapi/linux/signal.h>
10 extern int print_fatal_signals
;
12 * Real Time signals may be queued.
16 struct list_head list
;
19 struct user_struct
*user
;
23 #define SIGQUEUE_PREALLOC 1
26 struct list_head list
;
31 * Define some primitives to manipulate sigset_t.
34 #ifndef __HAVE_ARCH_SIG_BITOPS
35 #include <linux/bitops.h>
37 /* We don't use <linux/bitops.h> for these because there is no need to
39 static inline void sigaddset(sigset_t
*set
, int _sig
)
41 unsigned long sig
= _sig
- 1;
43 set
->sig
[0] |= 1UL << sig
;
45 set
->sig
[sig
/ _NSIG_BPW
] |= 1UL << (sig
% _NSIG_BPW
);
48 static inline void sigdelset(sigset_t
*set
, int _sig
)
50 unsigned long sig
= _sig
- 1;
52 set
->sig
[0] &= ~(1UL << sig
);
54 set
->sig
[sig
/ _NSIG_BPW
] &= ~(1UL << (sig
% _NSIG_BPW
));
57 static inline int sigismember(sigset_t
*set
, int _sig
)
59 unsigned long sig
= _sig
- 1;
61 return 1 & (set
->sig
[0] >> sig
);
63 return 1 & (set
->sig
[sig
/ _NSIG_BPW
] >> (sig
% _NSIG_BPW
));
66 static inline int sigfindinword(unsigned long word
)
71 #endif /* __HAVE_ARCH_SIG_BITOPS */
73 static inline int sigisemptyset(sigset_t
*set
)
75 extern void _NSIG_WORDS_is_unsupported_size(void);
76 switch (_NSIG_WORDS
) {
78 return (set
->sig
[3] | set
->sig
[2] |
79 set
->sig
[1] | set
->sig
[0]) == 0;
81 return (set
->sig
[1] | set
->sig
[0]) == 0;
83 return set
->sig
[0] == 0;
85 _NSIG_WORDS_is_unsupported_size();
90 #define sigmask(sig) (1UL << ((sig) - 1))
92 #ifndef __HAVE_ARCH_SIG_SETOPS
93 #include <linux/string.h>
95 #define _SIG_SET_BINOP(name, op) \
96 static inline void name(sigset_t *r, const sigset_t *a, const sigset_t *b) \
98 extern void _NSIG_WORDS_is_unsupported_size(void); \
99 unsigned long a0, a1, a2, a3, b0, b1, b2, b3; \
101 switch (_NSIG_WORDS) { \
103 a3 = a->sig[3]; a2 = a->sig[2]; \
104 b3 = b->sig[3]; b2 = b->sig[2]; \
105 r->sig[3] = op(a3, b3); \
106 r->sig[2] = op(a2, b2); \
108 a1 = a->sig[1]; b1 = b->sig[1]; \
109 r->sig[1] = op(a1, b1); \
111 a0 = a->sig[0]; b0 = b->sig[0]; \
112 r->sig[0] = op(a0, b0); \
115 _NSIG_WORDS_is_unsupported_size(); \
119 #define _sig_or(x,y) ((x) | (y))
120 _SIG_SET_BINOP(sigorsets
, _sig_or
)
122 #define _sig_and(x,y) ((x) & (y))
123 _SIG_SET_BINOP(sigandsets
, _sig_and
)
125 #define _sig_andn(x,y) ((x) & ~(y))
126 _SIG_SET_BINOP(sigandnsets
, _sig_andn
)
128 #undef _SIG_SET_BINOP
133 #define _SIG_SET_OP(name, op) \
134 static inline void name(sigset_t *set) \
136 extern void _NSIG_WORDS_is_unsupported_size(void); \
138 switch (_NSIG_WORDS) { \
139 case 4: set->sig[3] = op(set->sig[3]); \
140 set->sig[2] = op(set->sig[2]); \
141 case 2: set->sig[1] = op(set->sig[1]); \
142 case 1: set->sig[0] = op(set->sig[0]); \
145 _NSIG_WORDS_is_unsupported_size(); \
149 #define _sig_not(x) (~(x))
150 _SIG_SET_OP(signotset
, _sig_not
)
155 static inline void sigemptyset(sigset_t
*set
)
157 switch (_NSIG_WORDS
) {
159 memset(set
, 0, sizeof(sigset_t
));
161 case 2: set
->sig
[1] = 0;
162 case 1: set
->sig
[0] = 0;
167 static inline void sigfillset(sigset_t
*set
)
169 switch (_NSIG_WORDS
) {
171 memset(set
, -1, sizeof(sigset_t
));
173 case 2: set
->sig
[1] = -1;
174 case 1: set
->sig
[0] = -1;
179 /* Some extensions for manipulating the low 32 signals in particular. */
181 static inline void sigaddsetmask(sigset_t
*set
, unsigned long mask
)
186 static inline void sigdelsetmask(sigset_t
*set
, unsigned long mask
)
188 set
->sig
[0] &= ~mask
;
191 static inline int sigtestsetmask(sigset_t
*set
, unsigned long mask
)
193 return (set
->sig
[0] & mask
) != 0;
196 static inline void siginitset(sigset_t
*set
, unsigned long mask
)
199 switch (_NSIG_WORDS
) {
201 memset(&set
->sig
[1], 0, sizeof(long)*(_NSIG_WORDS
-1));
203 case 2: set
->sig
[1] = 0;
208 static inline void siginitsetinv(sigset_t
*set
, unsigned long mask
)
211 switch (_NSIG_WORDS
) {
213 memset(&set
->sig
[1], -1, sizeof(long)*(_NSIG_WORDS
-1));
215 case 2: set
->sig
[1] = -1;
220 #endif /* __HAVE_ARCH_SIG_SETOPS */
222 static inline void init_sigpending(struct sigpending
*sig
)
224 sigemptyset(&sig
->signal
);
225 INIT_LIST_HEAD(&sig
->list
);
228 extern void flush_sigqueue(struct sigpending
*queue
);
230 /* Test if 'sig' is valid signal. Use this instead of testing _NSIG directly */
231 static inline int valid_signal(unsigned long sig
)
233 return sig
<= _NSIG
? 1 : 0;
239 extern int next_signal(struct sigpending
*pending
, sigset_t
*mask
);
240 extern int do_send_sig_info(int sig
, struct siginfo
*info
,
241 struct task_struct
*p
, bool group
);
242 extern int group_send_sig_info(int sig
, struct siginfo
*info
, struct task_struct
*p
);
243 extern int __group_send_sig_info(int, struct siginfo
*, struct task_struct
*);
244 extern long do_rt_tgsigqueueinfo(pid_t tgid
, pid_t pid
, int sig
,
246 extern long do_sigpending(void __user
*, unsigned long);
247 extern int do_sigtimedwait(const sigset_t
*, siginfo_t
*,
248 const struct timespec
*);
249 extern int sigprocmask(int, sigset_t
*, sigset_t
*);
250 extern void set_current_blocked(sigset_t
*);
251 extern void __set_current_blocked(const sigset_t
*);
252 extern int show_unhandled_signals
;
253 extern int sigsuspend(sigset_t
*);
255 extern int get_signal_to_deliver(siginfo_t
*info
, struct k_sigaction
*return_ka
, struct pt_regs
*regs
, void *cookie
);
256 extern void signal_delivered(int sig
, siginfo_t
*info
, struct k_sigaction
*ka
, struct pt_regs
*regs
, int stepping
);
257 extern void exit_signals(struct task_struct
*tsk
);
259 extern struct kmem_cache
*sighand_cachep
;
261 int unhandled_signal(struct task_struct
*tsk
, int sig
);
264 * In POSIX a signal is sent either to a specific thread (Linux task)
265 * or to the process as a whole (Linux thread group). How the signal
266 * is sent determines whether it's to one thread or the whole group,
267 * which determines which signal mask(s) are involved in blocking it
268 * from being delivered until later. When the signal is delivered,
269 * either it's caught or ignored by a user handler or it has a default
270 * effect that applies to the whole thread group (POSIX process).
272 * The possible effects an unblocked signal set to SIG_DFL can have are:
273 * ignore - Nothing Happens
274 * terminate - kill the process, i.e. all threads in the group,
275 * similar to exit_group. The group leader (only) reports
276 * WIFSIGNALED status to its parent.
277 * coredump - write a core dump file describing all threads using
278 * the same mm and then kill all those threads
279 * stop - stop all the threads in the group, i.e. TASK_STOPPED state
281 * SIGKILL and SIGSTOP cannot be caught, blocked, or ignored.
282 * Other signals when not blocked and set to SIG_DFL behaves as follows.
283 * The job control signals also have other special effects.
285 * +--------------------+------------------+
286 * | POSIX signal | default action |
287 * +--------------------+------------------+
288 * | SIGHUP | terminate |
289 * | SIGINT | terminate |
290 * | SIGQUIT | coredump |
291 * | SIGILL | coredump |
292 * | SIGTRAP | coredump |
293 * | SIGABRT/SIGIOT | coredump |
294 * | SIGBUS | coredump |
295 * | SIGFPE | coredump |
296 * | SIGKILL | terminate(+) |
297 * | SIGUSR1 | terminate |
298 * | SIGSEGV | coredump |
299 * | SIGUSR2 | terminate |
300 * | SIGPIPE | terminate |
301 * | SIGALRM | terminate |
302 * | SIGTERM | terminate |
303 * | SIGCHLD | ignore |
304 * | SIGCONT | ignore(*) |
305 * | SIGSTOP | stop(*)(+) |
306 * | SIGTSTP | stop(*) |
307 * | SIGTTIN | stop(*) |
308 * | SIGTTOU | stop(*) |
309 * | SIGURG | ignore |
310 * | SIGXCPU | coredump |
311 * | SIGXFSZ | coredump |
312 * | SIGVTALRM | terminate |
313 * | SIGPROF | terminate |
314 * | SIGPOLL/SIGIO | terminate |
315 * | SIGSYS/SIGUNUSED | coredump |
316 * | SIGSTKFLT | terminate |
317 * | SIGWINCH | ignore |
318 * | SIGPWR | terminate |
319 * | SIGRTMIN-SIGRTMAX | terminate |
320 * +--------------------+------------------+
321 * | non-POSIX signal | default action |
322 * +--------------------+------------------+
323 * | SIGEMT | coredump |
324 * +--------------------+------------------+
326 * (+) For SIGKILL and SIGSTOP the action is "always", not just "default".
327 * (*) Special job control effects:
328 * When SIGCONT is sent, it resumes the process (all threads in the group)
329 * from TASK_STOPPED state and also clears any pending/queued stop signals
330 * (any of those marked with "stop(*)"). This happens regardless of blocking,
331 * catching, or ignoring SIGCONT. When any stop signal is sent, it clears
332 * any pending/queued SIGCONT signals; this happens regardless of blocking,
333 * catching, or ignored the stop signal, though (except for SIGSTOP) the
334 * default action of stopping the process may happen later or never.
338 #define SIGEMT_MASK rt_sigmask(SIGEMT)
340 #define SIGEMT_MASK 0
343 #if SIGRTMIN > BITS_PER_LONG
344 #define rt_sigmask(sig) (1ULL << ((sig)-1))
346 #define rt_sigmask(sig) sigmask(sig)
348 #define siginmask(sig, mask) (rt_sigmask(sig) & (mask))
350 #define SIG_KERNEL_ONLY_MASK (\
351 rt_sigmask(SIGKILL) | rt_sigmask(SIGSTOP))
353 #define SIG_KERNEL_STOP_MASK (\
354 rt_sigmask(SIGSTOP) | rt_sigmask(SIGTSTP) | \
355 rt_sigmask(SIGTTIN) | rt_sigmask(SIGTTOU) )
357 #define SIG_KERNEL_COREDUMP_MASK (\
358 rt_sigmask(SIGQUIT) | rt_sigmask(SIGILL) | \
359 rt_sigmask(SIGTRAP) | rt_sigmask(SIGABRT) | \
360 rt_sigmask(SIGFPE) | rt_sigmask(SIGSEGV) | \
361 rt_sigmask(SIGBUS) | rt_sigmask(SIGSYS) | \
362 rt_sigmask(SIGXCPU) | rt_sigmask(SIGXFSZ) | \
365 #define SIG_KERNEL_IGNORE_MASK (\
366 rt_sigmask(SIGCONT) | rt_sigmask(SIGCHLD) | \
367 rt_sigmask(SIGWINCH) | rt_sigmask(SIGURG) )
369 #define sig_kernel_only(sig) \
370 (((sig) < SIGRTMIN) && siginmask(sig, SIG_KERNEL_ONLY_MASK))
371 #define sig_kernel_coredump(sig) \
372 (((sig) < SIGRTMIN) && siginmask(sig, SIG_KERNEL_COREDUMP_MASK))
373 #define sig_kernel_ignore(sig) \
374 (((sig) < SIGRTMIN) && siginmask(sig, SIG_KERNEL_IGNORE_MASK))
375 #define sig_kernel_stop(sig) \
376 (((sig) < SIGRTMIN) && siginmask(sig, SIG_KERNEL_STOP_MASK))
378 #define sig_user_defined(t, signr) \
379 (((t)->sighand->action[(signr)-1].sa.sa_handler != SIG_DFL) && \
380 ((t)->sighand->action[(signr)-1].sa.sa_handler != SIG_IGN))
382 #define sig_fatal(t, signr) \
383 (!siginmask(signr, SIG_KERNEL_IGNORE_MASK|SIG_KERNEL_STOP_MASK) && \
384 (t)->sighand->action[(signr)-1].sa.sa_handler == SIG_DFL)
386 void signals_init(void);
388 int restore_altstack(const stack_t __user
*);
389 int __save_altstack(stack_t __user
*, unsigned long);
391 #endif /* _LINUX_SIGNAL_H */