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