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