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