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