blob: 4b42df3860ed8fad44716ecf8f773d4e8dd0ff55 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _LINUX_SIGNAL_H
2#define _LINUX_SIGNAL_H
3
Linus Torvalds1da177e2005-04-16 15:20:36 -07004#include <asm/signal.h>
5#include <asm/siginfo.h>
6
7#ifdef __KERNEL__
David Woodhouse7ab2feb2006-04-25 14:55:46 +01008#include <linux/list.h>
9#include <linux/spinlock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010
11/*
Stas Sergeev7f261b52005-05-01 08:59:02 -070012 * These values of sa_flags are used only by the kernel as part of the
13 * irq handling routines.
14 *
15 * SA_INTERRUPT is also used by the irq handling routines.
16 * SA_SHIRQ is for shared interrupt support on PCI and EISA.
17 */
18#define SA_PROBE SA_ONESHOT
19#define SA_SAMPLE_RANDOM SA_RESTART
20#define SA_SHIRQ 0x04000000
Russell King9ded96f2006-01-08 01:02:07 -080021/*
22 * As above, these correspond to the IORESOURCE_IRQ_* defines in
23 * linux/ioport.h to select the interrupt line behaviour. When
24 * requesting an interrupt without specifying a SA_TRIGGER, the
25 * setting should be assumed to be "as already configured", which
26 * may be as per machine or firmware initialisation.
27 */
28#define SA_TRIGGER_LOW 0x00000008
29#define SA_TRIGGER_HIGH 0x00000004
30#define SA_TRIGGER_FALLING 0x00000002
31#define SA_TRIGGER_RISING 0x00000001
32#define SA_TRIGGER_MASK (SA_TRIGGER_HIGH|SA_TRIGGER_LOW|\
33 SA_TRIGGER_RISING|SA_TRIGGER_FALLING)
Stas Sergeev7f261b52005-05-01 08:59:02 -070034
35/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 * Real Time signals may be queued.
37 */
38
39struct sigqueue {
40 struct list_head list;
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 int flags;
42 siginfo_t info;
43 struct user_struct *user;
44};
45
46/* flags values. */
47#define SIGQUEUE_PREALLOC 1
48
49struct sigpending {
50 struct list_head list;
51 sigset_t signal;
52};
53
54/*
55 * Define some primitives to manipulate sigset_t.
56 */
57
58#ifndef __HAVE_ARCH_SIG_BITOPS
59#include <linux/bitops.h>
60
61/* We don't use <linux/bitops.h> for these because there is no need to
62 be atomic. */
63static inline void sigaddset(sigset_t *set, int _sig)
64{
65 unsigned long sig = _sig - 1;
66 if (_NSIG_WORDS == 1)
67 set->sig[0] |= 1UL << sig;
68 else
69 set->sig[sig / _NSIG_BPW] |= 1UL << (sig % _NSIG_BPW);
70}
71
72static inline void sigdelset(sigset_t *set, int _sig)
73{
74 unsigned long sig = _sig - 1;
75 if (_NSIG_WORDS == 1)
76 set->sig[0] &= ~(1UL << sig);
77 else
78 set->sig[sig / _NSIG_BPW] &= ~(1UL << (sig % _NSIG_BPW));
79}
80
81static inline int sigismember(sigset_t *set, int _sig)
82{
83 unsigned long sig = _sig - 1;
84 if (_NSIG_WORDS == 1)
85 return 1 & (set->sig[0] >> sig);
86 else
87 return 1 & (set->sig[sig / _NSIG_BPW] >> (sig % _NSIG_BPW));
88}
89
90static inline int sigfindinword(unsigned long word)
91{
92 return ffz(~word);
93}
94
95#endif /* __HAVE_ARCH_SIG_BITOPS */
96
George Anzinger71fabd52006-01-08 01:02:48 -080097static inline int sigisemptyset(sigset_t *set)
98{
99 extern void _NSIG_WORDS_is_unsupported_size(void);
100 switch (_NSIG_WORDS) {
101 case 4:
102 return (set->sig[3] | set->sig[2] |
103 set->sig[1] | set->sig[0]) == 0;
104 case 2:
105 return (set->sig[1] | set->sig[0]) == 0;
106 case 1:
107 return set->sig[0] == 0;
108 default:
109 _NSIG_WORDS_is_unsupported_size();
110 return 0;
111 }
112}
113
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114#define sigmask(sig) (1UL << ((sig) - 1))
115
116#ifndef __HAVE_ARCH_SIG_SETOPS
117#include <linux/string.h>
118
119#define _SIG_SET_BINOP(name, op) \
120static inline void name(sigset_t *r, const sigset_t *a, const sigset_t *b) \
121{ \
122 extern void _NSIG_WORDS_is_unsupported_size(void); \
123 unsigned long a0, a1, a2, a3, b0, b1, b2, b3; \
124 \
125 switch (_NSIG_WORDS) { \
126 case 4: \
127 a3 = a->sig[3]; a2 = a->sig[2]; \
128 b3 = b->sig[3]; b2 = b->sig[2]; \
129 r->sig[3] = op(a3, b3); \
130 r->sig[2] = op(a2, b2); \
131 case 2: \
132 a1 = a->sig[1]; b1 = b->sig[1]; \
133 r->sig[1] = op(a1, b1); \
134 case 1: \
135 a0 = a->sig[0]; b0 = b->sig[0]; \
136 r->sig[0] = op(a0, b0); \
137 break; \
138 default: \
139 _NSIG_WORDS_is_unsupported_size(); \
140 } \
141}
142
143#define _sig_or(x,y) ((x) | (y))
144_SIG_SET_BINOP(sigorsets, _sig_or)
145
146#define _sig_and(x,y) ((x) & (y))
147_SIG_SET_BINOP(sigandsets, _sig_and)
148
149#define _sig_nand(x,y) ((x) & ~(y))
150_SIG_SET_BINOP(signandsets, _sig_nand)
151
152#undef _SIG_SET_BINOP
153#undef _sig_or
154#undef _sig_and
155#undef _sig_nand
156
157#define _SIG_SET_OP(name, op) \
158static inline void name(sigset_t *set) \
159{ \
160 extern void _NSIG_WORDS_is_unsupported_size(void); \
161 \
162 switch (_NSIG_WORDS) { \
163 case 4: set->sig[3] = op(set->sig[3]); \
164 set->sig[2] = op(set->sig[2]); \
165 case 2: set->sig[1] = op(set->sig[1]); \
166 case 1: set->sig[0] = op(set->sig[0]); \
167 break; \
168 default: \
169 _NSIG_WORDS_is_unsupported_size(); \
170 } \
171}
172
173#define _sig_not(x) (~(x))
174_SIG_SET_OP(signotset, _sig_not)
175
176#undef _SIG_SET_OP
177#undef _sig_not
178
179static inline void sigemptyset(sigset_t *set)
180{
181 switch (_NSIG_WORDS) {
182 default:
183 memset(set, 0, sizeof(sigset_t));
184 break;
185 case 2: set->sig[1] = 0;
186 case 1: set->sig[0] = 0;
187 break;
188 }
189}
190
191static inline void sigfillset(sigset_t *set)
192{
193 switch (_NSIG_WORDS) {
194 default:
195 memset(set, -1, sizeof(sigset_t));
196 break;
197 case 2: set->sig[1] = -1;
198 case 1: set->sig[0] = -1;
199 break;
200 }
201}
202
203/* Some extensions for manipulating the low 32 signals in particular. */
204
205static inline void sigaddsetmask(sigset_t *set, unsigned long mask)
206{
207 set->sig[0] |= mask;
208}
209
210static inline void sigdelsetmask(sigset_t *set, unsigned long mask)
211{
212 set->sig[0] &= ~mask;
213}
214
215static inline int sigtestsetmask(sigset_t *set, unsigned long mask)
216{
217 return (set->sig[0] & mask) != 0;
218}
219
220static inline void siginitset(sigset_t *set, unsigned long mask)
221{
222 set->sig[0] = mask;
223 switch (_NSIG_WORDS) {
224 default:
225 memset(&set->sig[1], 0, sizeof(long)*(_NSIG_WORDS-1));
226 break;
227 case 2: set->sig[1] = 0;
228 case 1: ;
229 }
230}
231
232static inline void siginitsetinv(sigset_t *set, unsigned long mask)
233{
234 set->sig[0] = ~mask;
235 switch (_NSIG_WORDS) {
236 default:
237 memset(&set->sig[1], -1, sizeof(long)*(_NSIG_WORDS-1));
238 break;
239 case 2: set->sig[1] = -1;
240 case 1: ;
241 }
242}
243
244#endif /* __HAVE_ARCH_SIG_SETOPS */
245
246static inline void init_sigpending(struct sigpending *sig)
247{
248 sigemptyset(&sig->signal);
249 INIT_LIST_HEAD(&sig->list);
250}
251
Oleg Nesterov6a14c5c2006-03-28 16:11:18 -0800252extern void flush_sigqueue(struct sigpending *queue);
253
Jesper Juhle5bdd882005-05-01 08:59:13 -0700254/* Test if 'sig' is valid signal. Use this instead of testing _NSIG directly */
255static inline int valid_signal(unsigned long sig)
256{
257 return sig <= _NSIG ? 1 : 0;
258}
259
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260extern int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p);
261extern int __group_send_sig_info(int, struct siginfo *, struct task_struct *);
262extern long do_sigpending(void __user *, unsigned long);
263extern int sigprocmask(int, sigset_t *, sigset_t *);
264
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265struct pt_regs;
266extern int get_signal_to_deliver(siginfo_t *info, struct k_sigaction *return_ka, struct pt_regs *regs, void *cookie);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
268#endif /* __KERNEL__ */
269
270#endif /* _LINUX_SIGNAL_H */