1/* siginfo_t, sigevent and constants. Linux x86-64 version.
2 Copyright (C) 2012-2016 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19#if !defined _SIGNAL_H && !defined __need_siginfo_t \
20 && !defined __need_sigevent_t
21# error "Never include this file directly. Use <signal.h> instead"
22#endif
23
24#include <bits/wordsize.h>
25
26#if (!defined __have_sigval_t \
27 && (defined _SIGNAL_H || defined __need_siginfo_t \
28 || defined __need_sigevent_t))
29# define __have_sigval_t 1
30
31/* Type for data associated with a signal. */
32typedef union sigval
33 {
34 int sival_int;
35 void *sival_ptr;
36 } sigval_t;
37#endif
38
39#if (!defined __have_siginfo_t \
40 && (defined _SIGNAL_H || defined __need_siginfo_t))
41# define __have_siginfo_t 1
42
43# define __SI_MAX_SIZE 128
44# if __WORDSIZE == 64
45# define __SI_PAD_SIZE ((__SI_MAX_SIZE / sizeof (int)) - 4)
46# else
47# define __SI_PAD_SIZE ((__SI_MAX_SIZE / sizeof (int)) - 3)
48# endif
49
50# if defined __x86_64__ && __WORDSIZE == 32
51/* si_utime and si_stime must be 4 byte aligned for x32 to match the
52 kernel. We align siginfo_t to 8 bytes so that si_utime and si_stime
53 are actually aligned to 8 bytes since their offsets are multiple of
54 8 bytes. */
55typedef __clock_t __attribute__ ((__aligned__ (4))) __sigchld_clock_t;
56# define __SI_ALIGNMENT __attribute__ ((__aligned__ (8)))
57# else
58typedef __clock_t __sigchld_clock_t;
59# define __SI_ALIGNMENT
60# endif
61
62typedef struct
63 {
64 int si_signo; /* Signal number. */
65 int si_errno; /* If non-zero, an errno value associated with
66 this signal, as defined in <errno.h>. */
67 int si_code; /* Signal code. */
68
69 union
70 {
71 int _pad[__SI_PAD_SIZE];
72
73 /* kill(). */
74 struct
75 {
76 __pid_t si_pid; /* Sending process ID. */
77 __uid_t si_uid; /* Real user ID of sending process. */
78 } _kill;
79
80 /* POSIX.1b timers. */
81 struct
82 {
83 int si_tid; /* Timer ID. */
84 int si_overrun; /* Overrun count. */
85 sigval_t si_sigval; /* Signal value. */
86 } _timer;
87
88 /* POSIX.1b signals. */
89 struct
90 {
91 __pid_t si_pid; /* Sending process ID. */
92 __uid_t si_uid; /* Real user ID of sending process. */
93 sigval_t si_sigval; /* Signal value. */
94 } _rt;
95
96 /* SIGCHLD. */
97 struct
98 {
99 __pid_t si_pid; /* Which child. */
100 __uid_t si_uid; /* Real user ID of sending process. */
101 int si_status; /* Exit value or signal. */
102 __sigchld_clock_t si_utime;
103 __sigchld_clock_t si_stime;
104 } _sigchld;
105
106 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS. */
107 struct
108 {
109 void *si_addr; /* Faulting insn/memory ref. */
110 short int si_addr_lsb; /* Valid LSB of the reported address. */
111 struct
112 {
113 void *_lower;
114 void *_upper;
115 } si_addr_bnd;
116 } _sigfault;
117
118 /* SIGPOLL. */
119 struct
120 {
121 long int si_band; /* Band event for SIGPOLL. */
122 int si_fd;
123 } _sigpoll;
124
125 /* SIGSYS. */
126 struct
127 {
128 void *_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 } siginfo_t __SI_ALIGNMENT;
134
135
136/* X/Open requires some more fields with fixed names. */
137# define si_pid _sifields._kill.si_pid
138# define si_uid _sifields._kill.si_uid
139# define si_timerid _sifields._timer.si_tid
140# define si_overrun _sifields._timer.si_overrun
141# define si_status _sifields._sigchld.si_status
142# define si_utime _sifields._sigchld.si_utime
143# define si_stime _sifields._sigchld.si_stime
144# define si_value _sifields._rt.si_sigval
145# define si_int _sifields._rt.si_sigval.sival_int
146# define si_ptr _sifields._rt.si_sigval.sival_ptr
147# define si_addr _sifields._sigfault.si_addr
148# define si_addr_lsb _sifields._sigfault.si_addr_lsb
149# define si_lower _sifields._sigfault.si_addr_bnd._lower
150# define si_upper _sifields._sigfault.si_addr_bnd._upper
151# define si_band _sifields._sigpoll.si_band
152# define si_fd _sifields._sigpoll.si_fd
153# define si_call_addr _sifields._sigsys._call_addr
154# define si_syscall _sifields._sigsys._syscall
155# define si_arch _sifields._sigsys._arch
156
157
158/* Values for `si_code'. Positive values are reserved for kernel-generated
159 signals. */
160enum
161{
162 SI_ASYNCNL = -60, /* Sent by asynch name lookup completion. */
163# define SI_ASYNCNL SI_ASYNCNL
164 SI_TKILL = -6, /* Sent by tkill. */
165# define SI_TKILL SI_TKILL
166 SI_SIGIO, /* Sent by queued SIGIO. */
167# define SI_SIGIO SI_SIGIO
168 SI_ASYNCIO, /* Sent by AIO completion. */
169# define SI_ASYNCIO SI_ASYNCIO
170 SI_MESGQ, /* Sent by real time mesq state change. */
171# define SI_MESGQ SI_MESGQ
172 SI_TIMER, /* Sent by timer expiration. */
173# define SI_TIMER SI_TIMER
174 SI_QUEUE, /* Sent by sigqueue. */
175# define SI_QUEUE SI_QUEUE
176 SI_USER, /* Sent by kill, sigsend. */
177# define SI_USER SI_USER
178 SI_KERNEL = 0x80 /* Send by kernel. */
179#define SI_KERNEL SI_KERNEL
180};
181
182
183# if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8
184/* `si_code' values for SIGILL signal. */
185enum
186{
187 ILL_ILLOPC = 1, /* Illegal opcode. */
188# define ILL_ILLOPC ILL_ILLOPC
189 ILL_ILLOPN, /* Illegal operand. */
190# define ILL_ILLOPN ILL_ILLOPN
191 ILL_ILLADR, /* Illegal addressing mode. */
192# define ILL_ILLADR ILL_ILLADR
193 ILL_ILLTRP, /* Illegal trap. */
194# define ILL_ILLTRP ILL_ILLTRP
195 ILL_PRVOPC, /* Privileged opcode. */
196# define ILL_PRVOPC ILL_PRVOPC
197 ILL_PRVREG, /* Privileged register. */
198# define ILL_PRVREG ILL_PRVREG
199 ILL_COPROC, /* Coprocessor error. */
200# define ILL_COPROC ILL_COPROC
201 ILL_BADSTK /* Internal stack error. */
202# define ILL_BADSTK ILL_BADSTK
203};
204
205/* `si_code' values for SIGFPE signal. */
206enum
207{
208 FPE_INTDIV = 1, /* Integer divide by zero. */
209# define FPE_INTDIV FPE_INTDIV
210 FPE_INTOVF, /* Integer overflow. */
211# define FPE_INTOVF FPE_INTOVF
212 FPE_FLTDIV, /* Floating point divide by zero. */
213# define FPE_FLTDIV FPE_FLTDIV
214 FPE_FLTOVF, /* Floating point overflow. */
215# define FPE_FLTOVF FPE_FLTOVF
216 FPE_FLTUND, /* Floating point underflow. */
217# define FPE_FLTUND FPE_FLTUND
218 FPE_FLTRES, /* Floating point inexact result. */
219# define FPE_FLTRES FPE_FLTRES
220 FPE_FLTINV, /* Floating point invalid operation. */
221# define FPE_FLTINV FPE_FLTINV
222 FPE_FLTSUB /* Subscript out of range. */
223# define FPE_FLTSUB FPE_FLTSUB
224};
225
226/* `si_code' values for SIGSEGV signal. */
227enum
228{
229 SEGV_MAPERR = 1, /* Address not mapped to object. */
230# define SEGV_MAPERR SEGV_MAPERR
231 SEGV_ACCERR /* Invalid permissions for mapped object. */
232# define SEGV_ACCERR SEGV_ACCERR
233};
234
235/* `si_code' values for SIGBUS signal. */
236enum
237{
238 BUS_ADRALN = 1, /* Invalid address alignment. */
239# define BUS_ADRALN BUS_ADRALN
240 BUS_ADRERR, /* Non-existant physical address. */
241# define BUS_ADRERR BUS_ADRERR
242 BUS_OBJERR, /* Object specific hardware error. */
243# define BUS_OBJERR BUS_OBJERR
244 BUS_MCEERR_AR, /* Hardware memory error: action required. */
245# define BUS_MCEERR_AR BUS_MCEERR_AR
246 BUS_MCEERR_AO /* Hardware memory error: action optional. */
247# define BUS_MCEERR_AO BUS_MCEERR_AO
248};
249# endif
250
251# ifdef __USE_XOPEN_EXTENDED
252/* `si_code' values for SIGTRAP signal. */
253enum
254{
255 TRAP_BRKPT = 1, /* Process breakpoint. */
256# define TRAP_BRKPT TRAP_BRKPT
257 TRAP_TRACE /* Process trace trap. */
258# define TRAP_TRACE TRAP_TRACE
259};
260# endif
261
262# if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8
263/* `si_code' values for SIGCHLD signal. */
264enum
265{
266 CLD_EXITED = 1, /* Child has exited. */
267# define CLD_EXITED CLD_EXITED
268 CLD_KILLED, /* Child was killed. */
269# define CLD_KILLED CLD_KILLED
270 CLD_DUMPED, /* Child terminated abnormally. */
271# define CLD_DUMPED CLD_DUMPED
272 CLD_TRAPPED, /* Traced child has trapped. */
273# define CLD_TRAPPED CLD_TRAPPED
274 CLD_STOPPED, /* Child has stopped. */
275# define CLD_STOPPED CLD_STOPPED
276 CLD_CONTINUED /* Stopped child has continued. */
277# define CLD_CONTINUED CLD_CONTINUED
278};
279
280/* `si_code' values for SIGPOLL signal. */
281enum
282{
283 POLL_IN = 1, /* Data input available. */
284# define POLL_IN POLL_IN
285 POLL_OUT, /* Output buffers available. */
286# define POLL_OUT POLL_OUT
287 POLL_MSG, /* Input message available. */
288# define POLL_MSG POLL_MSG
289 POLL_ERR, /* I/O error. */
290# define POLL_ERR POLL_ERR
291 POLL_PRI, /* High priority input available. */
292# define POLL_PRI POLL_PRI
293 POLL_HUP /* Device disconnected. */
294# define POLL_HUP POLL_HUP
295};
296# endif
297
298# undef __need_siginfo_t
299#endif /* !have siginfo_t && (have _SIGNAL_H || need siginfo_t). */
300
301
302#if (defined _SIGNAL_H || defined __need_sigevent_t) \
303 && !defined __have_sigevent_t
304# define __have_sigevent_t 1
305
306/* Structure to transport application-defined values with signals. */
307# define __SIGEV_MAX_SIZE 64
308# if __WORDSIZE == 64
309# define __SIGEV_PAD_SIZE ((__SIGEV_MAX_SIZE / sizeof (int)) - 4)
310# else
311# define __SIGEV_PAD_SIZE ((__SIGEV_MAX_SIZE / sizeof (int)) - 3)
312# endif
313
314/* Forward declaration. */
315# ifndef __have_pthread_attr_t
316typedef union pthread_attr_t pthread_attr_t;
317# define __have_pthread_attr_t 1
318# endif
319
320typedef struct sigevent
321 {
322 sigval_t sigev_value;
323 int sigev_signo;
324 int sigev_notify;
325
326 union
327 {
328 int _pad[__SIGEV_PAD_SIZE];
329
330 /* When SIGEV_SIGNAL and SIGEV_THREAD_ID set, LWP ID of the
331 thread to receive the signal. */
332 __pid_t _tid;
333
334 struct
335 {
336 void (*_function) (sigval_t); /* Function to start. */
337 pthread_attr_t *_attribute; /* Thread attributes. */
338 } _sigev_thread;
339 } _sigev_un;
340 } sigevent_t;
341
342/* POSIX names to access some of the members. */
343# define sigev_notify_function _sigev_un._sigev_thread._function
344# define sigev_notify_attributes _sigev_un._sigev_thread._attribute
345
346/* `sigev_notify' values. */
347enum
348{
349 SIGEV_SIGNAL = 0, /* Notify via signal. */
350# define SIGEV_SIGNAL SIGEV_SIGNAL
351 SIGEV_NONE, /* Other notification: meaningless. */
352# define SIGEV_NONE SIGEV_NONE
353 SIGEV_THREAD, /* Deliver via thread creation. */
354# define SIGEV_THREAD SIGEV_THREAD
355
356 SIGEV_THREAD_ID = 4 /* Send signal to specific thread. */
357#define SIGEV_THREAD_ID SIGEV_THREAD_ID
358};
359
360#endif /* have _SIGNAL_H. */
361