1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 * Copyright 2015, Joyent, Inc.
26 */
27
28 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
29 /* All Rights Reserved */
30
31 /*
32 * University Copyright- Copyright (c) 1982, 1986, 1988
33 * The Regents of the University of California
34 * All Rights Reserved
35 *
36 * University Acknowledgment- Portions of this document are derived from
37 * software developed by the University of California, Berkeley, and its
38 * contributors.
39 */
40
41 #ifndef _SYS_SIGNAL_H
42 #define _SYS_SIGNAL_H
43
44 #include <sys/feature_tests.h>
45 #include <sys/iso/signal_iso.h>
46
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50
51 #if defined(__EXTENSIONS__) || defined(_KERNEL) || !defined(_STRICT_STDC) || \
52 defined(__XOPEN_OR_POSIX)
53
54 #if defined(__EXTENSIONS__) || defined(_KERNEL) || \
55 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
56 (_POSIX_C_SOURCE > 2) || defined(_XPG4_2)
57 /*
58 * We need <sys/siginfo.h> for the declaration of siginfo_t.
59 */
60 #include <sys/siginfo.h>
61 #endif
62
63 /* Duplicated in <sys/ucontext.h> as a result of XPG4v2 requirements */
64 #ifndef _SIGSET_T
65 #define _SIGSET_T
66 typedef struct { /* signal set type */
67 unsigned int __sigbits[4];
68 } sigset_t;
69 #endif /* _SIGSET_T */
70
71 typedef struct {
72 unsigned int __sigbits[3];
73 } k_sigset_t;
74
75 /*
76 * The signal handler routine can have either one or three arguments.
77 * Existing C code has used either form so not specifing the arguments
78 * neatly finesses the problem. C++ doesn't accept this. To C++
79 * "(*sa_handler)()" indicates a routine with no arguments (ANSI C would
80 * specify this as "(*sa_handler)(void)"). One or the other form must be
81 * used for C++ and the only logical choice is "(*sa_handler)(int)" to allow
82 * the SIG_* defines to work. "(*sa_sigaction)(int, siginfo_t *, void *)"
83 * can be used for the three argument form.
84 */
85
86 /*
87 * Note: storage overlap by sa_handler and sa_sigaction
88 */
89 struct sigaction {
90 int sa_flags;
91 union {
92 #ifdef __cplusplus
93 void (*_handler)(int);
94 #else
95 void (*_handler)();
96 #endif
97 #if defined(__EXTENSIONS__) || defined(_KERNEL) || \
98 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
99 (_POSIX_C_SOURCE > 2) || defined(_XPG4_2)
100 void (*_sigaction)(int, siginfo_t *, void *);
101 #endif
102 } _funcptr;
103 sigset_t sa_mask;
104 #ifndef _LP64
105 int sa_resv[2];
106 #endif
107 };
108 #define sa_handler _funcptr._handler
109 #define sa_sigaction _funcptr._sigaction
110
111 #if defined(_SYSCALL32)
112
113 /* Kernel view of the ILP32 user sigaction structure */
114
115 struct sigaction32 {
116 int32_t sa_flags;
117 union {
118 caddr32_t _handler;
119 caddr32_t _sigaction;
120 } _funcptr;
121 sigset_t sa_mask;
122 int32_t sa_resv[2];
123 };
124
125 #endif /* _SYSCALL32 */
126
127 /* this is only valid for SIGCLD */
128 #define SA_NOCLDSTOP 0x00020000 /* don't send job control SIGCLD's */
129 #endif
130
131 #if defined(__EXTENSIONS__) || defined(_KERNEL) || \
132 (!defined(_STRICT_STDC) && !defined(_POSIX_C_SOURCE)) || \
133 defined(_XPG4_2)
134
135 /* non-conformant ANSI compilation */
136
137 /* definitions for the sa_flags field */
138 #define SA_ONSTACK 0x00000001
139 #define SA_RESETHAND 0x00000002
140 #define SA_RESTART 0x00000004
141 #endif
142
143 #if defined(__EXTENSIONS__) || defined(_KERNEL) || \
144 (!defined(_STRICT_STDC) && !defined(_POSIX_C_SOURCE)) || \
145 (_POSIX_C_SOURCE > 2) || defined(_XPG4_2)
146 #define SA_SIGINFO 0x00000008
147 #endif
148
149 #if defined(__EXTENSIONS__) || defined(_KERNEL) || \
150 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
151 defined(_XPG4_2)
152 #define SA_NODEFER 0x00000010
153
154 /* this is only valid for SIGCLD */
155 #define SA_NOCLDWAIT 0x00010000 /* don't save zombie children */
156
157 #if defined(__EXTENSIONS__) || !defined(_XPG4_2)
158 /*
159 * use of these symbols by applications is injurious
160 * to binary compatibility
161 */
162 #define NSIG 75 /* valid signals range from 1 to NSIG-1 */
163 #define MAXSIG 74 /* size of u_signal[], NSIG-1 <= MAXSIG */
164 #endif /* defined(__EXTENSIONS__) || !defined(_XPG4_2) */
165
166 #define MINSIGSTKSZ 2048
167 #define SIGSTKSZ 8192
168
169 #define SS_ONSTACK 0x00000001
170 #define SS_DISABLE 0x00000002
171
172 /* Duplicated in <sys/ucontext.h> as a result of XPG4v2 requirements. */
173 #ifndef _STACK_T
174 #define _STACK_T
175 #if defined(__EXTENSIONS__) || !defined(_XPG4_2)
176 typedef struct sigaltstack {
177 #else
178 typedef struct {
179 #endif
180 void *ss_sp;
181 size_t ss_size;
182 int ss_flags;
183 } stack_t;
184
185 #if defined(_SYSCALL32)
186
187 /* Kernel view of the ILP32 user sigaltstack structure */
188
189 typedef struct sigaltstack32 {
190 caddr32_t ss_sp;
191 size32_t ss_size;
192 int32_t ss_flags;
193 } stack32_t;
194
195 #endif /* _SYSCALL32 */
196
197 #endif /* _STACK_T */
198
199 #endif /* defined(__EXTENSIONS__) || defined(_KERNEL) ... */
200
201 #if defined(__EXTENSIONS__) || defined(_KERNEL) || \
202 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX))
203
204 /* signotify id used only by libc for mq_notify()/aio_notify() */
205 typedef struct signotify_id { /* signotify id struct */
206 pid_t sn_pid; /* pid of proc to be notified */
207 int sn_index; /* index in preallocated pool */
208 int sn_pad; /* reserved */
209 } signotify_id_t;
210
211 #if defined(_SYSCALL32)
212
213 /* Kernel view of the ILP32 user signotify_id structure */
214
215 typedef struct signotify32_id {
216 pid32_t sn_pid; /* pid of proc to be notified */
217 int32_t sn_index; /* index in preallocated pool */
218 int32_t sn_pad; /* reserved */
219 } signotify32_id_t;
220
221 #endif /* _SYSCALL32 */
222
223 /* Command codes for sig_notify call */
224
225 #define SN_PROC 1 /* queue signotify for process */
226 #define SN_CANCEL 2 /* cancel the queued signotify */
227 #define SN_SEND 3 /* send the notified signal */
228
229 #endif /* defined(__EXTENSIONS__) || defined(_KERNEL) ... */
230
231 /* Added as per XPG4v2 */
232 #if defined(__EXTENSIONS__) || defined(_KERNEL) || \
233 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
234 defined(_XPG4_2)
235 struct sigstack {
236 void *ss_sp;
237 int ss_onstack;
238 };
239 #endif /* defined(__EXTENSIONS__) || defined(_KERNEL) ... */
240
241 /*
242 * For definition of ucontext_t; must follow struct definition
243 * for sigset_t
244 */
245 #if defined(_XPG4_2)
246 #include <sys/ucontext.h>
247 #endif /* defined(_XPG4_2) */
248
249 #ifdef _KERNEL
250 #include <sys/t_lock.h>
251
252 extern const k_sigset_t nullsmask; /* a null signal mask */
253 extern const k_sigset_t fillset; /* all signals, guaranteed contiguous */
254 extern const k_sigset_t cantmask; /* cannot be caught or ignored */
255 extern const k_sigset_t cantreset; /* cannot be reset after catching */
256 extern const k_sigset_t ignoredefault; /* ignored by default */
257 extern const k_sigset_t stopdefault; /* stop by default */
258 extern const k_sigset_t coredefault; /* dumps core by default */
259 extern const k_sigset_t holdvfork; /* held while doing vfork */
260
261 #define sigmask(n) ((unsigned int)1 << (((n) - 1) & (32 - 1)))
262 #define sigword(n) (((unsigned int)((n) - 1))>>5)
263
264 #if ((MAXSIG > (2 * 32)) && (MAXSIG <= (3 * 32)))
265 #define FILLSET0 0xffffffffu
266 #define FILLSET1 0xffffffffu
267 #define FILLSET2 ((1u << (MAXSIG - 64)) - 1)
268 #else
269 #error "fix me: MAXSIG out of bounds"
270 #endif
271
272 #define CANTMASK0 (sigmask(SIGKILL)|sigmask(SIGSTOP))
273 #define CANTMASK1 0
274 #define CANTMASK2 0
275
276 #define sigemptyset(s) (*(s) = nullsmask)
277 #define sigfillset(s) (*(s) = fillset)
278 #define sigaddset(s, n) ((s)->__sigbits[sigword(n)] |= sigmask(n))
279 #define sigdelset(s, n) ((s)->__sigbits[sigword(n)] &= ~sigmask(n))
280 #define sigismember(s, n) (sigmask(n) & (s)->__sigbits[sigword(n)])
281 #define sigisempty(s) (!((s)->__sigbits[0] | (s)->__sigbits[1] | \
282 (s)->__sigbits[2]))
283 #define sigutok(us, ks) \
284 ((ks)->__sigbits[0] = (us)->__sigbits[0] & (FILLSET0 & ~CANTMASK0), \
285 (ks)->__sigbits[1] = (us)->__sigbits[1] & (FILLSET1 & ~CANTMASK1), \
286 (ks)->__sigbits[2] = (us)->__sigbits[2] & (FILLSET2 & ~CANTMASK2))
287 #define sigktou(ks, us) ((us)->__sigbits[0] = (ks)->__sigbits[0], \
288 (us)->__sigbits[1] = (ks)->__sigbits[1], \
289 (us)->__sigbits[2] = (ks)->__sigbits[2], \
290 (us)->__sigbits[3] = 0)
291 typedef struct {
292 int sig; /* signal no. */
293 int perm; /* flag for EPERM */
294 int checkperm; /* check perm or not */
295 int sicode; /* has siginfo.si_code */
296 union sigval value; /* user specified value */
297 } sigsend_t;
298
299 typedef struct {
300 sigqueue_t sn_sigq; /* sigq struct for notification */
301 u_longlong_t sn_snid; /* unique id for notification */
302 } signotifyq_t;
303
304 typedef struct sigqhdr { /* sigqueue pool header */
305 sigqueue_t *sqb_free; /* free sigq struct list */
306 int sqb_count; /* sigq free count */
307 uint_t sqb_maxcount; /* sigq max free count */
308 size_t sqb_size; /* size of header+free structs */
309 uchar_t sqb_pexited; /* process has exited */
310 uint_t sqb_sent; /* number of sigq sent */
311 kcondvar_t sqb_cv; /* waiting for a sigq struct */
312 kmutex_t sqb_lock; /* lock for sigq pool */
313 } sigqhdr_t;
314
315 #define _SIGQUEUE_SIZE_BASIC 128 /* basic limit */
316 #define _SIGQUEUE_SIZE_PRIVILEGED 512 /* privileged limit */
317
318 #define _SIGNOTIFY_MAX 32
319
320 extern void setsigact(int, void (*)(int), const k_sigset_t *, int);
321 extern void sigorset(k_sigset_t *, const k_sigset_t *);
322 extern void sigandset(k_sigset_t *, const k_sigset_t *);
323 extern void sigdiffset(k_sigset_t *, const k_sigset_t *);
324 extern void sigintr(k_sigset_t *, int);
325 extern void sigunintr(k_sigset_t *);
326 extern void sigreplace(k_sigset_t *, k_sigset_t *);
327
328 extern int kill(pid_t, int);
329
330 #endif /* _KERNEL */
331
332 #ifdef __cplusplus
333 }
334 #endif
335
336 #endif /* _SYS_SIGNAL_H */