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