xref: /freebsd/sys/compat/linux/linux_siginfo.h (revision faf25f48d601ae39f5752602f3020e2e92605625)
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 2004 Tim J. Robbins
5  * Copyright (c) 2001 Doug Rabson
6  * Copyright (c) 1994-1996 Søren Schmidt
7  * All rights reserved.
8  * Copyright (c) 2022 Dmitry Chagin <dchagin@FreeBSD.org>
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer
15  *    in this position and unchanged.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. The name of the author may not be used to endorse or promote products
20  *    derived from this software without specific prior written permission
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  * $FreeBSD$
34  */
35 
36 #ifndef _LINUX_SIGINFO_H_
37 #define _LINUX_SIGINFO_H_
38 
39 /*
40  * si_code values
41  */
42 #define	LINUX_SI_USER		0	/* sent by kill, sigsend, raise */
43 #define	LINUX_SI_KERNEL		0x80	/* sent by the kernel from somewhere */
44 #define	LINUX_SI_QUEUE		-1	/* sent by sigqueue */
45 #define	LINUX_SI_TIMER		-2	/* sent by timer expiration */
46 #define	LINUX_SI_MESGQ		-3	/* sent by real time mesq state change */
47 #define	LINUX_SI_ASYNCIO	-4	/* sent by AIO completion */
48 #define	LINUX_SI_SIGIO		-5	/* sent by queued SIGIO */
49 #define	LINUX_SI_TKILL		-6	/* sent by tkill system call */
50 
51 /*
52  * SIGILL si_codes
53  */
54 #define	LINUX_ILL_ILLOPC	1	/* illegal opcode */
55 #define	LINUX_ILL_ILLOPN	2	/* illegal operand */
56 #define	LINUX_ILL_ILLADR	3	/* illegal addressing mode */
57 #define	LINUX_ILL_ILLTRP	4	/* illegal trap */
58 #define	LINUX_ILL_PRVOPC	5	/* privileged opcode */
59 #define	LINUX_ILL_PRVREG	6	/* privileged register */
60 #define	LINUX_ILL_COPROC	7	/* coprocessor error */
61 #define	LINUX_ILL_BADSTK	8	/* internal stack error */
62 #define	LINUX_ILL_BADIADDR	9	/* unimplemented instruction address */
63 #define	LINUX___ILL_BREAK	10	/* (ia64) illegal break */
64 #define	LINUX___ILL_BNDMOD	11	/* (ia64) bundle-update (modification)
65 					 * in progress
66 					 */
67 
68 /*
69  * SIGFPE si_codes
70  */
71 #define	LINUX_FPE_INTDIV	1	/* integer divide by zero */
72 #define	LINUX_FPE_INTOVF	2	/* integer overflow */
73 #define	LINUX_FPE_FLTDIV	3	/* floating point divide by zero */
74 #define	LINUX_FPE_FLTOVF	4	/* floating point overflow */
75 #define	LINUX_FPE_FLTUND	5	/* floating point underflow */
76 #define	LINUX_FPE_FLTRES	6	/* floating point inexact result */
77 #define	LINUX_FPE_FLTINV	7	/* floating point invalid operation */
78 #define	LINUX_FPE_FLTSUB	8	/* (ia64) subscript out of range */
79 #define	LINUX___FPE_DECOVF	9	/* (ia64) decimal overflow */
80 #define	LINUX___FPE_DECDIV	10	/* (ia64) decimal division by zero */
81 #define	LINUX___FPE_DECERR	11	/* (ia64) packed decimal error */
82 #define	LINUX___FPE_INVASC	12	/* (ia64) invalid ASCII digit */
83 #define	LINUX___FPE_INVDEC	13	/* (ia64) invalid decimal digit */
84 #define	LINUX_FPE_FLTUNK	14	/* undiagnosed floating-point exception */
85 #define	LINUX_FPE_CONDTRAP	15	/* trap on condition */
86 
87 /*
88  * SIGSEGV si_codes
89  */
90 #define	LINUX_SEGV_MAPERR	1	/* address not mapped to object */
91 #define	LINUX_SEGV_ACCERR	2	/* invalid permissions for mapped object */
92 #define	LINUX_SEGV_BNDERR	3	/* failed address bound checks */
93 #ifdef __ia64__
94 #define	LINUX___SEGV_PSTKOVF	4	/* paragraph stack overflow */
95 #else
96 #define	LINUX_SEGV_PKUERR	4	/* failed protection key checks */
97 #endif
98 #define	LINUX_SEGV_ACCADI	5	/* ADI not enabled for mapped object */
99 #define	LINUX_SEGV_ADIDERR	6	/* Disrupting MCD error */
100 #define	LINUX_SEGV_ADIPERR	7	/* Precise MCD exception */
101 #define	LINUX_SEGV_MTEAERR	8	/* Asynchronous ARM MTE error */
102 #define	LINUX_SEGV_MTESERR	9	/* Synchronous ARM MTE exception */
103 
104 /*
105  * SIGBUS si_codes
106  */
107 #define	LINUX_BUS_ADRALN	1	/* invalid address alignment */
108 #define	LINUX_BUS_ADRERR	2	/* non-existent physical address */
109 #define	LINUX_BUS_OBJERR	3	/* object specific hardware error */
110 
111 #define	LINUX_BUS_MCEERR_AR	4	/* hardware memory error consumed
112 					 * on a machine check:
113 					 * action required
114 					 */
115 #define	LINUX_BUS_MCEERR_AO	5	/* hardware memory error detected
116 					 * in process but not consumed:
117 					 * action optional
118 					 */
119 
120 /*
121  * SIGTRAP si_codes
122  */
123 #define	LINUX_TRAP_BRKPT	1	/* process breakpoint */
124 #define	LINUX_TRAP_TRACE	2	/* process trace trap */
125 #define	LINUX_TRAP_BRANCH	3	/* process taken branch trap */
126 #define	LINUX_TRAP_HWBKPT	4	/* hardware breakpoint/watchpoint */
127 #define	LINUX_TRAP_UNK		5	/* undiagnosed trap */
128 #define	LINUX_TRAP_PERF		6	/* perf event with sigtrap=1 */
129 
130 /*
131  * SIGCHLD si_codes
132  */
133 #define	LINUX_CLD_EXITED	1	/* child has exited */
134 #define	LINUX_CLD_KILLED	2	/* child was killed */
135 #define	LINUX_CLD_DUMPED	3	/* child terminated abnormally */
136 #define	LINUX_CLD_TRAPPED	4	/* traced child has trapped */
137 #define	LINUX_CLD_STOPPED	5	/* child has stopped */
138 #define	LINUX_CLD_CONTINUED	6	/* stopped child has continued */
139 
140 /*
141  * SIGPOLL (or any other signal without signal specific si_codes) si_codes
142  */
143 #define	LINUX_POLL_IN		1	/* data input available */
144 #define	LINUX_POLL_OUT		2	/* output buffers available */
145 #define	LINUX_POLL_MSG		3	/* input message available */
146 #define	LINUX_POLL_ERR		4	/* i/o error */
147 #define	LINUX_POLL_PRI		5	/* high priority input available */
148 #define	LINUX_POLL_HUP		6	/* device disconnected */
149 
150 /*
151  * SIGSYS si_codes
152  */
153 #define	LINUX_SYS_SECCOMP	1	/* seccomp triggered */
154 #define	LINUX_SYS_USER_DISPATCH	2	/* syscall user dispatch triggered */
155 
156 /*
157  * SIGEMT si_codes
158  */
159 #define	LINUX_EMT_TAGOVF	1	/* tag overflow */
160 
161 typedef union l_sigval {
162 	l_int		sival_int;
163 	l_uintptr_t	sival_ptr;
164 } l_sigval_t;
165 
166 #define	LINUX_SI_MAX_SIZE		128
167 
168 union __sifields {
169 	struct {
170 		l_pid_t		_pid;
171 		l_uid_t		_uid;
172 	} _kill;
173 
174 	struct {
175 		l_timer_t	_tid;
176 		l_int		_overrun;
177 		char		_pad[sizeof(l_uid_t) - sizeof(int)];
178 		union l_sigval	_sigval;
179 		l_uint		_sys_private;
180 	} _timer;
181 
182 	struct {
183 		l_pid_t		_pid;		/* sender's pid */
184 		l_uid_t		_uid;		/* sender's uid */
185 		union l_sigval	_sigval;
186 	} _rt;
187 
188 	struct {
189 		l_pid_t		_pid;		/* which child */
190 		l_uid_t		_uid;		/* sender's uid */
191 		l_int		_status;	/* exit code */
192 		l_clock_t	_utime;
193 		l_clock_t	_stime;
194 	} _sigchld;
195 
196 	struct {
197 		l_uintptr_t	_addr;	/* Faulting insn/memory ref. */
198 	} _sigfault;
199 
200 	struct {
201 		l_long		_band;	/* POLL_IN,POLL_OUT,POLL_MSG */
202 		l_int		_fd;
203 	} _sigpoll;
204 };
205 
206 typedef struct l_siginfo {
207 	union {
208 		struct {
209 			l_int		lsi_signo;
210 			l_int		lsi_errno;
211 			l_int		lsi_code;
212 			union __sifields _sifields;
213 		};
214 		l_int	_pad[LINUX_SI_MAX_SIZE/sizeof(l_int)];
215 	};
216 } l_siginfo_t;
217 
218 _Static_assert(sizeof(l_siginfo_t) == LINUX_SI_MAX_SIZE, "l_siginfo_t size");
219 
220 #define	lsi_pid		_sifields._kill._pid
221 #define	lsi_uid		_sifields._kill._uid
222 #define	lsi_tid		_sifields._timer._tid
223 #define	lsi_overrun	_sifields._timer._overrun
224 #define	lsi_sys_private	_sifields._timer._sys_private
225 #define	lsi_status	_sifields._sigchld._status
226 #define	lsi_utime	_sifields._sigchld._utime
227 #define	lsi_stime	_sifields._sigchld._stime
228 #define	lsi_value	_sifields._rt._sigval
229 #define	lsi_int		_sifields._rt._sigval.sival_int
230 #define	lsi_ptr		_sifields._rt._sigval.sival_ptr
231 #define	lsi_addr	_sifields._sigfault._addr
232 #define	lsi_band	_sifields._sigpoll._band
233 #define	lsi_fd		_sifields._sigpoll._fd
234 
235 #endif /* _LINUX_SIGINFO_H_ */
236 
237