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