]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - include/linux/signal.h
Linux-2.6.12-rc2
[mirror_ubuntu-artful-kernel.git] / include / linux / signal.h
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
11 /*
12 * Real Time signals may be queued.
13 */
14
15 struct sigqueue {
16 struct list_head list;
17 spinlock_t *lock;
18 int flags;
19 siginfo_t info;
20 struct user_struct *user;
21 };
22
23 /* flags values. */
24 #define SIGQUEUE_PREALLOC 1
25
26 struct sigpending {
27 struct list_head list;
28 sigset_t signal;
29 };
30
31 /*
32 * Define some primitives to manipulate sigset_t.
33 */
34
35 #ifndef __HAVE_ARCH_SIG_BITOPS
36 #include <linux/bitops.h>
37
38 /* We don't use <linux/bitops.h> for these because there is no need to
39 be atomic. */
40 static inline void sigaddset(sigset_t *set, int _sig)
41 {
42 unsigned long sig = _sig - 1;
43 if (_NSIG_WORDS == 1)
44 set->sig[0] |= 1UL << sig;
45 else
46 set->sig[sig / _NSIG_BPW] |= 1UL << (sig % _NSIG_BPW);
47 }
48
49 static inline void sigdelset(sigset_t *set, int _sig)
50 {
51 unsigned long sig = _sig - 1;
52 if (_NSIG_WORDS == 1)
53 set->sig[0] &= ~(1UL << sig);
54 else
55 set->sig[sig / _NSIG_BPW] &= ~(1UL << (sig % _NSIG_BPW));
56 }
57
58 static inline int sigismember(sigset_t *set, int _sig)
59 {
60 unsigned long sig = _sig - 1;
61 if (_NSIG_WORDS == 1)
62 return 1 & (set->sig[0] >> sig);
63 else
64 return 1 & (set->sig[sig / _NSIG_BPW] >> (sig % _NSIG_BPW));
65 }
66
67 static inline int sigfindinword(unsigned long word)
68 {
69 return ffz(~word);
70 }
71
72 #endif /* __HAVE_ARCH_SIG_BITOPS */
73
74 #define sigmask(sig) (1UL << ((sig) - 1))
75
76 #ifndef __HAVE_ARCH_SIG_SETOPS
77 #include <linux/string.h>
78
79 #define _SIG_SET_BINOP(name, op) \
80 static inline void name(sigset_t *r, const sigset_t *a, const sigset_t *b) \
81 { \
82 extern void _NSIG_WORDS_is_unsupported_size(void); \
83 unsigned long a0, a1, a2, a3, b0, b1, b2, b3; \
84 \
85 switch (_NSIG_WORDS) { \
86 case 4: \
87 a3 = a->sig[3]; a2 = a->sig[2]; \
88 b3 = b->sig[3]; b2 = b->sig[2]; \
89 r->sig[3] = op(a3, b3); \
90 r->sig[2] = op(a2, b2); \
91 case 2: \
92 a1 = a->sig[1]; b1 = b->sig[1]; \
93 r->sig[1] = op(a1, b1); \
94 case 1: \
95 a0 = a->sig[0]; b0 = b->sig[0]; \
96 r->sig[0] = op(a0, b0); \
97 break; \
98 default: \
99 _NSIG_WORDS_is_unsupported_size(); \
100 } \
101 }
102
103 #define _sig_or(x,y) ((x) | (y))
104 _SIG_SET_BINOP(sigorsets, _sig_or)
105
106 #define _sig_and(x,y) ((x) & (y))
107 _SIG_SET_BINOP(sigandsets, _sig_and)
108
109 #define _sig_nand(x,y) ((x) & ~(y))
110 _SIG_SET_BINOP(signandsets, _sig_nand)
111
112 #undef _SIG_SET_BINOP
113 #undef _sig_or
114 #undef _sig_and
115 #undef _sig_nand
116
117 #define _SIG_SET_OP(name, op) \
118 static inline void name(sigset_t *set) \
119 { \
120 extern void _NSIG_WORDS_is_unsupported_size(void); \
121 \
122 switch (_NSIG_WORDS) { \
123 case 4: set->sig[3] = op(set->sig[3]); \
124 set->sig[2] = op(set->sig[2]); \
125 case 2: set->sig[1] = op(set->sig[1]); \
126 case 1: set->sig[0] = op(set->sig[0]); \
127 break; \
128 default: \
129 _NSIG_WORDS_is_unsupported_size(); \
130 } \
131 }
132
133 #define _sig_not(x) (~(x))
134 _SIG_SET_OP(signotset, _sig_not)
135
136 #undef _SIG_SET_OP
137 #undef _sig_not
138
139 static inline void sigemptyset(sigset_t *set)
140 {
141 switch (_NSIG_WORDS) {
142 default:
143 memset(set, 0, sizeof(sigset_t));
144 break;
145 case 2: set->sig[1] = 0;
146 case 1: set->sig[0] = 0;
147 break;
148 }
149 }
150
151 static inline void sigfillset(sigset_t *set)
152 {
153 switch (_NSIG_WORDS) {
154 default:
155 memset(set, -1, sizeof(sigset_t));
156 break;
157 case 2: set->sig[1] = -1;
158 case 1: set->sig[0] = -1;
159 break;
160 }
161 }
162
163 /* Some extensions for manipulating the low 32 signals in particular. */
164
165 static inline void sigaddsetmask(sigset_t *set, unsigned long mask)
166 {
167 set->sig[0] |= mask;
168 }
169
170 static inline void sigdelsetmask(sigset_t *set, unsigned long mask)
171 {
172 set->sig[0] &= ~mask;
173 }
174
175 static inline int sigtestsetmask(sigset_t *set, unsigned long mask)
176 {
177 return (set->sig[0] & mask) != 0;
178 }
179
180 static inline void siginitset(sigset_t *set, unsigned long mask)
181 {
182 set->sig[0] = mask;
183 switch (_NSIG_WORDS) {
184 default:
185 memset(&set->sig[1], 0, sizeof(long)*(_NSIG_WORDS-1));
186 break;
187 case 2: set->sig[1] = 0;
188 case 1: ;
189 }
190 }
191
192 static inline void siginitsetinv(sigset_t *set, unsigned long mask)
193 {
194 set->sig[0] = ~mask;
195 switch (_NSIG_WORDS) {
196 default:
197 memset(&set->sig[1], -1, sizeof(long)*(_NSIG_WORDS-1));
198 break;
199 case 2: set->sig[1] = -1;
200 case 1: ;
201 }
202 }
203
204 #endif /* __HAVE_ARCH_SIG_SETOPS */
205
206 static inline void init_sigpending(struct sigpending *sig)
207 {
208 sigemptyset(&sig->signal);
209 INIT_LIST_HEAD(&sig->list);
210 }
211
212 extern int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p);
213 extern int __group_send_sig_info(int, struct siginfo *, struct task_struct *);
214 extern long do_sigpending(void __user *, unsigned long);
215 extern int sigprocmask(int, sigset_t *, sigset_t *);
216
217 #ifndef HAVE_ARCH_GET_SIGNAL_TO_DELIVER
218 struct pt_regs;
219 extern int get_signal_to_deliver(siginfo_t *info, struct k_sigaction *return_ka, struct pt_regs *regs, void *cookie);
220 #endif
221
222 #endif /* __KERNEL__ */
223
224 #endif /* _LINUX_SIGNAL_H */