[PATCH] keys: Permit running process to instantiate keys
[linux-2.6-block.git] / include / linux / signal.h
CommitLineData
1da177e4
LT
1#ifndef _LINUX_SIGNAL_H
2#define _LINUX_SIGNAL_H
3
4#include <linux/list.h>
5#include <linux/spinlock.h>
6#include <asm/signal.h>
7#include <asm/siginfo.h>
8
9#ifdef __KERNEL__
10
7f261b5f
SS
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 */
18#define SA_PROBE SA_ONESHOT
19#define SA_SAMPLE_RANDOM SA_RESTART
20#define SA_SHIRQ 0x04000000
9ded96f2
RK
21/*
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)
7f261b5f 34
1da177e4
LT
35/*
36 * Real Time signals may be queued.
37 */
38
39struct sigqueue {
40 struct list_head list;
1da177e4
LT
41 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
97#define sigmask(sig) (1UL << ((sig) - 1))
98
99#ifndef __HAVE_ARCH_SIG_SETOPS
100#include <linux/string.h>
101
102#define _SIG_SET_BINOP(name, op) \
103static inline void name(sigset_t *r, const sigset_t *a, const sigset_t *b) \
104{ \
105 extern void _NSIG_WORDS_is_unsupported_size(void); \
106 unsigned long a0, a1, a2, a3, b0, b1, b2, b3; \
107 \
108 switch (_NSIG_WORDS) { \
109 case 4: \
110 a3 = a->sig[3]; a2 = a->sig[2]; \
111 b3 = b->sig[3]; b2 = b->sig[2]; \
112 r->sig[3] = op(a3, b3); \
113 r->sig[2] = op(a2, b2); \
114 case 2: \
115 a1 = a->sig[1]; b1 = b->sig[1]; \
116 r->sig[1] = op(a1, b1); \
117 case 1: \
118 a0 = a->sig[0]; b0 = b->sig[0]; \
119 r->sig[0] = op(a0, b0); \
120 break; \
121 default: \
122 _NSIG_WORDS_is_unsupported_size(); \
123 } \
124}
125
126#define _sig_or(x,y) ((x) | (y))
127_SIG_SET_BINOP(sigorsets, _sig_or)
128
129#define _sig_and(x,y) ((x) & (y))
130_SIG_SET_BINOP(sigandsets, _sig_and)
131
132#define _sig_nand(x,y) ((x) & ~(y))
133_SIG_SET_BINOP(signandsets, _sig_nand)
134
135#undef _SIG_SET_BINOP
136#undef _sig_or
137#undef _sig_and
138#undef _sig_nand
139
140#define _SIG_SET_OP(name, op) \
141static inline void name(sigset_t *set) \
142{ \
143 extern void _NSIG_WORDS_is_unsupported_size(void); \
144 \
145 switch (_NSIG_WORDS) { \
146 case 4: set->sig[3] = op(set->sig[3]); \
147 set->sig[2] = op(set->sig[2]); \
148 case 2: set->sig[1] = op(set->sig[1]); \
149 case 1: set->sig[0] = op(set->sig[0]); \
150 break; \
151 default: \
152 _NSIG_WORDS_is_unsupported_size(); \
153 } \
154}
155
156#define _sig_not(x) (~(x))
157_SIG_SET_OP(signotset, _sig_not)
158
159#undef _SIG_SET_OP
160#undef _sig_not
161
162static inline void sigemptyset(sigset_t *set)
163{
164 switch (_NSIG_WORDS) {
165 default:
166 memset(set, 0, sizeof(sigset_t));
167 break;
168 case 2: set->sig[1] = 0;
169 case 1: set->sig[0] = 0;
170 break;
171 }
172}
173
174static inline void sigfillset(sigset_t *set)
175{
176 switch (_NSIG_WORDS) {
177 default:
178 memset(set, -1, sizeof(sigset_t));
179 break;
180 case 2: set->sig[1] = -1;
181 case 1: set->sig[0] = -1;
182 break;
183 }
184}
185
186/* Some extensions for manipulating the low 32 signals in particular. */
187
188static inline void sigaddsetmask(sigset_t *set, unsigned long mask)
189{
190 set->sig[0] |= mask;
191}
192
193static inline void sigdelsetmask(sigset_t *set, unsigned long mask)
194{
195 set->sig[0] &= ~mask;
196}
197
198static inline int sigtestsetmask(sigset_t *set, unsigned long mask)
199{
200 return (set->sig[0] & mask) != 0;
201}
202
203static inline void siginitset(sigset_t *set, unsigned long mask)
204{
205 set->sig[0] = mask;
206 switch (_NSIG_WORDS) {
207 default:
208 memset(&set->sig[1], 0, sizeof(long)*(_NSIG_WORDS-1));
209 break;
210 case 2: set->sig[1] = 0;
211 case 1: ;
212 }
213}
214
215static inline void siginitsetinv(sigset_t *set, unsigned long mask)
216{
217 set->sig[0] = ~mask;
218 switch (_NSIG_WORDS) {
219 default:
220 memset(&set->sig[1], -1, sizeof(long)*(_NSIG_WORDS-1));
221 break;
222 case 2: set->sig[1] = -1;
223 case 1: ;
224 }
225}
226
227#endif /* __HAVE_ARCH_SIG_SETOPS */
228
229static inline void init_sigpending(struct sigpending *sig)
230{
231 sigemptyset(&sig->signal);
232 INIT_LIST_HEAD(&sig->list);
233}
234
e5bdd883
JJ
235/* Test if 'sig' is valid signal. Use this instead of testing _NSIG directly */
236static inline int valid_signal(unsigned long sig)
237{
238 return sig <= _NSIG ? 1 : 0;
239}
240
1da177e4
LT
241extern int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p);
242extern int __group_send_sig_info(int, struct siginfo *, struct task_struct *);
243extern long do_sigpending(void __user *, unsigned long);
244extern int sigprocmask(int, sigset_t *, sigset_t *);
245
1da177e4
LT
246struct pt_regs;
247extern int get_signal_to_deliver(siginfo_t *info, struct k_sigaction *return_ka, struct pt_regs *regs, void *cookie);
1da177e4
LT
248
249#endif /* __KERNEL__ */
250
251#endif /* _LINUX_SIGNAL_H */