1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 #ifndef _UAPI_ASM_GENERIC_SIGINFO_H
3 #define _UAPI_ASM_GENERIC_SIGINFO_H
4 
5 #include <linux/compiler.h>
6 #include <linux/types.h>
7 
8 typedef union sigval {
9 	int sival_int;
10 	void __user *sival_ptr;
11 } sigval_t;
12 
13 #define SI_MAX_SIZE	128
14 
15 /*
16  * The default "si_band" type is "long", as specified by POSIX.
17  * However, some architectures want to override this to "int"
18  * for historical compatibility reasons, so we allow that.
19  */
20 #ifndef __ARCH_SI_BAND_T
21 #define __ARCH_SI_BAND_T long
22 #endif
23 
24 #ifndef __ARCH_SI_CLOCK_T
25 #define __ARCH_SI_CLOCK_T __kernel_clock_t
26 #endif
27 
28 #ifndef __ARCH_SI_ATTRIBUTES
29 #define __ARCH_SI_ATTRIBUTES
30 #endif
31 
32 union __sifields {
33 	/* kill() */
34 	struct {
35 		__kernel_pid_t _pid;	/* sender's pid */
36 		__kernel_uid32_t _uid;	/* sender's uid */
37 	} _kill;
38 
39 	/* POSIX.1b timers */
40 	struct {
41 		__kernel_timer_t _tid;	/* timer id */
42 		int _overrun;		/* overrun count */
43 		sigval_t _sigval;	/* same as below */
44 		int _sys_private;       /* not to be passed to user */
45 	} _timer;
46 
47 	/* POSIX.1b signals */
48 	struct {
49 		__kernel_pid_t _pid;	/* sender's pid */
50 		__kernel_uid32_t _uid;	/* sender's uid */
51 		sigval_t _sigval;
52 	} _rt;
53 
54 	/* SIGCHLD */
55 	struct {
56 		__kernel_pid_t _pid;	/* which child */
57 		__kernel_uid32_t _uid;	/* sender's uid */
58 		int _status;		/* exit code */
59 		__ARCH_SI_CLOCK_T _utime;
60 		__ARCH_SI_CLOCK_T _stime;
61 	} _sigchld;
62 
63 	/* SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGTRAP, SIGEMT */
64 	struct {
65 		void __user *_addr; /* faulting insn/memory ref. */
66 #ifdef __ARCH_SI_TRAPNO
67 		int _trapno;	/* TRAP # which caused the signal */
68 #endif
69 #ifdef __ia64__
70 		int _imm;		/* immediate value for "break" */
71 		unsigned int _flags;	/* see ia64 si_flags */
72 		unsigned long _isr;	/* isr */
73 #endif
74 
75 #define __ADDR_BND_PKEY_PAD  (__alignof__(void *) < sizeof(short) ? \
76 			      sizeof(short) : __alignof__(void *))
77 		union {
78 			/*
79 			 * used when si_code=BUS_MCEERR_AR or
80 			 * used when si_code=BUS_MCEERR_AO
81 			 */
82 			short _addr_lsb; /* LSB of the reported address */
83 			/* used when si_code=SEGV_BNDERR */
84 			struct {
85 				char _dummy_bnd[__ADDR_BND_PKEY_PAD];
86 				void __user *_lower;
87 				void __user *_upper;
88 			} _addr_bnd;
89 			/* used when si_code=SEGV_PKUERR */
90 			struct {
91 				char _dummy_pkey[__ADDR_BND_PKEY_PAD];
92 				__u32 _pkey;
93 			} _addr_pkey;
94 			/* used when si_code=TRAP_PERF */
95 			unsigned long _perf;
96 		};
97 	} _sigfault;
98 
99 	/* SIGPOLL */
100 	struct {
101 		__ARCH_SI_BAND_T _band;	/* POLL_IN, POLL_OUT, POLL_MSG */
102 		int _fd;
103 	} _sigpoll;
104 
105 	/* SIGSYS */
106 	struct {
107 		void __user *_call_addr; /* calling user insn */
108 		int _syscall;	/* triggering system call number */
109 		unsigned int _arch;	/* AUDIT_ARCH_* of syscall */
110 	} _sigsys;
111 };
112 
113 #ifndef __ARCH_HAS_SWAPPED_SIGINFO
114 #define __SIGINFO 			\
115 struct {				\
116 	int si_signo;			\
117 	int si_errno;			\
118 	int si_code;			\
119 	union __sifields _sifields;	\
120 }
121 #else
122 #define __SIGINFO 			\
123 struct {				\
124 	int si_signo;			\
125 	int si_code;			\
126 	int si_errno;			\
127 	union __sifields _sifields;	\
128 }
129 #endif /* __ARCH_HAS_SWAPPED_SIGINFO */
130 
131 typedef struct siginfo {
132 	union {
133 		__SIGINFO;
134 		int _si_pad[SI_MAX_SIZE/sizeof(int)];
135 	};
136 } __ARCH_SI_ATTRIBUTES siginfo_t;
137 
138 /*
139  * How these fields are to be accessed.
140  */
141 #define si_pid		_sifields._kill._pid
142 #define si_uid		_sifields._kill._uid
143 #define si_tid		_sifields._timer._tid
144 #define si_overrun	_sifields._timer._overrun
145 #define si_sys_private  _sifields._timer._sys_private
146 #define si_status	_sifields._sigchld._status
147 #define si_utime	_sifields._sigchld._utime
148 #define si_stime	_sifields._sigchld._stime
149 #define si_value	_sifields._rt._sigval
150 #define si_int		_sifields._rt._sigval.sival_int
151 #define si_ptr		_sifields._rt._sigval.sival_ptr
152 #define si_addr		_sifields._sigfault._addr
153 #ifdef __ARCH_SI_TRAPNO
154 #define si_trapno	_sifields._sigfault._trapno
155 #endif
156 #define si_addr_lsb	_sifields._sigfault._addr_lsb
157 #define si_lower	_sifields._sigfault._addr_bnd._lower
158 #define si_upper	_sifields._sigfault._addr_bnd._upper
159 #define si_pkey		_sifields._sigfault._addr_pkey._pkey
160 #define si_perf		_sifields._sigfault._perf
161 #define si_band		_sifields._sigpoll._band
162 #define si_fd		_sifields._sigpoll._fd
163 #define si_call_addr	_sifields._sigsys._call_addr
164 #define si_syscall	_sifields._sigsys._syscall
165 #define si_arch		_sifields._sigsys._arch
166 
167 /*
168  * si_code values
169  * Digital reserves positive values for kernel-generated signals.
170  */
171 #define SI_USER		0		/* sent by kill, sigsend, raise */
172 #define SI_KERNEL	0x80		/* sent by the kernel from somewhere */
173 #define SI_QUEUE	-1		/* sent by sigqueue */
174 #define SI_TIMER	-2		/* sent by timer expiration */
175 #define SI_MESGQ	-3		/* sent by real time mesq state change */
176 #define SI_ASYNCIO	-4		/* sent by AIO completion */
177 #define SI_SIGIO	-5		/* sent by queued SIGIO */
178 #define SI_TKILL	-6		/* sent by tkill system call */
179 #define SI_DETHREAD	-7		/* sent by execve() killing subsidiary threads */
180 #define SI_ASYNCNL	-60		/* sent by glibc async name lookup completion */
181 
182 #define SI_FROMUSER(siptr)	((siptr)->si_code <= 0)
183 #define SI_FROMKERNEL(siptr)	((siptr)->si_code > 0)
184 
185 /*
186  * SIGILL si_codes
187  */
188 #define ILL_ILLOPC	1	/* illegal opcode */
189 #define ILL_ILLOPN	2	/* illegal operand */
190 #define ILL_ILLADR	3	/* illegal addressing mode */
191 #define ILL_ILLTRP	4	/* illegal trap */
192 #define ILL_PRVOPC	5	/* privileged opcode */
193 #define ILL_PRVREG	6	/* privileged register */
194 #define ILL_COPROC	7	/* coprocessor error */
195 #define ILL_BADSTK	8	/* internal stack error */
196 #define ILL_BADIADDR	9	/* unimplemented instruction address */
197 #define __ILL_BREAK	10	/* illegal break */
198 #define __ILL_BNDMOD	11	/* bundle-update (modification) in progress */
199 #define NSIGILL		11
200 
201 /*
202  * SIGFPE si_codes
203  */
204 #define FPE_INTDIV	1	/* integer divide by zero */
205 #define FPE_INTOVF	2	/* integer overflow */
206 #define FPE_FLTDIV	3	/* floating point divide by zero */
207 #define FPE_FLTOVF	4	/* floating point overflow */
208 #define FPE_FLTUND	5	/* floating point underflow */
209 #define FPE_FLTRES	6	/* floating point inexact result */
210 #define FPE_FLTINV	7	/* floating point invalid operation */
211 #define FPE_FLTSUB	8	/* subscript out of range */
212 #define __FPE_DECOVF	9	/* decimal overflow */
213 #define __FPE_DECDIV	10	/* decimal division by zero */
214 #define __FPE_DECERR	11	/* packed decimal error */
215 #define __FPE_INVASC	12	/* invalid ASCII digit */
216 #define __FPE_INVDEC	13	/* invalid decimal digit */
217 #define FPE_FLTUNK	14	/* undiagnosed floating-point exception */
218 #define FPE_CONDTRAP	15	/* trap on condition */
219 #define NSIGFPE		15
220 
221 /*
222  * SIGSEGV si_codes
223  */
224 #define SEGV_MAPERR	1	/* address not mapped to object */
225 #define SEGV_ACCERR	2	/* invalid permissions for mapped object */
226 #define SEGV_BNDERR	3	/* failed address bound checks */
227 #ifdef __ia64__
228 # define __SEGV_PSTKOVF	4	/* paragraph stack overflow */
229 #else
230 # define SEGV_PKUERR	4	/* failed protection key checks */
231 #endif
232 #define SEGV_ACCADI	5	/* ADI not enabled for mapped object */
233 #define SEGV_ADIDERR	6	/* Disrupting MCD error */
234 #define SEGV_ADIPERR	7	/* Precise MCD exception */
235 #define SEGV_MTEAERR	8	/* Asynchronous ARM MTE error */
236 #define SEGV_MTESERR	9	/* Synchronous ARM MTE exception */
237 #define NSIGSEGV	9
238 
239 /*
240  * SIGBUS si_codes
241  */
242 #define BUS_ADRALN	1	/* invalid address alignment */
243 #define BUS_ADRERR	2	/* non-existent physical address */
244 #define BUS_OBJERR	3	/* object specific hardware error */
245 /* hardware memory error consumed on a machine check: action required */
246 #define BUS_MCEERR_AR	4
247 /* hardware memory error detected in process but not consumed: action optional*/
248 #define BUS_MCEERR_AO	5
249 #define NSIGBUS		5
250 
251 /*
252  * SIGTRAP si_codes
253  */
254 #define TRAP_BRKPT	1	/* process breakpoint */
255 #define TRAP_TRACE	2	/* process trace trap */
256 #define TRAP_BRANCH     3	/* process taken branch trap */
257 #define TRAP_HWBKPT     4	/* hardware breakpoint/watchpoint */
258 #define TRAP_UNK	5	/* undiagnosed trap */
259 #define TRAP_PERF	6	/* perf event with sigtrap=1 */
260 #define NSIGTRAP	6
261 
262 /*
263  * There is an additional set of SIGTRAP si_codes used by ptrace
264  * that are of the form: ((PTRACE_EVENT_XXX << 8) | SIGTRAP)
265  */
266 
267 /*
268  * SIGCHLD si_codes
269  */
270 #define CLD_EXITED	1	/* child has exited */
271 #define CLD_KILLED	2	/* child was killed */
272 #define CLD_DUMPED	3	/* child terminated abnormally */
273 #define CLD_TRAPPED	4	/* traced child has trapped */
274 #define CLD_STOPPED	5	/* child has stopped */
275 #define CLD_CONTINUED	6	/* stopped child has continued */
276 #define NSIGCHLD	6
277 
278 /*
279  * SIGPOLL (or any other signal without signal specific si_codes) si_codes
280  */
281 #define POLL_IN		1	/* data input available */
282 #define POLL_OUT	2	/* output buffers available */
283 #define POLL_MSG	3	/* input message available */
284 #define POLL_ERR	4	/* i/o error */
285 #define POLL_PRI	5	/* high priority input available */
286 #define POLL_HUP	6	/* device disconnected */
287 #define NSIGPOLL	6
288 
289 /*
290  * SIGSYS si_codes
291  */
292 #define SYS_SECCOMP	1	/* seccomp triggered */
293 #define SYS_USER_DISPATCH 2	/* syscall user dispatch triggered */
294 #define NSIGSYS		2
295 
296 /*
297  * SIGEMT si_codes
298  */
299 #define EMT_TAGOVF	1	/* tag overflow */
300 #define NSIGEMT		1
301 
302 /*
303  * sigevent definitions
304  *
305  * It seems likely that SIGEV_THREAD will have to be handled from
306  * userspace, libpthread transmuting it to SIGEV_SIGNAL, which the
307  * thread manager then catches and does the appropriate nonsense.
308  * However, everything is written out here so as to not get lost.
309  */
310 #define SIGEV_SIGNAL	0	/* notify via signal */
311 #define SIGEV_NONE	1	/* other notification: meaningless */
312 #define SIGEV_THREAD	2	/* deliver via thread creation */
313 #define SIGEV_THREAD_ID 4	/* deliver to thread */
314 
315 /*
316  * This works because the alignment is ok on all current architectures
317  * but we leave open this being overridden in the future
318  */
319 #ifndef __ARCH_SIGEV_PREAMBLE_SIZE
320 #define __ARCH_SIGEV_PREAMBLE_SIZE	(sizeof(int) * 2 + sizeof(sigval_t))
321 #endif
322 
323 #define SIGEV_MAX_SIZE	64
324 #define SIGEV_PAD_SIZE	((SIGEV_MAX_SIZE - __ARCH_SIGEV_PREAMBLE_SIZE) \
325 		/ sizeof(int))
326 
327 typedef struct sigevent {
328 	sigval_t sigev_value;
329 	int sigev_signo;
330 	int sigev_notify;
331 	union {
332 		int _pad[SIGEV_PAD_SIZE];
333 		 int _tid;
334 
335 		struct {
336 			void (*_function)(sigval_t);
337 			void *_attribute;	/* really pthread_attr_t */
338 		} _sigev_thread;
339 	} _sigev_un;
340 } sigevent_t;
341 
342 #define sigev_notify_function	_sigev_un._sigev_thread._function
343 #define sigev_notify_attributes	_sigev_un._sigev_thread._attribute
344 #define sigev_notify_thread_id	 _sigev_un._tid
345 
346 
347 #endif /* _UAPI_ASM_GENERIC_SIGINFO_H */
348