blob: c840719a8c595cea463df2113d4934e6ff2a0ff8 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _ASM_GENERIC_SIGINFO_H
2#define _ASM_GENERIC_SIGINFO_H
3
4#include <linux/compiler.h>
5#include <linux/types.h>
6
7typedef union sigval {
8 int sival_int;
9 void __user *sival_ptr;
10} sigval_t;
11
12/*
13 * This is the size (including padding) of the part of the
14 * struct siginfo that is before the union.
15 */
16#ifndef __ARCH_SI_PREAMBLE_SIZE
17#define __ARCH_SI_PREAMBLE_SIZE (3 * sizeof(int))
18#endif
19
20#define SI_MAX_SIZE 128
21#ifndef SI_PAD_SIZE
22#define SI_PAD_SIZE ((SI_MAX_SIZE - __ARCH_SI_PREAMBLE_SIZE) / sizeof(int))
23#endif
24
25#ifndef __ARCH_SI_UID_T
Arnd Bergmann85efde62009-02-26 00:51:39 +010026#define __ARCH_SI_UID_T __kernel_uid32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#endif
28
29/*
30 * The default "si_band" type is "long", as specified by POSIX.
31 * However, some architectures want to override this to "int"
32 * for historical compatibility reasons, so we allow that.
33 */
34#ifndef __ARCH_SI_BAND_T
35#define __ARCH_SI_BAND_T long
36#endif
37
38#ifndef HAVE_ARCH_SIGINFO_T
39
40typedef struct siginfo {
41 int si_signo;
42 int si_errno;
43 int si_code;
44
45 union {
46 int _pad[SI_PAD_SIZE];
47
48 /* kill() */
49 struct {
Arnd Bergmann85efde62009-02-26 00:51:39 +010050 __kernel_pid_t _pid; /* sender's pid */
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 __ARCH_SI_UID_T _uid; /* sender's uid */
52 } _kill;
53
54 /* POSIX.1b timers */
55 struct {
Arnd Bergmann85efde62009-02-26 00:51:39 +010056 __kernel_timer_t _tid; /* timer id */
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 int _overrun; /* overrun count */
58 char _pad[sizeof( __ARCH_SI_UID_T) - sizeof(int)];
59 sigval_t _sigval; /* same as below */
60 int _sys_private; /* not to be passed to user */
61 } _timer;
62
63 /* POSIX.1b signals */
64 struct {
Arnd Bergmann85efde62009-02-26 00:51:39 +010065 __kernel_pid_t _pid; /* sender's pid */
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 __ARCH_SI_UID_T _uid; /* sender's uid */
67 sigval_t _sigval;
68 } _rt;
69
70 /* SIGCHLD */
71 struct {
Arnd Bergmann85efde62009-02-26 00:51:39 +010072 __kernel_pid_t _pid; /* which child */
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 __ARCH_SI_UID_T _uid; /* sender's uid */
74 int _status; /* exit code */
Arnd Bergmann85efde62009-02-26 00:51:39 +010075 __kernel_clock_t _utime;
76 __kernel_clock_t _stime;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 } _sigchld;
78
79 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS */
80 struct {
81 void __user *_addr; /* faulting insn/memory ref. */
82#ifdef __ARCH_SI_TRAPNO
83 int _trapno; /* TRAP # which caused the signal */
84#endif
85 } _sigfault;
86
87 /* SIGPOLL */
88 struct {
89 __ARCH_SI_BAND_T _band; /* POLL_IN, POLL_OUT, POLL_MSG */
90 int _fd;
91 } _sigpoll;
92 } _sifields;
93} siginfo_t;
94
95#endif
96
97/*
98 * How these fields are to be accessed.
99 */
100#define si_pid _sifields._kill._pid
101#define si_uid _sifields._kill._uid
102#define si_tid _sifields._timer._tid
103#define si_overrun _sifields._timer._overrun
104#define si_sys_private _sifields._timer._sys_private
105#define si_status _sifields._sigchld._status
106#define si_utime _sifields._sigchld._utime
107#define si_stime _sifields._sigchld._stime
108#define si_value _sifields._rt._sigval
109#define si_int _sifields._rt._sigval.sival_int
110#define si_ptr _sifields._rt._sigval.sival_ptr
111#define si_addr _sifields._sigfault._addr
112#ifdef __ARCH_SI_TRAPNO
113#define si_trapno _sifields._sigfault._trapno
114#endif
115#define si_band _sifields._sigpoll._band
116#define si_fd _sifields._sigpoll._fd
117
118#ifdef __KERNEL__
119#define __SI_MASK 0xffff0000u
120#define __SI_KILL (0 << 16)
121#define __SI_TIMER (1 << 16)
122#define __SI_POLL (2 << 16)
123#define __SI_FAULT (3 << 16)
124#define __SI_CHLD (4 << 16)
125#define __SI_RT (5 << 16)
126#define __SI_MESGQ (6 << 16)
127#define __SI_CODE(T,N) ((T) | ((N) & 0xffff))
128#else
129#define __SI_KILL 0
130#define __SI_TIMER 0
131#define __SI_POLL 0
132#define __SI_FAULT 0
133#define __SI_CHLD 0
134#define __SI_RT 0
135#define __SI_MESGQ 0
136#define __SI_CODE(T,N) (N)
137#endif
138
139/*
140 * si_code values
141 * Digital reserves positive values for kernel-generated signals.
142 */
143#define SI_USER 0 /* sent by kill, sigsend, raise */
144#define SI_KERNEL 0x80 /* sent by the kernel from somewhere */
145#define SI_QUEUE -1 /* sent by sigqueue */
146#define SI_TIMER __SI_CODE(__SI_TIMER,-2) /* sent by timer expiration */
147#define SI_MESGQ __SI_CODE(__SI_MESGQ,-3) /* sent by real time mesq state change */
148#define SI_ASYNCIO -4 /* sent by AIO completion */
149#define SI_SIGIO -5 /* sent by queued SIGIO */
150#define SI_TKILL -6 /* sent by tkill system call */
151#define SI_DETHREAD -7 /* sent by execve() killing subsidiary threads */
152
153#define SI_FROMUSER(siptr) ((siptr)->si_code <= 0)
154#define SI_FROMKERNEL(siptr) ((siptr)->si_code > 0)
155
156/*
157 * SIGILL si_codes
158 */
159#define ILL_ILLOPC (__SI_FAULT|1) /* illegal opcode */
160#define ILL_ILLOPN (__SI_FAULT|2) /* illegal operand */
161#define ILL_ILLADR (__SI_FAULT|3) /* illegal addressing mode */
162#define ILL_ILLTRP (__SI_FAULT|4) /* illegal trap */
163#define ILL_PRVOPC (__SI_FAULT|5) /* privileged opcode */
164#define ILL_PRVREG (__SI_FAULT|6) /* privileged register */
165#define ILL_COPROC (__SI_FAULT|7) /* coprocessor error */
166#define ILL_BADSTK (__SI_FAULT|8) /* internal stack error */
167#define NSIGILL 8
168
169/*
170 * SIGFPE si_codes
171 */
172#define FPE_INTDIV (__SI_FAULT|1) /* integer divide by zero */
173#define FPE_INTOVF (__SI_FAULT|2) /* integer overflow */
174#define FPE_FLTDIV (__SI_FAULT|3) /* floating point divide by zero */
175#define FPE_FLTOVF (__SI_FAULT|4) /* floating point overflow */
176#define FPE_FLTUND (__SI_FAULT|5) /* floating point underflow */
177#define FPE_FLTRES (__SI_FAULT|6) /* floating point inexact result */
178#define FPE_FLTINV (__SI_FAULT|7) /* floating point invalid operation */
179#define FPE_FLTSUB (__SI_FAULT|8) /* subscript out of range */
180#define NSIGFPE 8
181
182/*
183 * SIGSEGV si_codes
184 */
185#define SEGV_MAPERR (__SI_FAULT|1) /* address not mapped to object */
186#define SEGV_ACCERR (__SI_FAULT|2) /* invalid permissions for mapped object */
187#define NSIGSEGV 2
188
189/*
190 * SIGBUS si_codes
191 */
192#define BUS_ADRALN (__SI_FAULT|1) /* invalid address alignment */
193#define BUS_ADRERR (__SI_FAULT|2) /* non-existant physical address */
194#define BUS_OBJERR (__SI_FAULT|3) /* object specific hardware error */
195#define NSIGBUS 3
196
197/*
198 * SIGTRAP si_codes
199 */
200#define TRAP_BRKPT (__SI_FAULT|1) /* process breakpoint */
201#define TRAP_TRACE (__SI_FAULT|2) /* process trace trap */
Srinivasa Dsda654b72008-09-23 15:23:52 +0530202#define TRAP_BRANCH (__SI_FAULT|3) /* process taken branch trap */
203#define TRAP_HWBKPT (__SI_FAULT|4) /* hardware breakpoint/watchpoint */
Andi Kleen0769c292009-04-13 14:39:56 -0700204#define NSIGTRAP 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
206/*
207 * SIGCHLD si_codes
208 */
209#define CLD_EXITED (__SI_CHLD|1) /* child has exited */
210#define CLD_KILLED (__SI_CHLD|2) /* child was killed */
211#define CLD_DUMPED (__SI_CHLD|3) /* child terminated abnormally */
212#define CLD_TRAPPED (__SI_CHLD|4) /* traced child has trapped */
213#define CLD_STOPPED (__SI_CHLD|5) /* child has stopped */
214#define CLD_CONTINUED (__SI_CHLD|6) /* stopped child has continued */
215#define NSIGCHLD 6
216
217/*
218 * SIGPOLL si_codes
219 */
220#define POLL_IN (__SI_POLL|1) /* data input available */
221#define POLL_OUT (__SI_POLL|2) /* output buffers available */
222#define POLL_MSG (__SI_POLL|3) /* input message available */
223#define POLL_ERR (__SI_POLL|4) /* i/o error */
224#define POLL_PRI (__SI_POLL|5) /* high priority input available */
225#define POLL_HUP (__SI_POLL|6) /* device disconnected */
226#define NSIGPOLL 6
227
228/*
229 * sigevent definitions
230 *
231 * It seems likely that SIGEV_THREAD will have to be handled from
232 * userspace, libpthread transmuting it to SIGEV_SIGNAL, which the
233 * thread manager then catches and does the appropriate nonsense.
234 * However, everything is written out here so as to not get lost.
235 */
236#define SIGEV_SIGNAL 0 /* notify via signal */
237#define SIGEV_NONE 1 /* other notification: meaningless */
238#define SIGEV_THREAD 2 /* deliver via thread creation */
239#define SIGEV_THREAD_ID 4 /* deliver to thread */
240
Stephen Rothwella71c1ab2005-05-01 08:59:08 -0700241/*
242 * This works because the alignment is ok on all current architectures
243 * but we leave open this being overridden in the future
244 */
245#ifndef __ARCH_SIGEV_PREAMBLE_SIZE
246#define __ARCH_SIGEV_PREAMBLE_SIZE (sizeof(int) * 2 + sizeof(sigval_t))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247#endif
248
Stephen Rothwella71c1ab2005-05-01 08:59:08 -0700249#define SIGEV_MAX_SIZE 64
250#define SIGEV_PAD_SIZE ((SIGEV_MAX_SIZE - __ARCH_SIGEV_PREAMBLE_SIZE) \
251 / sizeof(int))
252
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253typedef struct sigevent {
254 sigval_t sigev_value;
255 int sigev_signo;
256 int sigev_notify;
257 union {
258 int _pad[SIGEV_PAD_SIZE];
259 int _tid;
260
261 struct {
262 void (*_function)(sigval_t);
263 void *_attribute; /* really pthread_attr_t */
264 } _sigev_thread;
265 } _sigev_un;
266} sigevent_t;
267
268#define sigev_notify_function _sigev_un._sigev_thread._function
269#define sigev_notify_attributes _sigev_un._sigev_thread._attribute
270#define sigev_notify_thread_id _sigev_un._tid
271
272#ifdef __KERNEL__
273
274struct siginfo;
275void do_schedule_next_timer(struct siginfo *info);
276
277#ifndef HAVE_ARCH_COPY_SIGINFO
278
279#include <linux/string.h>
280
281static inline void copy_siginfo(struct siginfo *to, struct siginfo *from)
282{
283 if (from->si_code < 0)
284 memcpy(to, from, sizeof(*to));
285 else
286 /* _sigchld is currently the largest know union member */
287 memcpy(to, from, __ARCH_SI_PREAMBLE_SIZE + sizeof(from->_sifields._sigchld));
288}
289
290#endif
291
292extern int copy_siginfo_to_user(struct siginfo __user *to, struct siginfo *from);
293
294#endif /* __KERNEL__ */
295
296#endif