root / linux-user / signal.c @ f97572e5
History | View | Annotate | Download (90.8 kB)
1 | 31e31b8a | bellard | /*
|
---|---|---|---|
2 | 66fb9763 | bellard | * Emulation of Linux signals
|
3 | 5fafdf24 | ths | *
|
4 | 31e31b8a | bellard | * Copyright (c) 2003 Fabrice Bellard
|
5 | 31e31b8a | bellard | *
|
6 | 31e31b8a | bellard | * This program is free software; you can redistribute it and/or modify
|
7 | 31e31b8a | bellard | * it under the terms of the GNU General Public License as published by
|
8 | 31e31b8a | bellard | * the Free Software Foundation; either version 2 of the License, or
|
9 | 31e31b8a | bellard | * (at your option) any later version.
|
10 | 31e31b8a | bellard | *
|
11 | 31e31b8a | bellard | * This program is distributed in the hope that it will be useful,
|
12 | 31e31b8a | bellard | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 31e31b8a | bellard | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 | 31e31b8a | bellard | * GNU General Public License for more details.
|
15 | 31e31b8a | bellard | *
|
16 | 31e31b8a | bellard | * You should have received a copy of the GNU General Public License
|
17 | 31e31b8a | bellard | * along with this program; if not, write to the Free Software
|
18 | 31e31b8a | bellard | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
19 | 31e31b8a | bellard | */
|
20 | 31e31b8a | bellard | #include <stdlib.h> |
21 | 31e31b8a | bellard | #include <stdio.h> |
22 | 66fb9763 | bellard | #include <string.h> |
23 | 31e31b8a | bellard | #include <stdarg.h> |
24 | 2677e107 | bellard | #include <unistd.h> |
25 | 31e31b8a | bellard | #include <signal.h> |
26 | 66fb9763 | bellard | #include <errno.h> |
27 | 31e31b8a | bellard | #include <sys/ucontext.h> |
28 | 31e31b8a | bellard | |
29 | 3ef693a0 | bellard | #include "qemu.h" |
30 | 992f48a0 | blueswir1 | #include "target_signal.h" |
31 | 66fb9763 | bellard | |
32 | 66fb9763 | bellard | //#define DEBUG_SIGNAL
|
33 | 66fb9763 | bellard | |
34 | a04e134a | ths | struct target_sigaltstack target_sigaltstack_used = {
|
35 | a04e134a | ths | .ss_sp = 0,
|
36 | a04e134a | ths | .ss_size = 0,
|
37 | a04e134a | ths | .ss_flags = TARGET_SS_DISABLE, |
38 | a04e134a | ths | }; |
39 | a04e134a | ths | |
40 | 624f7979 | pbrook | static struct target_sigaction sigact_table[TARGET_NSIG]; |
41 | 31e31b8a | bellard | |
42 | 5fafdf24 | ths | static void host_signal_handler(int host_signum, siginfo_t *info, |
43 | 66fb9763 | bellard | void *puc);
|
44 | 66fb9763 | bellard | |
45 | 9e5f5284 | bellard | static uint8_t host_to_target_signal_table[65] = { |
46 | 9e5f5284 | bellard | [SIGHUP] = TARGET_SIGHUP, |
47 | 9e5f5284 | bellard | [SIGINT] = TARGET_SIGINT, |
48 | 9e5f5284 | bellard | [SIGQUIT] = TARGET_SIGQUIT, |
49 | 9e5f5284 | bellard | [SIGILL] = TARGET_SIGILL, |
50 | 9e5f5284 | bellard | [SIGTRAP] = TARGET_SIGTRAP, |
51 | 9e5f5284 | bellard | [SIGABRT] = TARGET_SIGABRT, |
52 | 01e3b763 | bellard | /* [SIGIOT] = TARGET_SIGIOT,*/
|
53 | 9e5f5284 | bellard | [SIGBUS] = TARGET_SIGBUS, |
54 | 9e5f5284 | bellard | [SIGFPE] = TARGET_SIGFPE, |
55 | 9e5f5284 | bellard | [SIGKILL] = TARGET_SIGKILL, |
56 | 9e5f5284 | bellard | [SIGUSR1] = TARGET_SIGUSR1, |
57 | 9e5f5284 | bellard | [SIGSEGV] = TARGET_SIGSEGV, |
58 | 9e5f5284 | bellard | [SIGUSR2] = TARGET_SIGUSR2, |
59 | 9e5f5284 | bellard | [SIGPIPE] = TARGET_SIGPIPE, |
60 | 9e5f5284 | bellard | [SIGALRM] = TARGET_SIGALRM, |
61 | 9e5f5284 | bellard | [SIGTERM] = TARGET_SIGTERM, |
62 | 9e5f5284 | bellard | #ifdef SIGSTKFLT
|
63 | 9e5f5284 | bellard | [SIGSTKFLT] = TARGET_SIGSTKFLT, |
64 | 9e5f5284 | bellard | #endif
|
65 | 9e5f5284 | bellard | [SIGCHLD] = TARGET_SIGCHLD, |
66 | 9e5f5284 | bellard | [SIGCONT] = TARGET_SIGCONT, |
67 | 9e5f5284 | bellard | [SIGSTOP] = TARGET_SIGSTOP, |
68 | 9e5f5284 | bellard | [SIGTSTP] = TARGET_SIGTSTP, |
69 | 9e5f5284 | bellard | [SIGTTIN] = TARGET_SIGTTIN, |
70 | 9e5f5284 | bellard | [SIGTTOU] = TARGET_SIGTTOU, |
71 | 9e5f5284 | bellard | [SIGURG] = TARGET_SIGURG, |
72 | 9e5f5284 | bellard | [SIGXCPU] = TARGET_SIGXCPU, |
73 | 9e5f5284 | bellard | [SIGXFSZ] = TARGET_SIGXFSZ, |
74 | 9e5f5284 | bellard | [SIGVTALRM] = TARGET_SIGVTALRM, |
75 | 9e5f5284 | bellard | [SIGPROF] = TARGET_SIGPROF, |
76 | 9e5f5284 | bellard | [SIGWINCH] = TARGET_SIGWINCH, |
77 | 9e5f5284 | bellard | [SIGIO] = TARGET_SIGIO, |
78 | 9e5f5284 | bellard | [SIGPWR] = TARGET_SIGPWR, |
79 | 9e5f5284 | bellard | [SIGSYS] = TARGET_SIGSYS, |
80 | 9e5f5284 | bellard | /* next signals stay the same */
|
81 | 624f7979 | pbrook | /* Nasty hack: Reverse SIGRTMIN and SIGRTMAX to avoid overlap with
|
82 | 624f7979 | pbrook | host libpthread signals. This assumes noone actually uses SIGRTMAX :-/
|
83 | 624f7979 | pbrook | To fix this properly we need to do manual signal delivery multiplexed
|
84 | 624f7979 | pbrook | over a single host signal. */
|
85 | 624f7979 | pbrook | [__SIGRTMIN] = __SIGRTMAX, |
86 | 624f7979 | pbrook | [__SIGRTMAX] = __SIGRTMIN, |
87 | 9e5f5284 | bellard | }; |
88 | 9e5f5284 | bellard | static uint8_t target_to_host_signal_table[65]; |
89 | 9e5f5284 | bellard | |
90 | a04e134a | ths | static inline int on_sig_stack(unsigned long sp) |
91 | a04e134a | ths | { |
92 | a04e134a | ths | return (sp - target_sigaltstack_used.ss_sp
|
93 | a04e134a | ths | < target_sigaltstack_used.ss_size); |
94 | a04e134a | ths | } |
95 | a04e134a | ths | |
96 | a04e134a | ths | static inline int sas_ss_flags(unsigned long sp) |
97 | a04e134a | ths | { |
98 | a04e134a | ths | return (target_sigaltstack_used.ss_size == 0 ? SS_DISABLE |
99 | a04e134a | ths | : on_sig_stack(sp) ? SS_ONSTACK : 0);
|
100 | a04e134a | ths | } |
101 | a04e134a | ths | |
102 | 31e31b8a | bellard | static inline int host_to_target_signal(int sig) |
103 | 31e31b8a | bellard | { |
104 | 4cb05961 | pbrook | if (sig > 64) |
105 | 4cb05961 | pbrook | return sig;
|
106 | 9e5f5284 | bellard | return host_to_target_signal_table[sig];
|
107 | 31e31b8a | bellard | } |
108 | 31e31b8a | bellard | |
109 | 4cb05961 | pbrook | int target_to_host_signal(int sig) |
110 | 31e31b8a | bellard | { |
111 | 4cb05961 | pbrook | if (sig > 64) |
112 | 4cb05961 | pbrook | return sig;
|
113 | 9e5f5284 | bellard | return target_to_host_signal_table[sig];
|
114 | 31e31b8a | bellard | } |
115 | 31e31b8a | bellard | |
116 | f5545b5c | pbrook | static inline void target_sigemptyset(target_sigset_t *set) |
117 | f5545b5c | pbrook | { |
118 | f5545b5c | pbrook | memset(set, 0, sizeof(*set)); |
119 | f5545b5c | pbrook | } |
120 | f5545b5c | pbrook | |
121 | f5545b5c | pbrook | static inline void target_sigaddset(target_sigset_t *set, int signum) |
122 | f5545b5c | pbrook | { |
123 | f5545b5c | pbrook | signum--; |
124 | f5545b5c | pbrook | abi_ulong mask = (abi_ulong)1 << (signum % TARGET_NSIG_BPW);
|
125 | f5545b5c | pbrook | set->sig[signum / TARGET_NSIG_BPW] |= mask; |
126 | f5545b5c | pbrook | } |
127 | f5545b5c | pbrook | |
128 | f5545b5c | pbrook | static inline int target_sigismember(const target_sigset_t *set, int signum) |
129 | f5545b5c | pbrook | { |
130 | f5545b5c | pbrook | signum--; |
131 | f5545b5c | pbrook | abi_ulong mask = (abi_ulong)1 << (signum % TARGET_NSIG_BPW);
|
132 | f5545b5c | pbrook | return ((set->sig[signum / TARGET_NSIG_BPW] & mask) != 0); |
133 | f5545b5c | pbrook | } |
134 | f5545b5c | pbrook | |
135 | 5fafdf24 | ths | static void host_to_target_sigset_internal(target_sigset_t *d, |
136 | 9231944d | bellard | const sigset_t *s)
|
137 | 66fb9763 | bellard | { |
138 | 66fb9763 | bellard | int i;
|
139 | f5545b5c | pbrook | target_sigemptyset(d); |
140 | f5545b5c | pbrook | for (i = 1; i <= TARGET_NSIG; i++) { |
141 | f5545b5c | pbrook | if (sigismember(s, i)) {
|
142 | f5545b5c | pbrook | target_sigaddset(d, host_to_target_signal(i)); |
143 | f5545b5c | pbrook | } |
144 | 66fb9763 | bellard | } |
145 | 66fb9763 | bellard | } |
146 | 66fb9763 | bellard | |
147 | 9231944d | bellard | void host_to_target_sigset(target_sigset_t *d, const sigset_t *s) |
148 | 9231944d | bellard | { |
149 | 9231944d | bellard | target_sigset_t d1; |
150 | 9231944d | bellard | int i;
|
151 | 9231944d | bellard | |
152 | 9231944d | bellard | host_to_target_sigset_internal(&d1, s); |
153 | 9231944d | bellard | for(i = 0;i < TARGET_NSIG_WORDS; i++) |
154 | 53a5960a | pbrook | d->sig[i] = tswapl(d1.sig[i]); |
155 | 9231944d | bellard | } |
156 | 9231944d | bellard | |
157 | 8fcd3692 | blueswir1 | static void target_to_host_sigset_internal(sigset_t *d, |
158 | 8fcd3692 | blueswir1 | const target_sigset_t *s)
|
159 | 66fb9763 | bellard | { |
160 | 66fb9763 | bellard | int i;
|
161 | f5545b5c | pbrook | sigemptyset(d); |
162 | f5545b5c | pbrook | for (i = 1; i <= TARGET_NSIG; i++) { |
163 | f5545b5c | pbrook | if (target_sigismember(s, i)) {
|
164 | f5545b5c | pbrook | sigaddset(d, target_to_host_signal(i)); |
165 | f5545b5c | pbrook | } |
166 | f5545b5c | pbrook | } |
167 | 66fb9763 | bellard | } |
168 | 66fb9763 | bellard | |
169 | 9231944d | bellard | void target_to_host_sigset(sigset_t *d, const target_sigset_t *s) |
170 | 9231944d | bellard | { |
171 | 9231944d | bellard | target_sigset_t s1; |
172 | 9231944d | bellard | int i;
|
173 | 9231944d | bellard | |
174 | 9231944d | bellard | for(i = 0;i < TARGET_NSIG_WORDS; i++) |
175 | 53a5960a | pbrook | s1.sig[i] = tswapl(s->sig[i]); |
176 | 9231944d | bellard | target_to_host_sigset_internal(d, &s1); |
177 | 9231944d | bellard | } |
178 | 3b46e624 | ths | |
179 | 992f48a0 | blueswir1 | void host_to_target_old_sigset(abi_ulong *old_sigset,
|
180 | 66fb9763 | bellard | const sigset_t *sigset)
|
181 | 66fb9763 | bellard | { |
182 | 9e5f5284 | bellard | target_sigset_t d; |
183 | 9e5f5284 | bellard | host_to_target_sigset(&d, sigset); |
184 | 9e5f5284 | bellard | *old_sigset = d.sig[0];
|
185 | 66fb9763 | bellard | } |
186 | 66fb9763 | bellard | |
187 | 5fafdf24 | ths | void target_to_host_old_sigset(sigset_t *sigset,
|
188 | 992f48a0 | blueswir1 | const abi_ulong *old_sigset)
|
189 | 66fb9763 | bellard | { |
190 | 9e5f5284 | bellard | target_sigset_t d; |
191 | 9e5f5284 | bellard | int i;
|
192 | 9e5f5284 | bellard | |
193 | 9e5f5284 | bellard | d.sig[0] = *old_sigset;
|
194 | 9e5f5284 | bellard | for(i = 1;i < TARGET_NSIG_WORDS; i++) |
195 | 9e5f5284 | bellard | d.sig[i] = 0;
|
196 | 9e5f5284 | bellard | target_to_host_sigset(sigset, &d); |
197 | 66fb9763 | bellard | } |
198 | 66fb9763 | bellard | |
199 | 9de5e440 | bellard | /* siginfo conversion */
|
200 | 9de5e440 | bellard | |
201 | 5fafdf24 | ths | static inline void host_to_target_siginfo_noswap(target_siginfo_t *tinfo, |
202 | 9de5e440 | bellard | const siginfo_t *info)
|
203 | 66fb9763 | bellard | { |
204 | 9de5e440 | bellard | int sig;
|
205 | 9de5e440 | bellard | sig = host_to_target_signal(info->si_signo); |
206 | 9de5e440 | bellard | tinfo->si_signo = sig; |
207 | 9de5e440 | bellard | tinfo->si_errno = 0;
|
208 | afd7cd92 | pbrook | tinfo->si_code = info->si_code; |
209 | 5fafdf24 | ths | if (sig == SIGILL || sig == SIGFPE || sig == SIGSEGV ||
|
210 | 447db213 | bellard | sig == SIGBUS || sig == SIGTRAP) { |
211 | 9de5e440 | bellard | /* should never come here, but who knows. The information for
|
212 | 9de5e440 | bellard | the target is irrelevant */
|
213 | 9de5e440 | bellard | tinfo->_sifields._sigfault._addr = 0;
|
214 | 7f7f7c84 | ths | } else if (sig == SIGIO) { |
215 | 7f7f7c84 | ths | tinfo->_sifields._sigpoll._fd = info->si_fd; |
216 | 9de5e440 | bellard | } else if (sig >= TARGET_SIGRTMIN) { |
217 | 9de5e440 | bellard | tinfo->_sifields._rt._pid = info->si_pid; |
218 | 9de5e440 | bellard | tinfo->_sifields._rt._uid = info->si_uid; |
219 | 9de5e440 | bellard | /* XXX: potential problem if 64 bit */
|
220 | 5fafdf24 | ths | tinfo->_sifields._rt._sigval.sival_ptr = |
221 | 459a4017 | bellard | (abi_ulong)(unsigned long)info->si_value.sival_ptr; |
222 | 9de5e440 | bellard | } |
223 | 9de5e440 | bellard | } |
224 | 9de5e440 | bellard | |
225 | 5fafdf24 | ths | static void tswap_siginfo(target_siginfo_t *tinfo, |
226 | 9de5e440 | bellard | const target_siginfo_t *info)
|
227 | 9de5e440 | bellard | { |
228 | 9de5e440 | bellard | int sig;
|
229 | 9de5e440 | bellard | sig = info->si_signo; |
230 | 9de5e440 | bellard | tinfo->si_signo = tswap32(sig); |
231 | 66fb9763 | bellard | tinfo->si_errno = tswap32(info->si_errno); |
232 | 66fb9763 | bellard | tinfo->si_code = tswap32(info->si_code); |
233 | 5fafdf24 | ths | if (sig == SIGILL || sig == SIGFPE || sig == SIGSEGV ||
|
234 | 447db213 | bellard | sig == SIGBUS || sig == SIGTRAP) { |
235 | 5fafdf24 | ths | tinfo->_sifields._sigfault._addr = |
236 | 9de5e440 | bellard | tswapl(info->_sifields._sigfault._addr); |
237 | 7f7f7c84 | ths | } else if (sig == SIGIO) { |
238 | 7f7f7c84 | ths | tinfo->_sifields._sigpoll._fd = tswap32(info->_sifields._sigpoll._fd); |
239 | 9de5e440 | bellard | } else if (sig >= TARGET_SIGRTMIN) { |
240 | 9de5e440 | bellard | tinfo->_sifields._rt._pid = tswap32(info->_sifields._rt._pid); |
241 | 9de5e440 | bellard | tinfo->_sifields._rt._uid = tswap32(info->_sifields._rt._uid); |
242 | 5fafdf24 | ths | tinfo->_sifields._rt._sigval.sival_ptr = |
243 | 9de5e440 | bellard | tswapl(info->_sifields._rt._sigval.sival_ptr); |
244 | 9de5e440 | bellard | } |
245 | 9de5e440 | bellard | } |
246 | 9de5e440 | bellard | |
247 | 9de5e440 | bellard | |
248 | 9de5e440 | bellard | void host_to_target_siginfo(target_siginfo_t *tinfo, const siginfo_t *info) |
249 | 9de5e440 | bellard | { |
250 | 9de5e440 | bellard | host_to_target_siginfo_noswap(tinfo, info); |
251 | 9de5e440 | bellard | tswap_siginfo(tinfo, tinfo); |
252 | 66fb9763 | bellard | } |
253 | 66fb9763 | bellard | |
254 | 9de5e440 | bellard | /* XXX: we support only POSIX RT signals are used. */
|
255 | aa1f17c1 | ths | /* XXX: find a solution for 64 bit (additional malloced data is needed) */
|
256 | 9de5e440 | bellard | void target_to_host_siginfo(siginfo_t *info, const target_siginfo_t *tinfo) |
257 | 66fb9763 | bellard | { |
258 | 66fb9763 | bellard | info->si_signo = tswap32(tinfo->si_signo); |
259 | 66fb9763 | bellard | info->si_errno = tswap32(tinfo->si_errno); |
260 | 66fb9763 | bellard | info->si_code = tswap32(tinfo->si_code); |
261 | 9de5e440 | bellard | info->si_pid = tswap32(tinfo->_sifields._rt._pid); |
262 | 9de5e440 | bellard | info->si_uid = tswap32(tinfo->_sifields._rt._uid); |
263 | 5fafdf24 | ths | info->si_value.sival_ptr = |
264 | 459a4017 | bellard | (void *)(long)tswapl(tinfo->_sifields._rt._sigval.sival_ptr); |
265 | 66fb9763 | bellard | } |
266 | 66fb9763 | bellard | |
267 | 31e31b8a | bellard | void signal_init(void) |
268 | 31e31b8a | bellard | { |
269 | 31e31b8a | bellard | struct sigaction act;
|
270 | 624f7979 | pbrook | struct sigaction oact;
|
271 | 9e5f5284 | bellard | int i, j;
|
272 | 624f7979 | pbrook | int host_sig;
|
273 | 31e31b8a | bellard | |
274 | 9e5f5284 | bellard | /* generate signal conversion tables */
|
275 | 9e5f5284 | bellard | for(i = 1; i <= 64; i++) { |
276 | 9e5f5284 | bellard | if (host_to_target_signal_table[i] == 0) |
277 | 9e5f5284 | bellard | host_to_target_signal_table[i] = i; |
278 | 9e5f5284 | bellard | } |
279 | 9e5f5284 | bellard | for(i = 1; i <= 64; i++) { |
280 | 9e5f5284 | bellard | j = host_to_target_signal_table[i]; |
281 | 9e5f5284 | bellard | target_to_host_signal_table[j] = i; |
282 | 9e5f5284 | bellard | } |
283 | 3b46e624 | ths | |
284 | 9de5e440 | bellard | /* set all host signal handlers. ALL signals are blocked during
|
285 | 9de5e440 | bellard | the handlers to serialize them. */
|
286 | 624f7979 | pbrook | memset(sigact_table, 0, sizeof(sigact_table)); |
287 | 624f7979 | pbrook | |
288 | 9de5e440 | bellard | sigfillset(&act.sa_mask); |
289 | 31e31b8a | bellard | act.sa_flags = SA_SIGINFO; |
290 | 31e31b8a | bellard | act.sa_sigaction = host_signal_handler; |
291 | 624f7979 | pbrook | for(i = 1; i <= TARGET_NSIG; i++) { |
292 | 624f7979 | pbrook | host_sig = target_to_host_signal(i); |
293 | 624f7979 | pbrook | sigaction(host_sig, NULL, &oact);
|
294 | 624f7979 | pbrook | if (oact.sa_sigaction == (void *)SIG_IGN) { |
295 | 624f7979 | pbrook | sigact_table[i - 1]._sa_handler = TARGET_SIG_IGN;
|
296 | 624f7979 | pbrook | } else if (oact.sa_sigaction == (void *)SIG_DFL) { |
297 | 624f7979 | pbrook | sigact_table[i - 1]._sa_handler = TARGET_SIG_DFL;
|
298 | 624f7979 | pbrook | } |
299 | 624f7979 | pbrook | /* If there's already a handler installed then something has
|
300 | 624f7979 | pbrook | gone horribly wrong, so don't even try to handle that case. */
|
301 | 624f7979 | pbrook | /* Install some handlers for our own use. */
|
302 | 624f7979 | pbrook | if (host_sig == SIGSEGV || host_sig == SIGBUS) {
|
303 | 624f7979 | pbrook | sigaction(host_sig, &act, NULL);
|
304 | 624f7979 | pbrook | } |
305 | 31e31b8a | bellard | } |
306 | 66fb9763 | bellard | } |
307 | 66fb9763 | bellard | |
308 | 66fb9763 | bellard | /* signal queue handling */
|
309 | 66fb9763 | bellard | |
310 | 624f7979 | pbrook | static inline struct sigqueue *alloc_sigqueue(CPUState *env) |
311 | 66fb9763 | bellard | { |
312 | 624f7979 | pbrook | TaskState *ts = env->opaque; |
313 | 624f7979 | pbrook | struct sigqueue *q = ts->first_free;
|
314 | 66fb9763 | bellard | if (!q)
|
315 | 66fb9763 | bellard | return NULL; |
316 | 624f7979 | pbrook | ts->first_free = q->next; |
317 | 66fb9763 | bellard | return q;
|
318 | 31e31b8a | bellard | } |
319 | 31e31b8a | bellard | |
320 | 624f7979 | pbrook | static inline void free_sigqueue(CPUState *env, struct sigqueue *q) |
321 | 66fb9763 | bellard | { |
322 | 624f7979 | pbrook | TaskState *ts = env->opaque; |
323 | 624f7979 | pbrook | q->next = ts->first_free; |
324 | 624f7979 | pbrook | ts->first_free = q; |
325 | 66fb9763 | bellard | } |
326 | 66fb9763 | bellard | |
327 | 9de5e440 | bellard | /* abort execution with signal */
|
328 | 8fcd3692 | blueswir1 | static void __attribute((noreturn)) force_sig(int sig) |
329 | 66fb9763 | bellard | { |
330 | 66fb9763 | bellard | int host_sig;
|
331 | 66fb9763 | bellard | host_sig = target_to_host_signal(sig); |
332 | 5fafdf24 | ths | fprintf(stderr, "qemu: uncaught target signal %d (%s) - exiting\n",
|
333 | 66fb9763 | bellard | sig, strsignal(host_sig)); |
334 | 9de5e440 | bellard | #if 1 |
335 | 66fb9763 | bellard | _exit(-host_sig); |
336 | 9de5e440 | bellard | #else
|
337 | 9de5e440 | bellard | { |
338 | 9de5e440 | bellard | struct sigaction act;
|
339 | 9de5e440 | bellard | sigemptyset(&act.sa_mask); |
340 | 9de5e440 | bellard | act.sa_flags = SA_SIGINFO; |
341 | 9de5e440 | bellard | act.sa_sigaction = SIG_DFL; |
342 | 9de5e440 | bellard | sigaction(SIGABRT, &act, NULL);
|
343 | 9de5e440 | bellard | abort(); |
344 | 9de5e440 | bellard | } |
345 | 9de5e440 | bellard | #endif
|
346 | 66fb9763 | bellard | } |
347 | 66fb9763 | bellard | |
348 | 9de5e440 | bellard | /* queue a signal so that it will be send to the virtual CPU as soon
|
349 | 9de5e440 | bellard | as possible */
|
350 | 624f7979 | pbrook | int queue_signal(CPUState *env, int sig, target_siginfo_t *info) |
351 | 31e31b8a | bellard | { |
352 | 624f7979 | pbrook | TaskState *ts = env->opaque; |
353 | 624f7979 | pbrook | struct emulated_sigtable *k;
|
354 | 9de5e440 | bellard | struct sigqueue *q, **pq;
|
355 | 992f48a0 | blueswir1 | abi_ulong handler; |
356 | 66fb9763 | bellard | |
357 | 9de5e440 | bellard | #if defined(DEBUG_SIGNAL)
|
358 | 5fafdf24 | ths | fprintf(stderr, "queue_signal: sig=%d\n",
|
359 | 9de5e440 | bellard | sig); |
360 | 66fb9763 | bellard | #endif
|
361 | 624f7979 | pbrook | k = &ts->sigtab[sig - 1];
|
362 | 624f7979 | pbrook | handler = sigact_table[sig - 1]._sa_handler;
|
363 | 66fb9763 | bellard | if (handler == TARGET_SIG_DFL) {
|
364 | 66fb9763 | bellard | /* default handler : ignore some signal. The other are fatal */
|
365 | 5fafdf24 | ths | if (sig != TARGET_SIGCHLD &&
|
366 | 5fafdf24 | ths | sig != TARGET_SIGURG && |
367 | 66fb9763 | bellard | sig != TARGET_SIGWINCH) { |
368 | 66fb9763 | bellard | force_sig(sig); |
369 | 9de5e440 | bellard | } else {
|
370 | 9de5e440 | bellard | return 0; /* indicate ignored */ |
371 | 66fb9763 | bellard | } |
372 | 66fb9763 | bellard | } else if (handler == TARGET_SIG_IGN) { |
373 | 66fb9763 | bellard | /* ignore signal */
|
374 | 9de5e440 | bellard | return 0; |
375 | 66fb9763 | bellard | } else if (handler == TARGET_SIG_ERR) { |
376 | 66fb9763 | bellard | force_sig(sig); |
377 | 66fb9763 | bellard | } else {
|
378 | 9de5e440 | bellard | pq = &k->first; |
379 | 9de5e440 | bellard | if (sig < TARGET_SIGRTMIN) {
|
380 | 9de5e440 | bellard | /* if non real time signal, we queue exactly one signal */
|
381 | 9de5e440 | bellard | if (!k->pending)
|
382 | 9de5e440 | bellard | q = &k->info; |
383 | 9de5e440 | bellard | else
|
384 | 9de5e440 | bellard | return 0; |
385 | 9de5e440 | bellard | } else {
|
386 | 9de5e440 | bellard | if (!k->pending) {
|
387 | 9de5e440 | bellard | /* first signal */
|
388 | 9de5e440 | bellard | q = &k->info; |
389 | 9de5e440 | bellard | } else {
|
390 | 624f7979 | pbrook | q = alloc_sigqueue(env); |
391 | 9de5e440 | bellard | if (!q)
|
392 | 9de5e440 | bellard | return -EAGAIN;
|
393 | 9de5e440 | bellard | while (*pq != NULL) |
394 | 9de5e440 | bellard | pq = &(*pq)->next; |
395 | 9de5e440 | bellard | } |
396 | 9de5e440 | bellard | } |
397 | 9de5e440 | bellard | *pq = q; |
398 | 9de5e440 | bellard | q->info = *info; |
399 | 9de5e440 | bellard | q->next = NULL;
|
400 | 9de5e440 | bellard | k->pending = 1;
|
401 | 9de5e440 | bellard | /* signal that a new signal is pending */
|
402 | 624f7979 | pbrook | ts->signal_pending = 1;
|
403 | 9de5e440 | bellard | return 1; /* indicates that the signal was queued */ |
404 | 9de5e440 | bellard | } |
405 | 9de5e440 | bellard | } |
406 | 9de5e440 | bellard | |
407 | 5fafdf24 | ths | static void host_signal_handler(int host_signum, siginfo_t *info, |
408 | 9de5e440 | bellard | void *puc)
|
409 | 9de5e440 | bellard | { |
410 | 9de5e440 | bellard | int sig;
|
411 | 9de5e440 | bellard | target_siginfo_t tinfo; |
412 | 9de5e440 | bellard | |
413 | 9de5e440 | bellard | /* the CPU emulator uses some host signals to detect exceptions,
|
414 | 9de5e440 | bellard | we we forward to it some signals */
|
415 | ec6338ba | bellard | if (host_signum == SIGSEGV || host_signum == SIGBUS) {
|
416 | b346ff46 | bellard | if (cpu_signal_handler(host_signum, info, puc))
|
417 | 9de5e440 | bellard | return;
|
418 | 9de5e440 | bellard | } |
419 | 9de5e440 | bellard | |
420 | 9de5e440 | bellard | /* get target signal number */
|
421 | 9de5e440 | bellard | sig = host_to_target_signal(host_signum); |
422 | 9de5e440 | bellard | if (sig < 1 || sig > TARGET_NSIG) |
423 | 9de5e440 | bellard | return;
|
424 | 9de5e440 | bellard | #if defined(DEBUG_SIGNAL)
|
425 | bc8a22cc | bellard | fprintf(stderr, "qemu: got signal %d\n", sig);
|
426 | 9de5e440 | bellard | #endif
|
427 | 9de5e440 | bellard | host_to_target_siginfo_noswap(&tinfo, info); |
428 | d5975363 | pbrook | if (queue_signal(thread_env, sig, &tinfo) == 1) { |
429 | 9de5e440 | bellard | /* interrupt the virtual CPU as soon as possible */
|
430 | d5975363 | pbrook | cpu_interrupt(thread_env, CPU_INTERRUPT_EXIT); |
431 | 66fb9763 | bellard | } |
432 | 66fb9763 | bellard | } |
433 | 66fb9763 | bellard | |
434 | 0da46a6e | ths | /* do_sigaltstack() returns target values and errnos. */
|
435 | 579a97f7 | bellard | /* compare linux/kernel/signal.c:do_sigaltstack() */
|
436 | 579a97f7 | bellard | abi_long do_sigaltstack(abi_ulong uss_addr, abi_ulong uoss_addr, abi_ulong sp) |
437 | a04e134a | ths | { |
438 | a04e134a | ths | int ret;
|
439 | a04e134a | ths | struct target_sigaltstack oss;
|
440 | a04e134a | ths | |
441 | a04e134a | ths | /* XXX: test errors */
|
442 | 579a97f7 | bellard | if(uoss_addr)
|
443 | a04e134a | ths | { |
444 | a04e134a | ths | __put_user(target_sigaltstack_used.ss_sp, &oss.ss_sp); |
445 | a04e134a | ths | __put_user(target_sigaltstack_used.ss_size, &oss.ss_size); |
446 | a04e134a | ths | __put_user(sas_ss_flags(sp), &oss.ss_flags); |
447 | a04e134a | ths | } |
448 | a04e134a | ths | |
449 | 579a97f7 | bellard | if(uss_addr)
|
450 | a04e134a | ths | { |
451 | 579a97f7 | bellard | struct target_sigaltstack *uss;
|
452 | 579a97f7 | bellard | struct target_sigaltstack ss;
|
453 | a04e134a | ths | |
454 | 0da46a6e | ths | ret = -TARGET_EFAULT; |
455 | 579a97f7 | bellard | if (!lock_user_struct(VERIFY_READ, uss, uss_addr, 1) |
456 | a04e134a | ths | || __get_user(ss.ss_sp, &uss->ss_sp) |
457 | a04e134a | ths | || __get_user(ss.ss_size, &uss->ss_size) |
458 | a04e134a | ths | || __get_user(ss.ss_flags, &uss->ss_flags)) |
459 | a04e134a | ths | goto out;
|
460 | 579a97f7 | bellard | unlock_user_struct(uss, uss_addr, 0);
|
461 | a04e134a | ths | |
462 | 0da46a6e | ths | ret = -TARGET_EPERM; |
463 | a04e134a | ths | if (on_sig_stack(sp))
|
464 | a04e134a | ths | goto out;
|
465 | a04e134a | ths | |
466 | 0da46a6e | ths | ret = -TARGET_EINVAL; |
467 | a04e134a | ths | if (ss.ss_flags != TARGET_SS_DISABLE
|
468 | a04e134a | ths | && ss.ss_flags != TARGET_SS_ONSTACK |
469 | a04e134a | ths | && ss.ss_flags != 0)
|
470 | a04e134a | ths | goto out;
|
471 | a04e134a | ths | |
472 | a04e134a | ths | if (ss.ss_flags == TARGET_SS_DISABLE) {
|
473 | a04e134a | ths | ss.ss_size = 0;
|
474 | a04e134a | ths | ss.ss_sp = 0;
|
475 | a04e134a | ths | } else {
|
476 | 0da46a6e | ths | ret = -TARGET_ENOMEM; |
477 | a04e134a | ths | if (ss.ss_size < MINSIGSTKSZ)
|
478 | a04e134a | ths | goto out;
|
479 | a04e134a | ths | } |
480 | a04e134a | ths | |
481 | a04e134a | ths | target_sigaltstack_used.ss_sp = ss.ss_sp; |
482 | a04e134a | ths | target_sigaltstack_used.ss_size = ss.ss_size; |
483 | a04e134a | ths | } |
484 | a04e134a | ths | |
485 | 579a97f7 | bellard | if (uoss_addr) {
|
486 | 0da46a6e | ths | ret = -TARGET_EFAULT; |
487 | 579a97f7 | bellard | if (copy_to_user(uoss_addr, &oss, sizeof(oss))) |
488 | a04e134a | ths | goto out;
|
489 | a04e134a | ths | } |
490 | a04e134a | ths | |
491 | a04e134a | ths | ret = 0;
|
492 | a04e134a | ths | out:
|
493 | a04e134a | ths | return ret;
|
494 | a04e134a | ths | } |
495 | a04e134a | ths | |
496 | 0da46a6e | ths | /* do_sigaction() return host values and errnos */
|
497 | 66fb9763 | bellard | int do_sigaction(int sig, const struct target_sigaction *act, |
498 | 66fb9763 | bellard | struct target_sigaction *oact)
|
499 | 66fb9763 | bellard | { |
500 | 624f7979 | pbrook | struct target_sigaction *k;
|
501 | 773b93ee | bellard | struct sigaction act1;
|
502 | 773b93ee | bellard | int host_sig;
|
503 | 0da46a6e | ths | int ret = 0; |
504 | 66fb9763 | bellard | |
505 | 0aeaa8ce | ths | if (sig < 1 || sig > TARGET_NSIG || sig == SIGKILL || sig == SIGSTOP) |
506 | 66fb9763 | bellard | return -EINVAL;
|
507 | 66fb9763 | bellard | k = &sigact_table[sig - 1];
|
508 | 773b93ee | bellard | #if defined(DEBUG_SIGNAL)
|
509 | 5fafdf24 | ths | fprintf(stderr, "sigaction sig=%d act=0x%08x, oact=0x%08x\n",
|
510 | 66fb9763 | bellard | sig, (int)act, (int)oact); |
511 | 66fb9763 | bellard | #endif
|
512 | 66fb9763 | bellard | if (oact) {
|
513 | 624f7979 | pbrook | oact->_sa_handler = tswapl(k->_sa_handler); |
514 | 624f7979 | pbrook | oact->sa_flags = tswapl(k->sa_flags); |
515 | 388bb21a | ths | #if !defined(TARGET_MIPS)
|
516 | 624f7979 | pbrook | oact->sa_restorer = tswapl(k->sa_restorer); |
517 | 388bb21a | ths | #endif
|
518 | 624f7979 | pbrook | oact->sa_mask = k->sa_mask; |
519 | 66fb9763 | bellard | } |
520 | 66fb9763 | bellard | if (act) {
|
521 | 624f7979 | pbrook | /* FIXME: This is not threadsafe. */
|
522 | 624f7979 | pbrook | k->_sa_handler = tswapl(act->_sa_handler); |
523 | 624f7979 | pbrook | k->sa_flags = tswapl(act->sa_flags); |
524 | 388bb21a | ths | #if !defined(TARGET_MIPS)
|
525 | 624f7979 | pbrook | k->sa_restorer = tswapl(act->sa_restorer); |
526 | 388bb21a | ths | #endif
|
527 | 624f7979 | pbrook | k->sa_mask = act->sa_mask; |
528 | 773b93ee | bellard | |
529 | 773b93ee | bellard | /* we update the host linux signal state */
|
530 | 773b93ee | bellard | host_sig = target_to_host_signal(sig); |
531 | 773b93ee | bellard | if (host_sig != SIGSEGV && host_sig != SIGBUS) {
|
532 | 773b93ee | bellard | sigfillset(&act1.sa_mask); |
533 | 773b93ee | bellard | act1.sa_flags = SA_SIGINFO; |
534 | 624f7979 | pbrook | if (k->sa_flags & TARGET_SA_RESTART)
|
535 | 773b93ee | bellard | act1.sa_flags |= SA_RESTART; |
536 | 773b93ee | bellard | /* NOTE: it is important to update the host kernel signal
|
537 | 773b93ee | bellard | ignore state to avoid getting unexpected interrupted
|
538 | 773b93ee | bellard | syscalls */
|
539 | 624f7979 | pbrook | if (k->_sa_handler == TARGET_SIG_IGN) {
|
540 | 773b93ee | bellard | act1.sa_sigaction = (void *)SIG_IGN;
|
541 | 624f7979 | pbrook | } else if (k->_sa_handler == TARGET_SIG_DFL) { |
542 | 773b93ee | bellard | act1.sa_sigaction = (void *)SIG_DFL;
|
543 | 773b93ee | bellard | } else {
|
544 | 773b93ee | bellard | act1.sa_sigaction = host_signal_handler; |
545 | 773b93ee | bellard | } |
546 | 0da46a6e | ths | ret = sigaction(host_sig, &act1, NULL);
|
547 | 773b93ee | bellard | } |
548 | 66fb9763 | bellard | } |
549 | 0da46a6e | ths | return ret;
|
550 | 66fb9763 | bellard | } |
551 | 66fb9763 | bellard | |
552 | 43fff238 | bellard | #ifndef offsetof
|
553 | 43fff238 | bellard | #define offsetof(type, field) ((size_t) &((type *)0)->field) |
554 | 43fff238 | bellard | #endif
|
555 | 43fff238 | bellard | |
556 | 5fafdf24 | ths | static inline int copy_siginfo_to_user(target_siginfo_t *tinfo, |
557 | 43fff238 | bellard | const target_siginfo_t *info)
|
558 | 43fff238 | bellard | { |
559 | 43fff238 | bellard | tswap_siginfo(tinfo, info); |
560 | 43fff238 | bellard | return 0; |
561 | 43fff238 | bellard | } |
562 | 43fff238 | bellard | |
563 | c3b5bc8a | ths | static inline int current_exec_domain_sig(int sig) |
564 | c3b5bc8a | ths | { |
565 | c3b5bc8a | ths | return /* current->exec_domain && current->exec_domain->signal_invmap |
566 | c3b5bc8a | ths | && sig < 32 ? current->exec_domain->signal_invmap[sig] : */ sig;
|
567 | c3b5bc8a | ths | } |
568 | c3b5bc8a | ths | |
569 | 459a4017 | bellard | #if defined(TARGET_I386) && TARGET_ABI_BITS == 32 |
570 | 66fb9763 | bellard | |
571 | 66fb9763 | bellard | /* from the Linux kernel */
|
572 | 66fb9763 | bellard | |
573 | 66fb9763 | bellard | struct target_fpreg {
|
574 | 66fb9763 | bellard | uint16_t significand[4];
|
575 | 66fb9763 | bellard | uint16_t exponent; |
576 | 66fb9763 | bellard | }; |
577 | 66fb9763 | bellard | |
578 | 66fb9763 | bellard | struct target_fpxreg {
|
579 | 66fb9763 | bellard | uint16_t significand[4];
|
580 | 66fb9763 | bellard | uint16_t exponent; |
581 | 66fb9763 | bellard | uint16_t padding[3];
|
582 | 66fb9763 | bellard | }; |
583 | 66fb9763 | bellard | |
584 | 66fb9763 | bellard | struct target_xmmreg {
|
585 | 992f48a0 | blueswir1 | abi_ulong element[4];
|
586 | 66fb9763 | bellard | }; |
587 | 66fb9763 | bellard | |
588 | 66fb9763 | bellard | struct target_fpstate {
|
589 | 66fb9763 | bellard | /* Regular FPU environment */
|
590 | 992f48a0 | blueswir1 | abi_ulong cw; |
591 | 992f48a0 | blueswir1 | abi_ulong sw; |
592 | 992f48a0 | blueswir1 | abi_ulong tag; |
593 | 992f48a0 | blueswir1 | abi_ulong ipoff; |
594 | 992f48a0 | blueswir1 | abi_ulong cssel; |
595 | 992f48a0 | blueswir1 | abi_ulong dataoff; |
596 | 992f48a0 | blueswir1 | abi_ulong datasel; |
597 | 66fb9763 | bellard | struct target_fpreg _st[8]; |
598 | 66fb9763 | bellard | uint16_t status; |
599 | 66fb9763 | bellard | uint16_t magic; /* 0xffff = regular FPU data only */
|
600 | 66fb9763 | bellard | |
601 | 66fb9763 | bellard | /* FXSR FPU environment */
|
602 | 992f48a0 | blueswir1 | abi_ulong _fxsr_env[6]; /* FXSR FPU env is ignored */ |
603 | 992f48a0 | blueswir1 | abi_ulong mxcsr; |
604 | 992f48a0 | blueswir1 | abi_ulong reserved; |
605 | 66fb9763 | bellard | struct target_fpxreg _fxsr_st[8]; /* FXSR FPU reg data is ignored */ |
606 | 66fb9763 | bellard | struct target_xmmreg _xmm[8]; |
607 | 992f48a0 | blueswir1 | abi_ulong padding[56];
|
608 | 66fb9763 | bellard | }; |
609 | 66fb9763 | bellard | |
610 | 66fb9763 | bellard | #define X86_FXSR_MAGIC 0x0000 |
611 | 66fb9763 | bellard | |
612 | 66fb9763 | bellard | struct target_sigcontext {
|
613 | 66fb9763 | bellard | uint16_t gs, __gsh; |
614 | 66fb9763 | bellard | uint16_t fs, __fsh; |
615 | 66fb9763 | bellard | uint16_t es, __esh; |
616 | 66fb9763 | bellard | uint16_t ds, __dsh; |
617 | 992f48a0 | blueswir1 | abi_ulong edi; |
618 | 992f48a0 | blueswir1 | abi_ulong esi; |
619 | 992f48a0 | blueswir1 | abi_ulong ebp; |
620 | 992f48a0 | blueswir1 | abi_ulong esp; |
621 | 992f48a0 | blueswir1 | abi_ulong ebx; |
622 | 992f48a0 | blueswir1 | abi_ulong edx; |
623 | 992f48a0 | blueswir1 | abi_ulong ecx; |
624 | 992f48a0 | blueswir1 | abi_ulong eax; |
625 | 992f48a0 | blueswir1 | abi_ulong trapno; |
626 | 992f48a0 | blueswir1 | abi_ulong err; |
627 | 992f48a0 | blueswir1 | abi_ulong eip; |
628 | 66fb9763 | bellard | uint16_t cs, __csh; |
629 | 992f48a0 | blueswir1 | abi_ulong eflags; |
630 | 992f48a0 | blueswir1 | abi_ulong esp_at_signal; |
631 | 66fb9763 | bellard | uint16_t ss, __ssh; |
632 | 992f48a0 | blueswir1 | abi_ulong fpstate; /* pointer */
|
633 | 992f48a0 | blueswir1 | abi_ulong oldmask; |
634 | 992f48a0 | blueswir1 | abi_ulong cr2; |
635 | 66fb9763 | bellard | }; |
636 | 66fb9763 | bellard | |
637 | 66fb9763 | bellard | struct target_ucontext {
|
638 | 992f48a0 | blueswir1 | abi_ulong tuc_flags; |
639 | 992f48a0 | blueswir1 | abi_ulong tuc_link; |
640 | b8076a74 | bellard | target_stack_t tuc_stack; |
641 | b8076a74 | bellard | struct target_sigcontext tuc_mcontext;
|
642 | b8076a74 | bellard | target_sigset_t tuc_sigmask; /* mask last for extensibility */
|
643 | 66fb9763 | bellard | }; |
644 | 66fb9763 | bellard | |
645 | 66fb9763 | bellard | struct sigframe
|
646 | 66fb9763 | bellard | { |
647 | 992f48a0 | blueswir1 | abi_ulong pretcode; |
648 | 66fb9763 | bellard | int sig;
|
649 | 66fb9763 | bellard | struct target_sigcontext sc;
|
650 | 66fb9763 | bellard | struct target_fpstate fpstate;
|
651 | 992f48a0 | blueswir1 | abi_ulong extramask[TARGET_NSIG_WORDS-1];
|
652 | 66fb9763 | bellard | char retcode[8]; |
653 | 66fb9763 | bellard | }; |
654 | 66fb9763 | bellard | |
655 | 66fb9763 | bellard | struct rt_sigframe
|
656 | 66fb9763 | bellard | { |
657 | 992f48a0 | blueswir1 | abi_ulong pretcode; |
658 | 66fb9763 | bellard | int sig;
|
659 | 992f48a0 | blueswir1 | abi_ulong pinfo; |
660 | 992f48a0 | blueswir1 | abi_ulong puc; |
661 | 66fb9763 | bellard | struct target_siginfo info;
|
662 | 66fb9763 | bellard | struct target_ucontext uc;
|
663 | 66fb9763 | bellard | struct target_fpstate fpstate;
|
664 | 66fb9763 | bellard | char retcode[8]; |
665 | 66fb9763 | bellard | }; |
666 | 66fb9763 | bellard | |
667 | 66fb9763 | bellard | /*
|
668 | 66fb9763 | bellard | * Set up a signal frame.
|
669 | 66fb9763 | bellard | */
|
670 | 66fb9763 | bellard | |
671 | 66fb9763 | bellard | /* XXX: save x87 state */
|
672 | 66fb9763 | bellard | static int |
673 | 66fb9763 | bellard | setup_sigcontext(struct target_sigcontext *sc, struct target_fpstate *fpstate, |
674 | 28be6234 | bellard | CPUX86State *env, abi_ulong mask, abi_ulong fpstate_addr) |
675 | 66fb9763 | bellard | { |
676 | 66fb9763 | bellard | int err = 0; |
677 | 775b58d8 | bellard | uint16_t magic; |
678 | 66fb9763 | bellard | |
679 | 579a97f7 | bellard | /* already locked in setup_frame() */
|
680 | a52c757c | bellard | err |= __put_user(env->segs[R_GS].selector, (unsigned int *)&sc->gs); |
681 | a52c757c | bellard | err |= __put_user(env->segs[R_FS].selector, (unsigned int *)&sc->fs); |
682 | a52c757c | bellard | err |= __put_user(env->segs[R_ES].selector, (unsigned int *)&sc->es); |
683 | a52c757c | bellard | err |= __put_user(env->segs[R_DS].selector, (unsigned int *)&sc->ds); |
684 | 66fb9763 | bellard | err |= __put_user(env->regs[R_EDI], &sc->edi); |
685 | 66fb9763 | bellard | err |= __put_user(env->regs[R_ESI], &sc->esi); |
686 | 66fb9763 | bellard | err |= __put_user(env->regs[R_EBP], &sc->ebp); |
687 | 66fb9763 | bellard | err |= __put_user(env->regs[R_ESP], &sc->esp); |
688 | 66fb9763 | bellard | err |= __put_user(env->regs[R_EBX], &sc->ebx); |
689 | 66fb9763 | bellard | err |= __put_user(env->regs[R_EDX], &sc->edx); |
690 | 66fb9763 | bellard | err |= __put_user(env->regs[R_ECX], &sc->ecx); |
691 | 66fb9763 | bellard | err |= __put_user(env->regs[R_EAX], &sc->eax); |
692 | 66099dd9 | bellard | err |= __put_user(env->exception_index, &sc->trapno); |
693 | 66099dd9 | bellard | err |= __put_user(env->error_code, &sc->err); |
694 | 66fb9763 | bellard | err |= __put_user(env->eip, &sc->eip); |
695 | a52c757c | bellard | err |= __put_user(env->segs[R_CS].selector, (unsigned int *)&sc->cs); |
696 | 66fb9763 | bellard | err |= __put_user(env->eflags, &sc->eflags); |
697 | 66fb9763 | bellard | err |= __put_user(env->regs[R_ESP], &sc->esp_at_signal); |
698 | a52c757c | bellard | err |= __put_user(env->segs[R_SS].selector, (unsigned int *)&sc->ss); |
699 | ed2dcdf6 | bellard | |
700 | 28be6234 | bellard | cpu_x86_fsave(env, fpstate_addr, 1);
|
701 | ed2dcdf6 | bellard | fpstate->status = fpstate->sw; |
702 | 775b58d8 | bellard | magic = 0xffff;
|
703 | 775b58d8 | bellard | err |= __put_user(magic, &fpstate->magic); |
704 | 28be6234 | bellard | err |= __put_user(fpstate_addr, &sc->fpstate); |
705 | ed2dcdf6 | bellard | |
706 | 66fb9763 | bellard | /* non-iBCS2 extensions.. */
|
707 | 66fb9763 | bellard | err |= __put_user(mask, &sc->oldmask); |
708 | a52c757c | bellard | err |= __put_user(env->cr[2], &sc->cr2);
|
709 | 66fb9763 | bellard | return err;
|
710 | 31e31b8a | bellard | } |
711 | 31e31b8a | bellard | |
712 | 66fb9763 | bellard | /*
|
713 | 66fb9763 | bellard | * Determine which stack to use..
|
714 | 66fb9763 | bellard | */
|
715 | 31e31b8a | bellard | |
716 | 579a97f7 | bellard | static inline abi_ulong |
717 | 624f7979 | pbrook | get_sigframe(struct target_sigaction *ka, CPUX86State *env, size_t frame_size)
|
718 | 31e31b8a | bellard | { |
719 | 66fb9763 | bellard | unsigned long esp; |
720 | 66fb9763 | bellard | |
721 | 66fb9763 | bellard | /* Default to using normal stack */
|
722 | 66fb9763 | bellard | esp = env->regs[R_ESP]; |
723 | 66fb9763 | bellard | /* This is the X/Open sanctioned signal stack switching. */
|
724 | 624f7979 | pbrook | if (ka->sa_flags & TARGET_SA_ONSTACK) {
|
725 | a04e134a | ths | if (sas_ss_flags(esp) == 0) |
726 | a04e134a | ths | esp = target_sigaltstack_used.ss_sp + target_sigaltstack_used.ss_size; |
727 | a04e134a | ths | } |
728 | 66fb9763 | bellard | |
729 | 66fb9763 | bellard | /* This is the legacy signal stack switching. */
|
730 | 5fafdf24 | ths | else
|
731 | a52c757c | bellard | if ((env->segs[R_SS].selector & 0xffff) != __USER_DS && |
732 | 624f7979 | pbrook | !(ka->sa_flags & TARGET_SA_RESTORER) && |
733 | 624f7979 | pbrook | ka->sa_restorer) { |
734 | 624f7979 | pbrook | esp = (unsigned long) ka->sa_restorer; |
735 | a52c757c | bellard | } |
736 | 579a97f7 | bellard | return (esp - frame_size) & -8ul; |
737 | 66fb9763 | bellard | } |
738 | 66fb9763 | bellard | |
739 | 579a97f7 | bellard | /* compare linux/arch/i386/kernel/signal.c:setup_frame() */
|
740 | 624f7979 | pbrook | static void setup_frame(int sig, struct target_sigaction *ka, |
741 | 66fb9763 | bellard | target_sigset_t *set, CPUX86State *env) |
742 | 66fb9763 | bellard | { |
743 | 579a97f7 | bellard | abi_ulong frame_addr; |
744 | 66fb9763 | bellard | struct sigframe *frame;
|
745 | 9231944d | bellard | int i, err = 0; |
746 | 66fb9763 | bellard | |
747 | 579a97f7 | bellard | frame_addr = get_sigframe(ka, env, sizeof(*frame));
|
748 | 66fb9763 | bellard | |
749 | 579a97f7 | bellard | if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) |
750 | 66fb9763 | bellard | goto give_sigsegv;
|
751 | 579a97f7 | bellard | |
752 | c3b5bc8a | ths | err |= __put_user(current_exec_domain_sig(sig), |
753 | 66fb9763 | bellard | &frame->sig); |
754 | 66fb9763 | bellard | if (err)
|
755 | 66fb9763 | bellard | goto give_sigsegv;
|
756 | 66fb9763 | bellard | |
757 | 28be6234 | bellard | setup_sigcontext(&frame->sc, &frame->fpstate, env, set->sig[0],
|
758 | 28be6234 | bellard | frame_addr + offsetof(struct sigframe, fpstate));
|
759 | 66fb9763 | bellard | if (err)
|
760 | 66fb9763 | bellard | goto give_sigsegv;
|
761 | 66fb9763 | bellard | |
762 | 9231944d | bellard | for(i = 1; i < TARGET_NSIG_WORDS; i++) { |
763 | 9231944d | bellard | if (__put_user(set->sig[i], &frame->extramask[i - 1])) |
764 | 9231944d | bellard | goto give_sigsegv;
|
765 | 9231944d | bellard | } |
766 | 66fb9763 | bellard | |
767 | 66fb9763 | bellard | /* Set up to return from userspace. If provided, use a stub
|
768 | 66fb9763 | bellard | already in userspace. */
|
769 | 624f7979 | pbrook | if (ka->sa_flags & TARGET_SA_RESTORER) {
|
770 | 624f7979 | pbrook | err |= __put_user(ka->sa_restorer, &frame->pretcode); |
771 | 66fb9763 | bellard | } else {
|
772 | 775b58d8 | bellard | uint16_t val16; |
773 | 28be6234 | bellard | abi_ulong retcode_addr; |
774 | 28be6234 | bellard | retcode_addr = frame_addr + offsetof(struct sigframe, retcode);
|
775 | 28be6234 | bellard | err |= __put_user(retcode_addr, &frame->pretcode); |
776 | 66fb9763 | bellard | /* This is popl %eax ; movl $,%eax ; int $0x80 */
|
777 | 775b58d8 | bellard | val16 = 0xb858;
|
778 | 775b58d8 | bellard | err |= __put_user(val16, (uint16_t *)(frame->retcode+0));
|
779 | 66fb9763 | bellard | err |= __put_user(TARGET_NR_sigreturn, (int *)(frame->retcode+2)); |
780 | 775b58d8 | bellard | val16 = 0x80cd;
|
781 | 775b58d8 | bellard | err |= __put_user(val16, (uint16_t *)(frame->retcode+6));
|
782 | 66fb9763 | bellard | } |
783 | 66fb9763 | bellard | |
784 | 66fb9763 | bellard | if (err)
|
785 | 66fb9763 | bellard | goto give_sigsegv;
|
786 | 66fb9763 | bellard | |
787 | 66fb9763 | bellard | /* Set up registers for signal handler */
|
788 | 28be6234 | bellard | env->regs[R_ESP] = frame_addr; |
789 | 624f7979 | pbrook | env->eip = ka->_sa_handler; |
790 | 66fb9763 | bellard | |
791 | 66fb9763 | bellard | cpu_x86_load_seg(env, R_DS, __USER_DS); |
792 | 66fb9763 | bellard | cpu_x86_load_seg(env, R_ES, __USER_DS); |
793 | 66fb9763 | bellard | cpu_x86_load_seg(env, R_SS, __USER_DS); |
794 | 66fb9763 | bellard | cpu_x86_load_seg(env, R_CS, __USER_CS); |
795 | 66fb9763 | bellard | env->eflags &= ~TF_MASK; |
796 | 66fb9763 | bellard | |
797 | 579a97f7 | bellard | unlock_user_struct(frame, frame_addr, 1);
|
798 | 579a97f7 | bellard | |
799 | 66fb9763 | bellard | return;
|
800 | 66fb9763 | bellard | |
801 | 66fb9763 | bellard | give_sigsegv:
|
802 | 579a97f7 | bellard | unlock_user_struct(frame, frame_addr, 1);
|
803 | 66fb9763 | bellard | if (sig == TARGET_SIGSEGV)
|
804 | 624f7979 | pbrook | ka->_sa_handler = TARGET_SIG_DFL; |
805 | 66fb9763 | bellard | force_sig(TARGET_SIGSEGV /* , current */);
|
806 | 66fb9763 | bellard | } |
807 | 66fb9763 | bellard | |
808 | 579a97f7 | bellard | /* compare linux/arch/i386/kernel/signal.c:setup_rt_frame() */
|
809 | 624f7979 | pbrook | static void setup_rt_frame(int sig, struct target_sigaction *ka, |
810 | 9de5e440 | bellard | target_siginfo_t *info, |
811 | 66fb9763 | bellard | target_sigset_t *set, CPUX86State *env) |
812 | 66fb9763 | bellard | { |
813 | 28be6234 | bellard | abi_ulong frame_addr, addr; |
814 | 66fb9763 | bellard | struct rt_sigframe *frame;
|
815 | 9231944d | bellard | int i, err = 0; |
816 | 66fb9763 | bellard | |
817 | 579a97f7 | bellard | frame_addr = get_sigframe(ka, env, sizeof(*frame));
|
818 | 66fb9763 | bellard | |
819 | 579a97f7 | bellard | if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) |
820 | 66fb9763 | bellard | goto give_sigsegv;
|
821 | 66fb9763 | bellard | |
822 | c3b5bc8a | ths | err |= __put_user(current_exec_domain_sig(sig), |
823 | 66fb9763 | bellard | &frame->sig); |
824 | 28be6234 | bellard | addr = frame_addr + offsetof(struct rt_sigframe, info);
|
825 | 28be6234 | bellard | err |= __put_user(addr, &frame->pinfo); |
826 | 28be6234 | bellard | addr = frame_addr + offsetof(struct rt_sigframe, uc);
|
827 | 28be6234 | bellard | err |= __put_user(addr, &frame->puc); |
828 | 66fb9763 | bellard | err |= copy_siginfo_to_user(&frame->info, info); |
829 | 66fb9763 | bellard | if (err)
|
830 | 66fb9763 | bellard | goto give_sigsegv;
|
831 | 31e31b8a | bellard | |
832 | 66fb9763 | bellard | /* Create the ucontext. */
|
833 | b8076a74 | bellard | err |= __put_user(0, &frame->uc.tuc_flags);
|
834 | b8076a74 | bellard | err |= __put_user(0, &frame->uc.tuc_link);
|
835 | a04e134a | ths | err |= __put_user(target_sigaltstack_used.ss_sp, |
836 | b8076a74 | bellard | &frame->uc.tuc_stack.ss_sp); |
837 | a04e134a | ths | err |= __put_user(sas_ss_flags(get_sp_from_cpustate(env)), |
838 | b8076a74 | bellard | &frame->uc.tuc_stack.ss_flags); |
839 | a04e134a | ths | err |= __put_user(target_sigaltstack_used.ss_size, |
840 | b8076a74 | bellard | &frame->uc.tuc_stack.ss_size); |
841 | b8076a74 | bellard | err |= setup_sigcontext(&frame->uc.tuc_mcontext, &frame->fpstate, |
842 | 28be6234 | bellard | env, set->sig[0],
|
843 | 28be6234 | bellard | frame_addr + offsetof(struct rt_sigframe, fpstate));
|
844 | 9231944d | bellard | for(i = 0; i < TARGET_NSIG_WORDS; i++) { |
845 | b8076a74 | bellard | if (__put_user(set->sig[i], &frame->uc.tuc_sigmask.sig[i]))
|
846 | 9231944d | bellard | goto give_sigsegv;
|
847 | 9231944d | bellard | } |
848 | 31e31b8a | bellard | |
849 | 66fb9763 | bellard | /* Set up to return from userspace. If provided, use a stub
|
850 | 66fb9763 | bellard | already in userspace. */
|
851 | 624f7979 | pbrook | if (ka->sa_flags & TARGET_SA_RESTORER) {
|
852 | 624f7979 | pbrook | err |= __put_user(ka->sa_restorer, &frame->pretcode); |
853 | 66fb9763 | bellard | } else {
|
854 | 775b58d8 | bellard | uint16_t val16; |
855 | 28be6234 | bellard | addr = frame_addr + offsetof(struct rt_sigframe, retcode);
|
856 | 28be6234 | bellard | err |= __put_user(addr, &frame->pretcode); |
857 | 66fb9763 | bellard | /* This is movl $,%eax ; int $0x80 */
|
858 | 775b58d8 | bellard | err |= __put_user(0xb8, (char *)(frame->retcode+0)); |
859 | 66fb9763 | bellard | err |= __put_user(TARGET_NR_rt_sigreturn, (int *)(frame->retcode+1)); |
860 | 775b58d8 | bellard | val16 = 0x80cd;
|
861 | 775b58d8 | bellard | err |= __put_user(val16, (uint16_t *)(frame->retcode+5));
|
862 | 66fb9763 | bellard | } |
863 | 66fb9763 | bellard | |
864 | 66fb9763 | bellard | if (err)
|
865 | 66fb9763 | bellard | goto give_sigsegv;
|
866 | 66fb9763 | bellard | |
867 | 66fb9763 | bellard | /* Set up registers for signal handler */
|
868 | 28be6234 | bellard | env->regs[R_ESP] = frame_addr; |
869 | 624f7979 | pbrook | env->eip = ka->_sa_handler; |
870 | 66fb9763 | bellard | |
871 | 66fb9763 | bellard | cpu_x86_load_seg(env, R_DS, __USER_DS); |
872 | 66fb9763 | bellard | cpu_x86_load_seg(env, R_ES, __USER_DS); |
873 | 66fb9763 | bellard | cpu_x86_load_seg(env, R_SS, __USER_DS); |
874 | 66fb9763 | bellard | cpu_x86_load_seg(env, R_CS, __USER_CS); |
875 | 66fb9763 | bellard | env->eflags &= ~TF_MASK; |
876 | 66fb9763 | bellard | |
877 | 579a97f7 | bellard | unlock_user_struct(frame, frame_addr, 1);
|
878 | 579a97f7 | bellard | |
879 | 66fb9763 | bellard | return;
|
880 | 66fb9763 | bellard | |
881 | 66fb9763 | bellard | give_sigsegv:
|
882 | 579a97f7 | bellard | unlock_user_struct(frame, frame_addr, 1);
|
883 | 66fb9763 | bellard | if (sig == TARGET_SIGSEGV)
|
884 | 624f7979 | pbrook | ka->_sa_handler = TARGET_SIG_DFL; |
885 | 66fb9763 | bellard | force_sig(TARGET_SIGSEGV /* , current */);
|
886 | 66fb9763 | bellard | } |
887 | 66fb9763 | bellard | |
888 | 66fb9763 | bellard | static int |
889 | 66fb9763 | bellard | restore_sigcontext(CPUX86State *env, struct target_sigcontext *sc, int *peax) |
890 | 66fb9763 | bellard | { |
891 | 66fb9763 | bellard | unsigned int err = 0; |
892 | 28be6234 | bellard | abi_ulong fpstate_addr; |
893 | 28be6234 | bellard | unsigned int tmpflags; |
894 | 28be6234 | bellard | |
895 | 28be6234 | bellard | cpu_x86_load_seg(env, R_GS, tswap16(sc->gs)); |
896 | 28be6234 | bellard | cpu_x86_load_seg(env, R_FS, tswap16(sc->fs)); |
897 | 28be6234 | bellard | cpu_x86_load_seg(env, R_ES, tswap16(sc->es)); |
898 | 28be6234 | bellard | cpu_x86_load_seg(env, R_DS, tswap16(sc->ds)); |
899 | 28be6234 | bellard | |
900 | 28be6234 | bellard | env->regs[R_EDI] = tswapl(sc->edi); |
901 | 28be6234 | bellard | env->regs[R_ESI] = tswapl(sc->esi); |
902 | 28be6234 | bellard | env->regs[R_EBP] = tswapl(sc->ebp); |
903 | 28be6234 | bellard | env->regs[R_ESP] = tswapl(sc->esp); |
904 | 28be6234 | bellard | env->regs[R_EBX] = tswapl(sc->ebx); |
905 | 28be6234 | bellard | env->regs[R_EDX] = tswapl(sc->edx); |
906 | 28be6234 | bellard | env->regs[R_ECX] = tswapl(sc->ecx); |
907 | 28be6234 | bellard | env->eip = tswapl(sc->eip); |
908 | 66fb9763 | bellard | |
909 | 66fb9763 | bellard | cpu_x86_load_seg(env, R_CS, lduw(&sc->cs) | 3);
|
910 | 66fb9763 | bellard | cpu_x86_load_seg(env, R_SS, lduw(&sc->ss) | 3);
|
911 | 5fafdf24 | ths | |
912 | 28be6234 | bellard | tmpflags = tswapl(sc->eflags); |
913 | 28be6234 | bellard | env->eflags = (env->eflags & ~0x40DD5) | (tmpflags & 0x40DD5); |
914 | 28be6234 | bellard | // regs->orig_eax = -1; /* disable syscall checks */
|
915 | 66fb9763 | bellard | |
916 | 28be6234 | bellard | fpstate_addr = tswapl(sc->fpstate); |
917 | 28be6234 | bellard | if (fpstate_addr != 0) { |
918 | 28be6234 | bellard | if (!access_ok(VERIFY_READ, fpstate_addr,
|
919 | 28be6234 | bellard | sizeof(struct target_fpstate))) |
920 | 28be6234 | bellard | goto badframe;
|
921 | 28be6234 | bellard | cpu_x86_frstor(env, fpstate_addr, 1);
|
922 | 66fb9763 | bellard | } |
923 | ed2dcdf6 | bellard | |
924 | 28be6234 | bellard | *peax = tswapl(sc->eax); |
925 | 66fb9763 | bellard | return err;
|
926 | 66fb9763 | bellard | badframe:
|
927 | 66fb9763 | bellard | return 1; |
928 | 66fb9763 | bellard | } |
929 | 66fb9763 | bellard | |
930 | 66fb9763 | bellard | long do_sigreturn(CPUX86State *env)
|
931 | 66fb9763 | bellard | { |
932 | 579a97f7 | bellard | struct sigframe *frame;
|
933 | 579a97f7 | bellard | abi_ulong frame_addr = env->regs[R_ESP] - 8;
|
934 | 66fb9763 | bellard | target_sigset_t target_set; |
935 | 66fb9763 | bellard | sigset_t set; |
936 | 66fb9763 | bellard | int eax, i;
|
937 | 66fb9763 | bellard | |
938 | 447db213 | bellard | #if defined(DEBUG_SIGNAL)
|
939 | 447db213 | bellard | fprintf(stderr, "do_sigreturn\n");
|
940 | 447db213 | bellard | #endif
|
941 | 579a97f7 | bellard | if (!lock_user_struct(VERIFY_READ, frame, frame_addr, 1)) |
942 | 579a97f7 | bellard | goto badframe;
|
943 | 66fb9763 | bellard | /* set blocked signals */
|
944 | 9231944d | bellard | if (__get_user(target_set.sig[0], &frame->sc.oldmask)) |
945 | 9231944d | bellard | goto badframe;
|
946 | 9231944d | bellard | for(i = 1; i < TARGET_NSIG_WORDS; i++) { |
947 | 9231944d | bellard | if (__get_user(target_set.sig[i], &frame->extramask[i - 1])) |
948 | 9231944d | bellard | goto badframe;
|
949 | 9231944d | bellard | } |
950 | 66fb9763 | bellard | |
951 | 9231944d | bellard | target_to_host_sigset_internal(&set, &target_set); |
952 | 66fb9763 | bellard | sigprocmask(SIG_SETMASK, &set, NULL);
|
953 | 3b46e624 | ths | |
954 | 66fb9763 | bellard | /* restore registers */
|
955 | 66fb9763 | bellard | if (restore_sigcontext(env, &frame->sc, &eax))
|
956 | 66fb9763 | bellard | goto badframe;
|
957 | 579a97f7 | bellard | unlock_user_struct(frame, frame_addr, 0);
|
958 | 66fb9763 | bellard | return eax;
|
959 | 66fb9763 | bellard | |
960 | 66fb9763 | bellard | badframe:
|
961 | 579a97f7 | bellard | unlock_user_struct(frame, frame_addr, 0);
|
962 | 66fb9763 | bellard | force_sig(TARGET_SIGSEGV); |
963 | 66fb9763 | bellard | return 0; |
964 | 66fb9763 | bellard | } |
965 | 66fb9763 | bellard | |
966 | 66fb9763 | bellard | long do_rt_sigreturn(CPUX86State *env)
|
967 | 66fb9763 | bellard | { |
968 | 28be6234 | bellard | abi_ulong frame_addr; |
969 | 28be6234 | bellard | struct rt_sigframe *frame;
|
970 | 66fb9763 | bellard | sigset_t set; |
971 | 66fb9763 | bellard | int eax;
|
972 | 66fb9763 | bellard | |
973 | 28be6234 | bellard | frame_addr = env->regs[R_ESP] - 4;
|
974 | 28be6234 | bellard | if (!lock_user_struct(VERIFY_READ, frame, frame_addr, 1)) |
975 | 28be6234 | bellard | goto badframe;
|
976 | b8076a74 | bellard | target_to_host_sigset(&set, &frame->uc.tuc_sigmask); |
977 | 66fb9763 | bellard | sigprocmask(SIG_SETMASK, &set, NULL);
|
978 | 5fafdf24 | ths | |
979 | b8076a74 | bellard | if (restore_sigcontext(env, &frame->uc.tuc_mcontext, &eax))
|
980 | 66fb9763 | bellard | goto badframe;
|
981 | 66fb9763 | bellard | |
982 | 28be6234 | bellard | if (do_sigaltstack(frame_addr + offsetof(struct rt_sigframe, uc.tuc_stack), 0, |
983 | 28be6234 | bellard | get_sp_from_cpustate(env)) == -EFAULT) |
984 | 66fb9763 | bellard | goto badframe;
|
985 | a04e134a | ths | |
986 | 28be6234 | bellard | unlock_user_struct(frame, frame_addr, 0);
|
987 | 66fb9763 | bellard | return eax;
|
988 | 66fb9763 | bellard | |
989 | 66fb9763 | bellard | badframe:
|
990 | 28be6234 | bellard | unlock_user_struct(frame, frame_addr, 0);
|
991 | 28be6234 | bellard | force_sig(TARGET_SIGSEGV); |
992 | 66fb9763 | bellard | return 0; |
993 | 66fb9763 | bellard | } |
994 | 66fb9763 | bellard | |
995 | 43fff238 | bellard | #elif defined(TARGET_ARM)
|
996 | 43fff238 | bellard | |
997 | 43fff238 | bellard | struct target_sigcontext {
|
998 | 992f48a0 | blueswir1 | abi_ulong trap_no; |
999 | 992f48a0 | blueswir1 | abi_ulong error_code; |
1000 | 992f48a0 | blueswir1 | abi_ulong oldmask; |
1001 | 992f48a0 | blueswir1 | abi_ulong arm_r0; |
1002 | 992f48a0 | blueswir1 | abi_ulong arm_r1; |
1003 | 992f48a0 | blueswir1 | abi_ulong arm_r2; |
1004 | 992f48a0 | blueswir1 | abi_ulong arm_r3; |
1005 | 992f48a0 | blueswir1 | abi_ulong arm_r4; |
1006 | 992f48a0 | blueswir1 | abi_ulong arm_r5; |
1007 | 992f48a0 | blueswir1 | abi_ulong arm_r6; |
1008 | 992f48a0 | blueswir1 | abi_ulong arm_r7; |
1009 | 992f48a0 | blueswir1 | abi_ulong arm_r8; |
1010 | 992f48a0 | blueswir1 | abi_ulong arm_r9; |
1011 | 992f48a0 | blueswir1 | abi_ulong arm_r10; |
1012 | 992f48a0 | blueswir1 | abi_ulong arm_fp; |
1013 | 992f48a0 | blueswir1 | abi_ulong arm_ip; |
1014 | 992f48a0 | blueswir1 | abi_ulong arm_sp; |
1015 | 992f48a0 | blueswir1 | abi_ulong arm_lr; |
1016 | 992f48a0 | blueswir1 | abi_ulong arm_pc; |
1017 | 992f48a0 | blueswir1 | abi_ulong arm_cpsr; |
1018 | 992f48a0 | blueswir1 | abi_ulong fault_address; |
1019 | 43fff238 | bellard | }; |
1020 | 43fff238 | bellard | |
1021 | a745ec6d | pbrook | struct target_ucontext_v1 {
|
1022 | a745ec6d | pbrook | abi_ulong tuc_flags; |
1023 | a745ec6d | pbrook | abi_ulong tuc_link; |
1024 | a745ec6d | pbrook | target_stack_t tuc_stack; |
1025 | a745ec6d | pbrook | struct target_sigcontext tuc_mcontext;
|
1026 | a745ec6d | pbrook | target_sigset_t tuc_sigmask; /* mask last for extensibility */
|
1027 | a745ec6d | pbrook | }; |
1028 | a745ec6d | pbrook | |
1029 | a745ec6d | pbrook | struct target_ucontext_v2 {
|
1030 | 992f48a0 | blueswir1 | abi_ulong tuc_flags; |
1031 | 992f48a0 | blueswir1 | abi_ulong tuc_link; |
1032 | b8076a74 | bellard | target_stack_t tuc_stack; |
1033 | b8076a74 | bellard | struct target_sigcontext tuc_mcontext;
|
1034 | b8076a74 | bellard | target_sigset_t tuc_sigmask; /* mask last for extensibility */
|
1035 | a745ec6d | pbrook | char __unused[128 - sizeof(sigset_t)]; |
1036 | a745ec6d | pbrook | abi_ulong tuc_regspace[128] __attribute__((__aligned__(8))); |
1037 | 43fff238 | bellard | }; |
1038 | 43fff238 | bellard | |
1039 | a8c33204 | pbrook | struct sigframe_v1
|
1040 | 43fff238 | bellard | { |
1041 | 43fff238 | bellard | struct target_sigcontext sc;
|
1042 | 992f48a0 | blueswir1 | abi_ulong extramask[TARGET_NSIG_WORDS-1];
|
1043 | 992f48a0 | blueswir1 | abi_ulong retcode; |
1044 | 43fff238 | bellard | }; |
1045 | 43fff238 | bellard | |
1046 | a8c33204 | pbrook | struct sigframe_v2
|
1047 | a8c33204 | pbrook | { |
1048 | a8c33204 | pbrook | struct target_ucontext_v2 uc;
|
1049 | a8c33204 | pbrook | abi_ulong retcode; |
1050 | a8c33204 | pbrook | }; |
1051 | a8c33204 | pbrook | |
1052 | a745ec6d | pbrook | struct rt_sigframe_v1
|
1053 | 43fff238 | bellard | { |
1054 | f8b0aa25 | bellard | abi_ulong pinfo; |
1055 | f8b0aa25 | bellard | abi_ulong puc; |
1056 | 43fff238 | bellard | struct target_siginfo info;
|
1057 | a745ec6d | pbrook | struct target_ucontext_v1 uc;
|
1058 | a745ec6d | pbrook | abi_ulong retcode; |
1059 | a745ec6d | pbrook | }; |
1060 | a745ec6d | pbrook | |
1061 | a745ec6d | pbrook | struct rt_sigframe_v2
|
1062 | a745ec6d | pbrook | { |
1063 | a745ec6d | pbrook | struct target_siginfo info;
|
1064 | a745ec6d | pbrook | struct target_ucontext_v2 uc;
|
1065 | 992f48a0 | blueswir1 | abi_ulong retcode; |
1066 | 43fff238 | bellard | }; |
1067 | 43fff238 | bellard | |
1068 | 43fff238 | bellard | #define TARGET_CONFIG_CPU_32 1 |
1069 | 43fff238 | bellard | |
1070 | 43fff238 | bellard | /*
|
1071 | 43fff238 | bellard | * For ARM syscalls, we encode the syscall number into the instruction.
|
1072 | 43fff238 | bellard | */
|
1073 | 43fff238 | bellard | #define SWI_SYS_SIGRETURN (0xef000000|(TARGET_NR_sigreturn + ARM_SYSCALL_BASE)) |
1074 | 43fff238 | bellard | #define SWI_SYS_RT_SIGRETURN (0xef000000|(TARGET_NR_rt_sigreturn + ARM_SYSCALL_BASE)) |
1075 | 43fff238 | bellard | |
1076 | 43fff238 | bellard | /*
|
1077 | 43fff238 | bellard | * For Thumb syscalls, we pass the syscall number via r7. We therefore
|
1078 | 43fff238 | bellard | * need two 16-bit instructions.
|
1079 | 43fff238 | bellard | */
|
1080 | 43fff238 | bellard | #define SWI_THUMB_SIGRETURN (0xdf00 << 16 | 0x2700 | (TARGET_NR_sigreturn)) |
1081 | 43fff238 | bellard | #define SWI_THUMB_RT_SIGRETURN (0xdf00 << 16 | 0x2700 | (TARGET_NR_rt_sigreturn)) |
1082 | 43fff238 | bellard | |
1083 | 992f48a0 | blueswir1 | static const abi_ulong retcodes[4] = { |
1084 | 43fff238 | bellard | SWI_SYS_SIGRETURN, SWI_THUMB_SIGRETURN, |
1085 | 43fff238 | bellard | SWI_SYS_RT_SIGRETURN, SWI_THUMB_RT_SIGRETURN |
1086 | 43fff238 | bellard | }; |
1087 | 43fff238 | bellard | |
1088 | 43fff238 | bellard | |
1089 | 43fff238 | bellard | #define __get_user_error(x,p,e) __get_user(x, p)
|
1090 | 43fff238 | bellard | |
1091 | 43fff238 | bellard | static inline int valid_user_regs(CPUState *regs) |
1092 | 43fff238 | bellard | { |
1093 | 43fff238 | bellard | return 1; |
1094 | 43fff238 | bellard | } |
1095 | 43fff238 | bellard | |
1096 | a8c33204 | pbrook | static void |
1097 | 43fff238 | bellard | setup_sigcontext(struct target_sigcontext *sc, /*struct _fpstate *fpstate,*/ |
1098 | f8b0aa25 | bellard | CPUState *env, abi_ulong mask) |
1099 | 43fff238 | bellard | { |
1100 | a8c33204 | pbrook | __put_user(env->regs[0], &sc->arm_r0);
|
1101 | a8c33204 | pbrook | __put_user(env->regs[1], &sc->arm_r1);
|
1102 | a8c33204 | pbrook | __put_user(env->regs[2], &sc->arm_r2);
|
1103 | a8c33204 | pbrook | __put_user(env->regs[3], &sc->arm_r3);
|
1104 | a8c33204 | pbrook | __put_user(env->regs[4], &sc->arm_r4);
|
1105 | a8c33204 | pbrook | __put_user(env->regs[5], &sc->arm_r5);
|
1106 | a8c33204 | pbrook | __put_user(env->regs[6], &sc->arm_r6);
|
1107 | a8c33204 | pbrook | __put_user(env->regs[7], &sc->arm_r7);
|
1108 | a8c33204 | pbrook | __put_user(env->regs[8], &sc->arm_r8);
|
1109 | a8c33204 | pbrook | __put_user(env->regs[9], &sc->arm_r9);
|
1110 | a8c33204 | pbrook | __put_user(env->regs[10], &sc->arm_r10);
|
1111 | a8c33204 | pbrook | __put_user(env->regs[11], &sc->arm_fp);
|
1112 | a8c33204 | pbrook | __put_user(env->regs[12], &sc->arm_ip);
|
1113 | a8c33204 | pbrook | __put_user(env->regs[13], &sc->arm_sp);
|
1114 | a8c33204 | pbrook | __put_user(env->regs[14], &sc->arm_lr);
|
1115 | a8c33204 | pbrook | __put_user(env->regs[15], &sc->arm_pc);
|
1116 | 43fff238 | bellard | #ifdef TARGET_CONFIG_CPU_32
|
1117 | a8c33204 | pbrook | __put_user(cpsr_read(env), &sc->arm_cpsr); |
1118 | 43fff238 | bellard | #endif
|
1119 | 43fff238 | bellard | |
1120 | a8c33204 | pbrook | __put_user(/* current->thread.trap_no */ 0, &sc->trap_no); |
1121 | a8c33204 | pbrook | __put_user(/* current->thread.error_code */ 0, &sc->error_code); |
1122 | a8c33204 | pbrook | __put_user(/* current->thread.address */ 0, &sc->fault_address); |
1123 | a8c33204 | pbrook | __put_user(mask, &sc->oldmask); |
1124 | 43fff238 | bellard | } |
1125 | 43fff238 | bellard | |
1126 | 579a97f7 | bellard | static inline abi_ulong |
1127 | 624f7979 | pbrook | get_sigframe(struct target_sigaction *ka, CPUState *regs, int framesize) |
1128 | 43fff238 | bellard | { |
1129 | 43fff238 | bellard | unsigned long sp = regs->regs[13]; |
1130 | 43fff238 | bellard | |
1131 | 43fff238 | bellard | /*
|
1132 | 43fff238 | bellard | * This is the X/Open sanctioned signal stack switching.
|
1133 | 43fff238 | bellard | */
|
1134 | 624f7979 | pbrook | if ((ka->sa_flags & TARGET_SA_ONSTACK) && !sas_ss_flags(sp))
|
1135 | a04e134a | ths | sp = target_sigaltstack_used.ss_sp + target_sigaltstack_used.ss_size; |
1136 | 43fff238 | bellard | /*
|
1137 | 43fff238 | bellard | * ATPCS B01 mandates 8-byte alignment
|
1138 | 43fff238 | bellard | */
|
1139 | 579a97f7 | bellard | return (sp - framesize) & ~7; |
1140 | 43fff238 | bellard | } |
1141 | 43fff238 | bellard | |
1142 | 43fff238 | bellard | static int |
1143 | 624f7979 | pbrook | setup_return(CPUState *env, struct target_sigaction *ka,
|
1144 | f8b0aa25 | bellard | abi_ulong *rc, abi_ulong frame_addr, int usig, abi_ulong rc_addr)
|
1145 | 43fff238 | bellard | { |
1146 | 624f7979 | pbrook | abi_ulong handler = ka->_sa_handler; |
1147 | 992f48a0 | blueswir1 | abi_ulong retcode; |
1148 | 75b680e5 | pbrook | int thumb = handler & 1; |
1149 | 43fff238 | bellard | |
1150 | 624f7979 | pbrook | if (ka->sa_flags & TARGET_SA_RESTORER) {
|
1151 | 624f7979 | pbrook | retcode = ka->sa_restorer; |
1152 | 43fff238 | bellard | } else {
|
1153 | 43fff238 | bellard | unsigned int idx = thumb; |
1154 | 43fff238 | bellard | |
1155 | 624f7979 | pbrook | if (ka->sa_flags & TARGET_SA_SIGINFO)
|
1156 | 43fff238 | bellard | idx += 2;
|
1157 | 43fff238 | bellard | |
1158 | 43fff238 | bellard | if (__put_user(retcodes[idx], rc))
|
1159 | 43fff238 | bellard | return 1; |
1160 | 43fff238 | bellard | #if 0
|
1161 | 992f48a0 | blueswir1 | flush_icache_range((abi_ulong)rc,
|
1162 | 992f48a0 | blueswir1 | (abi_ulong)(rc + 1));
|
1163 | 43fff238 | bellard | #endif
|
1164 | f8b0aa25 | bellard | retcode = rc_addr + thumb; |
1165 | 43fff238 | bellard | } |
1166 | 43fff238 | bellard | |
1167 | 43fff238 | bellard | env->regs[0] = usig;
|
1168 | f8b0aa25 | bellard | env->regs[13] = frame_addr;
|
1169 | 43fff238 | bellard | env->regs[14] = retcode;
|
1170 | 43fff238 | bellard | env->regs[15] = handler & (thumb ? ~1 : ~3); |
1171 | 75b680e5 | pbrook | env->thumb = thumb; |
1172 | 43fff238 | bellard | |
1173 | b5ff1b31 | bellard | #if 0
|
1174 | 43fff238 | bellard | #ifdef TARGET_CONFIG_CPU_32
|
1175 | 43fff238 | bellard | env->cpsr = cpsr;
|
1176 | 43fff238 | bellard | #endif
|
1177 | b5ff1b31 | bellard | #endif
|
1178 | 43fff238 | bellard | |
1179 | 43fff238 | bellard | return 0; |
1180 | 43fff238 | bellard | } |
1181 | 43fff238 | bellard | |
1182 | a8c33204 | pbrook | static void setup_sigframe_v2(struct target_ucontext_v2 *uc, |
1183 | a8c33204 | pbrook | target_sigset_t *set, CPUState *env) |
1184 | a8c33204 | pbrook | { |
1185 | a8c33204 | pbrook | struct target_sigaltstack stack;
|
1186 | a8c33204 | pbrook | int i;
|
1187 | a8c33204 | pbrook | |
1188 | a8c33204 | pbrook | /* Clear all the bits of the ucontext we don't use. */
|
1189 | a8c33204 | pbrook | memset(uc, 0, offsetof(struct target_ucontext_v2, tuc_mcontext)); |
1190 | a8c33204 | pbrook | |
1191 | a8c33204 | pbrook | memset(&stack, 0, sizeof(stack)); |
1192 | a8c33204 | pbrook | __put_user(target_sigaltstack_used.ss_sp, &stack.ss_sp); |
1193 | a8c33204 | pbrook | __put_user(target_sigaltstack_used.ss_size, &stack.ss_size); |
1194 | a8c33204 | pbrook | __put_user(sas_ss_flags(get_sp_from_cpustate(env)), &stack.ss_flags); |
1195 | a8c33204 | pbrook | memcpy(&uc->tuc_stack, &stack, sizeof(stack));
|
1196 | a8c33204 | pbrook | |
1197 | a8c33204 | pbrook | setup_sigcontext(&uc->tuc_mcontext, env, set->sig[0]);
|
1198 | a8c33204 | pbrook | /* FIXME: Save coprocessor signal frame. */
|
1199 | a8c33204 | pbrook | for(i = 0; i < TARGET_NSIG_WORDS; i++) { |
1200 | a8c33204 | pbrook | __put_user(set->sig[i], &uc->tuc_sigmask.sig[i]); |
1201 | a8c33204 | pbrook | } |
1202 | a8c33204 | pbrook | } |
1203 | a8c33204 | pbrook | |
1204 | 579a97f7 | bellard | /* compare linux/arch/arm/kernel/signal.c:setup_frame() */
|
1205 | 624f7979 | pbrook | static void setup_frame_v1(int usig, struct target_sigaction *ka, |
1206 | a8c33204 | pbrook | target_sigset_t *set, CPUState *regs) |
1207 | 43fff238 | bellard | { |
1208 | a8c33204 | pbrook | struct sigframe_v1 *frame;
|
1209 | 579a97f7 | bellard | abi_ulong frame_addr = get_sigframe(ka, regs, sizeof(*frame));
|
1210 | a8c33204 | pbrook | int i;
|
1211 | 43fff238 | bellard | |
1212 | 579a97f7 | bellard | if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) |
1213 | 579a97f7 | bellard | return;
|
1214 | 579a97f7 | bellard | |
1215 | a8c33204 | pbrook | setup_sigcontext(&frame->sc, regs, set->sig[0]);
|
1216 | 43fff238 | bellard | |
1217 | 9231944d | bellard | for(i = 1; i < TARGET_NSIG_WORDS; i++) { |
1218 | 9231944d | bellard | if (__put_user(set->sig[i], &frame->extramask[i - 1])) |
1219 | 579a97f7 | bellard | goto end;
|
1220 | 43fff238 | bellard | } |
1221 | 43fff238 | bellard | |
1222 | a8c33204 | pbrook | setup_return(regs, ka, &frame->retcode, frame_addr, usig, |
1223 | a8c33204 | pbrook | frame_addr + offsetof(struct sigframe_v1, retcode));
|
1224 | 579a97f7 | bellard | |
1225 | 579a97f7 | bellard | end:
|
1226 | 579a97f7 | bellard | unlock_user_struct(frame, frame_addr, 1);
|
1227 | a8c33204 | pbrook | } |
1228 | a8c33204 | pbrook | |
1229 | 624f7979 | pbrook | static void setup_frame_v2(int usig, struct target_sigaction *ka, |
1230 | a8c33204 | pbrook | target_sigset_t *set, CPUState *regs) |
1231 | a8c33204 | pbrook | { |
1232 | a8c33204 | pbrook | struct sigframe_v2 *frame;
|
1233 | a8c33204 | pbrook | abi_ulong frame_addr = get_sigframe(ka, regs, sizeof(*frame));
|
1234 | a8c33204 | pbrook | |
1235 | a8c33204 | pbrook | if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) |
1236 | a8c33204 | pbrook | return;
|
1237 | a8c33204 | pbrook | |
1238 | a8c33204 | pbrook | setup_sigframe_v2(&frame->uc, set, regs); |
1239 | a8c33204 | pbrook | |
1240 | a8c33204 | pbrook | setup_return(regs, ka, &frame->retcode, frame_addr, usig, |
1241 | a8c33204 | pbrook | frame_addr + offsetof(struct sigframe_v2, retcode));
|
1242 | a8c33204 | pbrook | |
1243 | a8c33204 | pbrook | unlock_user_struct(frame, frame_addr, 1);
|
1244 | a8c33204 | pbrook | } |
1245 | a8c33204 | pbrook | |
1246 | 624f7979 | pbrook | static void setup_frame(int usig, struct target_sigaction *ka, |
1247 | a8c33204 | pbrook | target_sigset_t *set, CPUState *regs) |
1248 | a8c33204 | pbrook | { |
1249 | a8c33204 | pbrook | if (get_osversion() >= 0x020612) { |
1250 | a8c33204 | pbrook | setup_frame_v2(usig, ka, set, regs); |
1251 | a8c33204 | pbrook | } else {
|
1252 | a8c33204 | pbrook | setup_frame_v1(usig, ka, set, regs); |
1253 | a8c33204 | pbrook | } |
1254 | 43fff238 | bellard | } |
1255 | 43fff238 | bellard | |
1256 | 579a97f7 | bellard | /* compare linux/arch/arm/kernel/signal.c:setup_rt_frame() */
|
1257 | 624f7979 | pbrook | static void setup_rt_frame_v1(int usig, struct target_sigaction *ka, |
1258 | a745ec6d | pbrook | target_siginfo_t *info, |
1259 | a745ec6d | pbrook | target_sigset_t *set, CPUState *env) |
1260 | 43fff238 | bellard | { |
1261 | a745ec6d | pbrook | struct rt_sigframe_v1 *frame;
|
1262 | 579a97f7 | bellard | abi_ulong frame_addr = get_sigframe(ka, env, sizeof(*frame));
|
1263 | a04e134a | ths | struct target_sigaltstack stack;
|
1264 | a8c33204 | pbrook | int i;
|
1265 | f8b0aa25 | bellard | abi_ulong info_addr, uc_addr; |
1266 | 43fff238 | bellard | |
1267 | 579a97f7 | bellard | if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) |
1268 | edf779ff | bellard | return /* 1 */; |
1269 | edf779ff | bellard | |
1270 | a745ec6d | pbrook | info_addr = frame_addr + offsetof(struct rt_sigframe_v1, info);
|
1271 | a8c33204 | pbrook | __put_user(info_addr, &frame->pinfo); |
1272 | a745ec6d | pbrook | uc_addr = frame_addr + offsetof(struct rt_sigframe_v1, uc);
|
1273 | a8c33204 | pbrook | __put_user(uc_addr, &frame->puc); |
1274 | a8c33204 | pbrook | copy_siginfo_to_user(&frame->info, info); |
1275 | 43fff238 | bellard | |
1276 | 43fff238 | bellard | /* Clear all the bits of the ucontext we don't use. */
|
1277 | a745ec6d | pbrook | memset(&frame->uc, 0, offsetof(struct target_ucontext_v1, tuc_mcontext)); |
1278 | 43fff238 | bellard | |
1279 | a04e134a | ths | memset(&stack, 0, sizeof(stack)); |
1280 | a04e134a | ths | __put_user(target_sigaltstack_used.ss_sp, &stack.ss_sp); |
1281 | a04e134a | ths | __put_user(target_sigaltstack_used.ss_size, &stack.ss_size); |
1282 | a04e134a | ths | __put_user(sas_ss_flags(get_sp_from_cpustate(env)), &stack.ss_flags); |
1283 | 775b58d8 | bellard | memcpy(&frame->uc.tuc_stack, &stack, sizeof(stack));
|
1284 | a04e134a | ths | |
1285 | a8c33204 | pbrook | setup_sigcontext(&frame->uc.tuc_mcontext, env, set->sig[0]);
|
1286 | 9231944d | bellard | for(i = 0; i < TARGET_NSIG_WORDS; i++) { |
1287 | b8076a74 | bellard | if (__put_user(set->sig[i], &frame->uc.tuc_sigmask.sig[i]))
|
1288 | 579a97f7 | bellard | goto end;
|
1289 | 9231944d | bellard | } |
1290 | 43fff238 | bellard | |
1291 | a8c33204 | pbrook | setup_return(env, ka, &frame->retcode, frame_addr, usig, |
1292 | a8c33204 | pbrook | frame_addr + offsetof(struct rt_sigframe_v1, retcode));
|
1293 | a745ec6d | pbrook | |
1294 | a8c33204 | pbrook | env->regs[1] = info_addr;
|
1295 | a8c33204 | pbrook | env->regs[2] = uc_addr;
|
1296 | a745ec6d | pbrook | |
1297 | a745ec6d | pbrook | end:
|
1298 | a745ec6d | pbrook | unlock_user_struct(frame, frame_addr, 1);
|
1299 | a745ec6d | pbrook | } |
1300 | a745ec6d | pbrook | |
1301 | 624f7979 | pbrook | static void setup_rt_frame_v2(int usig, struct target_sigaction *ka, |
1302 | a745ec6d | pbrook | target_siginfo_t *info, |
1303 | a745ec6d | pbrook | target_sigset_t *set, CPUState *env) |
1304 | a745ec6d | pbrook | { |
1305 | a745ec6d | pbrook | struct rt_sigframe_v2 *frame;
|
1306 | a745ec6d | pbrook | abi_ulong frame_addr = get_sigframe(ka, env, sizeof(*frame));
|
1307 | a745ec6d | pbrook | abi_ulong info_addr, uc_addr; |
1308 | a745ec6d | pbrook | |
1309 | a745ec6d | pbrook | if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) |
1310 | a745ec6d | pbrook | return /* 1 */; |
1311 | a745ec6d | pbrook | |
1312 | a745ec6d | pbrook | info_addr = frame_addr + offsetof(struct rt_sigframe_v2, info);
|
1313 | a745ec6d | pbrook | uc_addr = frame_addr + offsetof(struct rt_sigframe_v2, uc);
|
1314 | a8c33204 | pbrook | copy_siginfo_to_user(&frame->info, info); |
1315 | a745ec6d | pbrook | |
1316 | a8c33204 | pbrook | setup_sigframe_v2(&frame->uc, set, env); |
1317 | a745ec6d | pbrook | |
1318 | a8c33204 | pbrook | setup_return(env, ka, &frame->retcode, frame_addr, usig, |
1319 | a8c33204 | pbrook | frame_addr + offsetof(struct rt_sigframe_v2, retcode));
|
1320 | a745ec6d | pbrook | |
1321 | a8c33204 | pbrook | env->regs[1] = info_addr;
|
1322 | a8c33204 | pbrook | env->regs[2] = uc_addr;
|
1323 | 43fff238 | bellard | |
1324 | 579a97f7 | bellard | unlock_user_struct(frame, frame_addr, 1);
|
1325 | 43fff238 | bellard | } |
1326 | 43fff238 | bellard | |
1327 | 624f7979 | pbrook | static void setup_rt_frame(int usig, struct target_sigaction *ka, |
1328 | a745ec6d | pbrook | target_siginfo_t *info, |
1329 | a745ec6d | pbrook | target_sigset_t *set, CPUState *env) |
1330 | a745ec6d | pbrook | { |
1331 | a745ec6d | pbrook | if (get_osversion() >= 0x020612) { |
1332 | a745ec6d | pbrook | setup_rt_frame_v2(usig, ka, info, set, env); |
1333 | a745ec6d | pbrook | } else {
|
1334 | a745ec6d | pbrook | setup_rt_frame_v1(usig, ka, info, set, env); |
1335 | a745ec6d | pbrook | } |
1336 | a745ec6d | pbrook | } |
1337 | a745ec6d | pbrook | |
1338 | 43fff238 | bellard | static int |
1339 | 43fff238 | bellard | restore_sigcontext(CPUState *env, struct target_sigcontext *sc)
|
1340 | 43fff238 | bellard | { |
1341 | 43fff238 | bellard | int err = 0; |
1342 | b5ff1b31 | bellard | uint32_t cpsr; |
1343 | 43fff238 | bellard | |
1344 | 43fff238 | bellard | __get_user_error(env->regs[0], &sc->arm_r0, err);
|
1345 | 43fff238 | bellard | __get_user_error(env->regs[1], &sc->arm_r1, err);
|
1346 | 43fff238 | bellard | __get_user_error(env->regs[2], &sc->arm_r2, err);
|
1347 | 43fff238 | bellard | __get_user_error(env->regs[3], &sc->arm_r3, err);
|
1348 | 43fff238 | bellard | __get_user_error(env->regs[4], &sc->arm_r4, err);
|
1349 | 43fff238 | bellard | __get_user_error(env->regs[5], &sc->arm_r5, err);
|
1350 | 43fff238 | bellard | __get_user_error(env->regs[6], &sc->arm_r6, err);
|
1351 | 43fff238 | bellard | __get_user_error(env->regs[7], &sc->arm_r7, err);
|
1352 | 43fff238 | bellard | __get_user_error(env->regs[8], &sc->arm_r8, err);
|
1353 | 43fff238 | bellard | __get_user_error(env->regs[9], &sc->arm_r9, err);
|
1354 | 43fff238 | bellard | __get_user_error(env->regs[10], &sc->arm_r10, err);
|
1355 | 43fff238 | bellard | __get_user_error(env->regs[11], &sc->arm_fp, err);
|
1356 | 43fff238 | bellard | __get_user_error(env->regs[12], &sc->arm_ip, err);
|
1357 | 43fff238 | bellard | __get_user_error(env->regs[13], &sc->arm_sp, err);
|
1358 | 43fff238 | bellard | __get_user_error(env->regs[14], &sc->arm_lr, err);
|
1359 | 43fff238 | bellard | __get_user_error(env->regs[15], &sc->arm_pc, err);
|
1360 | 43fff238 | bellard | #ifdef TARGET_CONFIG_CPU_32
|
1361 | b5ff1b31 | bellard | __get_user_error(cpsr, &sc->arm_cpsr, err); |
1362 | 75b680e5 | pbrook | cpsr_write(env, cpsr, CPSR_USER | CPSR_EXEC); |
1363 | 43fff238 | bellard | #endif
|
1364 | 43fff238 | bellard | |
1365 | 43fff238 | bellard | err |= !valid_user_regs(env); |
1366 | 43fff238 | bellard | |
1367 | 43fff238 | bellard | return err;
|
1368 | 43fff238 | bellard | } |
1369 | 43fff238 | bellard | |
1370 | a8c33204 | pbrook | long do_sigreturn_v1(CPUState *env)
|
1371 | 43fff238 | bellard | { |
1372 | f8b0aa25 | bellard | abi_ulong frame_addr; |
1373 | a8c33204 | pbrook | struct sigframe_v1 *frame;
|
1374 | 43fff238 | bellard | target_sigset_t set; |
1375 | 43fff238 | bellard | sigset_t host_set; |
1376 | 9231944d | bellard | int i;
|
1377 | 43fff238 | bellard | |
1378 | 43fff238 | bellard | /*
|
1379 | 43fff238 | bellard | * Since we stacked the signal on a 64-bit boundary,
|
1380 | 43fff238 | bellard | * then 'sp' should be word aligned here. If it's
|
1381 | 43fff238 | bellard | * not, then the user is trying to mess with us.
|
1382 | 43fff238 | bellard | */
|
1383 | 43fff238 | bellard | if (env->regs[13] & 7) |
1384 | 43fff238 | bellard | goto badframe;
|
1385 | 43fff238 | bellard | |
1386 | f8b0aa25 | bellard | frame_addr = env->regs[13];
|
1387 | f8b0aa25 | bellard | if (!lock_user_struct(VERIFY_READ, frame, frame_addr, 1)) |
1388 | f8b0aa25 | bellard | goto badframe;
|
1389 | 43fff238 | bellard | |
1390 | 9231944d | bellard | if (__get_user(set.sig[0], &frame->sc.oldmask)) |
1391 | 9231944d | bellard | goto badframe;
|
1392 | 9231944d | bellard | for(i = 1; i < TARGET_NSIG_WORDS; i++) { |
1393 | 9231944d | bellard | if (__get_user(set.sig[i], &frame->extramask[i - 1])) |
1394 | 9231944d | bellard | goto badframe;
|
1395 | 9231944d | bellard | } |
1396 | 43fff238 | bellard | |
1397 | 9231944d | bellard | target_to_host_sigset_internal(&host_set, &set); |
1398 | 43fff238 | bellard | sigprocmask(SIG_SETMASK, &host_set, NULL);
|
1399 | 43fff238 | bellard | |
1400 | 43fff238 | bellard | if (restore_sigcontext(env, &frame->sc))
|
1401 | 43fff238 | bellard | goto badframe;
|
1402 | 43fff238 | bellard | |
1403 | 43fff238 | bellard | #if 0
|
1404 | 43fff238 | bellard | /* Send SIGTRAP if we're single-stepping */
|
1405 | 43fff238 | bellard | if (ptrace_cancel_bpt(current))
|
1406 | 43fff238 | bellard | send_sig(SIGTRAP, current, 1);
|
1407 | 43fff238 | bellard | #endif
|
1408 | f8b0aa25 | bellard | unlock_user_struct(frame, frame_addr, 0);
|
1409 | f8b0aa25 | bellard | return env->regs[0]; |
1410 | 43fff238 | bellard | |
1411 | 43fff238 | bellard | badframe:
|
1412 | f8b0aa25 | bellard | unlock_user_struct(frame, frame_addr, 0);
|
1413 | 43fff238 | bellard | force_sig(SIGSEGV /* , current */);
|
1414 | 43fff238 | bellard | return 0; |
1415 | 43fff238 | bellard | } |
1416 | 43fff238 | bellard | |
1417 | a8c33204 | pbrook | static int do_sigframe_return_v2(CPUState *env, target_ulong frame_addr, |
1418 | a8c33204 | pbrook | struct target_ucontext_v2 *uc)
|
1419 | a8c33204 | pbrook | { |
1420 | a8c33204 | pbrook | sigset_t host_set; |
1421 | a8c33204 | pbrook | |
1422 | a8c33204 | pbrook | target_to_host_sigset(&host_set, &uc->tuc_sigmask); |
1423 | a8c33204 | pbrook | sigprocmask(SIG_SETMASK, &host_set, NULL);
|
1424 | a8c33204 | pbrook | |
1425 | a8c33204 | pbrook | if (restore_sigcontext(env, &uc->tuc_mcontext))
|
1426 | a8c33204 | pbrook | return 1; |
1427 | a8c33204 | pbrook | |
1428 | a8c33204 | pbrook | if (do_sigaltstack(frame_addr + offsetof(struct target_ucontext_v2, tuc_stack), 0, get_sp_from_cpustate(env)) == -EFAULT) |
1429 | a8c33204 | pbrook | return 1; |
1430 | a8c33204 | pbrook | |
1431 | a8c33204 | pbrook | #if 0
|
1432 | a8c33204 | pbrook | /* Send SIGTRAP if we're single-stepping */
|
1433 | a8c33204 | pbrook | if (ptrace_cancel_bpt(current))
|
1434 | a8c33204 | pbrook | send_sig(SIGTRAP, current, 1);
|
1435 | a8c33204 | pbrook | #endif
|
1436 | a8c33204 | pbrook | |
1437 | a8c33204 | pbrook | return 0; |
1438 | a8c33204 | pbrook | } |
1439 | a8c33204 | pbrook | |
1440 | a8c33204 | pbrook | long do_sigreturn_v2(CPUState *env)
|
1441 | a8c33204 | pbrook | { |
1442 | a8c33204 | pbrook | abi_ulong frame_addr; |
1443 | a8c33204 | pbrook | struct sigframe_v2 *frame;
|
1444 | a8c33204 | pbrook | |
1445 | a8c33204 | pbrook | /*
|
1446 | a8c33204 | pbrook | * Since we stacked the signal on a 64-bit boundary,
|
1447 | a8c33204 | pbrook | * then 'sp' should be word aligned here. If it's
|
1448 | a8c33204 | pbrook | * not, then the user is trying to mess with us.
|
1449 | a8c33204 | pbrook | */
|
1450 | a8c33204 | pbrook | if (env->regs[13] & 7) |
1451 | a8c33204 | pbrook | goto badframe;
|
1452 | a8c33204 | pbrook | |
1453 | a8c33204 | pbrook | frame_addr = env->regs[13];
|
1454 | a8c33204 | pbrook | if (!lock_user_struct(VERIFY_READ, frame, frame_addr, 1)) |
1455 | a8c33204 | pbrook | goto badframe;
|
1456 | a8c33204 | pbrook | |
1457 | a8c33204 | pbrook | if (do_sigframe_return_v2(env, frame_addr, &frame->uc))
|
1458 | a8c33204 | pbrook | goto badframe;
|
1459 | a8c33204 | pbrook | |
1460 | a8c33204 | pbrook | unlock_user_struct(frame, frame_addr, 0);
|
1461 | a8c33204 | pbrook | return env->regs[0]; |
1462 | a8c33204 | pbrook | |
1463 | a8c33204 | pbrook | badframe:
|
1464 | a8c33204 | pbrook | unlock_user_struct(frame, frame_addr, 0);
|
1465 | a8c33204 | pbrook | force_sig(SIGSEGV /* , current */);
|
1466 | a8c33204 | pbrook | return 0; |
1467 | a8c33204 | pbrook | } |
1468 | a8c33204 | pbrook | |
1469 | a8c33204 | pbrook | long do_sigreturn(CPUState *env)
|
1470 | a8c33204 | pbrook | { |
1471 | a8c33204 | pbrook | if (get_osversion() >= 0x020612) { |
1472 | a8c33204 | pbrook | return do_sigreturn_v2(env);
|
1473 | a8c33204 | pbrook | } else {
|
1474 | a8c33204 | pbrook | return do_sigreturn_v1(env);
|
1475 | a8c33204 | pbrook | } |
1476 | a8c33204 | pbrook | } |
1477 | a8c33204 | pbrook | |
1478 | a745ec6d | pbrook | long do_rt_sigreturn_v1(CPUState *env)
|
1479 | 43fff238 | bellard | { |
1480 | f8b0aa25 | bellard | abi_ulong frame_addr; |
1481 | a745ec6d | pbrook | struct rt_sigframe_v1 *frame;
|
1482 | a745ec6d | pbrook | sigset_t host_set; |
1483 | a745ec6d | pbrook | |
1484 | a745ec6d | pbrook | /*
|
1485 | a745ec6d | pbrook | * Since we stacked the signal on a 64-bit boundary,
|
1486 | a745ec6d | pbrook | * then 'sp' should be word aligned here. If it's
|
1487 | a745ec6d | pbrook | * not, then the user is trying to mess with us.
|
1488 | a745ec6d | pbrook | */
|
1489 | a745ec6d | pbrook | if (env->regs[13] & 7) |
1490 | a745ec6d | pbrook | goto badframe;
|
1491 | a745ec6d | pbrook | |
1492 | a745ec6d | pbrook | frame_addr = env->regs[13];
|
1493 | a745ec6d | pbrook | if (!lock_user_struct(VERIFY_READ, frame, frame_addr, 1)) |
1494 | a745ec6d | pbrook | goto badframe;
|
1495 | a745ec6d | pbrook | |
1496 | a745ec6d | pbrook | target_to_host_sigset(&host_set, &frame->uc.tuc_sigmask); |
1497 | a745ec6d | pbrook | sigprocmask(SIG_SETMASK, &host_set, NULL);
|
1498 | a745ec6d | pbrook | |
1499 | a745ec6d | pbrook | if (restore_sigcontext(env, &frame->uc.tuc_mcontext))
|
1500 | a745ec6d | pbrook | goto badframe;
|
1501 | a745ec6d | pbrook | |
1502 | a745ec6d | pbrook | if (do_sigaltstack(frame_addr + offsetof(struct rt_sigframe_v1, uc.tuc_stack), 0, get_sp_from_cpustate(env)) == -EFAULT) |
1503 | a745ec6d | pbrook | goto badframe;
|
1504 | a745ec6d | pbrook | |
1505 | a745ec6d | pbrook | #if 0
|
1506 | a745ec6d | pbrook | /* Send SIGTRAP if we're single-stepping */
|
1507 | a745ec6d | pbrook | if (ptrace_cancel_bpt(current))
|
1508 | a745ec6d | pbrook | send_sig(SIGTRAP, current, 1);
|
1509 | a745ec6d | pbrook | #endif
|
1510 | a745ec6d | pbrook | unlock_user_struct(frame, frame_addr, 0);
|
1511 | a745ec6d | pbrook | return env->regs[0]; |
1512 | a745ec6d | pbrook | |
1513 | a745ec6d | pbrook | badframe:
|
1514 | a745ec6d | pbrook | unlock_user_struct(frame, frame_addr, 0);
|
1515 | a745ec6d | pbrook | force_sig(SIGSEGV /* , current */);
|
1516 | a745ec6d | pbrook | return 0; |
1517 | a745ec6d | pbrook | } |
1518 | a745ec6d | pbrook | |
1519 | a745ec6d | pbrook | long do_rt_sigreturn_v2(CPUState *env)
|
1520 | a745ec6d | pbrook | { |
1521 | a745ec6d | pbrook | abi_ulong frame_addr; |
1522 | a745ec6d | pbrook | struct rt_sigframe_v2 *frame;
|
1523 | 43fff238 | bellard | |
1524 | 43fff238 | bellard | /*
|
1525 | 43fff238 | bellard | * Since we stacked the signal on a 64-bit boundary,
|
1526 | 43fff238 | bellard | * then 'sp' should be word aligned here. If it's
|
1527 | 43fff238 | bellard | * not, then the user is trying to mess with us.
|
1528 | 43fff238 | bellard | */
|
1529 | 43fff238 | bellard | if (env->regs[13] & 7) |
1530 | 43fff238 | bellard | goto badframe;
|
1531 | 43fff238 | bellard | |
1532 | f8b0aa25 | bellard | frame_addr = env->regs[13];
|
1533 | f8b0aa25 | bellard | if (!lock_user_struct(VERIFY_READ, frame, frame_addr, 1)) |
1534 | f8b0aa25 | bellard | goto badframe;
|
1535 | 43fff238 | bellard | |
1536 | a8c33204 | pbrook | if (do_sigframe_return_v2(env, frame_addr, &frame->uc))
|
1537 | a8c33204 | pbrook | goto badframe;
|
1538 | a04e134a | ths | |
1539 | f8b0aa25 | bellard | unlock_user_struct(frame, frame_addr, 0);
|
1540 | 43fff238 | bellard | return env->regs[0]; |
1541 | 43fff238 | bellard | |
1542 | 43fff238 | bellard | badframe:
|
1543 | f8b0aa25 | bellard | unlock_user_struct(frame, frame_addr, 0);
|
1544 | 43fff238 | bellard | force_sig(SIGSEGV /* , current */);
|
1545 | 43fff238 | bellard | return 0; |
1546 | 43fff238 | bellard | } |
1547 | 43fff238 | bellard | |
1548 | a745ec6d | pbrook | long do_rt_sigreturn(CPUState *env)
|
1549 | a745ec6d | pbrook | { |
1550 | a745ec6d | pbrook | if (get_osversion() >= 0x020612) { |
1551 | a745ec6d | pbrook | return do_rt_sigreturn_v2(env);
|
1552 | a745ec6d | pbrook | } else {
|
1553 | a745ec6d | pbrook | return do_rt_sigreturn_v1(env);
|
1554 | a745ec6d | pbrook | } |
1555 | a745ec6d | pbrook | } |
1556 | a745ec6d | pbrook | |
1557 | 6d5e216d | bellard | #elif defined(TARGET_SPARC)
|
1558 | 80a9d035 | bellard | |
1559 | 6d5e216d | bellard | #define __SUNOS_MAXWIN 31 |
1560 | 6d5e216d | bellard | |
1561 | 6d5e216d | bellard | /* This is what SunOS does, so shall I. */
|
1562 | 6d5e216d | bellard | struct target_sigcontext {
|
1563 | 992f48a0 | blueswir1 | abi_ulong sigc_onstack; /* state to restore */
|
1564 | 6d5e216d | bellard | |
1565 | 992f48a0 | blueswir1 | abi_ulong sigc_mask; /* sigmask to restore */
|
1566 | 992f48a0 | blueswir1 | abi_ulong sigc_sp; /* stack pointer */
|
1567 | 992f48a0 | blueswir1 | abi_ulong sigc_pc; /* program counter */
|
1568 | 992f48a0 | blueswir1 | abi_ulong sigc_npc; /* next program counter */
|
1569 | 992f48a0 | blueswir1 | abi_ulong sigc_psr; /* for condition codes etc */
|
1570 | 992f48a0 | blueswir1 | abi_ulong sigc_g1; /* User uses these two registers */
|
1571 | 992f48a0 | blueswir1 | abi_ulong sigc_o0; /* within the trampoline code. */
|
1572 | 6d5e216d | bellard | |
1573 | 6d5e216d | bellard | /* Now comes information regarding the users window set
|
1574 | 6d5e216d | bellard | * at the time of the signal.
|
1575 | 6d5e216d | bellard | */
|
1576 | 992f48a0 | blueswir1 | abi_ulong sigc_oswins; /* outstanding windows */
|
1577 | 6d5e216d | bellard | |
1578 | 6d5e216d | bellard | /* stack ptrs for each regwin buf */
|
1579 | 6d5e216d | bellard | char *sigc_spbuf[__SUNOS_MAXWIN];
|
1580 | 6d5e216d | bellard | |
1581 | 6d5e216d | bellard | /* Windows to restore after signal */
|
1582 | 6d5e216d | bellard | struct {
|
1583 | 992f48a0 | blueswir1 | abi_ulong locals[8];
|
1584 | 992f48a0 | blueswir1 | abi_ulong ins[8];
|
1585 | 6d5e216d | bellard | } sigc_wbuf[__SUNOS_MAXWIN]; |
1586 | 6d5e216d | bellard | }; |
1587 | 6d5e216d | bellard | /* A Sparc stack frame */
|
1588 | 6d5e216d | bellard | struct sparc_stackf {
|
1589 | 992f48a0 | blueswir1 | abi_ulong locals[8];
|
1590 | 992f48a0 | blueswir1 | abi_ulong ins[6];
|
1591 | 6d5e216d | bellard | struct sparc_stackf *fp;
|
1592 | 992f48a0 | blueswir1 | abi_ulong callers_pc; |
1593 | 6d5e216d | bellard | char *structptr;
|
1594 | 992f48a0 | blueswir1 | abi_ulong xargs[6];
|
1595 | 992f48a0 | blueswir1 | abi_ulong xxargs[1];
|
1596 | 6d5e216d | bellard | }; |
1597 | 6d5e216d | bellard | |
1598 | 6d5e216d | bellard | typedef struct { |
1599 | 6d5e216d | bellard | struct {
|
1600 | 992f48a0 | blueswir1 | abi_ulong psr; |
1601 | 992f48a0 | blueswir1 | abi_ulong pc; |
1602 | 992f48a0 | blueswir1 | abi_ulong npc; |
1603 | 992f48a0 | blueswir1 | abi_ulong y; |
1604 | 992f48a0 | blueswir1 | abi_ulong u_regs[16]; /* globals and ins */ |
1605 | 6d5e216d | bellard | } si_regs; |
1606 | 6d5e216d | bellard | int si_mask;
|
1607 | 6d5e216d | bellard | } __siginfo_t; |
1608 | 6d5e216d | bellard | |
1609 | 6d5e216d | bellard | typedef struct { |
1610 | 6d5e216d | bellard | unsigned long si_float_regs [32]; |
1611 | 6d5e216d | bellard | unsigned long si_fsr; |
1612 | 6d5e216d | bellard | unsigned long si_fpqdepth; |
1613 | 6d5e216d | bellard | struct {
|
1614 | 6d5e216d | bellard | unsigned long *insn_addr; |
1615 | 6d5e216d | bellard | unsigned long insn; |
1616 | 6d5e216d | bellard | } si_fpqueue [16];
|
1617 | 74ccb34e | bellard | } qemu_siginfo_fpu_t; |
1618 | 6d5e216d | bellard | |
1619 | 6d5e216d | bellard | |
1620 | 6d5e216d | bellard | struct target_signal_frame {
|
1621 | 6d5e216d | bellard | struct sparc_stackf ss;
|
1622 | 6d5e216d | bellard | __siginfo_t info; |
1623 | f8b0aa25 | bellard | abi_ulong fpu_save; |
1624 | 992f48a0 | blueswir1 | abi_ulong insns[2] __attribute__ ((aligned (8))); |
1625 | 992f48a0 | blueswir1 | abi_ulong extramask[TARGET_NSIG_WORDS - 1];
|
1626 | 992f48a0 | blueswir1 | abi_ulong extra_size; /* Should be 0 */
|
1627 | 74ccb34e | bellard | qemu_siginfo_fpu_t fpu_state; |
1628 | 6d5e216d | bellard | }; |
1629 | 6d5e216d | bellard | struct target_rt_signal_frame {
|
1630 | 6d5e216d | bellard | struct sparc_stackf ss;
|
1631 | 6d5e216d | bellard | siginfo_t info; |
1632 | 992f48a0 | blueswir1 | abi_ulong regs[20];
|
1633 | 6d5e216d | bellard | sigset_t mask; |
1634 | f8b0aa25 | bellard | abi_ulong fpu_save; |
1635 | 6d5e216d | bellard | unsigned int insns[2]; |
1636 | 6d5e216d | bellard | stack_t stack; |
1637 | 6d5e216d | bellard | unsigned int extra_size; /* Should be 0 */ |
1638 | 74ccb34e | bellard | qemu_siginfo_fpu_t fpu_state; |
1639 | 6d5e216d | bellard | }; |
1640 | 6d5e216d | bellard | |
1641 | e80cfcfc | bellard | #define UREG_O0 16 |
1642 | e80cfcfc | bellard | #define UREG_O6 22 |
1643 | e80cfcfc | bellard | #define UREG_I0 0 |
1644 | e80cfcfc | bellard | #define UREG_I1 1 |
1645 | e80cfcfc | bellard | #define UREG_I2 2 |
1646 | 5bfb56b2 | blueswir1 | #define UREG_I3 3 |
1647 | 5bfb56b2 | blueswir1 | #define UREG_I4 4 |
1648 | 5bfb56b2 | blueswir1 | #define UREG_I5 5 |
1649 | e80cfcfc | bellard | #define UREG_I6 6 |
1650 | e80cfcfc | bellard | #define UREG_I7 7 |
1651 | e80cfcfc | bellard | #define UREG_L0 8 |
1652 | 6d5e216d | bellard | #define UREG_FP UREG_I6
|
1653 | 6d5e216d | bellard | #define UREG_SP UREG_O6
|
1654 | 6d5e216d | bellard | |
1655 | 624f7979 | pbrook | static inline abi_ulong get_sigframe(struct target_sigaction *sa, |
1656 | 459a4017 | bellard | CPUState *env, unsigned long framesize) |
1657 | 6d5e216d | bellard | { |
1658 | 459a4017 | bellard | abi_ulong sp; |
1659 | 6d5e216d | bellard | |
1660 | 6d5e216d | bellard | sp = env->regwptr[UREG_FP]; |
1661 | 6d5e216d | bellard | |
1662 | 6d5e216d | bellard | /* This is the X/Open sanctioned signal stack switching. */
|
1663 | 624f7979 | pbrook | if (sa->sa_flags & TARGET_SA_ONSTACK) {
|
1664 | a04e134a | ths | if (!on_sig_stack(sp)
|
1665 | a04e134a | ths | && !((target_sigaltstack_used.ss_sp + target_sigaltstack_used.ss_size) & 7))
|
1666 | a04e134a | ths | sp = target_sigaltstack_used.ss_sp + target_sigaltstack_used.ss_size; |
1667 | 6d5e216d | bellard | } |
1668 | 459a4017 | bellard | return sp - framesize;
|
1669 | 6d5e216d | bellard | } |
1670 | 6d5e216d | bellard | |
1671 | 6d5e216d | bellard | static int |
1672 | 992f48a0 | blueswir1 | setup___siginfo(__siginfo_t *si, CPUState *env, abi_ulong mask) |
1673 | 6d5e216d | bellard | { |
1674 | 6d5e216d | bellard | int err = 0, i; |
1675 | 6d5e216d | bellard | |
1676 | 6d5e216d | bellard | err |= __put_user(env->psr, &si->si_regs.psr); |
1677 | 6d5e216d | bellard | err |= __put_user(env->pc, &si->si_regs.pc); |
1678 | 6d5e216d | bellard | err |= __put_user(env->npc, &si->si_regs.npc); |
1679 | 6d5e216d | bellard | err |= __put_user(env->y, &si->si_regs.y); |
1680 | a315a145 | bellard | for (i=0; i < 8; i++) { |
1681 | 6d5e216d | bellard | err |= __put_user(env->gregs[i], &si->si_regs.u_regs[i]); |
1682 | 6d5e216d | bellard | } |
1683 | a315a145 | bellard | for (i=0; i < 8; i++) { |
1684 | e80cfcfc | bellard | err |= __put_user(env->regwptr[UREG_I0 + i], &si->si_regs.u_regs[i+8]);
|
1685 | 6d5e216d | bellard | } |
1686 | 6d5e216d | bellard | err |= __put_user(mask, &si->si_mask); |
1687 | 6d5e216d | bellard | return err;
|
1688 | 6d5e216d | bellard | } |
1689 | e80cfcfc | bellard | |
1690 | 80a9d035 | bellard | #if 0
|
1691 | 6d5e216d | bellard | static int
|
1692 | 6d5e216d | bellard | setup_sigcontext(struct target_sigcontext *sc, /*struct _fpstate *fpstate,*/
|
1693 | 6d5e216d | bellard | CPUState *env, unsigned long mask)
|
1694 | 6d5e216d | bellard | {
|
1695 | 6d5e216d | bellard | int err = 0;
|
1696 | 6d5e216d | bellard | |
1697 | 6d5e216d | bellard | err |= __put_user(mask, &sc->sigc_mask);
|
1698 | 6d5e216d | bellard | err |= __put_user(env->regwptr[UREG_SP], &sc->sigc_sp);
|
1699 | 6d5e216d | bellard | err |= __put_user(env->pc, &sc->sigc_pc);
|
1700 | 6d5e216d | bellard | err |= __put_user(env->npc, &sc->sigc_npc);
|
1701 | 6d5e216d | bellard | err |= __put_user(env->psr, &sc->sigc_psr);
|
1702 | 6d5e216d | bellard | err |= __put_user(env->gregs[1], &sc->sigc_g1);
|
1703 | 6d5e216d | bellard | err |= __put_user(env->regwptr[UREG_O0], &sc->sigc_o0);
|
1704 | 6d5e216d | bellard | |
1705 | 6d5e216d | bellard | return err;
|
1706 | 6d5e216d | bellard | }
|
1707 | 80a9d035 | bellard | #endif
|
1708 | 6d5e216d | bellard | #define NF_ALIGNEDSZ (((sizeof(struct target_signal_frame) + 7) & (~7))) |
1709 | 6d5e216d | bellard | |
1710 | 624f7979 | pbrook | static void setup_frame(int sig, struct target_sigaction *ka, |
1711 | 6d5e216d | bellard | target_sigset_t *set, CPUState *env) |
1712 | 6d5e216d | bellard | { |
1713 | 459a4017 | bellard | abi_ulong sf_addr; |
1714 | 6d5e216d | bellard | struct target_signal_frame *sf;
|
1715 | 6d5e216d | bellard | int sigframe_size, err, i;
|
1716 | 6d5e216d | bellard | |
1717 | 6d5e216d | bellard | /* 1. Make sure everything is clean */
|
1718 | 6d5e216d | bellard | //synchronize_user_stack();
|
1719 | 6d5e216d | bellard | |
1720 | 6d5e216d | bellard | sigframe_size = NF_ALIGNEDSZ; |
1721 | 459a4017 | bellard | sf_addr = get_sigframe(ka, env, sigframe_size); |
1722 | 6d5e216d | bellard | |
1723 | 459a4017 | bellard | sf = lock_user(VERIFY_WRITE, sf_addr, |
1724 | 459a4017 | bellard | sizeof(struct target_signal_frame), 0); |
1725 | 459a4017 | bellard | if (!sf)
|
1726 | 459a4017 | bellard | goto sigsegv;
|
1727 | 459a4017 | bellard | |
1728 | e80cfcfc | bellard | //fprintf(stderr, "sf: %x pc %x fp %x sp %x\n", sf, env->pc, env->regwptr[UREG_FP], env->regwptr[UREG_SP]);
|
1729 | 6d5e216d | bellard | #if 0
|
1730 | 6d5e216d | bellard | if (invalid_frame_pointer(sf, sigframe_size))
|
1731 | 6d5e216d | bellard | goto sigill_and_return;
|
1732 | 6d5e216d | bellard | #endif
|
1733 | 6d5e216d | bellard | /* 2. Save the current process state */
|
1734 | 6d5e216d | bellard | err = setup___siginfo(&sf->info, env, set->sig[0]);
|
1735 | 6d5e216d | bellard | err |= __put_user(0, &sf->extra_size);
|
1736 | 6d5e216d | bellard | |
1737 | 6d5e216d | bellard | //err |= save_fpu_state(regs, &sf->fpu_state);
|
1738 | 6d5e216d | bellard | //err |= __put_user(&sf->fpu_state, &sf->fpu_save);
|
1739 | 6d5e216d | bellard | |
1740 | 6d5e216d | bellard | err |= __put_user(set->sig[0], &sf->info.si_mask);
|
1741 | 6d5e216d | bellard | for (i = 0; i < TARGET_NSIG_WORDS - 1; i++) { |
1742 | 6d5e216d | bellard | err |= __put_user(set->sig[i + 1], &sf->extramask[i]);
|
1743 | 6d5e216d | bellard | } |
1744 | 6d5e216d | bellard | |
1745 | a315a145 | bellard | for (i = 0; i < 8; i++) { |
1746 | e80cfcfc | bellard | err |= __put_user(env->regwptr[i + UREG_L0], &sf->ss.locals[i]); |
1747 | 6d5e216d | bellard | } |
1748 | a315a145 | bellard | for (i = 0; i < 8; i++) { |
1749 | e80cfcfc | bellard | err |= __put_user(env->regwptr[i + UREG_I0], &sf->ss.ins[i]); |
1750 | 6d5e216d | bellard | } |
1751 | 6d5e216d | bellard | if (err)
|
1752 | 6d5e216d | bellard | goto sigsegv;
|
1753 | 6d5e216d | bellard | |
1754 | 6d5e216d | bellard | /* 3. signal handler back-trampoline and parameters */
|
1755 | 459a4017 | bellard | env->regwptr[UREG_FP] = sf_addr; |
1756 | 6d5e216d | bellard | env->regwptr[UREG_I0] = sig; |
1757 | 459a4017 | bellard | env->regwptr[UREG_I1] = sf_addr + |
1758 | 459a4017 | bellard | offsetof(struct target_signal_frame, info);
|
1759 | 459a4017 | bellard | env->regwptr[UREG_I2] = sf_addr + |
1760 | 459a4017 | bellard | offsetof(struct target_signal_frame, info);
|
1761 | 6d5e216d | bellard | |
1762 | 6d5e216d | bellard | /* 4. signal handler */
|
1763 | 624f7979 | pbrook | env->pc = ka->_sa_handler; |
1764 | 6d5e216d | bellard | env->npc = (env->pc + 4);
|
1765 | 6d5e216d | bellard | /* 5. return to kernel instructions */
|
1766 | 624f7979 | pbrook | if (ka->sa_restorer)
|
1767 | 624f7979 | pbrook | env->regwptr[UREG_I7] = ka->sa_restorer; |
1768 | 6d5e216d | bellard | else {
|
1769 | 775b58d8 | bellard | uint32_t val32; |
1770 | 459a4017 | bellard | |
1771 | 459a4017 | bellard | env->regwptr[UREG_I7] = sf_addr + |
1772 | 459a4017 | bellard | offsetof(struct target_signal_frame, insns) - 2 * 4; |
1773 | 6d5e216d | bellard | |
1774 | 6d5e216d | bellard | /* mov __NR_sigreturn, %g1 */
|
1775 | 775b58d8 | bellard | val32 = 0x821020d8;
|
1776 | 775b58d8 | bellard | err |= __put_user(val32, &sf->insns[0]);
|
1777 | 6d5e216d | bellard | |
1778 | 6d5e216d | bellard | /* t 0x10 */
|
1779 | 775b58d8 | bellard | val32 = 0x91d02010;
|
1780 | 775b58d8 | bellard | err |= __put_user(val32, &sf->insns[1]);
|
1781 | 6d5e216d | bellard | if (err)
|
1782 | 6d5e216d | bellard | goto sigsegv;
|
1783 | 6d5e216d | bellard | |
1784 | 6d5e216d | bellard | /* Flush instruction space. */
|
1785 | 6d5e216d | bellard | //flush_sig_insns(current->mm, (unsigned long) &(sf->insns[0]));
|
1786 | 80a9d035 | bellard | // tb_flush(env);
|
1787 | 6d5e216d | bellard | } |
1788 | 459a4017 | bellard | unlock_user(sf, sf_addr, sizeof(struct target_signal_frame)); |
1789 | 6d5e216d | bellard | return;
|
1790 | 459a4017 | bellard | #if 0
|
1791 | 459a4017 | bellard | sigill_and_return:
|
1792 | 6d5e216d | bellard | force_sig(TARGET_SIGILL);
|
1793 | 459a4017 | bellard | #endif
|
1794 | 6d5e216d | bellard | sigsegv:
|
1795 | e80cfcfc | bellard | //fprintf(stderr, "force_sig\n");
|
1796 | 459a4017 | bellard | unlock_user(sf, sf_addr, sizeof(struct target_signal_frame)); |
1797 | 6d5e216d | bellard | force_sig(TARGET_SIGSEGV); |
1798 | 6d5e216d | bellard | } |
1799 | 6d5e216d | bellard | static inline int |
1800 | 74ccb34e | bellard | restore_fpu_state(CPUState *env, qemu_siginfo_fpu_t *fpu) |
1801 | 6d5e216d | bellard | { |
1802 | 6d5e216d | bellard | int err;
|
1803 | 6d5e216d | bellard | #if 0
|
1804 | 6d5e216d | bellard | #ifdef CONFIG_SMP
|
1805 | 6d5e216d | bellard | if (current->flags & PF_USEDFPU)
|
1806 | 6d5e216d | bellard | regs->psr &= ~PSR_EF;
|
1807 | 6d5e216d | bellard | #else
|
1808 | 6d5e216d | bellard | if (current == last_task_used_math) {
|
1809 | 6d5e216d | bellard | last_task_used_math = 0;
|
1810 | 6d5e216d | bellard | regs->psr &= ~PSR_EF; |
1811 | 6d5e216d | bellard | } |
1812 | 6d5e216d | bellard | #endif
|
1813 | 6d5e216d | bellard | current->used_math = 1;
|
1814 | 6d5e216d | bellard | current->flags &= ~PF_USEDFPU; |
1815 | 6d5e216d | bellard | #endif
|
1816 | 6d5e216d | bellard | #if 0
|
1817 | 6d5e216d | bellard | if (verify_area (VERIFY_READ, fpu, sizeof(*fpu)))
|
1818 | 6d5e216d | bellard | return -EFAULT;
|
1819 | 6d5e216d | bellard | #endif
|
1820 | 6d5e216d | bellard | |
1821 | fafffaef | bellard | #if 0
|
1822 | fafffaef | bellard | /* XXX: incorrect */
|
1823 | 6d5e216d | bellard | err = __copy_from_user(&env->fpr[0], &fpu->si_float_regs[0],
|
1824 | 6d5e216d | bellard | (sizeof(unsigned long) * 32));
|
1825 | fafffaef | bellard | #endif
|
1826 | 6d5e216d | bellard | err |= __get_user(env->fsr, &fpu->si_fsr); |
1827 | 6d5e216d | bellard | #if 0
|
1828 | 6d5e216d | bellard | err |= __get_user(current->thread.fpqdepth, &fpu->si_fpqdepth);
|
1829 | 6d5e216d | bellard | if (current->thread.fpqdepth != 0)
|
1830 | 6d5e216d | bellard | err |= __copy_from_user(¤t->thread.fpqueue[0],
|
1831 | 6d5e216d | bellard | &fpu->si_fpqueue[0],
|
1832 | 6d5e216d | bellard | ((sizeof(unsigned long) +
|
1833 | 6d5e216d | bellard | (sizeof(unsigned long *)))*16));
|
1834 | 6d5e216d | bellard | #endif
|
1835 | 6d5e216d | bellard | return err;
|
1836 | 6d5e216d | bellard | } |
1837 | 6d5e216d | bellard | |
1838 | 6d5e216d | bellard | |
1839 | 624f7979 | pbrook | static void setup_rt_frame(int sig, struct target_sigaction *ka, |
1840 | 6d5e216d | bellard | target_siginfo_t *info, |
1841 | 6d5e216d | bellard | target_sigset_t *set, CPUState *env) |
1842 | 6d5e216d | bellard | { |
1843 | 6d5e216d | bellard | fprintf(stderr, "setup_rt_frame: not implemented\n");
|
1844 | 6d5e216d | bellard | } |
1845 | 6d5e216d | bellard | |
1846 | 6d5e216d | bellard | long do_sigreturn(CPUState *env)
|
1847 | 6d5e216d | bellard | { |
1848 | f8b0aa25 | bellard | abi_ulong sf_addr; |
1849 | 6d5e216d | bellard | struct target_signal_frame *sf;
|
1850 | e80cfcfc | bellard | uint32_t up_psr, pc, npc; |
1851 | 6d5e216d | bellard | target_sigset_t set; |
1852 | e80cfcfc | bellard | sigset_t host_set; |
1853 | f8b0aa25 | bellard | abi_ulong fpu_save_addr; |
1854 | e80cfcfc | bellard | int err, i;
|
1855 | 6d5e216d | bellard | |
1856 | f8b0aa25 | bellard | sf_addr = env->regwptr[UREG_FP]; |
1857 | f8b0aa25 | bellard | if (!lock_user_struct(VERIFY_READ, sf, sf_addr, 1)) |
1858 | f8b0aa25 | bellard | goto segv_and_exit;
|
1859 | 80a9d035 | bellard | #if 0
|
1860 | e80cfcfc | bellard | fprintf(stderr, "sigreturn\n");
|
1861 | e80cfcfc | bellard | fprintf(stderr, "sf: %x pc %x fp %x sp %x\n", sf, env->pc, env->regwptr[UREG_FP], env->regwptr[UREG_SP]);
|
1862 | 80a9d035 | bellard | #endif
|
1863 | e80cfcfc | bellard | //cpu_dump_state(env, stderr, fprintf, 0);
|
1864 | 6d5e216d | bellard | |
1865 | 6d5e216d | bellard | /* 1. Make sure we are not getting garbage from the user */
|
1866 | 6d5e216d | bellard | |
1867 | f8b0aa25 | bellard | if (sf_addr & 3) |
1868 | 6d5e216d | bellard | goto segv_and_exit;
|
1869 | 6d5e216d | bellard | |
1870 | 6d5e216d | bellard | err = __get_user(pc, &sf->info.si_regs.pc); |
1871 | 6d5e216d | bellard | err |= __get_user(npc, &sf->info.si_regs.npc); |
1872 | 6d5e216d | bellard | |
1873 | 6d5e216d | bellard | if ((pc | npc) & 3) |
1874 | 6d5e216d | bellard | goto segv_and_exit;
|
1875 | 6d5e216d | bellard | |
1876 | 6d5e216d | bellard | /* 2. Restore the state */
|
1877 | e80cfcfc | bellard | err |= __get_user(up_psr, &sf->info.si_regs.psr); |
1878 | e80cfcfc | bellard | |
1879 | 6d5e216d | bellard | /* User can only change condition codes and FPU enabling in %psr. */
|
1880 | a315a145 | bellard | env->psr = (up_psr & (PSR_ICC /* | PSR_EF */))
|
1881 | a315a145 | bellard | | (env->psr & ~(PSR_ICC /* | PSR_EF */));
|
1882 | a315a145 | bellard | |
1883 | a315a145 | bellard | env->pc = pc; |
1884 | a315a145 | bellard | env->npc = npc; |
1885 | e80cfcfc | bellard | err |= __get_user(env->y, &sf->info.si_regs.y); |
1886 | a315a145 | bellard | for (i=0; i < 8; i++) { |
1887 | e80cfcfc | bellard | err |= __get_user(env->gregs[i], &sf->info.si_regs.u_regs[i]); |
1888 | e80cfcfc | bellard | } |
1889 | a315a145 | bellard | for (i=0; i < 8; i++) { |
1890 | e80cfcfc | bellard | err |= __get_user(env->regwptr[i + UREG_I0], &sf->info.si_regs.u_regs[i+8]);
|
1891 | e80cfcfc | bellard | } |
1892 | 6d5e216d | bellard | |
1893 | f8b0aa25 | bellard | err |= __get_user(fpu_save_addr, &sf->fpu_save); |
1894 | 6d5e216d | bellard | |
1895 | e80cfcfc | bellard | //if (fpu_save)
|
1896 | e80cfcfc | bellard | // err |= restore_fpu_state(env, fpu_save);
|
1897 | 6d5e216d | bellard | |
1898 | 6d5e216d | bellard | /* This is pretty much atomic, no amount locking would prevent
|
1899 | 6d5e216d | bellard | * the races which exist anyways.
|
1900 | 6d5e216d | bellard | */
|
1901 | 6d5e216d | bellard | err |= __get_user(set.sig[0], &sf->info.si_mask);
|
1902 | e80cfcfc | bellard | for(i = 1; i < TARGET_NSIG_WORDS; i++) { |
1903 | e80cfcfc | bellard | err |= (__get_user(set.sig[i], &sf->extramask[i - 1]));
|
1904 | e80cfcfc | bellard | } |
1905 | e80cfcfc | bellard | |
1906 | e80cfcfc | bellard | target_to_host_sigset_internal(&host_set, &set); |
1907 | e80cfcfc | bellard | sigprocmask(SIG_SETMASK, &host_set, NULL);
|
1908 | 6d5e216d | bellard | |
1909 | 6d5e216d | bellard | if (err)
|
1910 | 6d5e216d | bellard | goto segv_and_exit;
|
1911 | f8b0aa25 | bellard | unlock_user_struct(sf, sf_addr, 0);
|
1912 | 6d5e216d | bellard | return env->regwptr[0]; |
1913 | 6d5e216d | bellard | |
1914 | 6d5e216d | bellard | segv_and_exit:
|
1915 | f8b0aa25 | bellard | unlock_user_struct(sf, sf_addr, 0);
|
1916 | 6d5e216d | bellard | force_sig(TARGET_SIGSEGV); |
1917 | 6d5e216d | bellard | } |
1918 | 6d5e216d | bellard | |
1919 | 6d5e216d | bellard | long do_rt_sigreturn(CPUState *env)
|
1920 | 6d5e216d | bellard | { |
1921 | 6d5e216d | bellard | fprintf(stderr, "do_rt_sigreturn: not implemented\n");
|
1922 | f8b0aa25 | bellard | return -TARGET_ENOSYS;
|
1923 | 6d5e216d | bellard | } |
1924 | 6d5e216d | bellard | |
1925 | 459a4017 | bellard | #if defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
|
1926 | 5bfb56b2 | blueswir1 | #define MC_TSTATE 0 |
1927 | 5bfb56b2 | blueswir1 | #define MC_PC 1 |
1928 | 5bfb56b2 | blueswir1 | #define MC_NPC 2 |
1929 | 5bfb56b2 | blueswir1 | #define MC_Y 3 |
1930 | 5bfb56b2 | blueswir1 | #define MC_G1 4 |
1931 | 5bfb56b2 | blueswir1 | #define MC_G2 5 |
1932 | 5bfb56b2 | blueswir1 | #define MC_G3 6 |
1933 | 5bfb56b2 | blueswir1 | #define MC_G4 7 |
1934 | 5bfb56b2 | blueswir1 | #define MC_G5 8 |
1935 | 5bfb56b2 | blueswir1 | #define MC_G6 9 |
1936 | 5bfb56b2 | blueswir1 | #define MC_G7 10 |
1937 | 5bfb56b2 | blueswir1 | #define MC_O0 11 |
1938 | 5bfb56b2 | blueswir1 | #define MC_O1 12 |
1939 | 5bfb56b2 | blueswir1 | #define MC_O2 13 |
1940 | 5bfb56b2 | blueswir1 | #define MC_O3 14 |
1941 | 5bfb56b2 | blueswir1 | #define MC_O4 15 |
1942 | 5bfb56b2 | blueswir1 | #define MC_O5 16 |
1943 | 5bfb56b2 | blueswir1 | #define MC_O6 17 |
1944 | 5bfb56b2 | blueswir1 | #define MC_O7 18 |
1945 | 5bfb56b2 | blueswir1 | #define MC_NGREG 19 |
1946 | 5bfb56b2 | blueswir1 | |
1947 | 992f48a0 | blueswir1 | typedef abi_ulong target_mc_greg_t;
|
1948 | 5bfb56b2 | blueswir1 | typedef target_mc_greg_t target_mc_gregset_t[MC_NGREG];
|
1949 | 5bfb56b2 | blueswir1 | |
1950 | 5bfb56b2 | blueswir1 | struct target_mc_fq {
|
1951 | 992f48a0 | blueswir1 | abi_ulong *mcfq_addr; |
1952 | 5bfb56b2 | blueswir1 | uint32_t mcfq_insn; |
1953 | 5bfb56b2 | blueswir1 | }; |
1954 | 5bfb56b2 | blueswir1 | |
1955 | 5bfb56b2 | blueswir1 | struct target_mc_fpu {
|
1956 | 5bfb56b2 | blueswir1 | union {
|
1957 | 5bfb56b2 | blueswir1 | uint32_t sregs[32];
|
1958 | 5bfb56b2 | blueswir1 | uint64_t dregs[32];
|
1959 | 5bfb56b2 | blueswir1 | //uint128_t qregs[16];
|
1960 | 5bfb56b2 | blueswir1 | } mcfpu_fregs; |
1961 | 992f48a0 | blueswir1 | abi_ulong mcfpu_fsr; |
1962 | 992f48a0 | blueswir1 | abi_ulong mcfpu_fprs; |
1963 | 992f48a0 | blueswir1 | abi_ulong mcfpu_gsr; |
1964 | 5bfb56b2 | blueswir1 | struct target_mc_fq *mcfpu_fq;
|
1965 | 5bfb56b2 | blueswir1 | unsigned char mcfpu_qcnt; |
1966 | 5bfb56b2 | blueswir1 | unsigned char mcfpu_qentsz; |
1967 | 5bfb56b2 | blueswir1 | unsigned char mcfpu_enab; |
1968 | 5bfb56b2 | blueswir1 | }; |
1969 | 5bfb56b2 | blueswir1 | typedef struct target_mc_fpu target_mc_fpu_t; |
1970 | 5bfb56b2 | blueswir1 | |
1971 | 5bfb56b2 | blueswir1 | typedef struct { |
1972 | 5bfb56b2 | blueswir1 | target_mc_gregset_t mc_gregs; |
1973 | 5bfb56b2 | blueswir1 | target_mc_greg_t mc_fp; |
1974 | 5bfb56b2 | blueswir1 | target_mc_greg_t mc_i7; |
1975 | 5bfb56b2 | blueswir1 | target_mc_fpu_t mc_fpregs; |
1976 | 5bfb56b2 | blueswir1 | } target_mcontext_t; |
1977 | 5bfb56b2 | blueswir1 | |
1978 | 5bfb56b2 | blueswir1 | struct target_ucontext {
|
1979 | 5bfb56b2 | blueswir1 | struct target_ucontext *uc_link;
|
1980 | 992f48a0 | blueswir1 | abi_ulong uc_flags; |
1981 | 5bfb56b2 | blueswir1 | target_sigset_t uc_sigmask; |
1982 | 5bfb56b2 | blueswir1 | target_mcontext_t uc_mcontext; |
1983 | 5bfb56b2 | blueswir1 | }; |
1984 | 5bfb56b2 | blueswir1 | |
1985 | 5bfb56b2 | blueswir1 | /* A V9 register window */
|
1986 | 5bfb56b2 | blueswir1 | struct target_reg_window {
|
1987 | 992f48a0 | blueswir1 | abi_ulong locals[8];
|
1988 | 992f48a0 | blueswir1 | abi_ulong ins[8];
|
1989 | 5bfb56b2 | blueswir1 | }; |
1990 | 5bfb56b2 | blueswir1 | |
1991 | 5bfb56b2 | blueswir1 | #define TARGET_STACK_BIAS 2047 |
1992 | 5bfb56b2 | blueswir1 | |
1993 | 5bfb56b2 | blueswir1 | /* {set, get}context() needed for 64-bit SparcLinux userland. */
|
1994 | 5bfb56b2 | blueswir1 | void sparc64_set_context(CPUSPARCState *env)
|
1995 | 5bfb56b2 | blueswir1 | { |
1996 | 459a4017 | bellard | abi_ulong ucp_addr; |
1997 | 459a4017 | bellard | struct target_ucontext *ucp;
|
1998 | 5bfb56b2 | blueswir1 | target_mc_gregset_t *grp; |
1999 | 992f48a0 | blueswir1 | abi_ulong pc, npc, tstate; |
2000 | 459a4017 | bellard | abi_ulong fp, i7, w_addr; |
2001 | 5bfb56b2 | blueswir1 | unsigned char fenab; |
2002 | 5bfb56b2 | blueswir1 | int err;
|
2003 | 5bfb56b2 | blueswir1 | unsigned int i; |
2004 | 5bfb56b2 | blueswir1 | |
2005 | 459a4017 | bellard | ucp_addr = env->regwptr[UREG_I0]; |
2006 | 459a4017 | bellard | if (!lock_user_struct(VERIFY_READ, ucp, ucp_addr, 1)) |
2007 | 459a4017 | bellard | goto do_sigsegv;
|
2008 | 5bfb56b2 | blueswir1 | grp = &ucp->uc_mcontext.mc_gregs; |
2009 | 579a97f7 | bellard | err = __get_user(pc, &((*grp)[MC_PC])); |
2010 | 579a97f7 | bellard | err |= __get_user(npc, &((*grp)[MC_NPC])); |
2011 | 5bfb56b2 | blueswir1 | if (err || ((pc | npc) & 3)) |
2012 | 5bfb56b2 | blueswir1 | goto do_sigsegv;
|
2013 | 5bfb56b2 | blueswir1 | if (env->regwptr[UREG_I1]) {
|
2014 | 5bfb56b2 | blueswir1 | target_sigset_t target_set; |
2015 | 5bfb56b2 | blueswir1 | sigset_t set; |
2016 | 5bfb56b2 | blueswir1 | |
2017 | 5bfb56b2 | blueswir1 | if (TARGET_NSIG_WORDS == 1) { |
2018 | 579a97f7 | bellard | if (__get_user(target_set.sig[0], &ucp->uc_sigmask.sig[0])) |
2019 | 5bfb56b2 | blueswir1 | goto do_sigsegv;
|
2020 | 5bfb56b2 | blueswir1 | } else {
|
2021 | 459a4017 | bellard | abi_ulong *src, *dst; |
2022 | 459a4017 | bellard | src = ucp->uc_sigmask.sig; |
2023 | 459a4017 | bellard | dst = target_set.sig; |
2024 | 992f48a0 | blueswir1 | for (i = 0; i < sizeof(target_sigset_t) / sizeof(abi_ulong); |
2025 | 5bfb56b2 | blueswir1 | i++, dst++, src++) |
2026 | 459a4017 | bellard | err |= __get_user(*dst, src); |
2027 | 5bfb56b2 | blueswir1 | if (err)
|
2028 | 5bfb56b2 | blueswir1 | goto do_sigsegv;
|
2029 | 5bfb56b2 | blueswir1 | } |
2030 | 5bfb56b2 | blueswir1 | target_to_host_sigset_internal(&set, &target_set); |
2031 | 5bfb56b2 | blueswir1 | sigprocmask(SIG_SETMASK, &set, NULL);
|
2032 | 5bfb56b2 | blueswir1 | } |
2033 | 5bfb56b2 | blueswir1 | env->pc = pc; |
2034 | 5bfb56b2 | blueswir1 | env->npc = npc; |
2035 | 579a97f7 | bellard | err |= __get_user(env->y, &((*grp)[MC_Y])); |
2036 | 579a97f7 | bellard | err |= __get_user(tstate, &((*grp)[MC_TSTATE])); |
2037 | 5bfb56b2 | blueswir1 | env->asi = (tstate >> 24) & 0xff; |
2038 | 5bfb56b2 | blueswir1 | PUT_CCR(env, tstate >> 32);
|
2039 | 5bfb56b2 | blueswir1 | PUT_CWP64(env, tstate & 0x1f);
|
2040 | 579a97f7 | bellard | err |= __get_user(env->gregs[1], (&(*grp)[MC_G1]));
|
2041 | 579a97f7 | bellard | err |= __get_user(env->gregs[2], (&(*grp)[MC_G2]));
|
2042 | 579a97f7 | bellard | err |= __get_user(env->gregs[3], (&(*grp)[MC_G3]));
|
2043 | 579a97f7 | bellard | err |= __get_user(env->gregs[4], (&(*grp)[MC_G4]));
|
2044 | 579a97f7 | bellard | err |= __get_user(env->gregs[5], (&(*grp)[MC_G5]));
|
2045 | 579a97f7 | bellard | err |= __get_user(env->gregs[6], (&(*grp)[MC_G6]));
|
2046 | 579a97f7 | bellard | err |= __get_user(env->gregs[7], (&(*grp)[MC_G7]));
|
2047 | 579a97f7 | bellard | err |= __get_user(env->regwptr[UREG_I0], (&(*grp)[MC_O0])); |
2048 | 579a97f7 | bellard | err |= __get_user(env->regwptr[UREG_I1], (&(*grp)[MC_O1])); |
2049 | 579a97f7 | bellard | err |= __get_user(env->regwptr[UREG_I2], (&(*grp)[MC_O2])); |
2050 | 579a97f7 | bellard | err |= __get_user(env->regwptr[UREG_I3], (&(*grp)[MC_O3])); |
2051 | 579a97f7 | bellard | err |= __get_user(env->regwptr[UREG_I4], (&(*grp)[MC_O4])); |
2052 | 579a97f7 | bellard | err |= __get_user(env->regwptr[UREG_I5], (&(*grp)[MC_O5])); |
2053 | 579a97f7 | bellard | err |= __get_user(env->regwptr[UREG_I6], (&(*grp)[MC_O6])); |
2054 | 579a97f7 | bellard | err |= __get_user(env->regwptr[UREG_I7], (&(*grp)[MC_O7])); |
2055 | 579a97f7 | bellard | |
2056 | 579a97f7 | bellard | err |= __get_user(fp, &(ucp->uc_mcontext.mc_fp)); |
2057 | 579a97f7 | bellard | err |= __get_user(i7, &(ucp->uc_mcontext.mc_i7)); |
2058 | 579a97f7 | bellard | |
2059 | 459a4017 | bellard | w_addr = TARGET_STACK_BIAS+env->regwptr[UREG_I6]; |
2060 | 459a4017 | bellard | if (put_user(fp, w_addr + offsetof(struct target_reg_window, ins[6]), |
2061 | 459a4017 | bellard | abi_ulong) != 0)
|
2062 | 459a4017 | bellard | goto do_sigsegv;
|
2063 | 459a4017 | bellard | if (put_user(i7, w_addr + offsetof(struct target_reg_window, ins[7]), |
2064 | 459a4017 | bellard | abi_ulong) != 0)
|
2065 | 459a4017 | bellard | goto do_sigsegv;
|
2066 | 579a97f7 | bellard | err |= __get_user(fenab, &(ucp->uc_mcontext.mc_fpregs.mcfpu_enab)); |
2067 | 579a97f7 | bellard | err |= __get_user(env->fprs, &(ucp->uc_mcontext.mc_fpregs.mcfpu_fprs)); |
2068 | 459a4017 | bellard | { |
2069 | 459a4017 | bellard | uint32_t *src, *dst; |
2070 | 459a4017 | bellard | src = ucp->uc_mcontext.mc_fpregs.mcfpu_fregs.sregs; |
2071 | 459a4017 | bellard | dst = env->fpr; |
2072 | 459a4017 | bellard | /* XXX: check that the CPU storage is the same as user context */
|
2073 | 459a4017 | bellard | for (i = 0; i < 64; i++, dst++, src++) |
2074 | 459a4017 | bellard | err |= __get_user(*dst, src); |
2075 | 459a4017 | bellard | } |
2076 | 579a97f7 | bellard | err |= __get_user(env->fsr, |
2077 | 579a97f7 | bellard | &(ucp->uc_mcontext.mc_fpregs.mcfpu_fsr)); |
2078 | 579a97f7 | bellard | err |= __get_user(env->gsr, |
2079 | 579a97f7 | bellard | &(ucp->uc_mcontext.mc_fpregs.mcfpu_gsr)); |
2080 | 5bfb56b2 | blueswir1 | if (err)
|
2081 | 5bfb56b2 | blueswir1 | goto do_sigsegv;
|
2082 | 459a4017 | bellard | unlock_user_struct(ucp, ucp_addr, 0);
|
2083 | 5bfb56b2 | blueswir1 | return;
|
2084 | 5bfb56b2 | blueswir1 | do_sigsegv:
|
2085 | 459a4017 | bellard | unlock_user_struct(ucp, ucp_addr, 0);
|
2086 | 5bfb56b2 | blueswir1 | force_sig(SIGSEGV); |
2087 | 5bfb56b2 | blueswir1 | } |
2088 | 5bfb56b2 | blueswir1 | |
2089 | 5bfb56b2 | blueswir1 | void sparc64_get_context(CPUSPARCState *env)
|
2090 | 5bfb56b2 | blueswir1 | { |
2091 | 459a4017 | bellard | abi_ulong ucp_addr; |
2092 | 459a4017 | bellard | struct target_ucontext *ucp;
|
2093 | 5bfb56b2 | blueswir1 | target_mc_gregset_t *grp; |
2094 | 5bfb56b2 | blueswir1 | target_mcontext_t *mcp; |
2095 | 459a4017 | bellard | abi_ulong fp, i7, w_addr; |
2096 | 5bfb56b2 | blueswir1 | int err;
|
2097 | 5bfb56b2 | blueswir1 | unsigned int i; |
2098 | 5bfb56b2 | blueswir1 | target_sigset_t target_set; |
2099 | 5bfb56b2 | blueswir1 | sigset_t set; |
2100 | 5bfb56b2 | blueswir1 | |
2101 | 459a4017 | bellard | ucp_addr = env->regwptr[UREG_I0]; |
2102 | 459a4017 | bellard | if (!lock_user_struct(VERIFY_WRITE, ucp, ucp_addr, 0)) |
2103 | 459a4017 | bellard | goto do_sigsegv;
|
2104 | 459a4017 | bellard | |
2105 | 5bfb56b2 | blueswir1 | mcp = &ucp->uc_mcontext; |
2106 | 5bfb56b2 | blueswir1 | grp = &mcp->mc_gregs; |
2107 | 5bfb56b2 | blueswir1 | |
2108 | 5bfb56b2 | blueswir1 | /* Skip over the trap instruction, first. */
|
2109 | 5bfb56b2 | blueswir1 | env->pc = env->npc; |
2110 | 5bfb56b2 | blueswir1 | env->npc += 4;
|
2111 | 5bfb56b2 | blueswir1 | |
2112 | 5bfb56b2 | blueswir1 | err = 0;
|
2113 | 5bfb56b2 | blueswir1 | |
2114 | 5bfb56b2 | blueswir1 | sigprocmask(0, NULL, &set); |
2115 | 5bfb56b2 | blueswir1 | host_to_target_sigset_internal(&target_set, &set); |
2116 | 459a4017 | bellard | if (TARGET_NSIG_WORDS == 1) { |
2117 | 579a97f7 | bellard | err |= __put_user(target_set.sig[0],
|
2118 | 579a97f7 | bellard | (abi_ulong *)&ucp->uc_sigmask); |
2119 | 459a4017 | bellard | } else {
|
2120 | 459a4017 | bellard | abi_ulong *src, *dst; |
2121 | 459a4017 | bellard | src = target_set.sig; |
2122 | 459a4017 | bellard | dst = ucp->uc_sigmask.sig; |
2123 | 992f48a0 | blueswir1 | for (i = 0; i < sizeof(target_sigset_t) / sizeof(abi_ulong); |
2124 | 5bfb56b2 | blueswir1 | i++, dst++, src++) |
2125 | 459a4017 | bellard | err |= __put_user(*src, dst); |
2126 | 5bfb56b2 | blueswir1 | if (err)
|
2127 | 5bfb56b2 | blueswir1 | goto do_sigsegv;
|
2128 | 5bfb56b2 | blueswir1 | } |
2129 | 5bfb56b2 | blueswir1 | |
2130 | 459a4017 | bellard | /* XXX: tstate must be saved properly */
|
2131 | 459a4017 | bellard | // err |= __put_user(env->tstate, &((*grp)[MC_TSTATE]));
|
2132 | 579a97f7 | bellard | err |= __put_user(env->pc, &((*grp)[MC_PC])); |
2133 | 579a97f7 | bellard | err |= __put_user(env->npc, &((*grp)[MC_NPC])); |
2134 | 579a97f7 | bellard | err |= __put_user(env->y, &((*grp)[MC_Y])); |
2135 | 579a97f7 | bellard | err |= __put_user(env->gregs[1], &((*grp)[MC_G1]));
|
2136 | 579a97f7 | bellard | err |= __put_user(env->gregs[2], &((*grp)[MC_G2]));
|
2137 | 579a97f7 | bellard | err |= __put_user(env->gregs[3], &((*grp)[MC_G3]));
|
2138 | 579a97f7 | bellard | err |= __put_user(env->gregs[4], &((*grp)[MC_G4]));
|
2139 | 579a97f7 | bellard | err |= __put_user(env->gregs[5], &((*grp)[MC_G5]));
|
2140 | 579a97f7 | bellard | err |= __put_user(env->gregs[6], &((*grp)[MC_G6]));
|
2141 | 579a97f7 | bellard | err |= __put_user(env->gregs[7], &((*grp)[MC_G7]));
|
2142 | 579a97f7 | bellard | err |= __put_user(env->regwptr[UREG_I0], &((*grp)[MC_O0])); |
2143 | 579a97f7 | bellard | err |= __put_user(env->regwptr[UREG_I1], &((*grp)[MC_O1])); |
2144 | 579a97f7 | bellard | err |= __put_user(env->regwptr[UREG_I2], &((*grp)[MC_O2])); |
2145 | 579a97f7 | bellard | err |= __put_user(env->regwptr[UREG_I3], &((*grp)[MC_O3])); |
2146 | 579a97f7 | bellard | err |= __put_user(env->regwptr[UREG_I4], &((*grp)[MC_O4])); |
2147 | 579a97f7 | bellard | err |= __put_user(env->regwptr[UREG_I5], &((*grp)[MC_O5])); |
2148 | 579a97f7 | bellard | err |= __put_user(env->regwptr[UREG_I6], &((*grp)[MC_O6])); |
2149 | 579a97f7 | bellard | err |= __put_user(env->regwptr[UREG_I7], &((*grp)[MC_O7])); |
2150 | 579a97f7 | bellard | |
2151 | 459a4017 | bellard | w_addr = TARGET_STACK_BIAS+env->regwptr[UREG_I6]; |
2152 | 459a4017 | bellard | fp = i7 = 0;
|
2153 | 459a4017 | bellard | if (get_user(fp, w_addr + offsetof(struct target_reg_window, ins[6]), |
2154 | 459a4017 | bellard | abi_ulong) != 0)
|
2155 | 459a4017 | bellard | goto do_sigsegv;
|
2156 | 459a4017 | bellard | if (get_user(i7, w_addr + offsetof(struct target_reg_window, ins[7]), |
2157 | 459a4017 | bellard | abi_ulong) != 0)
|
2158 | 459a4017 | bellard | goto do_sigsegv;
|
2159 | 579a97f7 | bellard | err |= __put_user(fp, &(mcp->mc_fp)); |
2160 | 579a97f7 | bellard | err |= __put_user(i7, &(mcp->mc_i7)); |
2161 | 5bfb56b2 | blueswir1 | |
2162 | 459a4017 | bellard | { |
2163 | 459a4017 | bellard | uint32_t *src, *dst; |
2164 | 459a4017 | bellard | src = env->fpr; |
2165 | 459a4017 | bellard | dst = ucp->uc_mcontext.mc_fpregs.mcfpu_fregs.sregs; |
2166 | 459a4017 | bellard | /* XXX: check that the CPU storage is the same as user context */
|
2167 | 459a4017 | bellard | for (i = 0; i < 64; i++, dst++, src++) |
2168 | 459a4017 | bellard | err |= __put_user(*src, dst); |
2169 | 459a4017 | bellard | } |
2170 | 579a97f7 | bellard | err |= __put_user(env->fsr, &(mcp->mc_fpregs.mcfpu_fsr)); |
2171 | 579a97f7 | bellard | err |= __put_user(env->gsr, &(mcp->mc_fpregs.mcfpu_gsr)); |
2172 | 579a97f7 | bellard | err |= __put_user(env->fprs, &(mcp->mc_fpregs.mcfpu_fprs)); |
2173 | 5bfb56b2 | blueswir1 | |
2174 | 5bfb56b2 | blueswir1 | if (err)
|
2175 | 5bfb56b2 | blueswir1 | goto do_sigsegv;
|
2176 | 459a4017 | bellard | unlock_user_struct(ucp, ucp_addr, 1);
|
2177 | 5bfb56b2 | blueswir1 | return;
|
2178 | 5bfb56b2 | blueswir1 | do_sigsegv:
|
2179 | 459a4017 | bellard | unlock_user_struct(ucp, ucp_addr, 1);
|
2180 | 5bfb56b2 | blueswir1 | force_sig(SIGSEGV); |
2181 | 5bfb56b2 | blueswir1 | } |
2182 | 5bfb56b2 | blueswir1 | #endif
|
2183 | d26bc211 | ths | #elif defined(TARGET_ABI_MIPSN64)
|
2184 | 540635ba | ths | |
2185 | 540635ba | ths | # warning signal handling not implemented
|
2186 | 540635ba | ths | |
2187 | 624f7979 | pbrook | static void setup_frame(int sig, struct target_sigaction *ka, |
2188 | 540635ba | ths | target_sigset_t *set, CPUState *env) |
2189 | 540635ba | ths | { |
2190 | 540635ba | ths | fprintf(stderr, "setup_frame: not implemented\n");
|
2191 | 540635ba | ths | } |
2192 | 540635ba | ths | |
2193 | 624f7979 | pbrook | static void setup_rt_frame(int sig, struct target_sigaction *ka, |
2194 | 540635ba | ths | target_siginfo_t *info, |
2195 | 540635ba | ths | target_sigset_t *set, CPUState *env) |
2196 | 540635ba | ths | { |
2197 | 540635ba | ths | fprintf(stderr, "setup_rt_frame: not implemented\n");
|
2198 | 540635ba | ths | } |
2199 | 540635ba | ths | |
2200 | 540635ba | ths | long do_sigreturn(CPUState *env)
|
2201 | 540635ba | ths | { |
2202 | 540635ba | ths | fprintf(stderr, "do_sigreturn: not implemented\n");
|
2203 | f8b0aa25 | bellard | return -TARGET_ENOSYS;
|
2204 | 540635ba | ths | } |
2205 | 540635ba | ths | |
2206 | 540635ba | ths | long do_rt_sigreturn(CPUState *env)
|
2207 | 540635ba | ths | { |
2208 | 540635ba | ths | fprintf(stderr, "do_rt_sigreturn: not implemented\n");
|
2209 | f8b0aa25 | bellard | return -TARGET_ENOSYS;
|
2210 | 540635ba | ths | } |
2211 | 540635ba | ths | |
2212 | d26bc211 | ths | #elif defined(TARGET_ABI_MIPSN32)
|
2213 | 540635ba | ths | |
2214 | 540635ba | ths | # warning signal handling not implemented
|
2215 | 540635ba | ths | |
2216 | 624f7979 | pbrook | static void setup_frame(int sig, struct target_sigaction *ka, |
2217 | 540635ba | ths | target_sigset_t *set, CPUState *env) |
2218 | 540635ba | ths | { |
2219 | 540635ba | ths | fprintf(stderr, "setup_frame: not implemented\n");
|
2220 | 540635ba | ths | } |
2221 | 540635ba | ths | |
2222 | 624f7979 | pbrook | static void setup_rt_frame(int sig, struct target_sigaction *ka, |
2223 | 540635ba | ths | target_siginfo_t *info, |
2224 | 540635ba | ths | target_sigset_t *set, CPUState *env) |
2225 | 540635ba | ths | { |
2226 | 540635ba | ths | fprintf(stderr, "setup_rt_frame: not implemented\n");
|
2227 | 540635ba | ths | } |
2228 | 540635ba | ths | |
2229 | 540635ba | ths | long do_sigreturn(CPUState *env)
|
2230 | 540635ba | ths | { |
2231 | 540635ba | ths | fprintf(stderr, "do_sigreturn: not implemented\n");
|
2232 | f8b0aa25 | bellard | return -TARGET_ENOSYS;
|
2233 | 540635ba | ths | } |
2234 | 540635ba | ths | |
2235 | 540635ba | ths | long do_rt_sigreturn(CPUState *env)
|
2236 | 540635ba | ths | { |
2237 | 540635ba | ths | fprintf(stderr, "do_rt_sigreturn: not implemented\n");
|
2238 | f8b0aa25 | bellard | return -TARGET_ENOSYS;
|
2239 | 540635ba | ths | } |
2240 | 540635ba | ths | |
2241 | d26bc211 | ths | #elif defined(TARGET_ABI_MIPSO32)
|
2242 | 106ec879 | bellard | |
2243 | 106ec879 | bellard | struct target_sigcontext {
|
2244 | 106ec879 | bellard | uint32_t sc_regmask; /* Unused */
|
2245 | 106ec879 | bellard | uint32_t sc_status; |
2246 | 106ec879 | bellard | uint64_t sc_pc; |
2247 | 106ec879 | bellard | uint64_t sc_regs[32];
|
2248 | 106ec879 | bellard | uint64_t sc_fpregs[32];
|
2249 | 106ec879 | bellard | uint32_t sc_ownedfp; /* Unused */
|
2250 | 106ec879 | bellard | uint32_t sc_fpc_csr; |
2251 | 106ec879 | bellard | uint32_t sc_fpc_eir; /* Unused */
|
2252 | 106ec879 | bellard | uint32_t sc_used_math; |
2253 | 106ec879 | bellard | uint32_t sc_dsp; /* dsp status, was sc_ssflags */
|
2254 | 106ec879 | bellard | uint64_t sc_mdhi; |
2255 | 106ec879 | bellard | uint64_t sc_mdlo; |
2256 | 106ec879 | bellard | target_ulong sc_hi1; /* Was sc_cause */
|
2257 | 106ec879 | bellard | target_ulong sc_lo1; /* Was sc_badvaddr */
|
2258 | 106ec879 | bellard | target_ulong sc_hi2; /* Was sc_sigset[4] */
|
2259 | 106ec879 | bellard | target_ulong sc_lo2; |
2260 | 106ec879 | bellard | target_ulong sc_hi3; |
2261 | 106ec879 | bellard | target_ulong sc_lo3; |
2262 | 106ec879 | bellard | }; |
2263 | 106ec879 | bellard | |
2264 | 106ec879 | bellard | struct sigframe {
|
2265 | 106ec879 | bellard | uint32_t sf_ass[4]; /* argument save space for o32 */ |
2266 | 106ec879 | bellard | uint32_t sf_code[2]; /* signal trampoline */ |
2267 | 106ec879 | bellard | struct target_sigcontext sf_sc;
|
2268 | 106ec879 | bellard | target_sigset_t sf_mask; |
2269 | 106ec879 | bellard | }; |
2270 | 106ec879 | bellard | |
2271 | 106ec879 | bellard | /* Install trampoline to jump back from signal handler */
|
2272 | 106ec879 | bellard | static inline int install_sigtramp(unsigned int *tramp, unsigned int syscall) |
2273 | 106ec879 | bellard | { |
2274 | 106ec879 | bellard | int err;
|
2275 | 106ec879 | bellard | |
2276 | 106ec879 | bellard | /*
|
2277 | 106ec879 | bellard | * Set up the return code ...
|
2278 | 106ec879 | bellard | *
|
2279 | 106ec879 | bellard | * li v0, __NR__foo_sigreturn
|
2280 | 106ec879 | bellard | * syscall
|
2281 | 106ec879 | bellard | */
|
2282 | 106ec879 | bellard | |
2283 | 106ec879 | bellard | err = __put_user(0x24020000 + syscall, tramp + 0); |
2284 | 106ec879 | bellard | err |= __put_user(0x0000000c , tramp + 1); |
2285 | 106ec879 | bellard | /* flush_cache_sigtramp((unsigned long) tramp); */
|
2286 | 106ec879 | bellard | return err;
|
2287 | 106ec879 | bellard | } |
2288 | 106ec879 | bellard | |
2289 | 106ec879 | bellard | static inline int |
2290 | 106ec879 | bellard | setup_sigcontext(CPUState *regs, struct target_sigcontext *sc)
|
2291 | 106ec879 | bellard | { |
2292 | 106ec879 | bellard | int err = 0; |
2293 | 106ec879 | bellard | |
2294 | b5dc7732 | ths | err |= __put_user(regs->active_tc.PC, &sc->sc_pc); |
2295 | 106ec879 | bellard | |
2296 | b5dc7732 | ths | #define save_gp_reg(i) do { \ |
2297 | b5dc7732 | ths | err |= __put_user(regs->active_tc.gpr[i], &sc->sc_regs[i]); \ |
2298 | 106ec879 | bellard | } while(0) |
2299 | 106ec879 | bellard | __put_user(0, &sc->sc_regs[0]); save_gp_reg(1); save_gp_reg(2); |
2300 | 106ec879 | bellard | save_gp_reg(3); save_gp_reg(4); save_gp_reg(5); save_gp_reg(6); |
2301 | 106ec879 | bellard | save_gp_reg(7); save_gp_reg(8); save_gp_reg(9); save_gp_reg(10); |
2302 | 106ec879 | bellard | save_gp_reg(11); save_gp_reg(12); save_gp_reg(13); save_gp_reg(14); |
2303 | 106ec879 | bellard | save_gp_reg(15); save_gp_reg(16); save_gp_reg(17); save_gp_reg(18); |
2304 | 106ec879 | bellard | save_gp_reg(19); save_gp_reg(20); save_gp_reg(21); save_gp_reg(22); |
2305 | 106ec879 | bellard | save_gp_reg(23); save_gp_reg(24); save_gp_reg(25); save_gp_reg(26); |
2306 | 106ec879 | bellard | save_gp_reg(27); save_gp_reg(28); save_gp_reg(29); save_gp_reg(30); |
2307 | 106ec879 | bellard | save_gp_reg(31);
|
2308 | 388bb21a | ths | #undef save_gp_reg
|
2309 | 106ec879 | bellard | |
2310 | b5dc7732 | ths | err |= __put_user(regs->active_tc.HI[0], &sc->sc_mdhi);
|
2311 | b5dc7732 | ths | err |= __put_user(regs->active_tc.LO[0], &sc->sc_mdlo);
|
2312 | 106ec879 | bellard | |
2313 | 106ec879 | bellard | /* Not used yet, but might be useful if we ever have DSP suppport */
|
2314 | 106ec879 | bellard | #if 0
|
2315 | 106ec879 | bellard | if (cpu_has_dsp) {
|
2316 | 106ec879 | bellard | err |= __put_user(mfhi1(), &sc->sc_hi1);
|
2317 | 106ec879 | bellard | err |= __put_user(mflo1(), &sc->sc_lo1);
|
2318 | 106ec879 | bellard | err |= __put_user(mfhi2(), &sc->sc_hi2);
|
2319 | 106ec879 | bellard | err |= __put_user(mflo2(), &sc->sc_lo2);
|
2320 | 106ec879 | bellard | err |= __put_user(mfhi3(), &sc->sc_hi3);
|
2321 | 106ec879 | bellard | err |= __put_user(mflo3(), &sc->sc_lo3);
|
2322 | 106ec879 | bellard | err |= __put_user(rddsp(DSP_MASK), &sc->sc_dsp);
|
2323 | 106ec879 | bellard | }
|
2324 | 106ec879 | bellard | /* same with 64 bit */
|
2325 | 388bb21a | ths | #ifdef CONFIG_64BIT
|
2326 | 106ec879 | bellard | err |= __put_user(regs->hi, &sc->sc_hi[0]);
|
2327 | 106ec879 | bellard | err |= __put_user(regs->lo, &sc->sc_lo[0]);
|
2328 | 106ec879 | bellard | if (cpu_has_dsp) {
|
2329 | 106ec879 | bellard | err |= __put_user(mfhi1(), &sc->sc_hi[1]);
|
2330 | 106ec879 | bellard | err |= __put_user(mflo1(), &sc->sc_lo[1]);
|
2331 | 106ec879 | bellard | err |= __put_user(mfhi2(), &sc->sc_hi[2]);
|
2332 | 106ec879 | bellard | err |= __put_user(mflo2(), &sc->sc_lo[2]);
|
2333 | 106ec879 | bellard | err |= __put_user(mfhi3(), &sc->sc_hi[3]);
|
2334 | 106ec879 | bellard | err |= __put_user(mflo3(), &sc->sc_lo[3]);
|
2335 | 106ec879 | bellard | err |= __put_user(rddsp(DSP_MASK), &sc->sc_dsp);
|
2336 | 106ec879 | bellard | }
|
2337 | 388bb21a | ths | #endif
|
2338 | 388bb21a | ths | #endif
|
2339 | 106ec879 | bellard | |
2340 | 388bb21a | ths | #if 0
|
2341 | 106ec879 | bellard | err |= __put_user(!!used_math(), &sc->sc_used_math);
|
2342 | 106ec879 | bellard | |
2343 | 106ec879 | bellard | if (!used_math())
|
2344 | 106ec879 | bellard | goto out;
|
2345 | 106ec879 | bellard | |
2346 | 106ec879 | bellard | /*
|
2347 | 106ec879 | bellard | * Save FPU state to signal context. Signal handler will "inherit"
|
2348 | 106ec879 | bellard | * current FPU state.
|
2349 | 106ec879 | bellard | */
|
2350 | 106ec879 | bellard | preempt_disable();
|
2351 | 106ec879 | bellard | |
2352 | 106ec879 | bellard | if (!is_fpu_owner()) {
|
2353 | 106ec879 | bellard | own_fpu();
|
2354 | 106ec879 | bellard | restore_fp(current);
|
2355 | 106ec879 | bellard | }
|
2356 | 106ec879 | bellard | err |= save_fp_context(sc);
|
2357 | 106ec879 | bellard | |
2358 | 106ec879 | bellard | preempt_enable();
|
2359 | 106ec879 | bellard | out:
|
2360 | 106ec879 | bellard | #endif
|
2361 | 106ec879 | bellard | return err;
|
2362 | 106ec879 | bellard | } |
2363 | 106ec879 | bellard | |
2364 | 106ec879 | bellard | static inline int |
2365 | 106ec879 | bellard | restore_sigcontext(CPUState *regs, struct target_sigcontext *sc)
|
2366 | 106ec879 | bellard | { |
2367 | 106ec879 | bellard | int err = 0; |
2368 | 106ec879 | bellard | |
2369 | 106ec879 | bellard | err |= __get_user(regs->CP0_EPC, &sc->sc_pc); |
2370 | 106ec879 | bellard | |
2371 | b5dc7732 | ths | err |= __get_user(regs->active_tc.HI[0], &sc->sc_mdhi);
|
2372 | b5dc7732 | ths | err |= __get_user(regs->active_tc.LO[0], &sc->sc_mdlo);
|
2373 | 106ec879 | bellard | |
2374 | ead9360e | ths | #define restore_gp_reg(i) do { \ |
2375 | b5dc7732 | ths | err |= __get_user(regs->active_tc.gpr[i], &sc->sc_regs[i]); \ |
2376 | 106ec879 | bellard | } while(0) |
2377 | 106ec879 | bellard | restore_gp_reg( 1); restore_gp_reg( 2); restore_gp_reg( 3); |
2378 | 106ec879 | bellard | restore_gp_reg( 4); restore_gp_reg( 5); restore_gp_reg( 6); |
2379 | 106ec879 | bellard | restore_gp_reg( 7); restore_gp_reg( 8); restore_gp_reg( 9); |
2380 | 106ec879 | bellard | restore_gp_reg(10); restore_gp_reg(11); restore_gp_reg(12); |
2381 | 106ec879 | bellard | restore_gp_reg(13); restore_gp_reg(14); restore_gp_reg(15); |
2382 | 106ec879 | bellard | restore_gp_reg(16); restore_gp_reg(17); restore_gp_reg(18); |
2383 | 106ec879 | bellard | restore_gp_reg(19); restore_gp_reg(20); restore_gp_reg(21); |
2384 | 106ec879 | bellard | restore_gp_reg(22); restore_gp_reg(23); restore_gp_reg(24); |
2385 | 106ec879 | bellard | restore_gp_reg(25); restore_gp_reg(26); restore_gp_reg(27); |
2386 | 106ec879 | bellard | restore_gp_reg(28); restore_gp_reg(29); restore_gp_reg(30); |
2387 | 106ec879 | bellard | restore_gp_reg(31);
|
2388 | 388bb21a | ths | #undef restore_gp_reg
|
2389 | 106ec879 | bellard | |
2390 | 106ec879 | bellard | #if 0
|
2391 | 106ec879 | bellard | if (cpu_has_dsp) {
|
2392 | 106ec879 | bellard | err |= __get_user(treg, &sc->sc_hi1); mthi1(treg);
|
2393 | 106ec879 | bellard | err |= __get_user(treg, &sc->sc_lo1); mtlo1(treg);
|
2394 | 106ec879 | bellard | err |= __get_user(treg, &sc->sc_hi2); mthi2(treg);
|
2395 | 106ec879 | bellard | err |= __get_user(treg, &sc->sc_lo2); mtlo2(treg);
|
2396 | 106ec879 | bellard | err |= __get_user(treg, &sc->sc_hi3); mthi3(treg);
|
2397 | 106ec879 | bellard | err |= __get_user(treg, &sc->sc_lo3); mtlo3(treg);
|
2398 | 106ec879 | bellard | err |= __get_user(treg, &sc->sc_dsp); wrdsp(treg, DSP_MASK);
|
2399 | 106ec879 | bellard | }
|
2400 | 388bb21a | ths | #ifdef CONFIG_64BIT
|
2401 | 106ec879 | bellard | err |= __get_user(regs->hi, &sc->sc_hi[0]);
|
2402 | 106ec879 | bellard | err |= __get_user(regs->lo, &sc->sc_lo[0]);
|
2403 | 106ec879 | bellard | if (cpu_has_dsp) {
|
2404 | 106ec879 | bellard | err |= __get_user(treg, &sc->sc_hi[1]); mthi1(treg);
|
2405 | 106ec879 | bellard | err |= __get_user(treg, &sc->sc_lo[1]); mthi1(treg);
|
2406 | 106ec879 | bellard | err |= __get_user(treg, &sc->sc_hi[2]); mthi2(treg);
|
2407 | 106ec879 | bellard | err |= __get_user(treg, &sc->sc_lo[2]); mthi2(treg);
|
2408 | 106ec879 | bellard | err |= __get_user(treg, &sc->sc_hi[3]); mthi3(treg);
|
2409 | 106ec879 | bellard | err |= __get_user(treg, &sc->sc_lo[3]); mthi3(treg);
|
2410 | 106ec879 | bellard | err |= __get_user(treg, &sc->sc_dsp); wrdsp(treg, DSP_MASK);
|
2411 | 106ec879 | bellard | }
|
2412 | 388bb21a | ths | #endif
|
2413 | 106ec879 | bellard | |
2414 | 106ec879 | bellard | err |= __get_user(used_math, &sc->sc_used_math); |
2415 | 106ec879 | bellard | conditional_used_math(used_math); |
2416 | 106ec879 | bellard | |
2417 | 106ec879 | bellard | preempt_disable(); |
2418 | 106ec879 | bellard | |
2419 | 106ec879 | bellard | if (used_math()) {
|
2420 | 106ec879 | bellard | /* restore fpu context if we have used it before */
|
2421 | 106ec879 | bellard | own_fpu(); |
2422 | 106ec879 | bellard | err |= restore_fp_context(sc); |
2423 | 106ec879 | bellard | } else {
|
2424 | 106ec879 | bellard | /* signal handler may have used FPU. Give it up. */
|
2425 | 106ec879 | bellard | lose_fpu(); |
2426 | 106ec879 | bellard | } |
2427 | 106ec879 | bellard | |
2428 | 106ec879 | bellard | preempt_enable(); |
2429 | 106ec879 | bellard | #endif
|
2430 | 106ec879 | bellard | return err;
|
2431 | 106ec879 | bellard | } |
2432 | 106ec879 | bellard | /*
|
2433 | 106ec879 | bellard | * Determine which stack to use..
|
2434 | 106ec879 | bellard | */
|
2435 | 579a97f7 | bellard | static inline abi_ulong |
2436 | 624f7979 | pbrook | get_sigframe(struct target_sigaction *ka, CPUState *regs, size_t frame_size)
|
2437 | 106ec879 | bellard | { |
2438 | 106ec879 | bellard | unsigned long sp; |
2439 | 106ec879 | bellard | |
2440 | 106ec879 | bellard | /* Default to using normal stack */
|
2441 | b5dc7732 | ths | sp = regs->active_tc.gpr[29];
|
2442 | 106ec879 | bellard | |
2443 | 106ec879 | bellard | /*
|
2444 | 106ec879 | bellard | * FPU emulator may have it's own trampoline active just
|
2445 | 106ec879 | bellard | * above the user stack, 16-bytes before the next lowest
|
2446 | 106ec879 | bellard | * 16 byte boundary. Try to avoid trashing it.
|
2447 | 106ec879 | bellard | */
|
2448 | 106ec879 | bellard | sp -= 32;
|
2449 | 106ec879 | bellard | |
2450 | 106ec879 | bellard | /* This is the X/Open sanctioned signal stack switching. */
|
2451 | 624f7979 | pbrook | if ((ka->sa_flags & TARGET_SA_ONSTACK) && (sas_ss_flags (sp) == 0)) { |
2452 | a04e134a | ths | sp = target_sigaltstack_used.ss_sp + target_sigaltstack_used.ss_size; |
2453 | a04e134a | ths | } |
2454 | 106ec879 | bellard | |
2455 | 579a97f7 | bellard | return (sp - frame_size) & ~7; |
2456 | 106ec879 | bellard | } |
2457 | 106ec879 | bellard | |
2458 | 579a97f7 | bellard | /* compare linux/arch/mips/kernel/signal.c:setup_frame() */
|
2459 | 624f7979 | pbrook | static void setup_frame(int sig, struct target_sigaction * ka, |
2460 | 579a97f7 | bellard | target_sigset_t *set, CPUState *regs) |
2461 | 106ec879 | bellard | { |
2462 | 106ec879 | bellard | struct sigframe *frame;
|
2463 | 579a97f7 | bellard | abi_ulong frame_addr; |
2464 | 106ec879 | bellard | int i;
|
2465 | 106ec879 | bellard | |
2466 | 579a97f7 | bellard | frame_addr = get_sigframe(ka, regs, sizeof(*frame));
|
2467 | 579a97f7 | bellard | if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) |
2468 | 106ec879 | bellard | goto give_sigsegv;
|
2469 | 106ec879 | bellard | |
2470 | 106ec879 | bellard | install_sigtramp(frame->sf_code, TARGET_NR_sigreturn); |
2471 | 106ec879 | bellard | |
2472 | 106ec879 | bellard | if(setup_sigcontext(regs, &frame->sf_sc))
|
2473 | 106ec879 | bellard | goto give_sigsegv;
|
2474 | 106ec879 | bellard | |
2475 | 106ec879 | bellard | for(i = 0; i < TARGET_NSIG_WORDS; i++) { |
2476 | 106ec879 | bellard | if(__put_user(set->sig[i], &frame->sf_mask.sig[i]))
|
2477 | 106ec879 | bellard | goto give_sigsegv;
|
2478 | 106ec879 | bellard | } |
2479 | 106ec879 | bellard | |
2480 | 106ec879 | bellard | /*
|
2481 | 106ec879 | bellard | * Arguments to signal handler:
|
2482 | 106ec879 | bellard | *
|
2483 | 106ec879 | bellard | * a0 = signal number
|
2484 | 106ec879 | bellard | * a1 = 0 (should be cause)
|
2485 | 106ec879 | bellard | * a2 = pointer to struct sigcontext
|
2486 | 106ec879 | bellard | *
|
2487 | 106ec879 | bellard | * $25 and PC point to the signal handler, $29 points to the
|
2488 | 106ec879 | bellard | * struct sigframe.
|
2489 | 106ec879 | bellard | */
|
2490 | b5dc7732 | ths | regs->active_tc.gpr[ 4] = sig;
|
2491 | b5dc7732 | ths | regs->active_tc.gpr[ 5] = 0; |
2492 | b5dc7732 | ths | regs->active_tc.gpr[ 6] = frame_addr + offsetof(struct sigframe, sf_sc); |
2493 | b5dc7732 | ths | regs->active_tc.gpr[29] = frame_addr;
|
2494 | b5dc7732 | ths | regs->active_tc.gpr[31] = frame_addr + offsetof(struct sigframe, sf_code); |
2495 | 106ec879 | bellard | /* The original kernel code sets CP0_EPC to the handler
|
2496 | 106ec879 | bellard | * since it returns to userland using eret
|
2497 | 106ec879 | bellard | * we cannot do this here, and we must set PC directly */
|
2498 | b5dc7732 | ths | regs->active_tc.PC = regs->active_tc.gpr[25] = ka->_sa_handler;
|
2499 | 579a97f7 | bellard | unlock_user_struct(frame, frame_addr, 1);
|
2500 | 106ec879 | bellard | return;
|
2501 | 106ec879 | bellard | |
2502 | 106ec879 | bellard | give_sigsegv:
|
2503 | 579a97f7 | bellard | unlock_user_struct(frame, frame_addr, 1);
|
2504 | 106ec879 | bellard | force_sig(TARGET_SIGSEGV/*, current*/);
|
2505 | 5fafdf24 | ths | return;
|
2506 | 106ec879 | bellard | } |
2507 | 106ec879 | bellard | |
2508 | 106ec879 | bellard | long do_sigreturn(CPUState *regs)
|
2509 | 106ec879 | bellard | { |
2510 | 388bb21a | ths | struct sigframe *frame;
|
2511 | 579a97f7 | bellard | abi_ulong frame_addr; |
2512 | 388bb21a | ths | sigset_t blocked; |
2513 | 388bb21a | ths | target_sigset_t target_set; |
2514 | 388bb21a | ths | int i;
|
2515 | 106ec879 | bellard | |
2516 | 106ec879 | bellard | #if defined(DEBUG_SIGNAL)
|
2517 | 388bb21a | ths | fprintf(stderr, "do_sigreturn\n");
|
2518 | 106ec879 | bellard | #endif
|
2519 | b5dc7732 | ths | frame_addr = regs->active_tc.gpr[29];
|
2520 | 579a97f7 | bellard | if (!lock_user_struct(VERIFY_READ, frame, frame_addr, 1)) |
2521 | 106ec879 | bellard | goto badframe;
|
2522 | 106ec879 | bellard | |
2523 | 388bb21a | ths | for(i = 0; i < TARGET_NSIG_WORDS; i++) { |
2524 | 106ec879 | bellard | if(__get_user(target_set.sig[i], &frame->sf_mask.sig[i]))
|
2525 | 106ec879 | bellard | goto badframe;
|
2526 | 388bb21a | ths | } |
2527 | 106ec879 | bellard | |
2528 | 388bb21a | ths | target_to_host_sigset_internal(&blocked, &target_set); |
2529 | 388bb21a | ths | sigprocmask(SIG_SETMASK, &blocked, NULL);
|
2530 | 106ec879 | bellard | |
2531 | 388bb21a | ths | if (restore_sigcontext(regs, &frame->sf_sc))
|
2532 | 106ec879 | bellard | goto badframe;
|
2533 | 106ec879 | bellard | |
2534 | 106ec879 | bellard | #if 0
|
2535 | 388bb21a | ths | /*
|
2536 | 388bb21a | ths | * Don't let your children do this ...
|
2537 | 388bb21a | ths | */
|
2538 | 388bb21a | ths | __asm__ __volatile__(
|
2539 | 106ec879 | bellard | "move\t$29, %0\n\t"
|
2540 | 106ec879 | bellard | "j\tsyscall_exit"
|
2541 | 106ec879 | bellard | :/* no outputs */
|
2542 | 106ec879 | bellard | :"r" (®s));
|
2543 | 388bb21a | ths | /* Unreached */
|
2544 | 106ec879 | bellard | #endif
|
2545 | 3b46e624 | ths | |
2546 | b5dc7732 | ths | regs->active_tc.PC = regs->CP0_EPC; |
2547 | 388bb21a | ths | /* I am not sure this is right, but it seems to work
|
2548 | 106ec879 | bellard | * maybe a problem with nested signals ? */
|
2549 | 106ec879 | bellard | regs->CP0_EPC = 0;
|
2550 | 106ec879 | bellard | return 0; |
2551 | 106ec879 | bellard | |
2552 | 106ec879 | bellard | badframe:
|
2553 | 388bb21a | ths | force_sig(TARGET_SIGSEGV/*, current*/);
|
2554 | 388bb21a | ths | return 0; |
2555 | 106ec879 | bellard | } |
2556 | 106ec879 | bellard | |
2557 | 624f7979 | pbrook | static void setup_rt_frame(int sig, struct target_sigaction *ka, |
2558 | 106ec879 | bellard | target_siginfo_t *info, |
2559 | 106ec879 | bellard | target_sigset_t *set, CPUState *env) |
2560 | 106ec879 | bellard | { |
2561 | 106ec879 | bellard | fprintf(stderr, "setup_rt_frame: not implemented\n");
|
2562 | 106ec879 | bellard | } |
2563 | 106ec879 | bellard | |
2564 | 106ec879 | bellard | long do_rt_sigreturn(CPUState *env)
|
2565 | 106ec879 | bellard | { |
2566 | 106ec879 | bellard | fprintf(stderr, "do_rt_sigreturn: not implemented\n");
|
2567 | f8b0aa25 | bellard | return -TARGET_ENOSYS;
|
2568 | 106ec879 | bellard | } |
2569 | 6d5e216d | bellard | |
2570 | c3b5bc8a | ths | #elif defined(TARGET_SH4)
|
2571 | c3b5bc8a | ths | |
2572 | c3b5bc8a | ths | /*
|
2573 | c3b5bc8a | ths | * code and data structures from linux kernel:
|
2574 | c3b5bc8a | ths | * include/asm-sh/sigcontext.h
|
2575 | c3b5bc8a | ths | * arch/sh/kernel/signal.c
|
2576 | c3b5bc8a | ths | */
|
2577 | c3b5bc8a | ths | |
2578 | c3b5bc8a | ths | struct target_sigcontext {
|
2579 | c3b5bc8a | ths | target_ulong oldmask; |
2580 | c3b5bc8a | ths | |
2581 | c3b5bc8a | ths | /* CPU registers */
|
2582 | c3b5bc8a | ths | target_ulong sc_gregs[16];
|
2583 | c3b5bc8a | ths | target_ulong sc_pc; |
2584 | c3b5bc8a | ths | target_ulong sc_pr; |
2585 | c3b5bc8a | ths | target_ulong sc_sr; |
2586 | c3b5bc8a | ths | target_ulong sc_gbr; |
2587 | c3b5bc8a | ths | target_ulong sc_mach; |
2588 | c3b5bc8a | ths | target_ulong sc_macl; |
2589 | c3b5bc8a | ths | |
2590 | c3b5bc8a | ths | /* FPU registers */
|
2591 | c3b5bc8a | ths | target_ulong sc_fpregs[16];
|
2592 | c3b5bc8a | ths | target_ulong sc_xfpregs[16];
|
2593 | c3b5bc8a | ths | unsigned int sc_fpscr; |
2594 | c3b5bc8a | ths | unsigned int sc_fpul; |
2595 | c3b5bc8a | ths | unsigned int sc_ownedfp; |
2596 | c3b5bc8a | ths | }; |
2597 | c3b5bc8a | ths | |
2598 | c3b5bc8a | ths | struct target_sigframe
|
2599 | c3b5bc8a | ths | { |
2600 | c3b5bc8a | ths | struct target_sigcontext sc;
|
2601 | c3b5bc8a | ths | target_ulong extramask[TARGET_NSIG_WORDS-1];
|
2602 | c3b5bc8a | ths | uint16_t retcode[3];
|
2603 | c3b5bc8a | ths | }; |
2604 | c3b5bc8a | ths | |
2605 | c3b5bc8a | ths | |
2606 | c3b5bc8a | ths | struct target_ucontext {
|
2607 | c3b5bc8a | ths | target_ulong uc_flags; |
2608 | c3b5bc8a | ths | struct target_ucontext *uc_link;
|
2609 | c3b5bc8a | ths | target_stack_t uc_stack; |
2610 | c3b5bc8a | ths | struct target_sigcontext uc_mcontext;
|
2611 | c3b5bc8a | ths | target_sigset_t uc_sigmask; /* mask last for extensibility */
|
2612 | c3b5bc8a | ths | }; |
2613 | c3b5bc8a | ths | |
2614 | c3b5bc8a | ths | struct target_rt_sigframe
|
2615 | c3b5bc8a | ths | { |
2616 | c3b5bc8a | ths | struct target_siginfo info;
|
2617 | c3b5bc8a | ths | struct target_ucontext uc;
|
2618 | c3b5bc8a | ths | uint16_t retcode[3];
|
2619 | c3b5bc8a | ths | }; |
2620 | c3b5bc8a | ths | |
2621 | c3b5bc8a | ths | |
2622 | c3b5bc8a | ths | #define MOVW(n) (0x9300|((n)-2)) /* Move mem word at PC+n to R3 */ |
2623 | c3b5bc8a | ths | #define TRAP_NOARG 0xc310 /* Syscall w/no args (NR in R3) SH3/4 */ |
2624 | c3b5bc8a | ths | |
2625 | 624f7979 | pbrook | static abi_ulong get_sigframe(struct target_sigaction *ka, |
2626 | c3b5bc8a | ths | unsigned long sp, size_t frame_size) |
2627 | c3b5bc8a | ths | { |
2628 | 624f7979 | pbrook | if ((ka->sa_flags & TARGET_SA_ONSTACK) && (sas_ss_flags(sp) == 0)) { |
2629 | c3b5bc8a | ths | sp = target_sigaltstack_used.ss_sp + target_sigaltstack_used.ss_size; |
2630 | c3b5bc8a | ths | } |
2631 | c3b5bc8a | ths | |
2632 | c3b5bc8a | ths | return (sp - frame_size) & -8ul; |
2633 | c3b5bc8a | ths | } |
2634 | c3b5bc8a | ths | |
2635 | c3b5bc8a | ths | static int setup_sigcontext(struct target_sigcontext *sc, |
2636 | c3b5bc8a | ths | CPUState *regs, unsigned long mask) |
2637 | c3b5bc8a | ths | { |
2638 | c3b5bc8a | ths | int err = 0; |
2639 | c3b5bc8a | ths | |
2640 | c3b5bc8a | ths | #define COPY(x) err |= __put_user(regs->x, &sc->sc_##x) |
2641 | c3b5bc8a | ths | COPY(gregs[0]); COPY(gregs[1]); |
2642 | c3b5bc8a | ths | COPY(gregs[2]); COPY(gregs[3]); |
2643 | c3b5bc8a | ths | COPY(gregs[4]); COPY(gregs[5]); |
2644 | c3b5bc8a | ths | COPY(gregs[6]); COPY(gregs[7]); |
2645 | c3b5bc8a | ths | COPY(gregs[8]); COPY(gregs[9]); |
2646 | c3b5bc8a | ths | COPY(gregs[10]); COPY(gregs[11]); |
2647 | c3b5bc8a | ths | COPY(gregs[12]); COPY(gregs[13]); |
2648 | c3b5bc8a | ths | COPY(gregs[14]); COPY(gregs[15]); |
2649 | c3b5bc8a | ths | COPY(gbr); COPY(mach); |
2650 | c3b5bc8a | ths | COPY(macl); COPY(pr); |
2651 | c3b5bc8a | ths | COPY(sr); COPY(pc); |
2652 | c3b5bc8a | ths | #undef COPY
|
2653 | c3b5bc8a | ths | |
2654 | c3b5bc8a | ths | /* todo: save FPU registers here */
|
2655 | c3b5bc8a | ths | |
2656 | c3b5bc8a | ths | /* non-iBCS2 extensions.. */
|
2657 | c3b5bc8a | ths | err |= __put_user(mask, &sc->oldmask); |
2658 | c3b5bc8a | ths | |
2659 | c3b5bc8a | ths | return err;
|
2660 | c3b5bc8a | ths | } |
2661 | c3b5bc8a | ths | |
2662 | c3b5bc8a | ths | static int restore_sigcontext(struct CPUState *regs, |
2663 | c3b5bc8a | ths | struct target_sigcontext *sc)
|
2664 | c3b5bc8a | ths | { |
2665 | c3b5bc8a | ths | unsigned int err = 0; |
2666 | c3b5bc8a | ths | |
2667 | c3b5bc8a | ths | #define COPY(x) err |= __get_user(regs->x, &sc->sc_##x) |
2668 | c3b5bc8a | ths | COPY(gregs[1]);
|
2669 | c3b5bc8a | ths | COPY(gregs[2]); COPY(gregs[3]); |
2670 | c3b5bc8a | ths | COPY(gregs[4]); COPY(gregs[5]); |
2671 | c3b5bc8a | ths | COPY(gregs[6]); COPY(gregs[7]); |
2672 | c3b5bc8a | ths | COPY(gregs[8]); COPY(gregs[9]); |
2673 | c3b5bc8a | ths | COPY(gregs[10]); COPY(gregs[11]); |
2674 | c3b5bc8a | ths | COPY(gregs[12]); COPY(gregs[13]); |
2675 | c3b5bc8a | ths | COPY(gregs[14]); COPY(gregs[15]); |
2676 | c3b5bc8a | ths | COPY(gbr); COPY(mach); |
2677 | c3b5bc8a | ths | COPY(macl); COPY(pr); |
2678 | c3b5bc8a | ths | COPY(sr); COPY(pc); |
2679 | c3b5bc8a | ths | #undef COPY
|
2680 | c3b5bc8a | ths | |
2681 | c3b5bc8a | ths | /* todo: restore FPU registers here */
|
2682 | c3b5bc8a | ths | |
2683 | c3b5bc8a | ths | regs->tra = -1; /* disable syscall checks */ |
2684 | c3b5bc8a | ths | return err;
|
2685 | c3b5bc8a | ths | } |
2686 | c3b5bc8a | ths | |
2687 | 624f7979 | pbrook | static void setup_frame(int sig, struct target_sigaction *ka, |
2688 | c3b5bc8a | ths | target_sigset_t *set, CPUState *regs) |
2689 | c3b5bc8a | ths | { |
2690 | c3b5bc8a | ths | struct target_sigframe *frame;
|
2691 | c3b5bc8a | ths | abi_ulong frame_addr; |
2692 | c3b5bc8a | ths | int i;
|
2693 | c3b5bc8a | ths | int err = 0; |
2694 | c3b5bc8a | ths | int signal;
|
2695 | c3b5bc8a | ths | |
2696 | c3b5bc8a | ths | frame_addr = get_sigframe(ka, regs->gregs[15], sizeof(*frame)); |
2697 | c3b5bc8a | ths | if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) |
2698 | c3b5bc8a | ths | goto give_sigsegv;
|
2699 | c3b5bc8a | ths | |
2700 | c3b5bc8a | ths | signal = current_exec_domain_sig(sig); |
2701 | c3b5bc8a | ths | |
2702 | c3b5bc8a | ths | err |= setup_sigcontext(&frame->sc, regs, set->sig[0]);
|
2703 | c3b5bc8a | ths | |
2704 | c3b5bc8a | ths | for (i = 0; i < TARGET_NSIG_WORDS - 1; i++) { |
2705 | c3b5bc8a | ths | err |= __put_user(set->sig[i + 1], &frame->extramask[i]);
|
2706 | c3b5bc8a | ths | } |
2707 | c3b5bc8a | ths | |
2708 | c3b5bc8a | ths | /* Set up to return from userspace. If provided, use a stub
|
2709 | c3b5bc8a | ths | already in userspace. */
|
2710 | 624f7979 | pbrook | if (ka->sa_flags & TARGET_SA_RESTORER) {
|
2711 | 624f7979 | pbrook | regs->pr = (unsigned long) ka->sa_restorer; |
2712 | c3b5bc8a | ths | } else {
|
2713 | c3b5bc8a | ths | /* Generate return code (system call to sigreturn) */
|
2714 | c3b5bc8a | ths | err |= __put_user(MOVW(2), &frame->retcode[0]); |
2715 | c3b5bc8a | ths | err |= __put_user(TRAP_NOARG, &frame->retcode[1]);
|
2716 | c3b5bc8a | ths | err |= __put_user((TARGET_NR_sigreturn), &frame->retcode[2]);
|
2717 | c3b5bc8a | ths | regs->pr = (unsigned long) frame->retcode; |
2718 | c3b5bc8a | ths | } |
2719 | c3b5bc8a | ths | |
2720 | c3b5bc8a | ths | if (err)
|
2721 | c3b5bc8a | ths | goto give_sigsegv;
|
2722 | c3b5bc8a | ths | |
2723 | c3b5bc8a | ths | /* Set up registers for signal handler */
|
2724 | c3b5bc8a | ths | regs->gregs[15] = (unsigned long) frame; |
2725 | c3b5bc8a | ths | regs->gregs[4] = signal; /* Arg for signal handler */ |
2726 | c3b5bc8a | ths | regs->gregs[5] = 0; |
2727 | c3b5bc8a | ths | regs->gregs[6] = (unsigned long) &frame->sc; |
2728 | 624f7979 | pbrook | regs->pc = (unsigned long) ka->_sa_handler; |
2729 | c3b5bc8a | ths | |
2730 | c3b5bc8a | ths | unlock_user_struct(frame, frame_addr, 1);
|
2731 | c3b5bc8a | ths | return;
|
2732 | c3b5bc8a | ths | |
2733 | c3b5bc8a | ths | give_sigsegv:
|
2734 | c3b5bc8a | ths | unlock_user_struct(frame, frame_addr, 1);
|
2735 | c3b5bc8a | ths | force_sig(SIGSEGV); |
2736 | c3b5bc8a | ths | } |
2737 | c3b5bc8a | ths | |
2738 | 624f7979 | pbrook | static void setup_rt_frame(int sig, struct target_sigaction *ka, |
2739 | c3b5bc8a | ths | target_siginfo_t *info, |
2740 | c3b5bc8a | ths | target_sigset_t *set, CPUState *regs) |
2741 | c3b5bc8a | ths | { |
2742 | c3b5bc8a | ths | struct target_rt_sigframe *frame;
|
2743 | c3b5bc8a | ths | abi_ulong frame_addr; |
2744 | c3b5bc8a | ths | int i;
|
2745 | c3b5bc8a | ths | int err = 0; |
2746 | c3b5bc8a | ths | int signal;
|
2747 | c3b5bc8a | ths | |
2748 | c3b5bc8a | ths | frame_addr = get_sigframe(ka, regs->gregs[15], sizeof(*frame)); |
2749 | c3b5bc8a | ths | if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) |
2750 | c3b5bc8a | ths | goto give_sigsegv;
|
2751 | c3b5bc8a | ths | |
2752 | c3b5bc8a | ths | signal = current_exec_domain_sig(sig); |
2753 | c3b5bc8a | ths | |
2754 | c3b5bc8a | ths | err |= copy_siginfo_to_user(&frame->info, info); |
2755 | c3b5bc8a | ths | |
2756 | c3b5bc8a | ths | /* Create the ucontext. */
|
2757 | c3b5bc8a | ths | err |= __put_user(0, &frame->uc.uc_flags);
|
2758 | c3b5bc8a | ths | err |= __put_user(0, (unsigned long *)&frame->uc.uc_link); |
2759 | 526ccb7a | balrog | err |= __put_user((unsigned long)target_sigaltstack_used.ss_sp, |
2760 | c3b5bc8a | ths | &frame->uc.uc_stack.ss_sp); |
2761 | c3b5bc8a | ths | err |= __put_user(sas_ss_flags(regs->gregs[15]),
|
2762 | c3b5bc8a | ths | &frame->uc.uc_stack.ss_flags); |
2763 | c3b5bc8a | ths | err |= __put_user(target_sigaltstack_used.ss_size, |
2764 | c3b5bc8a | ths | &frame->uc.uc_stack.ss_size); |
2765 | c3b5bc8a | ths | err |= setup_sigcontext(&frame->uc.uc_mcontext, |
2766 | c3b5bc8a | ths | regs, set->sig[0]);
|
2767 | c3b5bc8a | ths | for(i = 0; i < TARGET_NSIG_WORDS; i++) { |
2768 | c3b5bc8a | ths | err |= __put_user(set->sig[i], &frame->uc.uc_sigmask.sig[i]); |
2769 | c3b5bc8a | ths | } |
2770 | c3b5bc8a | ths | |
2771 | c3b5bc8a | ths | /* Set up to return from userspace. If provided, use a stub
|
2772 | c3b5bc8a | ths | already in userspace. */
|
2773 | 624f7979 | pbrook | if (ka->sa_flags & TARGET_SA_RESTORER) {
|
2774 | 624f7979 | pbrook | regs->pr = (unsigned long) ka->sa_restorer; |
2775 | c3b5bc8a | ths | } else {
|
2776 | c3b5bc8a | ths | /* Generate return code (system call to sigreturn) */
|
2777 | c3b5bc8a | ths | err |= __put_user(MOVW(2), &frame->retcode[0]); |
2778 | c3b5bc8a | ths | err |= __put_user(TRAP_NOARG, &frame->retcode[1]);
|
2779 | c3b5bc8a | ths | err |= __put_user((TARGET_NR_rt_sigreturn), &frame->retcode[2]);
|
2780 | c3b5bc8a | ths | regs->pr = (unsigned long) frame->retcode; |
2781 | c3b5bc8a | ths | } |
2782 | c3b5bc8a | ths | |
2783 | c3b5bc8a | ths | if (err)
|
2784 | c3b5bc8a | ths | goto give_sigsegv;
|
2785 | c3b5bc8a | ths | |
2786 | c3b5bc8a | ths | /* Set up registers for signal handler */
|
2787 | c3b5bc8a | ths | regs->gregs[15] = (unsigned long) frame; |
2788 | c3b5bc8a | ths | regs->gregs[4] = signal; /* Arg for signal handler */ |
2789 | c3b5bc8a | ths | regs->gregs[5] = (unsigned long) &frame->info; |
2790 | c3b5bc8a | ths | regs->gregs[6] = (unsigned long) &frame->uc; |
2791 | 624f7979 | pbrook | regs->pc = (unsigned long) ka->_sa_handler; |
2792 | c3b5bc8a | ths | |
2793 | c3b5bc8a | ths | unlock_user_struct(frame, frame_addr, 1);
|
2794 | c3b5bc8a | ths | return;
|
2795 | c3b5bc8a | ths | |
2796 | c3b5bc8a | ths | give_sigsegv:
|
2797 | c3b5bc8a | ths | unlock_user_struct(frame, frame_addr, 1);
|
2798 | c3b5bc8a | ths | force_sig(SIGSEGV); |
2799 | c3b5bc8a | ths | } |
2800 | c3b5bc8a | ths | |
2801 | c3b5bc8a | ths | long do_sigreturn(CPUState *regs)
|
2802 | c3b5bc8a | ths | { |
2803 | c3b5bc8a | ths | struct target_sigframe *frame;
|
2804 | c3b5bc8a | ths | abi_ulong frame_addr; |
2805 | c3b5bc8a | ths | sigset_t blocked; |
2806 | c3b5bc8a | ths | target_sigset_t target_set; |
2807 | c3b5bc8a | ths | int i;
|
2808 | c3b5bc8a | ths | int err = 0; |
2809 | c3b5bc8a | ths | |
2810 | c3b5bc8a | ths | #if defined(DEBUG_SIGNAL)
|
2811 | c3b5bc8a | ths | fprintf(stderr, "do_sigreturn\n");
|
2812 | c3b5bc8a | ths | #endif
|
2813 | c3b5bc8a | ths | frame_addr = regs->gregs[15];
|
2814 | c3b5bc8a | ths | if (!lock_user_struct(VERIFY_READ, frame, frame_addr, 1)) |
2815 | c3b5bc8a | ths | goto badframe;
|
2816 | c3b5bc8a | ths | |
2817 | c3b5bc8a | ths | err |= __get_user(target_set.sig[0], &frame->sc.oldmask);
|
2818 | c3b5bc8a | ths | for(i = 1; i < TARGET_NSIG_WORDS; i++) { |
2819 | c3b5bc8a | ths | err |= (__get_user(target_set.sig[i], &frame->extramask[i - 1]));
|
2820 | c3b5bc8a | ths | } |
2821 | c3b5bc8a | ths | |
2822 | c3b5bc8a | ths | if (err)
|
2823 | c3b5bc8a | ths | goto badframe;
|
2824 | c3b5bc8a | ths | |
2825 | c3b5bc8a | ths | target_to_host_sigset_internal(&blocked, &target_set); |
2826 | c3b5bc8a | ths | sigprocmask(SIG_SETMASK, &blocked, NULL);
|
2827 | c3b5bc8a | ths | |
2828 | c3b5bc8a | ths | if (restore_sigcontext(regs, &frame->sc))
|
2829 | c3b5bc8a | ths | goto badframe;
|
2830 | c3b5bc8a | ths | |
2831 | c3b5bc8a | ths | unlock_user_struct(frame, frame_addr, 0);
|
2832 | c3b5bc8a | ths | return regs->gregs[0]; |
2833 | c3b5bc8a | ths | |
2834 | c3b5bc8a | ths | badframe:
|
2835 | c3b5bc8a | ths | unlock_user_struct(frame, frame_addr, 0);
|
2836 | c3b5bc8a | ths | force_sig(TARGET_SIGSEGV); |
2837 | c3b5bc8a | ths | return 0; |
2838 | c3b5bc8a | ths | } |
2839 | c3b5bc8a | ths | |
2840 | c3b5bc8a | ths | long do_rt_sigreturn(CPUState *regs)
|
2841 | c3b5bc8a | ths | { |
2842 | c3b5bc8a | ths | struct target_rt_sigframe *frame;
|
2843 | c3b5bc8a | ths | abi_ulong frame_addr; |
2844 | c3b5bc8a | ths | sigset_t blocked; |
2845 | c3b5bc8a | ths | |
2846 | c3b5bc8a | ths | #if defined(DEBUG_SIGNAL)
|
2847 | c3b5bc8a | ths | fprintf(stderr, "do_rt_sigreturn\n");
|
2848 | c3b5bc8a | ths | #endif
|
2849 | c3b5bc8a | ths | frame_addr = regs->gregs[15];
|
2850 | c3b5bc8a | ths | if (!lock_user_struct(VERIFY_READ, frame, frame_addr, 1)) |
2851 | c3b5bc8a | ths | goto badframe;
|
2852 | c3b5bc8a | ths | |
2853 | c3b5bc8a | ths | target_to_host_sigset(&blocked, &frame->uc.uc_sigmask); |
2854 | c3b5bc8a | ths | sigprocmask(SIG_SETMASK, &blocked, NULL);
|
2855 | c3b5bc8a | ths | |
2856 | c3b5bc8a | ths | if (restore_sigcontext(regs, &frame->uc.uc_mcontext))
|
2857 | c3b5bc8a | ths | goto badframe;
|
2858 | c3b5bc8a | ths | |
2859 | c3b5bc8a | ths | if (do_sigaltstack(frame_addr +
|
2860 | c3b5bc8a | ths | offsetof(struct target_rt_sigframe, uc.uc_stack),
|
2861 | c3b5bc8a | ths | 0, get_sp_from_cpustate(regs)) == -EFAULT)
|
2862 | c3b5bc8a | ths | goto badframe;
|
2863 | c3b5bc8a | ths | |
2864 | c3b5bc8a | ths | unlock_user_struct(frame, frame_addr, 0);
|
2865 | c3b5bc8a | ths | return regs->gregs[0]; |
2866 | c3b5bc8a | ths | |
2867 | c3b5bc8a | ths | badframe:
|
2868 | c3b5bc8a | ths | unlock_user_struct(frame, frame_addr, 0);
|
2869 | c3b5bc8a | ths | force_sig(TARGET_SIGSEGV); |
2870 | c3b5bc8a | ths | return 0; |
2871 | c3b5bc8a | ths | } |
2872 | b6d3abda | edgar_igl | #elif defined(TARGET_CRIS)
|
2873 | b6d3abda | edgar_igl | |
2874 | b6d3abda | edgar_igl | struct target_sigcontext {
|
2875 | b6d3abda | edgar_igl | struct target_pt_regs regs; /* needs to be first */ |
2876 | b6d3abda | edgar_igl | uint32_t oldmask; |
2877 | b6d3abda | edgar_igl | uint32_t usp; /* usp before stacking this gunk on it */
|
2878 | b6d3abda | edgar_igl | }; |
2879 | b6d3abda | edgar_igl | |
2880 | b6d3abda | edgar_igl | /* Signal frames. */
|
2881 | b6d3abda | edgar_igl | struct target_signal_frame {
|
2882 | b6d3abda | edgar_igl | struct target_sigcontext sc;
|
2883 | b6d3abda | edgar_igl | uint32_t extramask[TARGET_NSIG_WORDS - 1];
|
2884 | b6d3abda | edgar_igl | uint8_t retcode[8]; /* Trampoline code. */ |
2885 | b6d3abda | edgar_igl | }; |
2886 | b6d3abda | edgar_igl | |
2887 | b6d3abda | edgar_igl | struct rt_signal_frame {
|
2888 | b6d3abda | edgar_igl | struct siginfo *pinfo;
|
2889 | b6d3abda | edgar_igl | void *puc;
|
2890 | b6d3abda | edgar_igl | struct siginfo info;
|
2891 | b6d3abda | edgar_igl | struct ucontext uc;
|
2892 | b6d3abda | edgar_igl | uint8_t retcode[8]; /* Trampoline code. */ |
2893 | b6d3abda | edgar_igl | }; |
2894 | b6d3abda | edgar_igl | |
2895 | b6d3abda | edgar_igl | static void setup_sigcontext(struct target_sigcontext *sc, CPUState *env) |
2896 | b6d3abda | edgar_igl | { |
2897 | 9664d928 | edgar_igl | __put_user(env->regs[0], &sc->regs.r0);
|
2898 | 9664d928 | edgar_igl | __put_user(env->regs[1], &sc->regs.r1);
|
2899 | 9664d928 | edgar_igl | __put_user(env->regs[2], &sc->regs.r2);
|
2900 | 9664d928 | edgar_igl | __put_user(env->regs[3], &sc->regs.r3);
|
2901 | 9664d928 | edgar_igl | __put_user(env->regs[4], &sc->regs.r4);
|
2902 | 9664d928 | edgar_igl | __put_user(env->regs[5], &sc->regs.r5);
|
2903 | 9664d928 | edgar_igl | __put_user(env->regs[6], &sc->regs.r6);
|
2904 | 9664d928 | edgar_igl | __put_user(env->regs[7], &sc->regs.r7);
|
2905 | 9664d928 | edgar_igl | __put_user(env->regs[8], &sc->regs.r8);
|
2906 | 9664d928 | edgar_igl | __put_user(env->regs[9], &sc->regs.r9);
|
2907 | 9664d928 | edgar_igl | __put_user(env->regs[10], &sc->regs.r10);
|
2908 | 9664d928 | edgar_igl | __put_user(env->regs[11], &sc->regs.r11);
|
2909 | 9664d928 | edgar_igl | __put_user(env->regs[12], &sc->regs.r12);
|
2910 | 9664d928 | edgar_igl | __put_user(env->regs[13], &sc->regs.r13);
|
2911 | 9664d928 | edgar_igl | __put_user(env->regs[14], &sc->usp);
|
2912 | 9664d928 | edgar_igl | __put_user(env->regs[15], &sc->regs.acr);
|
2913 | 9664d928 | edgar_igl | __put_user(env->pregs[PR_MOF], &sc->regs.mof); |
2914 | 9664d928 | edgar_igl | __put_user(env->pregs[PR_SRP], &sc->regs.srp); |
2915 | 9664d928 | edgar_igl | __put_user(env->pc, &sc->regs.erp); |
2916 | b6d3abda | edgar_igl | } |
2917 | 9664d928 | edgar_igl | |
2918 | b6d3abda | edgar_igl | static void restore_sigcontext(struct target_sigcontext *sc, CPUState *env) |
2919 | b6d3abda | edgar_igl | { |
2920 | 9664d928 | edgar_igl | __get_user(env->regs[0], &sc->regs.r0);
|
2921 | 9664d928 | edgar_igl | __get_user(env->regs[1], &sc->regs.r1);
|
2922 | 9664d928 | edgar_igl | __get_user(env->regs[2], &sc->regs.r2);
|
2923 | 9664d928 | edgar_igl | __get_user(env->regs[3], &sc->regs.r3);
|
2924 | 9664d928 | edgar_igl | __get_user(env->regs[4], &sc->regs.r4);
|
2925 | 9664d928 | edgar_igl | __get_user(env->regs[5], &sc->regs.r5);
|
2926 | 9664d928 | edgar_igl | __get_user(env->regs[6], &sc->regs.r6);
|
2927 | 9664d928 | edgar_igl | __get_user(env->regs[7], &sc->regs.r7);
|
2928 | 9664d928 | edgar_igl | __get_user(env->regs[8], &sc->regs.r8);
|
2929 | 9664d928 | edgar_igl | __get_user(env->regs[9], &sc->regs.r9);
|
2930 | 9664d928 | edgar_igl | __get_user(env->regs[10], &sc->regs.r10);
|
2931 | 9664d928 | edgar_igl | __get_user(env->regs[11], &sc->regs.r11);
|
2932 | 9664d928 | edgar_igl | __get_user(env->regs[12], &sc->regs.r12);
|
2933 | 9664d928 | edgar_igl | __get_user(env->regs[13], &sc->regs.r13);
|
2934 | 9664d928 | edgar_igl | __get_user(env->regs[14], &sc->usp);
|
2935 | 9664d928 | edgar_igl | __get_user(env->regs[15], &sc->regs.acr);
|
2936 | 9664d928 | edgar_igl | __get_user(env->pregs[PR_MOF], &sc->regs.mof); |
2937 | 9664d928 | edgar_igl | __get_user(env->pregs[PR_SRP], &sc->regs.srp); |
2938 | 9664d928 | edgar_igl | __get_user(env->pc, &sc->regs.erp); |
2939 | 9664d928 | edgar_igl | } |
2940 | 9664d928 | edgar_igl | |
2941 | 9664d928 | edgar_igl | static abi_ulong get_sigframe(CPUState *env, int framesize) |
2942 | 9664d928 | edgar_igl | { |
2943 | 9664d928 | edgar_igl | abi_ulong sp; |
2944 | b6d3abda | edgar_igl | /* Align the stack downwards to 4. */
|
2945 | 9664d928 | edgar_igl | sp = (env->regs[R_SP] & ~3);
|
2946 | 9664d928 | edgar_igl | return sp - framesize;
|
2947 | b6d3abda | edgar_igl | } |
2948 | b6d3abda | edgar_igl | |
2949 | 624f7979 | pbrook | static void setup_frame(int sig, struct target_sigaction *ka, |
2950 | b6d3abda | edgar_igl | target_sigset_t *set, CPUState *env) |
2951 | b6d3abda | edgar_igl | { |
2952 | b6d3abda | edgar_igl | struct target_signal_frame *frame;
|
2953 | 9664d928 | edgar_igl | abi_ulong frame_addr; |
2954 | b6d3abda | edgar_igl | int err = 0; |
2955 | b6d3abda | edgar_igl | int i;
|
2956 | b6d3abda | edgar_igl | |
2957 | 9664d928 | edgar_igl | frame_addr = get_sigframe(env, sizeof *frame);
|
2958 | 9664d928 | edgar_igl | if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) |
2959 | b6d3abda | edgar_igl | goto badframe;
|
2960 | b6d3abda | edgar_igl | |
2961 | b6d3abda | edgar_igl | /*
|
2962 | b6d3abda | edgar_igl | * The CRIS signal return trampoline. A real linux/CRIS kernel doesn't
|
2963 | b6d3abda | edgar_igl | * use this trampoline anymore but it sets it up for GDB.
|
2964 | b6d3abda | edgar_igl | * In QEMU, using the trampoline simplifies things a bit so we use it.
|
2965 | b6d3abda | edgar_igl | *
|
2966 | b6d3abda | edgar_igl | * This is movu.w __NR_sigreturn, r9; break 13;
|
2967 | b6d3abda | edgar_igl | */
|
2968 | b6d3abda | edgar_igl | err |= __put_user(0x9c5f, frame->retcode+0); |
2969 | b6d3abda | edgar_igl | err |= __put_user(TARGET_NR_sigreturn, |
2970 | b6d3abda | edgar_igl | frame->retcode+2);
|
2971 | b6d3abda | edgar_igl | err |= __put_user(0xe93d, frame->retcode+4); |
2972 | b6d3abda | edgar_igl | |
2973 | b6d3abda | edgar_igl | /* Save the mask. */
|
2974 | b6d3abda | edgar_igl | err |= __put_user(set->sig[0], &frame->sc.oldmask);
|
2975 | b6d3abda | edgar_igl | if (err)
|
2976 | b6d3abda | edgar_igl | goto badframe;
|
2977 | b6d3abda | edgar_igl | |
2978 | b6d3abda | edgar_igl | for(i = 1; i < TARGET_NSIG_WORDS; i++) { |
2979 | b6d3abda | edgar_igl | if (__put_user(set->sig[i], &frame->extramask[i - 1])) |
2980 | b6d3abda | edgar_igl | goto badframe;
|
2981 | b6d3abda | edgar_igl | } |
2982 | b6d3abda | edgar_igl | |
2983 | b6d3abda | edgar_igl | setup_sigcontext(&frame->sc, env); |
2984 | b6d3abda | edgar_igl | |
2985 | b6d3abda | edgar_igl | /* Move the stack and setup the arguments for the handler. */
|
2986 | 526ccb7a | balrog | env->regs[R_SP] = (uint32_t) (unsigned long) frame; |
2987 | b6d3abda | edgar_igl | env->regs[10] = sig;
|
2988 | 624f7979 | pbrook | env->pc = (unsigned long) ka->_sa_handler; |
2989 | b6d3abda | edgar_igl | /* Link SRP so the guest returns through the trampoline. */
|
2990 | 526ccb7a | balrog | env->pregs[PR_SRP] = (uint32_t) (unsigned long) &frame->retcode[0]; |
2991 | b6d3abda | edgar_igl | |
2992 | 9664d928 | edgar_igl | unlock_user_struct(frame, frame_addr, 1);
|
2993 | b6d3abda | edgar_igl | return;
|
2994 | b6d3abda | edgar_igl | badframe:
|
2995 | 9664d928 | edgar_igl | unlock_user_struct(frame, frame_addr, 1);
|
2996 | b6d3abda | edgar_igl | force_sig(TARGET_SIGSEGV); |
2997 | b6d3abda | edgar_igl | } |
2998 | b6d3abda | edgar_igl | |
2999 | 624f7979 | pbrook | static void setup_rt_frame(int sig, struct target_sigaction *ka, |
3000 | b6d3abda | edgar_igl | target_siginfo_t *info, |
3001 | b6d3abda | edgar_igl | target_sigset_t *set, CPUState *env) |
3002 | b6d3abda | edgar_igl | { |
3003 | b6d3abda | edgar_igl | fprintf(stderr, "CRIS setup_rt_frame: not implemented\n");
|
3004 | b6d3abda | edgar_igl | } |
3005 | b6d3abda | edgar_igl | |
3006 | b6d3abda | edgar_igl | long do_sigreturn(CPUState *env)
|
3007 | b6d3abda | edgar_igl | { |
3008 | b6d3abda | edgar_igl | struct target_signal_frame *frame;
|
3009 | 9664d928 | edgar_igl | abi_ulong frame_addr; |
3010 | b6d3abda | edgar_igl | target_sigset_t target_set; |
3011 | b6d3abda | edgar_igl | sigset_t set; |
3012 | b6d3abda | edgar_igl | int i;
|
3013 | b6d3abda | edgar_igl | |
3014 | 9664d928 | edgar_igl | frame_addr = env->regs[R_SP]; |
3015 | b6d3abda | edgar_igl | /* Make sure the guest isn't playing games. */
|
3016 | 9664d928 | edgar_igl | if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 1)) |
3017 | b6d3abda | edgar_igl | goto badframe;
|
3018 | b6d3abda | edgar_igl | |
3019 | b6d3abda | edgar_igl | /* Restore blocked signals */
|
3020 | b6d3abda | edgar_igl | if (__get_user(target_set.sig[0], &frame->sc.oldmask)) |
3021 | b6d3abda | edgar_igl | goto badframe;
|
3022 | b6d3abda | edgar_igl | for(i = 1; i < TARGET_NSIG_WORDS; i++) { |
3023 | b6d3abda | edgar_igl | if (__get_user(target_set.sig[i], &frame->extramask[i - 1])) |
3024 | b6d3abda | edgar_igl | goto badframe;
|
3025 | b6d3abda | edgar_igl | } |
3026 | b6d3abda | edgar_igl | target_to_host_sigset_internal(&set, &target_set); |
3027 | b6d3abda | edgar_igl | sigprocmask(SIG_SETMASK, &set, NULL);
|
3028 | b6d3abda | edgar_igl | |
3029 | b6d3abda | edgar_igl | restore_sigcontext(&frame->sc, env); |
3030 | 9664d928 | edgar_igl | /* Compensate for the syscall return path advancing brk. */
|
3031 | 9664d928 | edgar_igl | env->pc -= 2;
|
3032 | b6d3abda | edgar_igl | |
3033 | 9664d928 | edgar_igl | unlock_user_struct(frame, frame_addr, 0);
|
3034 | b6d3abda | edgar_igl | return env->regs[10]; |
3035 | b6d3abda | edgar_igl | badframe:
|
3036 | 9664d928 | edgar_igl | unlock_user_struct(frame, frame_addr, 0);
|
3037 | b6d3abda | edgar_igl | force_sig(TARGET_SIGSEGV); |
3038 | b6d3abda | edgar_igl | } |
3039 | b6d3abda | edgar_igl | |
3040 | b6d3abda | edgar_igl | long do_rt_sigreturn(CPUState *env)
|
3041 | b6d3abda | edgar_igl | { |
3042 | b6d3abda | edgar_igl | fprintf(stderr, "CRIS do_rt_sigreturn: not implemented\n");
|
3043 | b6d3abda | edgar_igl | return -TARGET_ENOSYS;
|
3044 | b6d3abda | edgar_igl | } |
3045 | c3b5bc8a | ths | |
3046 | b346ff46 | bellard | #else
|
3047 | b346ff46 | bellard | |
3048 | 624f7979 | pbrook | static void setup_frame(int sig, struct target_sigaction *ka, |
3049 | b346ff46 | bellard | target_sigset_t *set, CPUState *env) |
3050 | b346ff46 | bellard | { |
3051 | b346ff46 | bellard | fprintf(stderr, "setup_frame: not implemented\n");
|
3052 | b346ff46 | bellard | } |
3053 | b346ff46 | bellard | |
3054 | 624f7979 | pbrook | static void setup_rt_frame(int sig, struct target_sigaction *ka, |
3055 | b346ff46 | bellard | target_siginfo_t *info, |
3056 | b346ff46 | bellard | target_sigset_t *set, CPUState *env) |
3057 | b346ff46 | bellard | { |
3058 | b346ff46 | bellard | fprintf(stderr, "setup_rt_frame: not implemented\n");
|
3059 | b346ff46 | bellard | } |
3060 | b346ff46 | bellard | |
3061 | b346ff46 | bellard | long do_sigreturn(CPUState *env)
|
3062 | b346ff46 | bellard | { |
3063 | b346ff46 | bellard | fprintf(stderr, "do_sigreturn: not implemented\n");
|
3064 | f8b0aa25 | bellard | return -TARGET_ENOSYS;
|
3065 | b346ff46 | bellard | } |
3066 | b346ff46 | bellard | |
3067 | b346ff46 | bellard | long do_rt_sigreturn(CPUState *env)
|
3068 | b346ff46 | bellard | { |
3069 | b346ff46 | bellard | fprintf(stderr, "do_rt_sigreturn: not implemented\n");
|
3070 | f8b0aa25 | bellard | return -TARGET_ENOSYS;
|
3071 | b346ff46 | bellard | } |
3072 | b346ff46 | bellard | |
3073 | 66fb9763 | bellard | #endif
|
3074 | 66fb9763 | bellard | |
3075 | 624f7979 | pbrook | void process_pending_signals(CPUState *cpu_env)
|
3076 | 66fb9763 | bellard | { |
3077 | 66fb9763 | bellard | int sig;
|
3078 | 992f48a0 | blueswir1 | abi_ulong handler; |
3079 | 9de5e440 | bellard | sigset_t set, old_set; |
3080 | 9de5e440 | bellard | target_sigset_t target_old_set; |
3081 | 624f7979 | pbrook | struct emulated_sigtable *k;
|
3082 | 624f7979 | pbrook | struct target_sigaction *sa;
|
3083 | 66fb9763 | bellard | struct sigqueue *q;
|
3084 | 624f7979 | pbrook | TaskState *ts = cpu_env->opaque; |
3085 | 3b46e624 | ths | |
3086 | 624f7979 | pbrook | if (!ts->signal_pending)
|
3087 | 31e31b8a | bellard | return;
|
3088 | 31e31b8a | bellard | |
3089 | 624f7979 | pbrook | /* FIXME: This is not threadsafe. */
|
3090 | 624f7979 | pbrook | k = ts->sigtab; |
3091 | 66fb9763 | bellard | for(sig = 1; sig <= TARGET_NSIG; sig++) { |
3092 | 66fb9763 | bellard | if (k->pending)
|
3093 | 31e31b8a | bellard | goto handle_signal;
|
3094 | 66fb9763 | bellard | k++; |
3095 | 31e31b8a | bellard | } |
3096 | 31e31b8a | bellard | /* if no signal is pending, just return */
|
3097 | 624f7979 | pbrook | ts->signal_pending = 0;
|
3098 | 31e31b8a | bellard | return;
|
3099 | 66fb9763 | bellard | |
3100 | 31e31b8a | bellard | handle_signal:
|
3101 | 66fb9763 | bellard | #ifdef DEBUG_SIGNAL
|
3102 | bc8a22cc | bellard | fprintf(stderr, "qemu: process signal %d\n", sig);
|
3103 | 66fb9763 | bellard | #endif
|
3104 | 66fb9763 | bellard | /* dequeue signal */
|
3105 | 66fb9763 | bellard | q = k->first; |
3106 | 66fb9763 | bellard | k->first = q->next; |
3107 | 66fb9763 | bellard | if (!k->first)
|
3108 | 66fb9763 | bellard | k->pending = 0;
|
3109 | 3b46e624 | ths | |
3110 | 1fddef4b | bellard | sig = gdb_handlesig (cpu_env, sig); |
3111 | 1fddef4b | bellard | if (!sig) {
|
3112 | 1fddef4b | bellard | fprintf (stderr, "Lost signal\n");
|
3113 | 1fddef4b | bellard | abort(); |
3114 | 1fddef4b | bellard | } |
3115 | 66fb9763 | bellard | |
3116 | 624f7979 | pbrook | sa = &sigact_table[sig - 1];
|
3117 | 624f7979 | pbrook | handler = sa->_sa_handler; |
3118 | 66fb9763 | bellard | if (handler == TARGET_SIG_DFL) {
|
3119 | 66fb9763 | bellard | /* default handler : ignore some signal. The other are fatal */
|
3120 | 5fafdf24 | ths | if (sig != TARGET_SIGCHLD &&
|
3121 | 5fafdf24 | ths | sig != TARGET_SIGURG && |
3122 | 66fb9763 | bellard | sig != TARGET_SIGWINCH) { |
3123 | 66fb9763 | bellard | force_sig(sig); |
3124 | 66fb9763 | bellard | } |
3125 | 66fb9763 | bellard | } else if (handler == TARGET_SIG_IGN) { |
3126 | 66fb9763 | bellard | /* ignore sig */
|
3127 | 66fb9763 | bellard | } else if (handler == TARGET_SIG_ERR) { |
3128 | 66fb9763 | bellard | force_sig(sig); |
3129 | 66fb9763 | bellard | } else {
|
3130 | 9de5e440 | bellard | /* compute the blocked signals during the handler execution */
|
3131 | 624f7979 | pbrook | target_to_host_sigset(&set, &sa->sa_mask); |
3132 | 9de5e440 | bellard | /* SA_NODEFER indicates that the current signal should not be
|
3133 | 9de5e440 | bellard | blocked during the handler */
|
3134 | 624f7979 | pbrook | if (!(sa->sa_flags & TARGET_SA_NODEFER))
|
3135 | 9de5e440 | bellard | sigaddset(&set, target_to_host_signal(sig)); |
3136 | 3b46e624 | ths | |
3137 | 9de5e440 | bellard | /* block signals in the handler using Linux */
|
3138 | 9de5e440 | bellard | sigprocmask(SIG_BLOCK, &set, &old_set); |
3139 | 9de5e440 | bellard | /* save the previous blocked signal state to restore it at the
|
3140 | 9de5e440 | bellard | end of the signal execution (see do_sigreturn) */
|
3141 | 9231944d | bellard | host_to_target_sigset_internal(&target_old_set, &old_set); |
3142 | 9de5e440 | bellard | |
3143 | bc8a22cc | bellard | /* if the CPU is in VM86 mode, we restore the 32 bit values */
|
3144 | 84409ddb | j_mayer | #if defined(TARGET_I386) && !defined(TARGET_X86_64)
|
3145 | bc8a22cc | bellard | { |
3146 | bc8a22cc | bellard | CPUX86State *env = cpu_env; |
3147 | bc8a22cc | bellard | if (env->eflags & VM_MASK)
|
3148 | bc8a22cc | bellard | save_v86_state(env); |
3149 | bc8a22cc | bellard | } |
3150 | bc8a22cc | bellard | #endif
|
3151 | 9de5e440 | bellard | /* prepare the stack frame of the virtual CPU */
|
3152 | 624f7979 | pbrook | if (sa->sa_flags & TARGET_SA_SIGINFO)
|
3153 | 624f7979 | pbrook | setup_rt_frame(sig, sa, &q->info, &target_old_set, cpu_env); |
3154 | 66fb9763 | bellard | else
|
3155 | 624f7979 | pbrook | setup_frame(sig, sa, &target_old_set, cpu_env); |
3156 | 624f7979 | pbrook | if (sa->sa_flags & TARGET_SA_RESETHAND)
|
3157 | 624f7979 | pbrook | sa->_sa_handler = TARGET_SIG_DFL; |
3158 | 31e31b8a | bellard | } |
3159 | 66fb9763 | bellard | if (q != &k->info)
|
3160 | 624f7979 | pbrook | free_sigqueue(cpu_env, q); |
3161 | 66fb9763 | bellard | } |