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