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