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