1 /* siginfo_t, sigevent and constants.  Linux version.
2    Copyright (C) 1997-2002, 2003 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.  */
32 typedef 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 typedef struct siginfo
51   {
52     int si_signo;		/* Signal number.  */
53     int si_errno;		/* If non-zero, an errno value associated with
54 				   this signal, as defined in <errno.h>.  */
55     int si_code;		/* Signal code.  */
56 
57     union
58       {
59 	int _pad[__SI_PAD_SIZE];
60 
61 	 /* kill().  */
62 	struct
63 	  {
64 	    __pid_t si_pid;	/* Sending process ID.  */
65 	    __uid_t si_uid;	/* Real user ID of sending process.  */
66 	  } _kill;
67 
68 	/* POSIX.1b timers.  */
69 	struct
70 	  {
71 	    int si_tid;		/* Timer ID.  */
72 	    int si_overrun;	/* Overrun count.  */
73 	    sigval_t si_sigval;	/* Signal value.  */
74 	  } _timer;
75 
76 	/* POSIX.1b signals.  */
77 	struct
78 	  {
79 	    __pid_t si_pid;	/* Sending process ID.  */
80 	    __uid_t si_uid;	/* Real user ID of sending process.  */
81 	    sigval_t si_sigval;	/* Signal value.  */
82 	  } _rt;
83 
84 	/* SIGCHLD.  */
85 	struct
86 	  {
87 	    __pid_t si_pid;	/* Which child.  */
88 	    __uid_t si_uid;	/* Real user ID of sending process.  */
89 	    int si_status;	/* Exit value or signal.  */
90 	    __clock_t si_utime;
91 	    __clock_t si_stime;
92 	  } _sigchld;
93 
94 	/* SIGILL, SIGFPE, SIGSEGV, SIGBUS.  */
95 	struct
96 	  {
97 	    void *si_addr;	/* Faulting insn/memory ref.  */
98 	  } _sigfault;
99 
100 	/* SIGPOLL.  */
101 	struct
102 	  {
103 	    long int si_band;	/* Band event for SIGPOLL.  */
104 	    int si_fd;
105 	  } _sigpoll;
106 
107 	/* SIGSYS.  */
108 	struct
109 	  {
110 	    void *_call_addr;   /* Calling user insn.  */
111 	    int _syscall;       /* Triggering system call number.  */
112 	    unsigned int _arch; /* AUDIT_ARCH_* of syscall.  */
113 	  } _sigsys;
114       } _sifields;
115   } siginfo_t;
116 
117 
118 /* X/Open requires some more fields with fixed names.  */
119 # define si_pid		_sifields._kill.si_pid
120 # define si_uid		_sifields._kill.si_uid
121 # define si_timerid	_sifields._timer.si_tid
122 # define si_overrun	_sifields._timer.si_overrun
123 # define si_status	_sifields._sigchld.si_status
124 # define si_utime	_sifields._sigchld.si_utime
125 # define si_stime	_sifields._sigchld.si_stime
126 # define si_value	_sifields._rt.si_sigval
127 # define si_int		_sifields._rt.si_sigval.sival_int
128 # define si_ptr		_sifields._rt.si_sigval.sival_ptr
129 # define si_addr	_sifields._sigfault.si_addr
130 # define si_band	_sifields._sigpoll.si_band
131 # define si_fd		_sifields._sigpoll.si_fd
132 # define si_call_addr	_sifields._sigsys._call_addr
133 # define si_syscall	_sifields._sigsys._syscall
134 # define si_arch	_sifields._sigsys._arch
135 
136 
137 /* Values for `si_code'.  Positive values are reserved for kernel-generated
138    signals.  */
139 enum
140 {
141   SI_ASYNCNL = -60,		/* Sent by asynch name lookup completion.  */
142 # define SI_ASYNCNL	SI_ASYNCNL
143   SI_TKILL = -6,		/* Sent by tkill.  */
144 # define SI_TKILL	SI_TKILL
145   SI_SIGIO,			/* Sent by queued SIGIO. */
146 # define SI_SIGIO	SI_SIGIO
147   SI_ASYNCIO,			/* Sent by AIO completion.  */
148 # define SI_ASYNCIO	SI_ASYNCIO
149   SI_MESGQ,			/* Sent by real time mesq state change.  */
150 # define SI_MESGQ	SI_MESGQ
151   SI_TIMER,			/* Sent by timer expiration.  */
152 # define SI_TIMER	SI_TIMER
153   SI_QUEUE,			/* Sent by sigqueue.  */
154 # define SI_QUEUE	SI_QUEUE
155   SI_USER,			/* Sent by kill, sigsend, raise.  */
156 # define SI_USER	SI_USER
157   SI_KERNEL = 0x80		/* Send by kernel.  */
158 #define SI_KERNEL	SI_KERNEL
159 };
160 
161 
162 /* `si_code' values for SIGILL signal.  */
163 enum
164 {
165   ILL_ILLOPC = 1,		/* Illegal opcode.  */
166 # define ILL_ILLOPC	ILL_ILLOPC
167   ILL_ILLOPN,			/* Illegal operand.  */
168 # define ILL_ILLOPN	ILL_ILLOPN
169   ILL_ILLADR,			/* Illegal addressing mode.  */
170 # define ILL_ILLADR	ILL_ILLADR
171   ILL_ILLTRP,			/* Illegal trap. */
172 # define ILL_ILLTRP	ILL_ILLTRP
173   ILL_PRVOPC,			/* Privileged opcode.  */
174 # define ILL_PRVOPC	ILL_PRVOPC
175   ILL_PRVREG,			/* Privileged register.  */
176 # define ILL_PRVREG	ILL_PRVREG
177   ILL_COPROC,			/* Coprocessor error.  */
178 # define ILL_COPROC	ILL_COPROC
179   ILL_BADSTK			/* Internal stack error.  */
180 # define ILL_BADSTK	ILL_BADSTK
181 };
182 
183 /* `si_code' values for SIGFPE signal.  */
184 enum
185 {
186   FPE_INTDIV = 1,		/* Integer divide by zero.  */
187 # define FPE_INTDIV	FPE_INTDIV
188   FPE_INTOVF,			/* Integer overflow.  */
189 # define FPE_INTOVF	FPE_INTOVF
190   FPE_FLTDIV,			/* Floating point divide by zero.  */
191 # define FPE_FLTDIV	FPE_FLTDIV
192   FPE_FLTOVF,			/* Floating point overflow.  */
193 # define FPE_FLTOVF	FPE_FLTOVF
194   FPE_FLTUND,			/* Floating point underflow.  */
195 # define FPE_FLTUND	FPE_FLTUND
196   FPE_FLTRES,			/* Floating point inexact result.  */
197 # define FPE_FLTRES	FPE_FLTRES
198   FPE_FLTINV,			/* Floating point invalid operation.  */
199 # define FPE_FLTINV	FPE_FLTINV
200   FPE_FLTSUB			/* Subscript out of range.  */
201 # define FPE_FLTSUB	FPE_FLTSUB
202 };
203 
204 /* `si_code' values for SIGSEGV signal.  */
205 enum
206 {
207   SEGV_MAPERR = 1,		/* Address not mapped to object.  */
208 # define SEGV_MAPERR	SEGV_MAPERR
209   SEGV_ACCERR			/* Invalid permissions for mapped object.  */
210 # define SEGV_ACCERR	SEGV_ACCERR
211 };
212 
213 /* `si_code' values for SIGBUS signal.  */
214 enum
215 {
216   BUS_ADRALN = 1,		/* Invalid address alignment.  */
217 # define BUS_ADRALN	BUS_ADRALN
218   BUS_ADRERR,			/* Non-existant physical address.  */
219 # define BUS_ADRERR	BUS_ADRERR
220   BUS_OBJERR			/* Object specific hardware error.  */
221 # define BUS_OBJERR	BUS_OBJERR
222 };
223 
224 /* `si_code' values for SIGTRAP signal.  */
225 enum
226 {
227   TRAP_BRKPT = 1,		/* Process breakpoint.  */
228 # define TRAP_BRKPT	TRAP_BRKPT
229   TRAP_TRACE			/* Process trace trap.  */
230 # define TRAP_TRACE	TRAP_TRACE
231 };
232 
233 /* `si_code' values for SIGCHLD signal.  */
234 enum
235 {
236   CLD_EXITED = 1,		/* Child has exited.  */
237 # define CLD_EXITED	CLD_EXITED
238   CLD_KILLED,			/* Child was killed.  */
239 # define CLD_KILLED	CLD_KILLED
240   CLD_DUMPED,			/* Child terminated abnormally.  */
241 # define CLD_DUMPED	CLD_DUMPED
242   CLD_TRAPPED,			/* Traced child has trapped.  */
243 # define CLD_TRAPPED	CLD_TRAPPED
244   CLD_STOPPED,			/* Child has stopped.  */
245 # define CLD_STOPPED	CLD_STOPPED
246   CLD_CONTINUED			/* Stopped child has continued.  */
247 # define CLD_CONTINUED	CLD_CONTINUED
248 };
249 
250 /* `si_code' values for SIGPOLL signal.  */
251 enum
252 {
253   POLL_IN = 1,			/* Data input available.  */
254 # define POLL_IN	POLL_IN
255   POLL_OUT,			/* Output buffers available.  */
256 # define POLL_OUT	POLL_OUT
257   POLL_MSG,			/* Input message available.   */
258 # define POLL_MSG	POLL_MSG
259   POLL_ERR,			/* I/O error.  */
260 # define POLL_ERR	POLL_ERR
261   POLL_PRI,			/* High priority input available.  */
262 # define POLL_PRI	POLL_PRI
263   POLL_HUP			/* Device disconnected.  */
264 # define POLL_HUP	POLL_HUP
265 };
266 
267 # undef __need_siginfo_t
268 #endif	/* !have siginfo_t && (have _SIGNAL_H || need siginfo_t).  */
269 
270 
271 #if (defined _SIGNAL_H || defined __need_sigevent_t) \
272     && !defined __have_sigevent_t
273 # define __have_sigevent_t	1
274 
275 /* Structure to transport application-defined values with signals.  */
276 # define __SIGEV_MAX_SIZE	64
277 # if __WORDSIZE == 64
278 #  define __SIGEV_PAD_SIZE	((__SIGEV_MAX_SIZE / sizeof (int)) - 4)
279 # else
280 #  define __SIGEV_PAD_SIZE	((__SIGEV_MAX_SIZE / sizeof (int)) - 3)
281 # endif
282 
283 typedef struct sigevent
284   {
285     sigval_t sigev_value;
286     int sigev_signo;
287     int sigev_notify;
288 
289     union
290       {
291 	int _pad[__SIGEV_PAD_SIZE];
292 
293 	/* When SIGEV_SIGNAL and SIGEV_THREAD_ID set, LWP ID of the
294 	   thread to receive the signal.  */
295 	__pid_t _tid;
296 
297 	struct
298 	  {
299 	    void (*_function) (sigval_t);	/* Function to start.  */
300 	    void *_attribute;			/* Really pthread_attr_t.  */
301 	  } _sigev_thread;
302       } _sigev_un;
303   } sigevent_t;
304 
305 /* POSIX names to access some of the members.  */
306 # define sigev_notify_function   _sigev_un._sigev_thread._function
307 # define sigev_notify_attributes _sigev_un._sigev_thread._attribute
308 
309 /* `sigev_notify' values.  */
310 enum
311 {
312   SIGEV_SIGNAL = 0,		/* Notify via signal.  */
313 # define SIGEV_SIGNAL	SIGEV_SIGNAL
314   SIGEV_NONE,			/* Other notification: meaningless.  */
315 # define SIGEV_NONE	SIGEV_NONE
316   SIGEV_THREAD,			/* Deliver via thread creation.  */
317 # define SIGEV_THREAD	SIGEV_THREAD
318 
319   SIGEV_THREAD_ID = 4		/* Send signal to specific thread.  */
320 #define SIGEV_THREAD_ID	SIGEV_THREAD_ID
321 };
322 
323 #endif	/* have _SIGNAL_H.  */
324