xref: /titanic_51/usr/src/uts/common/sys/siginfo.h (revision efd4c9b63ad77503c101fc6c2ed8ba96c9d52964)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 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 #ifndef _SYS_SIGINFO_H
31 #define	_SYS_SIGINFO_H
32 
33 #pragma ident	"%Z%%M%	%I%	%E% SMI"
34 
35 #include <sys/feature_tests.h>
36 #include <sys/types.h>
37 
38 #ifdef	__cplusplus
39 extern "C" {
40 #endif
41 
42 #if !defined(__XOPEN_OR_POSIX) || (_POSIX_C_SOURCE > 2) || \
43 	defined(__EXTENSIONS__)
44 
45 /*
46  * The union sigval is also defined in <time.h> as per X/Open and
47  * POSIX requirements.
48  */
49 #ifndef	_SIGVAL
50 #define	_SIGVAL
51 union sigval {
52 	int	sival_int;	/* integer value */
53 	void	*sival_ptr;	/* pointer value */
54 };
55 #endif /* _SIGVAL */
56 
57 #if defined(_SYSCALL32)
58 
59 /* Kernel view of user ILP32 sigval */
60 
61 union sigval32 {
62 	int32_t	sival_int;	/* integer value */
63 	caddr32_t sival_ptr;	/* pointer value */
64 };
65 
66 #endif	/* _SYSCALL32 */
67 
68 #else 				/* needed in siginfo_t structure */
69 
70 union __sigval {
71 	int	__sival_int;	/* integer value */
72 	void	*__sival_ptr;	/* pointer value */
73 };
74 
75 #endif /* !defined(_POSIX_C_SOURCE) || (_POSIX_C_SOURCE > 2)... */
76 
77 #if !defined(__XOPEN_OR_POSIX) || (_POSIX_C_SOURCE > 2) || \
78 	defined(__EXTENSIONS__)
79 
80 /*
81  * The sigevent structure is also defined in <time.h> as per X/Open and
82  * POSIX requirements.
83  */
84 #ifndef	_SIGEVENT
85 #define	_SIGEVENT
86 struct sigevent {
87 	int		sigev_notify;	/* notification mode */
88 	int		sigev_signo;	/* signal number */
89 	union sigval	sigev_value;	/* signal value */
90 	void		(*sigev_notify_function)(union sigval);
91 	pthread_attr_t	*sigev_notify_attributes;
92 	int		__sigev_pad2;
93 };
94 #endif	/* _SIGEVENT */
95 
96 /* values of sigev_notify */
97 #define	SIGEV_NONE	1		/* no notification */
98 #define	SIGEV_SIGNAL	2		/* queued signal notification */
99 #define	SIGEV_THREAD	3		/* call back from another thread */
100 #define	SIGEV_PORT	4		/* use event port for notification */
101 
102 #if defined(_SYSCALL32)
103 
104 /* Kernel view of user ILP32 sigevent */
105 
106 struct sigevent32 {
107 	int32_t		sigev_notify;	/* notification mode */
108 	int32_t		sigev_signo;	/* signal number */
109 	union sigval32	sigev_value;	/* signal value */
110 	caddr32_t	sigev_notify_function;
111 	caddr32_t	sigev_notify_attributes;
112 	int32_t		__sigev_pad2;
113 };
114 
115 #endif	/* _SYSCALL32 */
116 
117 #endif /* !defined(__XOPEN_OR_POSIX) || (_POSIX_C_SOURCE > 2)... */
118 
119 #if !defined(_POSIX_C_SOURCE) || (_POSIX_C_SOURCE > 2) || \
120 	defined(__EXTENSIONS__)
121 /*
122  * negative signal codes are reserved for future use for user generated
123  * signals
124  */
125 
126 #define	SI_FROMUSER(sip)	((sip)->si_code <= 0)
127 #define	SI_FROMKERNEL(sip)	((sip)->si_code > 0)
128 
129 #define	SI_NOINFO	32767	/* no signal information */
130 #define	SI_DTRACE	2050	/* kernel generated signal via DTrace action */
131 #define	SI_RCTL		2049	/* kernel generated signal via rctl action */
132 #define	SI_USER		0	/* user generated signal via kill() */
133 #define	SI_LWP		(-1)	/* user generated signal via lwp_kill() */
134 #define	SI_QUEUE	(-2)	/* user generated signal via sigqueue() */
135 #define	SI_TIMER	(-3)	/* from timer expiration */
136 #define	SI_ASYNCIO	(-4)	/* from asynchronous I/O completion */
137 #define	SI_MESGQ	(-5)	/* from message arrival */
138 #endif /* !defined(_POSIX_C_SOURCE) || (_POSIX_C_SOURCE > 2)... */
139 
140 #if !defined(_POSIX_C_SOURCE) || defined(_XPG4_2) || defined(__EXTENSIONS__)
141 /*
142  * Get the machine dependent signal codes (SIGILL, SIGFPE, SIGSEGV, and
143  * SIGBUS) from <sys/machsig.h>
144  */
145 
146 #include <sys/machsig.h>
147 
148 /*
149  * SIGTRAP signal codes
150  */
151 
152 #define	TRAP_BRKPT	1	/* breakpoint trap */
153 #define	TRAP_TRACE	2	/* trace trap */
154 #define	TRAP_RWATCH	3	/* read access watchpoint trap */
155 #define	TRAP_WWATCH	4	/* write access watchpoint trap */
156 #define	TRAP_XWATCH	5	/* execute access watchpoint trap */
157 #define	TRAP_DTRACE	6	/* problem with fasttrap DTrace provider */
158 #if !defined(_XOPEN_SOURCE) || defined(__EXTENSIONS__)
159 #define	NSIGTRAP	6
160 #endif /* !defined(_XOPEN_SOURCE) || defined(__EXTENSIONS__) */
161 
162 /*
163  * SIGCLD signal codes
164  */
165 
166 #define	CLD_EXITED	1	/* child has exited */
167 #define	CLD_KILLED	2	/* child was killed */
168 #define	CLD_DUMPED	3	/* child has coredumped */
169 #define	CLD_TRAPPED	4	/* traced child has stopped */
170 #define	CLD_STOPPED	5	/* child has stopped on signal */
171 #define	CLD_CONTINUED	6	/* stopped child has continued */
172 
173 #if !defined(_XOPEN_SOURCE) || defined(__EXTENSIONS__)
174 #define	NSIGCLD		6
175 #endif /* !defined(_XOPEN_SOURCE) || defined(__EXTENSIONS__) */
176 
177 /*
178  * SIGPOLL signal codes
179  */
180 
181 #define	POLL_IN		1	/* input available */
182 #define	POLL_OUT	2	/* output possible */
183 #define	POLL_MSG	3	/* message available */
184 #define	POLL_ERR	4	/* I/O error */
185 #define	POLL_PRI	5	/* high priority input available */
186 #define	POLL_HUP	6	/* device disconnected */
187 
188 #if !defined(_XOPEN_SOURCE) || defined(__EXTENSIONS__)
189 #define	NSIGPOLL	6
190 #endif /* !defined(_XOPEN_SOURCE) || defined(__EXTENSIONS__) */
191 
192 #endif /* !defined(_POSIX_C_SOURCE) || defined(_XPG4_2) ... */
193 
194 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
195 /*
196  * SIGPROF signal codes
197  */
198 
199 #define	PROF_SIG	1	/* have to set code non-zero */
200 #define	NSIGPROF	1
201 
202 #endif /* !defined(__XOPEN_OR_POSIX) || defined (__EXTENSIONS__) */
203 
204 #if !defined(_POSIX_C_SOURCE) || (_POSIX_C_SOURCE > 2) || \
205 	defined(__EXTENSIONS__)
206 
207 #ifdef _LP64
208 #define	SI_MAXSZ	256
209 #define	SI_PAD		((SI_MAXSZ / sizeof (int)) - 4)
210 #else
211 #define	SI_MAXSZ	128
212 #define	SI_PAD		((SI_MAXSZ / sizeof (int)) - 3)
213 #endif
214 
215 /*
216  * Inclusion of <sys/time_impl.h> is needed for the declaration of
217  * timestruc_t.  However, since inclusion of <sys/time_impl.h> results
218  * in X/Open and POSIX namespace pollution, the definition for
219  * timestruct_t has been duplicated in a standards namespace safe header
220  * <sys/time_std_impl.h>.  In <sys/time_std_impl.h>, the structure
221  * name, tag, and member names, as well as the type itself, all have
222  * leading underscores to protect namespace.
223  */
224 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
225 #include <sys/time_impl.h>
226 #else
227 #include <sys/time_std_impl.h>
228 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
229 
230 /*
231  * The inclusion of <sys/types.h> is needed for definitions of pid_t, etc.
232  * Placement here is due to a dependency in <sys/select.h> which is included
233  * by <sys/types.h> for the sigevent structure.  Hence this inclusion must
234  * follow that definition.
235  */
236 #include <sys/types.h>		/* for definitions of pid_t, etc. */
237 
238 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
239 typedef struct siginfo { 		/* pollutes POSIX/XOPEN namespace */
240 #else
241 typedef struct {
242 #endif
243 	int	si_signo;			/* signal from signal.h	*/
244 	int 	si_code;			/* code from above	*/
245 	int	si_errno;			/* error from errno.h	*/
246 #ifdef _LP64
247 	int	si_pad;		/* _LP64 union starts on an 8-byte boundary */
248 #endif
249 	union {
250 
251 		int	__pad[SI_PAD];		/* for future growth	*/
252 
253 		struct {			/* kill(), SIGCLD, siqqueue() */
254 			pid_t	__pid;		/* process ID		*/
255 			union {
256 				struct {
257 					uid_t	__uid;
258 #if !defined(__XOPEN_OR_POSIX) || (_POSIX_C_SOURCE > 2) || \
259 	defined(__EXTENSIONS__)
260 					union sigval	__value;
261 #else
262 					union __sigval	__value;
263 #endif
264 				} __kill;
265 				struct {
266 					clock_t __utime;
267 					int	__status;
268 					clock_t __stime;
269 				} __cld;
270 			} __pdata;
271 			ctid_t	__ctid;		/* contract ID		*/
272 			zoneid_t __zoneid;	/* zone ID		*/
273 		} __proc;
274 
275 		struct {	/* SIGSEGV, SIGBUS, SIGILL, SIGTRAP, SIGFPE */
276 			void 	*__addr;	/* faulting address	*/
277 			int	__trapno;	/* illegal trap number	*/
278 			caddr_t	__pc;		/* instruction address	*/
279 		} __fault;
280 
281 		struct {			/* SIGPOLL, SIGXFSZ	*/
282 		/* fd not currently available for SIGPOLL */
283 			int	__fd;		/* file descriptor	*/
284 			long	__band;
285 		} __file;
286 
287 		struct {			/* SIGPROF */
288 			caddr_t	__faddr;	/* last fault address	*/
289 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
290 			timestruc_t __tstamp;	/* real time stamp	*/
291 #else
292 			_timestruc_t __tstamp;	/* real time stamp	*/
293 #endif
294 			short	__syscall;	/* current syscall	*/
295 			char	__nsysarg;	/* number of arguments	*/
296 			char	__fault;	/* last fault type	*/
297 			long	__sysarg[8];	/* syscall arguments	*/
298 			int	__mstate[10];	/* see <sys/msacct.h>	*/
299 		} __prof;
300 
301 		struct {			/* SI_RCTL */
302 			int32_t	__entity;	/* type of entity exceeding */
303 		} __rctl;
304 	} __data;
305 
306 } siginfo_t;
307 
308 #if defined(_SYSCALL32)
309 
310 /* Kernel view of user ILP32 siginfo struct */
311 
312 #define	SI32_MAXSZ	128
313 #define	SI32_PAD	((SI32_MAXSZ / sizeof (int32_t)) - 3)
314 
315 typedef struct siginfo32 {
316 
317 	int32_t	si_signo;			/* signal from signal.h	*/
318 	int32_t	si_code;			/* code from above	*/
319 	int32_t	si_errno;			/* error from errno.h	*/
320 
321 	union {
322 
323 		int32_t	__pad[SI32_PAD];	/* for future growth	*/
324 
325 		struct {			/* kill(), SIGCLD, siqqueue() */
326 			pid32_t	__pid;		/* process ID		*/
327 			union {
328 				struct {
329 					uid32_t	__uid;
330 					union sigval32	__value;
331 				} __kill;
332 				struct {
333 					clock32_t __utime;
334 					int32_t	__status;
335 					clock32_t __stime;
336 				} __cld;
337 			} __pdata;
338 			id32_t	__ctid;		/* contract ID		*/
339 			id32_t __zoneid;	/* zone ID		*/
340 		} __proc;
341 
342 		struct {	/* SIGSEGV, SIGBUS, SIGILL, SIGTRAP, SIGFPE */
343 			caddr32_t __addr;	/* faulting address	*/
344 			int32_t	__trapno;	/* illegal trap number	*/
345 			caddr32_t __pc;		/* instruction address	*/
346 		} __fault;
347 
348 		struct {			/* SIGPOLL, SIGXFSZ	*/
349 		/* fd not currently available for SIGPOLL */
350 			int32_t	__fd;		/* file descriptor	*/
351 			int32_t	__band;
352 		} __file;
353 
354 		struct {			/* SIGPROF */
355 			caddr32_t __faddr;	/* last fault address	*/
356 			timestruc32_t __tstamp; /* real time stamp	*/
357 			int16_t	__syscall;	/* current syscall	*/
358 			int8_t	__nsysarg;	/* number of arguments	*/
359 			int8_t	__fault;	/* last fault type	*/
360 			int32_t	__sysarg[8];	/* syscall arguments	*/
361 			int32_t	__mstate[10];	/* see <sys/msacct.h>	*/
362 		} __prof;
363 
364 		struct {			/* SI_RCTL */
365 			int32_t	__entity;	/* type of entity exceeding */
366 		} __rctl;
367 
368 	} __data;
369 
370 } siginfo32_t;
371 
372 #endif	/* _SYSCALL32 */
373 
374 /*
375  * XXX -- internal version is identical to siginfo_t but without the padding.
376  * This must be maintained in sync with it.
377  */
378 
379 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
380 
381 typedef struct k_siginfo {
382 	int	si_signo;			/* signal from signal.h	*/
383 	int 	si_code;			/* code from above	*/
384 	int	si_errno;			/* error from errno.h	*/
385 #ifdef _LP64
386 	int	si_pad;		/* _LP64 union starts on an 8-byte boundary */
387 #endif
388 	union {
389 		struct {			/* kill(), SIGCLD, siqqueue() */
390 			pid_t	__pid;		/* process ID		*/
391 			union {
392 				struct {
393 					uid_t	__uid;
394 					union sigval	__value;
395 				} __kill;
396 				struct {
397 					clock_t __utime;
398 					int	__status;
399 					clock_t __stime;
400 				} __cld;
401 			} __pdata;
402 			ctid_t	__ctid;		/* contract ID		*/
403 			zoneid_t __zoneid;	/* zone ID		*/
404 		} __proc;
405 
406 		struct {	/* SIGSEGV, SIGBUS, SIGILL, SIGTRAP, SIGFPE */
407 			void 	*__addr;	/* faulting address	*/
408 			int	__trapno;	/* illegal trap number	*/
409 			caddr_t	__pc;		/* instruction address	*/
410 		} __fault;
411 
412 		struct {			/* SIGPOLL, SIGXFSZ	*/
413 		/* fd not currently available for SIGPOLL */
414 			int	__fd;		/* file descriptor	*/
415 			long	__band;
416 		} __file;
417 
418 		struct {			/* SIGPROF */
419 			caddr_t	__faddr;	/* last fault address	*/
420 
421 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
422 			timestruc_t __tstamp;	/* real time stamp	*/
423 #else
424 			_timestruc_t __tstamp;	/* real time stamp	*/
425 #endif
426 			short	__syscall;	/* current syscall	*/
427 			char	__nsysarg;	/* number of arguments	*/
428 			char	__fault;	/* last fault type	*/
429 			/* these are omitted to keep k_siginfo_t small	*/
430 			/* long	__sysarg[8]; */
431 			/* int	__mstate[10]; */
432 		} __prof;
433 
434 		struct {			/* SI_RCTL */
435 			int32_t	__entity;	/* type of entity exceeding */
436 		} __rctl;
437 
438 	} __data;
439 
440 } k_siginfo_t;
441 
442 typedef struct sigqueue {
443 	struct sigqueue	*sq_next;
444 	k_siginfo_t	sq_info;
445 	void		(*sq_func)(struct sigqueue *); /* destructor function */
446 	void		*sq_backptr;	/* pointer to the data structure */
447 					/* associated by sq_func()	*/
448 	int		sq_external;	/* comes from outside the contract */
449 } sigqueue_t;
450 
451 /*  indication whether to queue the signal or not */
452 #define	SI_CANQUEUE(c)	((c) <= SI_QUEUE)
453 
454 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
455 
456 #define	si_pid		__data.__proc.__pid
457 #define	si_ctid		__data.__proc.__ctid
458 #define	si_zoneid	__data.__proc.__zoneid
459 #define	si_status	__data.__proc.__pdata.__cld.__status
460 #define	si_stime	__data.__proc.__pdata.__cld.__stime
461 #define	si_utime	__data.__proc.__pdata.__cld.__utime
462 #define	si_uid		__data.__proc.__pdata.__kill.__uid
463 #define	si_value	__data.__proc.__pdata.__kill.__value
464 #define	si_addr		__data.__fault.__addr
465 #define	si_trapno	__data.__fault.__trapno
466 #define	si_trapafter	__data.__fault.__trapno
467 #define	si_pc		__data.__fault.__pc
468 #define	si_fd		__data.__file.__fd
469 #define	si_band		__data.__file.__band
470 #define	si_tstamp	__data.__prof.__tstamp
471 #define	si_syscall	__data.__prof.__syscall
472 #define	si_nsysarg	__data.__prof.__nsysarg
473 #define	si_sysarg	__data.__prof.__sysarg
474 #define	si_fault	__data.__prof.__fault
475 #define	si_faddr	__data.__prof.__faddr
476 #define	si_mstate	__data.__prof.__mstate
477 #define	si_entity	__data.__rctl.__entity
478 
479 #endif /* !defined(_POSIX_C_SOURCE) || (_POSIX_C_SOURCE > 2) ... */
480 
481 
482 #if defined(_SYSCALL32_IMPL)
483 
484 extern void siginfo_kto32(const k_siginfo_t *, siginfo32_t *);
485 extern void siginfo_32tok(const siginfo32_t *, k_siginfo_t *);
486 
487 #endif /* _SYSCALL32_IMPL */
488 
489 #ifdef	__cplusplus
490 }
491 #endif
492 
493 #endif	/* _SYS_SIGINFO_H */
494