Linux 2.6.33-rc2
[pohmelfs.git] / include / linux / signal.h
blobab9272cc270c2a4b4f5a8c0d0d479f3eceeeb32d
1 #ifndef _LINUX_SIGNAL_H
2 #define _LINUX_SIGNAL_H
4 #include <asm/signal.h>
5 #include <asm/siginfo.h>
7 #ifdef __KERNEL__
8 #include <linux/list.h>
11 * Real Time signals may be queued.
14 struct sigqueue {
15 struct list_head list;
16 int flags;
17 siginfo_t info;
18 struct user_struct *user;
21 /* flags values. */
22 #define SIGQUEUE_PREALLOC 1
24 struct sigpending {
25 struct list_head list;
26 sigset_t signal;
30 * Define some primitives to manipulate sigset_t.
33 #ifndef __HAVE_ARCH_SIG_BITOPS
34 #include <linux/bitops.h>
36 /* We don't use <linux/bitops.h> for these because there is no need to
37 be atomic. */
38 static inline void sigaddset(sigset_t *set, int _sig)
40 unsigned long sig = _sig - 1;
41 if (_NSIG_WORDS == 1)
42 set->sig[0] |= 1UL << sig;
43 else
44 set->sig[sig / _NSIG_BPW] |= 1UL << (sig % _NSIG_BPW);
47 static inline void sigdelset(sigset_t *set, int _sig)
49 unsigned long sig = _sig - 1;
50 if (_NSIG_WORDS == 1)
51 set->sig[0] &= ~(1UL << sig);
52 else
53 set->sig[sig / _NSIG_BPW] &= ~(1UL << (sig % _NSIG_BPW));
56 static inline int sigismember(sigset_t *set, int _sig)
58 unsigned long sig = _sig - 1;
59 if (_NSIG_WORDS == 1)
60 return 1 & (set->sig[0] >> sig);
61 else
62 return 1 & (set->sig[sig / _NSIG_BPW] >> (sig % _NSIG_BPW));
65 static inline int sigfindinword(unsigned long word)
67 return ffz(~word);
70 #endif /* __HAVE_ARCH_SIG_BITOPS */
72 static inline int sigisemptyset(sigset_t *set)
74 extern void _NSIG_WORDS_is_unsupported_size(void);
75 switch (_NSIG_WORDS) {
76 case 4:
77 return (set->sig[3] | set->sig[2] |
78 set->sig[1] | set->sig[0]) == 0;
79 case 2:
80 return (set->sig[1] | set->sig[0]) == 0;
81 case 1:
82 return set->sig[0] == 0;
83 default:
84 _NSIG_WORDS_is_unsupported_size();
85 return 0;
89 #define sigmask(sig) (1UL << ((sig) - 1))
91 #ifndef __HAVE_ARCH_SIG_SETOPS
92 #include <linux/string.h>
94 #define _SIG_SET_BINOP(name, op) \
95 static inline void name(sigset_t *r, const sigset_t *a, const sigset_t *b) \
96 { \
97 extern void _NSIG_WORDS_is_unsupported_size(void); \
98 unsigned long a0, a1, a2, a3, b0, b1, b2, b3; \
100 switch (_NSIG_WORDS) { \
101 case 4: \
102 a3 = a->sig[3]; a2 = a->sig[2]; \
103 b3 = b->sig[3]; b2 = b->sig[2]; \
104 r->sig[3] = op(a3, b3); \
105 r->sig[2] = op(a2, b2); \
106 case 2: \
107 a1 = a->sig[1]; b1 = b->sig[1]; \
108 r->sig[1] = op(a1, b1); \
109 case 1: \
110 a0 = a->sig[0]; b0 = b->sig[0]; \
111 r->sig[0] = op(a0, b0); \
112 break; \
113 default: \
114 _NSIG_WORDS_is_unsupported_size(); \
118 #define _sig_or(x,y) ((x) | (y))
119 _SIG_SET_BINOP(sigorsets, _sig_or)
121 #define _sig_and(x,y) ((x) & (y))
122 _SIG_SET_BINOP(sigandsets, _sig_and)
124 #define _sig_nand(x,y) ((x) & ~(y))
125 _SIG_SET_BINOP(signandsets, _sig_nand)
127 #undef _SIG_SET_BINOP
128 #undef _sig_or
129 #undef _sig_and
130 #undef _sig_nand
132 #define _SIG_SET_OP(name, op) \
133 static inline void name(sigset_t *set) \
135 extern void _NSIG_WORDS_is_unsupported_size(void); \
137 switch (_NSIG_WORDS) { \
138 case 4: set->sig[3] = op(set->sig[3]); \
139 set->sig[2] = op(set->sig[2]); \
140 case 2: set->sig[1] = op(set->sig[1]); \
141 case 1: set->sig[0] = op(set->sig[0]); \
142 break; \
143 default: \
144 _NSIG_WORDS_is_unsupported_size(); \
148 #define _sig_not(x) (~(x))
149 _SIG_SET_OP(signotset, _sig_not)
151 #undef _SIG_SET_OP
152 #undef _sig_not
154 static inline void sigemptyset(sigset_t *set)
156 switch (_NSIG_WORDS) {
157 default:
158 memset(set, 0, sizeof(sigset_t));
159 break;
160 case 2: set->sig[1] = 0;
161 case 1: set->sig[0] = 0;
162 break;
166 static inline void sigfillset(sigset_t *set)
168 switch (_NSIG_WORDS) {
169 default:
170 memset(set, -1, sizeof(sigset_t));
171 break;
172 case 2: set->sig[1] = -1;
173 case 1: set->sig[0] = -1;
174 break;
178 /* Some extensions for manipulating the low 32 signals in particular. */
180 static inline void sigaddsetmask(sigset_t *set, unsigned long mask)
182 set->sig[0] |= mask;
185 static inline void sigdelsetmask(sigset_t *set, unsigned long mask)
187 set->sig[0] &= ~mask;
190 static inline int sigtestsetmask(sigset_t *set, unsigned long mask)
192 return (set->sig[0] & mask) != 0;
195 static inline void siginitset(sigset_t *set, unsigned long mask)
197 set->sig[0] = mask;
198 switch (_NSIG_WORDS) {
199 default:
200 memset(&set->sig[1], 0, sizeof(long)*(_NSIG_WORDS-1));
201 break;
202 case 2: set->sig[1] = 0;
203 case 1: ;
207 static inline void siginitsetinv(sigset_t *set, unsigned long mask)
209 set->sig[0] = ~mask;
210 switch (_NSIG_WORDS) {
211 default:
212 memset(&set->sig[1], -1, sizeof(long)*(_NSIG_WORDS-1));
213 break;
214 case 2: set->sig[1] = -1;
215 case 1: ;
219 #endif /* __HAVE_ARCH_SIG_SETOPS */
221 static inline void init_sigpending(struct sigpending *sig)
223 sigemptyset(&sig->signal);
224 INIT_LIST_HEAD(&sig->list);
227 extern void flush_sigqueue(struct sigpending *queue);
229 /* Test if 'sig' is valid signal. Use this instead of testing _NSIG directly */
230 static inline int valid_signal(unsigned long sig)
232 return sig <= _NSIG ? 1 : 0;
235 extern int next_signal(struct sigpending *pending, sigset_t *mask);
236 extern int do_send_sig_info(int sig, struct siginfo *info,
237 struct task_struct *p, bool group);
238 extern int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p);
239 extern int __group_send_sig_info(int, struct siginfo *, struct task_struct *);
240 extern long do_rt_tgsigqueueinfo(pid_t tgid, pid_t pid, int sig,
241 siginfo_t *info);
242 extern long do_sigpending(void __user *, unsigned long);
243 extern int sigprocmask(int, sigset_t *, sigset_t *);
244 extern int show_unhandled_signals;
246 struct pt_regs;
247 extern int get_signal_to_deliver(siginfo_t *info, struct k_sigaction *return_ka, struct pt_regs *regs, void *cookie);
248 extern void exit_signals(struct task_struct *tsk);
250 extern struct kmem_cache *sighand_cachep;
252 int unhandled_signal(struct task_struct *tsk, int sig);
255 * In POSIX a signal is sent either to a specific thread (Linux task)
256 * or to the process as a whole (Linux thread group). How the signal
257 * is sent determines whether it's to one thread or the whole group,
258 * which determines which signal mask(s) are involved in blocking it
259 * from being delivered until later. When the signal is delivered,
260 * either it's caught or ignored by a user handler or it has a default
261 * effect that applies to the whole thread group (POSIX process).
263 * The possible effects an unblocked signal set to SIG_DFL can have are:
264 * ignore - Nothing Happens
265 * terminate - kill the process, i.e. all threads in the group,
266 * similar to exit_group. The group leader (only) reports
267 * WIFSIGNALED status to its parent.
268 * coredump - write a core dump file describing all threads using
269 * the same mm and then kill all those threads
270 * stop - stop all the threads in the group, i.e. TASK_STOPPED state
272 * SIGKILL and SIGSTOP cannot be caught, blocked, or ignored.
273 * Other signals when not blocked and set to SIG_DFL behaves as follows.
274 * The job control signals also have other special effects.
276 * +--------------------+------------------+
277 * | POSIX signal | default action |
278 * +--------------------+------------------+
279 * | SIGHUP | terminate |
280 * | SIGINT | terminate |
281 * | SIGQUIT | coredump |
282 * | SIGILL | coredump |
283 * | SIGTRAP | coredump |
284 * | SIGABRT/SIGIOT | coredump |
285 * | SIGBUS | coredump |
286 * | SIGFPE | coredump |
287 * | SIGKILL | terminate(+) |
288 * | SIGUSR1 | terminate |
289 * | SIGSEGV | coredump |
290 * | SIGUSR2 | terminate |
291 * | SIGPIPE | terminate |
292 * | SIGALRM | terminate |
293 * | SIGTERM | terminate |
294 * | SIGCHLD | ignore |
295 * | SIGCONT | ignore(*) |
296 * | SIGSTOP | stop(*)(+) |
297 * | SIGTSTP | stop(*) |
298 * | SIGTTIN | stop(*) |
299 * | SIGTTOU | stop(*) |
300 * | SIGURG | ignore |
301 * | SIGXCPU | coredump |
302 * | SIGXFSZ | coredump |
303 * | SIGVTALRM | terminate |
304 * | SIGPROF | terminate |
305 * | SIGPOLL/SIGIO | terminate |
306 * | SIGSYS/SIGUNUSED | coredump |
307 * | SIGSTKFLT | terminate |
308 * | SIGWINCH | ignore |
309 * | SIGPWR | terminate |
310 * | SIGRTMIN-SIGRTMAX | terminate |
311 * +--------------------+------------------+
312 * | non-POSIX signal | default action |
313 * +--------------------+------------------+
314 * | SIGEMT | coredump |
315 * +--------------------+------------------+
317 * (+) For SIGKILL and SIGSTOP the action is "always", not just "default".
318 * (*) Special job control effects:
319 * When SIGCONT is sent, it resumes the process (all threads in the group)
320 * from TASK_STOPPED state and also clears any pending/queued stop signals
321 * (any of those marked with "stop(*)"). This happens regardless of blocking,
322 * catching, or ignoring SIGCONT. When any stop signal is sent, it clears
323 * any pending/queued SIGCONT signals; this happens regardless of blocking,
324 * catching, or ignored the stop signal, though (except for SIGSTOP) the
325 * default action of stopping the process may happen later or never.
328 #ifdef SIGEMT
329 #define SIGEMT_MASK rt_sigmask(SIGEMT)
330 #else
331 #define SIGEMT_MASK 0
332 #endif
334 #if SIGRTMIN > BITS_PER_LONG
335 #define rt_sigmask(sig) (1ULL << ((sig)-1))
336 #else
337 #define rt_sigmask(sig) sigmask(sig)
338 #endif
339 #define siginmask(sig, mask) (rt_sigmask(sig) & (mask))
341 #define SIG_KERNEL_ONLY_MASK (\
342 rt_sigmask(SIGKILL) | rt_sigmask(SIGSTOP))
344 #define SIG_KERNEL_STOP_MASK (\
345 rt_sigmask(SIGSTOP) | rt_sigmask(SIGTSTP) | \
346 rt_sigmask(SIGTTIN) | rt_sigmask(SIGTTOU) )
348 #define SIG_KERNEL_COREDUMP_MASK (\
349 rt_sigmask(SIGQUIT) | rt_sigmask(SIGILL) | \
350 rt_sigmask(SIGTRAP) | rt_sigmask(SIGABRT) | \
351 rt_sigmask(SIGFPE) | rt_sigmask(SIGSEGV) | \
352 rt_sigmask(SIGBUS) | rt_sigmask(SIGSYS) | \
353 rt_sigmask(SIGXCPU) | rt_sigmask(SIGXFSZ) | \
354 SIGEMT_MASK )
356 #define SIG_KERNEL_IGNORE_MASK (\
357 rt_sigmask(SIGCONT) | rt_sigmask(SIGCHLD) | \
358 rt_sigmask(SIGWINCH) | rt_sigmask(SIGURG) )
360 #define sig_kernel_only(sig) \
361 (((sig) < SIGRTMIN) && siginmask(sig, SIG_KERNEL_ONLY_MASK))
362 #define sig_kernel_coredump(sig) \
363 (((sig) < SIGRTMIN) && siginmask(sig, SIG_KERNEL_COREDUMP_MASK))
364 #define sig_kernel_ignore(sig) \
365 (((sig) < SIGRTMIN) && siginmask(sig, SIG_KERNEL_IGNORE_MASK))
366 #define sig_kernel_stop(sig) \
367 (((sig) < SIGRTMIN) && siginmask(sig, SIG_KERNEL_STOP_MASK))
369 #define sig_user_defined(t, signr) \
370 (((t)->sighand->action[(signr)-1].sa.sa_handler != SIG_DFL) && \
371 ((t)->sighand->action[(signr)-1].sa.sa_handler != SIG_IGN))
373 #define sig_fatal(t, signr) \
374 (!siginmask(signr, SIG_KERNEL_IGNORE_MASK|SIG_KERNEL_STOP_MASK) && \
375 (t)->sighand->action[(signr)-1].sa.sa_handler == SIG_DFL)
377 void signals_init(void);
379 #endif /* __KERNEL__ */
381 #endif /* _LINUX_SIGNAL_H */