1 /*
2  * This file is subject to the terms and conditions of the GNU General Public
3  * License.  See the file "COPYING" in the main directory of this archive
4  * for more details.
5  *
6  * Copyright (C) 1998, 1999, 2001, 03, 04 Ralf Baechle
7  * Copyright (C) 2000, 2001 Silicon Graphics, Inc.
8  */
9 #ifndef _ASM_SIGINFO_H
10 #define _ASM_SIGINFO_H
11 
12 #include <linux/config.h>
13 #include <linux/types.h>
14 
15 /* This structure matches IRIX 32/n32 ABIs for binary compatibility. */
16 
17 typedef union sigval {
18 	int sival_int;
19 	void *sival_ptr;
20 } sigval_t;
21 
22 /* This structure matches IRIX 32/n32 ABIs for binary compatibility but
23    has Linux extensions.  */
24 
25 #define SI_MAX_SIZE	128
26 #ifdef CONFIG_MIPS32
27 #define SI_PAD_SIZE	((SI_MAX_SIZE/sizeof(int)) - 3)
28 #endif
29 #ifdef CONFIG_MIPS64
30 #define SI_PAD_SIZE	((SI_MAX_SIZE/sizeof(int)) - 4)
31 #endif
32 
33 typedef struct siginfo {
34 	int si_signo;
35 	int si_code;
36 	int si_errno;
37 	int __pad0[SI_MAX_SIZE / sizeof(int) - SI_PAD_SIZE - 3];
38 
39 	union {
40 		int _pad[SI_PAD_SIZE];
41 
42 		/* kill() */
43 		struct {
44 			pid_t _pid;		/* sender's pid */
45 			uid_t _uid;		/* sender's uid */
46 		} _kill;
47 
48 		/* SIGCHLD */
49 		struct {
50 			pid_t _pid;		/* which child */
51 			uid_t _uid;		/* sender's uid */
52 			int _status;		/* exit code */
53 			clock_t _utime;
54 			clock_t _stime;
55 		} _sigchld;
56 
57 		/* IRIX SIGCHLD */
58 		struct {
59 			pid_t _pid;		/* which child */
60 			clock_t _utime;
61 			int _status;		/* exit code */
62 			clock_t _stime;
63 		} _irix_sigchld;
64 
65 		/* SIGILL, SIGFPE, SIGSEGV, SIGBUS */
66 		struct {
67 			void *_addr; /* faulting insn/memory ref. */
68 		} _sigfault;
69 
70 		/* SIGPOLL, SIGXFSZ (To do ...)  */
71 		struct {
72 			long _band;	/* POLL_IN, POLL_OUT, POLL_MSG */
73 			int _fd;
74 		} _sigpoll;
75 
76 		/* POSIX.1b timers */
77 		struct {
78 			unsigned int _timer1;
79 			unsigned int _timer2;
80 		} _timer;
81 
82 		/* POSIX.1b signals */
83 		struct {
84 			pid_t _pid;		/* sender's pid */
85 			uid_t _uid;		/* sender's uid */
86 			sigval_t _sigval;
87 		} _rt;
88 
89 	} _sifields;
90 } siginfo_t;
91 
92 /*
93  * How these fields are to be accessed.
94  */
95 #define si_pid		_sifields._kill._pid
96 #define si_uid		_sifields._kill._uid
97 #define si_status	_sifields._sigchld._status
98 #define si_utime	_sifields._sigchld._utime
99 #define si_stime	_sifields._sigchld._stime
100 #define si_value	_sifields._rt._sigval
101 #define si_int		_sifields._rt._sigval.sival_int
102 #define si_ptr		_sifields._rt._sigval.sival_ptr
103 #define si_addr		_sifields._sigfault._addr
104 #define si_band		_sifields._sigpoll._band
105 #define si_fd		_sifields._sigpoll._fd
106 
107 #ifdef __KERNEL__
108 #define __SI_MASK	0xffff0000
109 #define __SI_KILL	(0 << 16)
110 #define __SI_TIMER	(1 << 16)
111 #define __SI_POLL	(2 << 16)
112 #define __SI_FAULT	(3 << 16)
113 #define __SI_CHLD	(4 << 16)
114 #define __SI_RT		(5 << 16)
115 #define __SI_CODE(T,N)	((T) << 16 | ((N) & 0xffff))
116 #else
117 #define __SI_KILL	0
118 #define __SI_TIMER	0
119 #define __SI_POLL	0
120 #define __SI_FAULT	0
121 #define __SI_CHLD	0
122 #define __SI_RT		0
123 #define __SI_CODE(T,N)	(N)
124 #endif
125 
126 /*
127  * si_code values
128  * Again these have been choosen to be IRIX compatible.
129  */
130 #define SI_USER		0	/* sent by kill, sigsend, raise */
131 #define SI_KERNEL	0x80	/* sent by the kernel from somewhere */
132 #define SI_QUEUE	-1	/* sent by sigqueue */
133 #define SI_ASYNCIO	-2	/* sent by AIO completion */
134 #define SI_TIMER __SI_CODE(__SI_TIMER,-3) /* sent by timer expiration */
135 #define SI_MESGQ	-4	/* sent by real time mesq state change */
136 #define SI_SIGIO	-5	/* sent by queued SIGIO */
137 #define SI_TKILL	-6	/* sent by tkill system call */
138 
139 #define SI_FROMUSER(siptr)	((siptr)->si_code <= 0)
140 #define SI_FROMKERNEL(siptr)	((siptr)->si_code > 0)
141 
142 /*
143  * SIGILL si_codes
144  */
145 #define ILL_ILLOPC	(__SI_FAULT|1)	/* illegal opcode */
146 #define ILL_ILLOPN	(__SI_FAULT|2)	/* illegal operand */
147 #define ILL_ILLADR	(__SI_FAULT|3)	/* illegal addressing mode */
148 #define ILL_ILLTRP	(__SI_FAULT|4)	/* illegal trap */
149 #define ILL_PRVOPC	(__SI_FAULT|5)	/* privileged opcode */
150 #define ILL_PRVREG	(__SI_FAULT|6)	/* privileged register */
151 #define ILL_COPROC	(__SI_FAULT|7)	/* coprocessor error */
152 #define ILL_BADSTK	(__SI_FAULT|8)	/* internal stack error */
153 #define NSIGILL		8
154 
155 /*
156  * SIGFPE si_codes
157  */
158 #define FPE_INTDIV	(__SI_FAULT|1)	/* integer divide by zero */
159 #define FPE_INTOVF	(__SI_FAULT|2)	/* integer overflow */
160 #define FPE_FLTDIV	(__SI_FAULT|3)	/* floating point divide by zero */
161 #define FPE_FLTOVF	(__SI_FAULT|4)	/* floating point overflow */
162 #define FPE_FLTUND	(__SI_FAULT|5)	/* floating point underflow */
163 #define FPE_FLTRES	(__SI_FAULT|6)	/* floating point inexact result */
164 #define FPE_FLTINV	(__SI_FAULT|7)	/* floating point invalid operation */
165 #define FPE_FLTSUB	(__SI_FAULT|8)	/* subscript out of range */
166 #define NSIGFPE		8
167 
168 /*
169  * SIGSEGV si_codes
170  */
171 #define SEGV_MAPERR	(__SI_FAULT|1)	/* address not mapped to object */
172 #define SEGV_ACCERR	(__SI_FAULT|2)	/* invalid permissions for mapped object */
173 #define NSIGSEGV	2
174 
175 /*
176  * SIGBUS si_codes
177  */
178 #define BUS_ADRALN	(__SI_FAULT|1)	/* invalid address alignment */
179 #define BUS_ADRERR	(__SI_FAULT|2)	/* non-existant physical address */
180 #define BUS_OBJERR	(__SI_FAULT|3)	/* object specific hardware error */
181 #define NSIGBUS		3
182 
183 /*
184  * SIGTRAP si_codes
185  */
186 #define TRAP_BRKPT	(__SI_FAULT|1)	/* process breakpoint */
187 #define TRAP_TRACE	(__SI_FAULT|2)	/* process trace trap */
188 #define NSIGTRAP	2
189 
190 /*
191  * SIGCHLD si_codes
192  */
193 #define CLD_EXITED	(__SI_CHLD|1)	/* child has exited */
194 #define CLD_KILLED	(__SI_CHLD|2)	/* child was killed */
195 #define CLD_DUMPED	(__SI_CHLD|3)	/* child terminated abnormally */
196 #define CLD_TRAPPED	(__SI_CHLD|4)	/* traced child has trapped */
197 #define CLD_STOPPED	(__SI_CHLD|5)	/* child has stopped */
198 #define CLD_CONTINUED	(__SI_CHLD|6)	/* stopped child has continued */
199 #define NSIGCHLD	6
200 
201 /*
202  * SIGPOLL si_codes
203  */
204 #define POLL_IN		(__SI_POLL|1)	/* data input available */
205 #define POLL_OUT	(__SI_POLL|2)	/* output buffers available */
206 #define POLL_MSG	(__SI_POLL|3)	/* input message available */
207 #define POLL_ERR	(__SI_POLL|4)	/* i/o error */
208 #define POLL_PRI	(__SI_POLL|5)	/* high priority input available */
209 #define POLL_HUP	(__SI_POLL|6)	/* device disconnected */
210 #define NSIGPOLL	6
211 
212 /*
213  * sigevent definitions
214  *
215  * It seems likely that SIGEV_THREAD will have to be handled from
216  * userspace, libpthread transmuting it to SIGEV_SIGNAL, which the
217  * thread manager then catches and does the appropriate nonsense.
218  * However, everything is written out here so as to not get lost.
219  */
220 #define SIGEV_SIGNAL	0	/* notify via signal */
221 #define SIGEV_NONE	1	/* other notification: meaningless */
222 #define SIGEV_THREAD	2	/* deliver via thread creation */
223 
224 #define SIGEV_MAX_SIZE	64
225 #define SIGEV_HEAD_SIZE	(sizeof(long) + 2*sizeof(int))
226 #define SIGEV_PAD_SIZE	((SIGEV_MAX_SIZE-SIGEV_HEAD_SIZE) / sizeof(int))
227 
228 typedef struct sigevent {
229 	sigval_t sigev_value;
230 	int sigev_signo;
231 	int sigev_notify;
232 	union {
233 		int _pad[SIGEV_PAD_SIZE];
234 
235 		struct {
236 			void (*_function)(sigval_t);
237 			void *_attribute;	/* really pthread_attr_t */
238 		} _sigev_thread;
239 	} _sigev_un;
240 } sigevent_t;
241 
242 #define sigev_notify_function	_sigev_un._sigev_thread._function
243 #define sigev_notify_attributes	_sigev_un._sigev_thread._attribute
244 
245 #ifdef __KERNEL__
246 #include <linux/string.h>
247 
copy_siginfo(siginfo_t * to,siginfo_t * from)248 static inline void copy_siginfo(siginfo_t *to, siginfo_t *from)
249 {
250 	if (from->si_code < 0)
251 		memcpy(to, from, sizeof(siginfo_t));
252 	else
253 		/* _sigchld is currently the largest know union member */
254 		memcpy(to, from, 3*sizeof(int) + sizeof(from->_sifields._sigchld));
255 }
256 
257 extern int copy_siginfo_to_user(siginfo_t *to, siginfo_t *from);
258 
259 #endif /* __KERNEL__ */
260 
261 #endif /* _ASM_SIGINFO_H */
262