1 /*	$OpenBSD: siginfo.h,v 1.8 2003/06/02 04:04:54 deraadt Exp $	*/
2 
3 /*
4  * Copyright (c) 1997 Theo de Raadt
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef _SYS_SIGINFO_H
29 #define _SYS_SIGINFO_H
30 
31 union sigval {
32 	int	sival_int;	/* integer value */
33 	void	*sival_ptr;	/* pointer value */
34 };
35 
36 /*
37  * Negative signal codes are reserved for future use for
38  * user generated signals.
39  */
40 #define SI_FROMUSER(sip)	((sip)->si_code <= 0)
41 #define SI_FROMKERNEL(sip)	((sip)->si_code > 0)
42 
43 #define SI_NOINFO	32767	/* no signal information */
44 #define SI_USER		0	/* user generated signal via kill() */
45 #define SI_LWP		(-1)	/* user generated signal via lwp_kill()*/
46 #define SI_QUEUE	(-2)	/* user generated signal via sigqueue()*/
47 #define SI_TIMER	(-3)	/* from timer expiration */
48 
49 #if !defined(_POSIX_C_SOURCE)
50 /*
51  * The machine dependent signal codes (SIGILL, SIGFPE,
52  * SIGSEGV, and SIGBUS)
53  */
54 #define ILL_ILLOPC	1	/* illegal opcode */
55 #define ILL_ILLOPN	2	/* illegal operand */
56 #define ILL_ILLADR	3	/* illegal addressing mode */
57 #define ILL_ILLTRP	4	/* illegal trap */
58 #define ILL_PRVOPC	5	/* privileged opcode */
59 #define ILL_PRVREG	6	/* privileged register */
60 #define ILL_COPROC	7	/* co-processor */
61 #define ILL_BADSTK	8	/* bad stack */
62 #define NSIGILL		8
63 
64 #define EMT_TAGOVF	1	/* tag overflow */
65 #define NSIGEMT		1
66 
67 #define FPE_INTDIV	1	/* integer divide by zero */
68 #define FPE_INTOVF	2	/* integer overflow */
69 #define FPE_FLTDIV	3	/* floating point divide by zero */
70 #define FPE_FLTOVF	4	/* floating point overflow */
71 #define FPE_FLTUND	5	/* floating point underflow */
72 #define FPE_FLTRES	6	/* floating point inexact result */
73 #define FPE_FLTINV	7	/* invalid floating point operation */
74 #define FPE_FLTSUB	8	/* subscript out of range */
75 #define NSIGFPE		8
76 
77 #define SEGV_MAPERR	1	/* address not mapped to object */
78 #define SEGV_ACCERR	2	/* invalid permissions */
79 #define NSIGSEGV	2
80 
81 #define BUS_ADRALN	1	/* invalid address alignment */
82 #define BUS_ADRERR	2	/* non-existent physical address */
83 #define BUS_OBJERR	3	/* object specific hardware error */
84 #define NSIGBUS		3
85 
86 #endif /* _POSIX_C_SOURCE */
87 
88 /*
89  * SIGTRAP signal codes
90  */
91 #define TRAP_BRKPT	1	/* breakpoint trap */
92 #define TRAP_TRACE	2	/* trace trap */
93 #define NSIGTRAP	2
94 
95 /*
96  * SIGCLD signal codes
97  */
98 #define CLD_EXITED	1	/* child has exited */
99 #define CLD_KILLED	2	/* child was killed */
100 #define CLD_DUMPED	3	/* child has coredumped */
101 #define CLD_TRAPPED	4	/* traced child has stopped */
102 #define CLD_STOPPED	5	/* child has stopped on signal */
103 #define CLD_CONTINUED	6	/* stopped child has continued */
104 #define NSIGCLD		6
105 
106 #if 0
107 /*
108  * SIGPOLL signal codes - not supported
109  */
110 #define POLL_IN		1	/* input available */
111 #define POLL_OUT	2	/* output possible */
112 #define POLL_MSG	3	/* message available */
113 #define POLL_ERR	4	/* I/O error */
114 #define POLL_PRI	5	/* high priority input available */
115 #define POLL_HUP	6	/* device disconnected */
116 #define NSIGPOLL	6
117 
118 /*
119  * SIGPROF signal codes - not supported
120  */
121 #define PROF_SIG	1	/* have to set code non-zero */
122 #define NSIGPROF	1
123 #endif
124 
125 #define SI_MAXSZ	128
126 #define SI_PAD		((SI_MAXSZ / sizeof (int)) - 3)
127 
128 #include <sys/time.h>
129 
130 typedef struct {
131 	int	si_signo;			/* signal from signal.h */
132 	int	si_code;			/* code from above */
133 	int	si_errno;			/* error from errno.h */
134 	union {
135 		int	_pad[SI_PAD];		/* for future growth */
136 		struct {			/* kill(), SIGCLD, siqqueue() */
137 			pid_t	_pid;		/* process ID */
138 			union {
139 				struct {
140 					uid_t	_uid;
141 					union sigval	_value;
142 				} _kill;
143 				struct {
144 					clock_t	_utime;
145 					int	_status;
146 					clock_t	_stime;
147 				} _cld;
148 			} _pdata;
149 		} _proc;
150 		struct {	/* SIGSEGV, SIGBUS, SIGILL and SIGFPE */
151 			caddr_t	_addr;		/* faulting address */
152 			int	_trapno;	/* illegal trap number */
153 		} _fault;
154 #if 0
155 		struct {			/* SIGPOLL, SIGXFSZ */
156 			/* fd not currently available for SIGPOLL */
157 			int	_fd;		/* file descriptor */
158 			long	_band;
159 		} _file;
160 		struct {			/* SIGPROF */
161 			caddr_t _faddr;		/* last fault address */
162 			timespec _tstamp;	/* real time stamp */
163 			short	_syscall;	/* current syscall */
164 			char	_nsysarg;	/* number of arguments */
165 			char	_fault;		/* last fault type */
166 			long	_sysarg[8];	/* syscall arguments */
167 			long	_mstate[17];	/* exactly fills struct*/
168 		} _prof;
169 #endif
170 	} _data;
171 } siginfo_t;
172 
173 #define si_pid		_data._proc._pid
174 
175 #define si_status	_data._proc._pdata._cld._status
176 #define si_stime	_data._proc._pdata._cld._stime
177 #define si_utime	_data._proc._pdata._cld._utime
178 #define si_uid		_data._proc._pdata._kill._uid
179 #define si_value	_data._proc._pdata._kill._value
180 #define si_addr		_data._fault._addr
181 #define si_trapno	_data._fault._trapno
182 #define si_fd		_data._file._fd
183 #define si_band		_data._file._band
184 
185 #define si_tstamp	_data._prof._tstamp
186 #define si_syscall	_data._prof._syscall
187 #define si_nsysarg	_data._prof._nsysarg
188 #define si_sysarg	_data._prof._sysarg
189 #define si_fault	_data._prof._fault
190 #define si_faddr	_data._prof._faddr
191 #define si_mstate	_data._prof._mstate
192 
193 #if defined(_KERNEL)
194 void	initsiginfo(siginfo_t *, int, u_long, int, union sigval);
195 #endif
196 
197 #endif	/* _SYS_SIGINFO_H */
198