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