root / linux-user / signal.c @ 4dbc422b
History | View | Annotate | Download (73 kB)
1 |
/*
|
---|---|
2 |
* Emulation of Linux signals
|
3 |
*
|
4 |
* Copyright (c) 2003 Fabrice Bellard
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or modify
|
7 |
* it under the terms of the GNU General Public License as published by
|
8 |
* the Free Software Foundation; either version 2 of the License, or
|
9 |
* (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
19 |
*/
|
20 |
#include <stdlib.h> |
21 |
#include <stdio.h> |
22 |
#include <string.h> |
23 |
#include <stdarg.h> |
24 |
#include <unistd.h> |
25 |
#include <signal.h> |
26 |
#include <errno.h> |
27 |
#include <sys/ucontext.h> |
28 |
|
29 |
#include "qemu.h" |
30 |
#include "target_signal.h" |
31 |
|
32 |
//#define DEBUG_SIGNAL
|
33 |
|
34 |
#define MAX_SIGQUEUE_SIZE 1024 |
35 |
|
36 |
struct sigqueue {
|
37 |
struct sigqueue *next;
|
38 |
target_siginfo_t info; |
39 |
}; |
40 |
|
41 |
struct emulated_sigaction {
|
42 |
struct target_sigaction sa;
|
43 |
int pending; /* true if signal is pending */ |
44 |
struct sigqueue *first;
|
45 |
struct sigqueue info; /* in order to always have memory for the |
46 |
first signal, we put it here */
|
47 |
}; |
48 |
|
49 |
struct target_sigaltstack target_sigaltstack_used = {
|
50 |
.ss_sp = 0,
|
51 |
.ss_size = 0,
|
52 |
.ss_flags = TARGET_SS_DISABLE, |
53 |
}; |
54 |
|
55 |
static struct emulated_sigaction sigact_table[TARGET_NSIG]; |
56 |
static struct sigqueue sigqueue_table[MAX_SIGQUEUE_SIZE]; /* siginfo queue */ |
57 |
static struct sigqueue *first_free; /* first free siginfo queue entry */ |
58 |
static int signal_pending; /* non zero if a signal may be pending */ |
59 |
|
60 |
static void host_signal_handler(int host_signum, siginfo_t *info, |
61 |
void *puc);
|
62 |
|
63 |
static uint8_t host_to_target_signal_table[65] = { |
64 |
[SIGHUP] = TARGET_SIGHUP, |
65 |
[SIGINT] = TARGET_SIGINT, |
66 |
[SIGQUIT] = TARGET_SIGQUIT, |
67 |
[SIGILL] = TARGET_SIGILL, |
68 |
[SIGTRAP] = TARGET_SIGTRAP, |
69 |
[SIGABRT] = TARGET_SIGABRT, |
70 |
/* [SIGIOT] = TARGET_SIGIOT,*/
|
71 |
[SIGBUS] = TARGET_SIGBUS, |
72 |
[SIGFPE] = TARGET_SIGFPE, |
73 |
[SIGKILL] = TARGET_SIGKILL, |
74 |
[SIGUSR1] = TARGET_SIGUSR1, |
75 |
[SIGSEGV] = TARGET_SIGSEGV, |
76 |
[SIGUSR2] = TARGET_SIGUSR2, |
77 |
[SIGPIPE] = TARGET_SIGPIPE, |
78 |
[SIGALRM] = TARGET_SIGALRM, |
79 |
[SIGTERM] = TARGET_SIGTERM, |
80 |
#ifdef SIGSTKFLT
|
81 |
[SIGSTKFLT] = TARGET_SIGSTKFLT, |
82 |
#endif
|
83 |
[SIGCHLD] = TARGET_SIGCHLD, |
84 |
[SIGCONT] = TARGET_SIGCONT, |
85 |
[SIGSTOP] = TARGET_SIGSTOP, |
86 |
[SIGTSTP] = TARGET_SIGTSTP, |
87 |
[SIGTTIN] = TARGET_SIGTTIN, |
88 |
[SIGTTOU] = TARGET_SIGTTOU, |
89 |
[SIGURG] = TARGET_SIGURG, |
90 |
[SIGXCPU] = TARGET_SIGXCPU, |
91 |
[SIGXFSZ] = TARGET_SIGXFSZ, |
92 |
[SIGVTALRM] = TARGET_SIGVTALRM, |
93 |
[SIGPROF] = TARGET_SIGPROF, |
94 |
[SIGWINCH] = TARGET_SIGWINCH, |
95 |
[SIGIO] = TARGET_SIGIO, |
96 |
[SIGPWR] = TARGET_SIGPWR, |
97 |
[SIGSYS] = TARGET_SIGSYS, |
98 |
/* next signals stay the same */
|
99 |
}; |
100 |
static uint8_t target_to_host_signal_table[65]; |
101 |
|
102 |
static inline int on_sig_stack(unsigned long sp) |
103 |
{ |
104 |
return (sp - target_sigaltstack_used.ss_sp
|
105 |
< target_sigaltstack_used.ss_size); |
106 |
} |
107 |
|
108 |
static inline int sas_ss_flags(unsigned long sp) |
109 |
{ |
110 |
return (target_sigaltstack_used.ss_size == 0 ? SS_DISABLE |
111 |
: on_sig_stack(sp) ? SS_ONSTACK : 0);
|
112 |
} |
113 |
|
114 |
static inline int host_to_target_signal(int sig) |
115 |
{ |
116 |
return host_to_target_signal_table[sig];
|
117 |
} |
118 |
|
119 |
static inline int target_to_host_signal(int sig) |
120 |
{ |
121 |
return target_to_host_signal_table[sig];
|
122 |
} |
123 |
|
124 |
static void host_to_target_sigset_internal(target_sigset_t *d, |
125 |
const sigset_t *s)
|
126 |
{ |
127 |
int i;
|
128 |
unsigned long sigmask; |
129 |
uint32_t target_sigmask; |
130 |
|
131 |
sigmask = ((unsigned long *)s)[0]; |
132 |
target_sigmask = 0;
|
133 |
for(i = 0; i < 32; i++) { |
134 |
if (sigmask & (1 << i)) |
135 |
target_sigmask |= 1 << (host_to_target_signal(i + 1) - 1); |
136 |
} |
137 |
#if TARGET_ABI_BITS == 32 && HOST_LONG_BITS == 32 |
138 |
d->sig[0] = target_sigmask;
|
139 |
for(i = 1;i < TARGET_NSIG_WORDS; i++) { |
140 |
d->sig[i] = ((unsigned long *)s)[i]; |
141 |
} |
142 |
#elif TARGET_ABI_BITS == 32 && HOST_LONG_BITS == 64 && TARGET_NSIG_WORDS == 2 |
143 |
d->sig[0] = target_sigmask;
|
144 |
d->sig[1] = sigmask >> 32; |
145 |
#else
|
146 |
/* XXX: do it */
|
147 |
#endif
|
148 |
} |
149 |
|
150 |
void host_to_target_sigset(target_sigset_t *d, const sigset_t *s) |
151 |
{ |
152 |
target_sigset_t d1; |
153 |
int i;
|
154 |
|
155 |
host_to_target_sigset_internal(&d1, s); |
156 |
for(i = 0;i < TARGET_NSIG_WORDS; i++) |
157 |
d->sig[i] = tswapl(d1.sig[i]); |
158 |
} |
159 |
|
160 |
void target_to_host_sigset_internal(sigset_t *d, const target_sigset_t *s) |
161 |
{ |
162 |
int i;
|
163 |
unsigned long sigmask; |
164 |
abi_ulong target_sigmask; |
165 |
|
166 |
target_sigmask = s->sig[0];
|
167 |
sigmask = 0;
|
168 |
for(i = 0; i < 32; i++) { |
169 |
if (target_sigmask & (1 << i)) |
170 |
sigmask |= 1 << (target_to_host_signal(i + 1) - 1); |
171 |
} |
172 |
#if TARGET_ABI_BITS == 32 && HOST_LONG_BITS == 32 |
173 |
((unsigned long *)d)[0] = sigmask; |
174 |
for(i = 1;i < TARGET_NSIG_WORDS; i++) { |
175 |
((unsigned long *)d)[i] = s->sig[i]; |
176 |
} |
177 |
#elif TARGET_ABI_BITS == 32 && HOST_LONG_BITS == 64 && TARGET_NSIG_WORDS == 2 |
178 |
((unsigned long *)d)[0] = sigmask | ((unsigned long)(s->sig[1]) << 32); |
179 |
#else
|
180 |
/* XXX: do it */
|
181 |
#endif /* TARGET_ABI_BITS */ |
182 |
} |
183 |
|
184 |
void target_to_host_sigset(sigset_t *d, const target_sigset_t *s) |
185 |
{ |
186 |
target_sigset_t s1; |
187 |
int i;
|
188 |
|
189 |
for(i = 0;i < TARGET_NSIG_WORDS; i++) |
190 |
s1.sig[i] = tswapl(s->sig[i]); |
191 |
target_to_host_sigset_internal(d, &s1); |
192 |
} |
193 |
|
194 |
void host_to_target_old_sigset(abi_ulong *old_sigset,
|
195 |
const sigset_t *sigset)
|
196 |
{ |
197 |
target_sigset_t d; |
198 |
host_to_target_sigset(&d, sigset); |
199 |
*old_sigset = d.sig[0];
|
200 |
} |
201 |
|
202 |
void target_to_host_old_sigset(sigset_t *sigset,
|
203 |
const abi_ulong *old_sigset)
|
204 |
{ |
205 |
target_sigset_t d; |
206 |
int i;
|
207 |
|
208 |
d.sig[0] = *old_sigset;
|
209 |
for(i = 1;i < TARGET_NSIG_WORDS; i++) |
210 |
d.sig[i] = 0;
|
211 |
target_to_host_sigset(sigset, &d); |
212 |
} |
213 |
|
214 |
/* siginfo conversion */
|
215 |
|
216 |
static inline void host_to_target_siginfo_noswap(target_siginfo_t *tinfo, |
217 |
const siginfo_t *info)
|
218 |
{ |
219 |
int sig;
|
220 |
sig = host_to_target_signal(info->si_signo); |
221 |
tinfo->si_signo = sig; |
222 |
tinfo->si_errno = 0;
|
223 |
tinfo->si_code = 0;
|
224 |
if (sig == SIGILL || sig == SIGFPE || sig == SIGSEGV ||
|
225 |
sig == SIGBUS || sig == SIGTRAP) { |
226 |
/* should never come here, but who knows. The information for
|
227 |
the target is irrelevant */
|
228 |
tinfo->_sifields._sigfault._addr = 0;
|
229 |
} else if (sig == SIGIO) { |
230 |
tinfo->_sifields._sigpoll._fd = info->si_fd; |
231 |
} else if (sig >= TARGET_SIGRTMIN) { |
232 |
tinfo->_sifields._rt._pid = info->si_pid; |
233 |
tinfo->_sifields._rt._uid = info->si_uid; |
234 |
/* XXX: potential problem if 64 bit */
|
235 |
tinfo->_sifields._rt._sigval.sival_ptr = |
236 |
(abi_ulong)(unsigned long)info->si_value.sival_ptr; |
237 |
} |
238 |
} |
239 |
|
240 |
static void tswap_siginfo(target_siginfo_t *tinfo, |
241 |
const target_siginfo_t *info)
|
242 |
{ |
243 |
int sig;
|
244 |
sig = info->si_signo; |
245 |
tinfo->si_signo = tswap32(sig); |
246 |
tinfo->si_errno = tswap32(info->si_errno); |
247 |
tinfo->si_code = tswap32(info->si_code); |
248 |
if (sig == SIGILL || sig == SIGFPE || sig == SIGSEGV ||
|
249 |
sig == SIGBUS || sig == SIGTRAP) { |
250 |
tinfo->_sifields._sigfault._addr = |
251 |
tswapl(info->_sifields._sigfault._addr); |
252 |
} else if (sig == SIGIO) { |
253 |
tinfo->_sifields._sigpoll._fd = tswap32(info->_sifields._sigpoll._fd); |
254 |
} else if (sig >= TARGET_SIGRTMIN) { |
255 |
tinfo->_sifields._rt._pid = tswap32(info->_sifields._rt._pid); |
256 |
tinfo->_sifields._rt._uid = tswap32(info->_sifields._rt._uid); |
257 |
tinfo->_sifields._rt._sigval.sival_ptr = |
258 |
tswapl(info->_sifields._rt._sigval.sival_ptr); |
259 |
} |
260 |
} |
261 |
|
262 |
|
263 |
void host_to_target_siginfo(target_siginfo_t *tinfo, const siginfo_t *info) |
264 |
{ |
265 |
host_to_target_siginfo_noswap(tinfo, info); |
266 |
tswap_siginfo(tinfo, tinfo); |
267 |
} |
268 |
|
269 |
/* XXX: we support only POSIX RT signals are used. */
|
270 |
/* XXX: find a solution for 64 bit (additional malloced data is needed) */
|
271 |
void target_to_host_siginfo(siginfo_t *info, const target_siginfo_t *tinfo) |
272 |
{ |
273 |
info->si_signo = tswap32(tinfo->si_signo); |
274 |
info->si_errno = tswap32(tinfo->si_errno); |
275 |
info->si_code = tswap32(tinfo->si_code); |
276 |
info->si_pid = tswap32(tinfo->_sifields._rt._pid); |
277 |
info->si_uid = tswap32(tinfo->_sifields._rt._uid); |
278 |
info->si_value.sival_ptr = |
279 |
(void *)(long)tswapl(tinfo->_sifields._rt._sigval.sival_ptr); |
280 |
} |
281 |
|
282 |
void signal_init(void) |
283 |
{ |
284 |
struct sigaction act;
|
285 |
int i, j;
|
286 |
|
287 |
/* generate signal conversion tables */
|
288 |
for(i = 1; i <= 64; i++) { |
289 |
if (host_to_target_signal_table[i] == 0) |
290 |
host_to_target_signal_table[i] = i; |
291 |
} |
292 |
for(i = 1; i <= 64; i++) { |
293 |
j = host_to_target_signal_table[i]; |
294 |
target_to_host_signal_table[j] = i; |
295 |
} |
296 |
|
297 |
/* set all host signal handlers. ALL signals are blocked during
|
298 |
the handlers to serialize them. */
|
299 |
sigfillset(&act.sa_mask); |
300 |
act.sa_flags = SA_SIGINFO; |
301 |
act.sa_sigaction = host_signal_handler; |
302 |
for(i = 1; i < NSIG; i++) { |
303 |
sigaction(i, &act, NULL);
|
304 |
} |
305 |
|
306 |
memset(sigact_table, 0, sizeof(sigact_table)); |
307 |
|
308 |
first_free = &sigqueue_table[0];
|
309 |
for(i = 0; i < MAX_SIGQUEUE_SIZE - 1; i++) |
310 |
sigqueue_table[i].next = &sigqueue_table[i + 1];
|
311 |
sigqueue_table[MAX_SIGQUEUE_SIZE - 1].next = NULL; |
312 |
} |
313 |
|
314 |
/* signal queue handling */
|
315 |
|
316 |
static inline struct sigqueue *alloc_sigqueue(void) |
317 |
{ |
318 |
struct sigqueue *q = first_free;
|
319 |
if (!q)
|
320 |
return NULL; |
321 |
first_free = q->next; |
322 |
return q;
|
323 |
} |
324 |
|
325 |
static inline void free_sigqueue(struct sigqueue *q) |
326 |
{ |
327 |
q->next = first_free; |
328 |
first_free = q; |
329 |
} |
330 |
|
331 |
/* abort execution with signal */
|
332 |
void __attribute((noreturn)) force_sig(int sig) |
333 |
{ |
334 |
int host_sig;
|
335 |
host_sig = target_to_host_signal(sig); |
336 |
fprintf(stderr, "qemu: uncaught target signal %d (%s) - exiting\n",
|
337 |
sig, strsignal(host_sig)); |
338 |
#if 1 |
339 |
_exit(-host_sig); |
340 |
#else
|
341 |
{ |
342 |
struct sigaction act;
|
343 |
sigemptyset(&act.sa_mask); |
344 |
act.sa_flags = SA_SIGINFO; |
345 |
act.sa_sigaction = SIG_DFL; |
346 |
sigaction(SIGABRT, &act, NULL);
|
347 |
abort(); |
348 |
} |
349 |
#endif
|
350 |
} |
351 |
|
352 |
/* queue a signal so that it will be send to the virtual CPU as soon
|
353 |
as possible */
|
354 |
int queue_signal(int sig, target_siginfo_t *info) |
355 |
{ |
356 |
struct emulated_sigaction *k;
|
357 |
struct sigqueue *q, **pq;
|
358 |
abi_ulong handler; |
359 |
|
360 |
#if defined(DEBUG_SIGNAL)
|
361 |
fprintf(stderr, "queue_signal: sig=%d\n",
|
362 |
sig); |
363 |
#endif
|
364 |
k = &sigact_table[sig - 1];
|
365 |
handler = k->sa._sa_handler; |
366 |
if (handler == TARGET_SIG_DFL) {
|
367 |
/* default handler : ignore some signal. The other are fatal */
|
368 |
if (sig != TARGET_SIGCHLD &&
|
369 |
sig != TARGET_SIGURG && |
370 |
sig != TARGET_SIGWINCH) { |
371 |
force_sig(sig); |
372 |
} else {
|
373 |
return 0; /* indicate ignored */ |
374 |
} |
375 |
} else if (handler == TARGET_SIG_IGN) { |
376 |
/* ignore signal */
|
377 |
return 0; |
378 |
} else if (handler == TARGET_SIG_ERR) { |
379 |
force_sig(sig); |
380 |
} else {
|
381 |
pq = &k->first; |
382 |
if (sig < TARGET_SIGRTMIN) {
|
383 |
/* if non real time signal, we queue exactly one signal */
|
384 |
if (!k->pending)
|
385 |
q = &k->info; |
386 |
else
|
387 |
return 0; |
388 |
} else {
|
389 |
if (!k->pending) {
|
390 |
/* first signal */
|
391 |
q = &k->info; |
392 |
} else {
|
393 |
q = alloc_sigqueue(); |
394 |
if (!q)
|
395 |
return -EAGAIN;
|
396 |
while (*pq != NULL) |
397 |
pq = &(*pq)->next; |
398 |
} |
399 |
} |
400 |
*pq = q; |
401 |
q->info = *info; |
402 |
q->next = NULL;
|
403 |
k->pending = 1;
|
404 |
/* signal that a new signal is pending */
|
405 |
signal_pending = 1;
|
406 |
return 1; /* indicates that the signal was queued */ |
407 |
} |
408 |
} |
409 |
|
410 |
static void host_signal_handler(int host_signum, siginfo_t *info, |
411 |
void *puc)
|
412 |
{ |
413 |
int sig;
|
414 |
target_siginfo_t tinfo; |
415 |
|
416 |
/* the CPU emulator uses some host signals to detect exceptions,
|
417 |
we we forward to it some signals */
|
418 |
if (host_signum == SIGSEGV || host_signum == SIGBUS) {
|
419 |
if (cpu_signal_handler(host_signum, info, puc))
|
420 |
return;
|
421 |
} |
422 |
|
423 |
/* get target signal number */
|
424 |
sig = host_to_target_signal(host_signum); |
425 |
if (sig < 1 || sig > TARGET_NSIG) |
426 |
return;
|
427 |
#if defined(DEBUG_SIGNAL)
|
428 |
fprintf(stderr, "qemu: got signal %d\n", sig);
|
429 |
#endif
|
430 |
host_to_target_siginfo_noswap(&tinfo, info); |
431 |
if (queue_signal(sig, &tinfo) == 1) { |
432 |
/* interrupt the virtual CPU as soon as possible */
|
433 |
cpu_interrupt(global_env, CPU_INTERRUPT_EXIT); |
434 |
} |
435 |
} |
436 |
|
437 |
/* do_sigaltstack() returns target values and errnos. */
|
438 |
/* compare linux/kernel/signal.c:do_sigaltstack() */
|
439 |
abi_long do_sigaltstack(abi_ulong uss_addr, abi_ulong uoss_addr, abi_ulong sp) |
440 |
{ |
441 |
int ret;
|
442 |
struct target_sigaltstack oss;
|
443 |
|
444 |
/* XXX: test errors */
|
445 |
if(uoss_addr)
|
446 |
{ |
447 |
__put_user(target_sigaltstack_used.ss_sp, &oss.ss_sp); |
448 |
__put_user(target_sigaltstack_used.ss_size, &oss.ss_size); |
449 |
__put_user(sas_ss_flags(sp), &oss.ss_flags); |
450 |
} |
451 |
|
452 |
if(uss_addr)
|
453 |
{ |
454 |
struct target_sigaltstack *uss;
|
455 |
struct target_sigaltstack ss;
|
456 |
|
457 |
ret = -TARGET_EFAULT; |
458 |
if (!lock_user_struct(VERIFY_READ, uss, uss_addr, 1) |
459 |
|| __get_user(ss.ss_sp, &uss->ss_sp) |
460 |
|| __get_user(ss.ss_size, &uss->ss_size) |
461 |
|| __get_user(ss.ss_flags, &uss->ss_flags)) |
462 |
goto out;
|
463 |
unlock_user_struct(uss, uss_addr, 0);
|
464 |
|
465 |
ret = -TARGET_EPERM; |
466 |
if (on_sig_stack(sp))
|
467 |
goto out;
|
468 |
|
469 |
ret = -TARGET_EINVAL; |
470 |
if (ss.ss_flags != TARGET_SS_DISABLE
|
471 |
&& ss.ss_flags != TARGET_SS_ONSTACK |
472 |
&& ss.ss_flags != 0)
|
473 |
goto out;
|
474 |
|
475 |
if (ss.ss_flags == TARGET_SS_DISABLE) {
|
476 |
ss.ss_size = 0;
|
477 |
ss.ss_sp = 0;
|
478 |
} else {
|
479 |
ret = -TARGET_ENOMEM; |
480 |
if (ss.ss_size < MINSIGSTKSZ)
|
481 |
goto out;
|
482 |
} |
483 |
|
484 |
target_sigaltstack_used.ss_sp = ss.ss_sp; |
485 |
target_sigaltstack_used.ss_size = ss.ss_size; |
486 |
} |
487 |
|
488 |
if (uoss_addr) {
|
489 |
ret = -TARGET_EFAULT; |
490 |
if (copy_to_user(uoss_addr, &oss, sizeof(oss))) |
491 |
goto out;
|
492 |
} |
493 |
|
494 |
ret = 0;
|
495 |
out:
|
496 |
return ret;
|
497 |
} |
498 |
|
499 |
/* do_sigaction() return host values and errnos */
|
500 |
int do_sigaction(int sig, const struct target_sigaction *act, |
501 |
struct target_sigaction *oact)
|
502 |
{ |
503 |
struct emulated_sigaction *k;
|
504 |
struct sigaction act1;
|
505 |
int host_sig;
|
506 |
int ret = 0; |
507 |
|
508 |
if (sig < 1 || sig > TARGET_NSIG || sig == SIGKILL || sig == SIGSTOP) |
509 |
return -EINVAL;
|
510 |
k = &sigact_table[sig - 1];
|
511 |
#if defined(DEBUG_SIGNAL)
|
512 |
fprintf(stderr, "sigaction sig=%d act=0x%08x, oact=0x%08x\n",
|
513 |
sig, (int)act, (int)oact); |
514 |
#endif
|
515 |
if (oact) {
|
516 |
oact->_sa_handler = tswapl(k->sa._sa_handler); |
517 |
oact->sa_flags = tswapl(k->sa.sa_flags); |
518 |
#if !defined(TARGET_MIPS)
|
519 |
oact->sa_restorer = tswapl(k->sa.sa_restorer); |
520 |
#endif
|
521 |
oact->sa_mask = k->sa.sa_mask; |
522 |
} |
523 |
if (act) {
|
524 |
k->sa._sa_handler = tswapl(act->_sa_handler); |
525 |
k->sa.sa_flags = tswapl(act->sa_flags); |
526 |
#if !defined(TARGET_MIPS)
|
527 |
k->sa.sa_restorer = tswapl(act->sa_restorer); |
528 |
#endif
|
529 |
k->sa.sa_mask = act->sa_mask; |
530 |
|
531 |
/* we update the host linux signal state */
|
532 |
host_sig = target_to_host_signal(sig); |
533 |
if (host_sig != SIGSEGV && host_sig != SIGBUS) {
|
534 |
sigfillset(&act1.sa_mask); |
535 |
act1.sa_flags = SA_SIGINFO; |
536 |
if (k->sa.sa_flags & TARGET_SA_RESTART)
|
537 |
act1.sa_flags |= SA_RESTART; |
538 |
/* NOTE: it is important to update the host kernel signal
|
539 |
ignore state to avoid getting unexpected interrupted
|
540 |
syscalls */
|
541 |
if (k->sa._sa_handler == TARGET_SIG_IGN) {
|
542 |
act1.sa_sigaction = (void *)SIG_IGN;
|
543 |
} else if (k->sa._sa_handler == TARGET_SIG_DFL) { |
544 |
act1.sa_sigaction = (void *)SIG_DFL;
|
545 |
} else {
|
546 |
act1.sa_sigaction = host_signal_handler; |
547 |
} |
548 |
ret = sigaction(host_sig, &act1, NULL);
|
549 |
} |
550 |
} |
551 |
return ret;
|
552 |
} |
553 |
|
554 |
#ifndef offsetof
|
555 |
#define offsetof(type, field) ((size_t) &((type *)0)->field) |
556 |
#endif
|
557 |
|
558 |
static inline int copy_siginfo_to_user(target_siginfo_t *tinfo, |
559 |
const target_siginfo_t *info)
|
560 |
{ |
561 |
tswap_siginfo(tinfo, info); |
562 |
return 0; |
563 |
} |
564 |
|
565 |
#if defined(TARGET_I386) && TARGET_ABI_BITS == 32 |
566 |
|
567 |
/* from the Linux kernel */
|
568 |
|
569 |
struct target_fpreg {
|
570 |
uint16_t significand[4];
|
571 |
uint16_t exponent; |
572 |
}; |
573 |
|
574 |
struct target_fpxreg {
|
575 |
uint16_t significand[4];
|
576 |
uint16_t exponent; |
577 |
uint16_t padding[3];
|
578 |
}; |
579 |
|
580 |
struct target_xmmreg {
|
581 |
abi_ulong element[4];
|
582 |
}; |
583 |
|
584 |
struct target_fpstate {
|
585 |
/* Regular FPU environment */
|
586 |
abi_ulong cw; |
587 |
abi_ulong sw; |
588 |
abi_ulong tag; |
589 |
abi_ulong ipoff; |
590 |
abi_ulong cssel; |
591 |
abi_ulong dataoff; |
592 |
abi_ulong datasel; |
593 |
struct target_fpreg _st[8]; |
594 |
uint16_t status; |
595 |
uint16_t magic; /* 0xffff = regular FPU data only */
|
596 |
|
597 |
/* FXSR FPU environment */
|
598 |
abi_ulong _fxsr_env[6]; /* FXSR FPU env is ignored */ |
599 |
abi_ulong mxcsr; |
600 |
abi_ulong reserved; |
601 |
struct target_fpxreg _fxsr_st[8]; /* FXSR FPU reg data is ignored */ |
602 |
struct target_xmmreg _xmm[8]; |
603 |
abi_ulong padding[56];
|
604 |
}; |
605 |
|
606 |
#define X86_FXSR_MAGIC 0x0000 |
607 |
|
608 |
struct target_sigcontext {
|
609 |
uint16_t gs, __gsh; |
610 |
uint16_t fs, __fsh; |
611 |
uint16_t es, __esh; |
612 |
uint16_t ds, __dsh; |
613 |
abi_ulong edi; |
614 |
abi_ulong esi; |
615 |
abi_ulong ebp; |
616 |
abi_ulong esp; |
617 |
abi_ulong ebx; |
618 |
abi_ulong edx; |
619 |
abi_ulong ecx; |
620 |
abi_ulong eax; |
621 |
abi_ulong trapno; |
622 |
abi_ulong err; |
623 |
abi_ulong eip; |
624 |
uint16_t cs, __csh; |
625 |
abi_ulong eflags; |
626 |
abi_ulong esp_at_signal; |
627 |
uint16_t ss, __ssh; |
628 |
abi_ulong fpstate; /* pointer */
|
629 |
abi_ulong oldmask; |
630 |
abi_ulong cr2; |
631 |
}; |
632 |
|
633 |
struct target_ucontext {
|
634 |
abi_ulong tuc_flags; |
635 |
abi_ulong tuc_link; |
636 |
target_stack_t tuc_stack; |
637 |
struct target_sigcontext tuc_mcontext;
|
638 |
target_sigset_t tuc_sigmask; /* mask last for extensibility */
|
639 |
}; |
640 |
|
641 |
struct sigframe
|
642 |
{ |
643 |
abi_ulong pretcode; |
644 |
int sig;
|
645 |
struct target_sigcontext sc;
|
646 |
struct target_fpstate fpstate;
|
647 |
abi_ulong extramask[TARGET_NSIG_WORDS-1];
|
648 |
char retcode[8]; |
649 |
}; |
650 |
|
651 |
struct rt_sigframe
|
652 |
{ |
653 |
abi_ulong pretcode; |
654 |
int sig;
|
655 |
abi_ulong pinfo; |
656 |
abi_ulong puc; |
657 |
struct target_siginfo info;
|
658 |
struct target_ucontext uc;
|
659 |
struct target_fpstate fpstate;
|
660 |
char retcode[8]; |
661 |
}; |
662 |
|
663 |
/*
|
664 |
* Set up a signal frame.
|
665 |
*/
|
666 |
|
667 |
/* XXX: save x87 state */
|
668 |
static int |
669 |
setup_sigcontext(struct target_sigcontext *sc, struct target_fpstate *fpstate, |
670 |
CPUX86State *env, abi_ulong mask, abi_ulong fpstate_addr) |
671 |
{ |
672 |
int err = 0; |
673 |
uint16_t magic; |
674 |
|
675 |
/* already locked in setup_frame() */
|
676 |
err |= __put_user(env->segs[R_GS].selector, (unsigned int *)&sc->gs); |
677 |
err |= __put_user(env->segs[R_FS].selector, (unsigned int *)&sc->fs); |
678 |
err |= __put_user(env->segs[R_ES].selector, (unsigned int *)&sc->es); |
679 |
err |= __put_user(env->segs[R_DS].selector, (unsigned int *)&sc->ds); |
680 |
err |= __put_user(env->regs[R_EDI], &sc->edi); |
681 |
err |= __put_user(env->regs[R_ESI], &sc->esi); |
682 |
err |= __put_user(env->regs[R_EBP], &sc->ebp); |
683 |
err |= __put_user(env->regs[R_ESP], &sc->esp); |
684 |
err |= __put_user(env->regs[R_EBX], &sc->ebx); |
685 |
err |= __put_user(env->regs[R_EDX], &sc->edx); |
686 |
err |= __put_user(env->regs[R_ECX], &sc->ecx); |
687 |
err |= __put_user(env->regs[R_EAX], &sc->eax); |
688 |
err |= __put_user(env->exception_index, &sc->trapno); |
689 |
err |= __put_user(env->error_code, &sc->err); |
690 |
err |= __put_user(env->eip, &sc->eip); |
691 |
err |= __put_user(env->segs[R_CS].selector, (unsigned int *)&sc->cs); |
692 |
err |= __put_user(env->eflags, &sc->eflags); |
693 |
err |= __put_user(env->regs[R_ESP], &sc->esp_at_signal); |
694 |
err |= __put_user(env->segs[R_SS].selector, (unsigned int *)&sc->ss); |
695 |
|
696 |
cpu_x86_fsave(env, fpstate_addr, 1);
|
697 |
fpstate->status = fpstate->sw; |
698 |
magic = 0xffff;
|
699 |
err |= __put_user(magic, &fpstate->magic); |
700 |
err |= __put_user(fpstate_addr, &sc->fpstate); |
701 |
|
702 |
/* non-iBCS2 extensions.. */
|
703 |
err |= __put_user(mask, &sc->oldmask); |
704 |
err |= __put_user(env->cr[2], &sc->cr2);
|
705 |
return err;
|
706 |
} |
707 |
|
708 |
/*
|
709 |
* Determine which stack to use..
|
710 |
*/
|
711 |
|
712 |
static inline abi_ulong |
713 |
get_sigframe(struct emulated_sigaction *ka, CPUX86State *env, size_t frame_size)
|
714 |
{ |
715 |
unsigned long esp; |
716 |
|
717 |
/* Default to using normal stack */
|
718 |
esp = env->regs[R_ESP]; |
719 |
/* This is the X/Open sanctioned signal stack switching. */
|
720 |
if (ka->sa.sa_flags & TARGET_SA_ONSTACK) {
|
721 |
if (sas_ss_flags(esp) == 0) |
722 |
esp = target_sigaltstack_used.ss_sp + target_sigaltstack_used.ss_size; |
723 |
} |
724 |
|
725 |
/* This is the legacy signal stack switching. */
|
726 |
else
|
727 |
if ((env->segs[R_SS].selector & 0xffff) != __USER_DS && |
728 |
!(ka->sa.sa_flags & TARGET_SA_RESTORER) && |
729 |
ka->sa.sa_restorer) { |
730 |
esp = (unsigned long) ka->sa.sa_restorer; |
731 |
} |
732 |
return (esp - frame_size) & -8ul; |
733 |
} |
734 |
|
735 |
/* compare linux/arch/i386/kernel/signal.c:setup_frame() */
|
736 |
static void setup_frame(int sig, struct emulated_sigaction *ka, |
737 |
target_sigset_t *set, CPUX86State *env) |
738 |
{ |
739 |
abi_ulong frame_addr; |
740 |
struct sigframe *frame;
|
741 |
int i, err = 0; |
742 |
|
743 |
frame_addr = get_sigframe(ka, env, sizeof(*frame));
|
744 |
|
745 |
if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) |
746 |
goto give_sigsegv;
|
747 |
|
748 |
err |= __put_user((/*current->exec_domain
|
749 |
&& current->exec_domain->signal_invmap
|
750 |
&& sig < 32
|
751 |
? current->exec_domain->signal_invmap[sig]
|
752 |
: */ sig),
|
753 |
&frame->sig); |
754 |
if (err)
|
755 |
goto give_sigsegv;
|
756 |
|
757 |
setup_sigcontext(&frame->sc, &frame->fpstate, env, set->sig[0],
|
758 |
frame_addr + offsetof(struct sigframe, fpstate));
|
759 |
if (err)
|
760 |
goto give_sigsegv;
|
761 |
|
762 |
for(i = 1; i < TARGET_NSIG_WORDS; i++) { |
763 |
if (__put_user(set->sig[i], &frame->extramask[i - 1])) |
764 |
goto give_sigsegv;
|
765 |
} |
766 |
|
767 |
/* Set up to return from userspace. If provided, use a stub
|
768 |
already in userspace. */
|
769 |
if (ka->sa.sa_flags & TARGET_SA_RESTORER) {
|
770 |
err |= __put_user(ka->sa.sa_restorer, &frame->pretcode); |
771 |
} else {
|
772 |
uint16_t val16; |
773 |
abi_ulong retcode_addr; |
774 |
retcode_addr = frame_addr + offsetof(struct sigframe, retcode);
|
775 |
err |= __put_user(retcode_addr, &frame->pretcode); |
776 |
/* This is popl %eax ; movl $,%eax ; int $0x80 */
|
777 |
val16 = 0xb858;
|
778 |
err |= __put_user(val16, (uint16_t *)(frame->retcode+0));
|
779 |
err |= __put_user(TARGET_NR_sigreturn, (int *)(frame->retcode+2)); |
780 |
val16 = 0x80cd;
|
781 |
err |= __put_user(val16, (uint16_t *)(frame->retcode+6));
|
782 |
} |
783 |
|
784 |
if (err)
|
785 |
goto give_sigsegv;
|
786 |
|
787 |
/* Set up registers for signal handler */
|
788 |
env->regs[R_ESP] = frame_addr; |
789 |
env->eip = ka->sa._sa_handler; |
790 |
|
791 |
cpu_x86_load_seg(env, R_DS, __USER_DS); |
792 |
cpu_x86_load_seg(env, R_ES, __USER_DS); |
793 |
cpu_x86_load_seg(env, R_SS, __USER_DS); |
794 |
cpu_x86_load_seg(env, R_CS, __USER_CS); |
795 |
env->eflags &= ~TF_MASK; |
796 |
|
797 |
unlock_user_struct(frame, frame_addr, 1);
|
798 |
|
799 |
return;
|
800 |
|
801 |
give_sigsegv:
|
802 |
unlock_user_struct(frame, frame_addr, 1);
|
803 |
if (sig == TARGET_SIGSEGV)
|
804 |
ka->sa._sa_handler = TARGET_SIG_DFL; |
805 |
force_sig(TARGET_SIGSEGV /* , current */);
|
806 |
} |
807 |
|
808 |
/* compare linux/arch/i386/kernel/signal.c:setup_rt_frame() */
|
809 |
static void setup_rt_frame(int sig, struct emulated_sigaction *ka, |
810 |
target_siginfo_t *info, |
811 |
target_sigset_t *set, CPUX86State *env) |
812 |
{ |
813 |
abi_ulong frame_addr, addr; |
814 |
struct rt_sigframe *frame;
|
815 |
int i, err = 0; |
816 |
|
817 |
frame_addr = get_sigframe(ka, env, sizeof(*frame));
|
818 |
|
819 |
if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) |
820 |
goto give_sigsegv;
|
821 |
|
822 |
err |= __put_user((/*current->exec_domain
|
823 |
&& current->exec_domain->signal_invmap
|
824 |
&& sig < 32
|
825 |
? current->exec_domain->signal_invmap[sig]
|
826 |
: */sig),
|
827 |
&frame->sig); |
828 |
addr = frame_addr + offsetof(struct rt_sigframe, info);
|
829 |
err |= __put_user(addr, &frame->pinfo); |
830 |
addr = frame_addr + offsetof(struct rt_sigframe, uc);
|
831 |
err |= __put_user(addr, &frame->puc); |
832 |
err |= copy_siginfo_to_user(&frame->info, info); |
833 |
if (err)
|
834 |
goto give_sigsegv;
|
835 |
|
836 |
/* Create the ucontext. */
|
837 |
err |= __put_user(0, &frame->uc.tuc_flags);
|
838 |
err |= __put_user(0, &frame->uc.tuc_link);
|
839 |
err |= __put_user(target_sigaltstack_used.ss_sp, |
840 |
&frame->uc.tuc_stack.ss_sp); |
841 |
err |= __put_user(sas_ss_flags(get_sp_from_cpustate(env)), |
842 |
&frame->uc.tuc_stack.ss_flags); |
843 |
err |= __put_user(target_sigaltstack_used.ss_size, |
844 |
&frame->uc.tuc_stack.ss_size); |
845 |
err |= setup_sigcontext(&frame->uc.tuc_mcontext, &frame->fpstate, |
846 |
env, set->sig[0],
|
847 |
frame_addr + offsetof(struct rt_sigframe, fpstate));
|
848 |
for(i = 0; i < TARGET_NSIG_WORDS; i++) { |
849 |
if (__put_user(set->sig[i], &frame->uc.tuc_sigmask.sig[i]))
|
850 |
goto give_sigsegv;
|
851 |
} |
852 |
|
853 |
/* Set up to return from userspace. If provided, use a stub
|
854 |
already in userspace. */
|
855 |
if (ka->sa.sa_flags & TARGET_SA_RESTORER) {
|
856 |
err |= __put_user(ka->sa.sa_restorer, &frame->pretcode); |
857 |
} else {
|
858 |
uint16_t val16; |
859 |
addr = frame_addr + offsetof(struct rt_sigframe, retcode);
|
860 |
err |= __put_user(addr, &frame->pretcode); |
861 |
/* This is movl $,%eax ; int $0x80 */
|
862 |
err |= __put_user(0xb8, (char *)(frame->retcode+0)); |
863 |
err |= __put_user(TARGET_NR_rt_sigreturn, (int *)(frame->retcode+1)); |
864 |
val16 = 0x80cd;
|
865 |
err |= __put_user(val16, (uint16_t *)(frame->retcode+5));
|
866 |
} |
867 |
|
868 |
if (err)
|
869 |
goto give_sigsegv;
|
870 |
|
871 |
/* Set up registers for signal handler */
|
872 |
env->regs[R_ESP] = frame_addr; |
873 |
env->eip = ka->sa._sa_handler; |
874 |
|
875 |
cpu_x86_load_seg(env, R_DS, __USER_DS); |
876 |
cpu_x86_load_seg(env, R_ES, __USER_DS); |
877 |
cpu_x86_load_seg(env, R_SS, __USER_DS); |
878 |
cpu_x86_load_seg(env, R_CS, __USER_CS); |
879 |
env->eflags &= ~TF_MASK; |
880 |
|
881 |
unlock_user_struct(frame, frame_addr, 1);
|
882 |
|
883 |
return;
|
884 |
|
885 |
give_sigsegv:
|
886 |
unlock_user_struct(frame, frame_addr, 1);
|
887 |
if (sig == TARGET_SIGSEGV)
|
888 |
ka->sa._sa_handler = TARGET_SIG_DFL; |
889 |
force_sig(TARGET_SIGSEGV /* , current */);
|
890 |
} |
891 |
|
892 |
static int |
893 |
restore_sigcontext(CPUX86State *env, struct target_sigcontext *sc, int *peax) |
894 |
{ |
895 |
unsigned int err = 0; |
896 |
abi_ulong fpstate_addr; |
897 |
unsigned int tmpflags; |
898 |
|
899 |
cpu_x86_load_seg(env, R_GS, tswap16(sc->gs)); |
900 |
cpu_x86_load_seg(env, R_FS, tswap16(sc->fs)); |
901 |
cpu_x86_load_seg(env, R_ES, tswap16(sc->es)); |
902 |
cpu_x86_load_seg(env, R_DS, tswap16(sc->ds)); |
903 |
|
904 |
env->regs[R_EDI] = tswapl(sc->edi); |
905 |
env->regs[R_ESI] = tswapl(sc->esi); |
906 |
env->regs[R_EBP] = tswapl(sc->ebp); |
907 |
env->regs[R_ESP] = tswapl(sc->esp); |
908 |
env->regs[R_EBX] = tswapl(sc->ebx); |
909 |
env->regs[R_EDX] = tswapl(sc->edx); |
910 |
env->regs[R_ECX] = tswapl(sc->ecx); |
911 |
env->eip = tswapl(sc->eip); |
912 |
|
913 |
cpu_x86_load_seg(env, R_CS, lduw(&sc->cs) | 3);
|
914 |
cpu_x86_load_seg(env, R_SS, lduw(&sc->ss) | 3);
|
915 |
|
916 |
tmpflags = tswapl(sc->eflags); |
917 |
env->eflags = (env->eflags & ~0x40DD5) | (tmpflags & 0x40DD5); |
918 |
// regs->orig_eax = -1; /* disable syscall checks */
|
919 |
|
920 |
fpstate_addr = tswapl(sc->fpstate); |
921 |
if (fpstate_addr != 0) { |
922 |
if (!access_ok(VERIFY_READ, fpstate_addr,
|
923 |
sizeof(struct target_fpstate))) |
924 |
goto badframe;
|
925 |
cpu_x86_frstor(env, fpstate_addr, 1);
|
926 |
} |
927 |
|
928 |
*peax = tswapl(sc->eax); |
929 |
return err;
|
930 |
badframe:
|
931 |
return 1; |
932 |
} |
933 |
|
934 |
long do_sigreturn(CPUX86State *env)
|
935 |
{ |
936 |
struct sigframe *frame;
|
937 |
abi_ulong frame_addr = env->regs[R_ESP] - 8;
|
938 |
target_sigset_t target_set; |
939 |
sigset_t set; |
940 |
int eax, i;
|
941 |
|
942 |
#if defined(DEBUG_SIGNAL)
|
943 |
fprintf(stderr, "do_sigreturn\n");
|
944 |
#endif
|
945 |
if (!lock_user_struct(VERIFY_READ, frame, frame_addr, 1)) |
946 |
goto badframe;
|
947 |
/* set blocked signals */
|
948 |
if (__get_user(target_set.sig[0], &frame->sc.oldmask)) |
949 |
goto badframe;
|
950 |
for(i = 1; i < TARGET_NSIG_WORDS; i++) { |
951 |
if (__get_user(target_set.sig[i], &frame->extramask[i - 1])) |
952 |
goto badframe;
|
953 |
} |
954 |
|
955 |
target_to_host_sigset_internal(&set, &target_set); |
956 |
sigprocmask(SIG_SETMASK, &set, NULL);
|
957 |
|
958 |
/* restore registers */
|
959 |
if (restore_sigcontext(env, &frame->sc, &eax))
|
960 |
goto badframe;
|
961 |
unlock_user_struct(frame, frame_addr, 0);
|
962 |
return eax;
|
963 |
|
964 |
badframe:
|
965 |
unlock_user_struct(frame, frame_addr, 0);
|
966 |
force_sig(TARGET_SIGSEGV); |
967 |
return 0; |
968 |
} |
969 |
|
970 |
long do_rt_sigreturn(CPUX86State *env)
|
971 |
{ |
972 |
abi_ulong frame_addr; |
973 |
struct rt_sigframe *frame;
|
974 |
sigset_t set; |
975 |
int eax;
|
976 |
|
977 |
frame_addr = env->regs[R_ESP] - 4;
|
978 |
if (!lock_user_struct(VERIFY_READ, frame, frame_addr, 1)) |
979 |
goto badframe;
|
980 |
target_to_host_sigset(&set, &frame->uc.tuc_sigmask); |
981 |
sigprocmask(SIG_SETMASK, &set, NULL);
|
982 |
|
983 |
if (restore_sigcontext(env, &frame->uc.tuc_mcontext, &eax))
|
984 |
goto badframe;
|
985 |
|
986 |
if (do_sigaltstack(frame_addr + offsetof(struct rt_sigframe, uc.tuc_stack), 0, |
987 |
get_sp_from_cpustate(env)) == -EFAULT) |
988 |
goto badframe;
|
989 |
|
990 |
unlock_user_struct(frame, frame_addr, 0);
|
991 |
return eax;
|
992 |
|
993 |
badframe:
|
994 |
unlock_user_struct(frame, frame_addr, 0);
|
995 |
force_sig(TARGET_SIGSEGV); |
996 |
return 0; |
997 |
} |
998 |
|
999 |
#elif defined(TARGET_ARM)
|
1000 |
|
1001 |
struct target_sigcontext {
|
1002 |
abi_ulong trap_no; |
1003 |
abi_ulong error_code; |
1004 |
abi_ulong oldmask; |
1005 |
abi_ulong arm_r0; |
1006 |
abi_ulong arm_r1; |
1007 |
abi_ulong arm_r2; |
1008 |
abi_ulong arm_r3; |
1009 |
abi_ulong arm_r4; |
1010 |
abi_ulong arm_r5; |
1011 |
abi_ulong arm_r6; |
1012 |
abi_ulong arm_r7; |
1013 |
abi_ulong arm_r8; |
1014 |
abi_ulong arm_r9; |
1015 |
abi_ulong arm_r10; |
1016 |
abi_ulong arm_fp; |
1017 |
abi_ulong arm_ip; |
1018 |
abi_ulong arm_sp; |
1019 |
abi_ulong arm_lr; |
1020 |
abi_ulong arm_pc; |
1021 |
abi_ulong arm_cpsr; |
1022 |
abi_ulong fault_address; |
1023 |
}; |
1024 |
|
1025 |
struct target_ucontext {
|
1026 |
abi_ulong tuc_flags; |
1027 |
abi_ulong tuc_link; |
1028 |
target_stack_t tuc_stack; |
1029 |
struct target_sigcontext tuc_mcontext;
|
1030 |
target_sigset_t tuc_sigmask; /* mask last for extensibility */
|
1031 |
}; |
1032 |
|
1033 |
struct sigframe
|
1034 |
{ |
1035 |
struct target_sigcontext sc;
|
1036 |
abi_ulong extramask[TARGET_NSIG_WORDS-1];
|
1037 |
abi_ulong retcode; |
1038 |
}; |
1039 |
|
1040 |
struct rt_sigframe
|
1041 |
{ |
1042 |
abi_ulong pinfo; |
1043 |
abi_ulong puc; |
1044 |
struct target_siginfo info;
|
1045 |
struct target_ucontext uc;
|
1046 |
abi_ulong retcode; |
1047 |
}; |
1048 |
|
1049 |
#define TARGET_CONFIG_CPU_32 1 |
1050 |
|
1051 |
/*
|
1052 |
* For ARM syscalls, we encode the syscall number into the instruction.
|
1053 |
*/
|
1054 |
#define SWI_SYS_SIGRETURN (0xef000000|(TARGET_NR_sigreturn + ARM_SYSCALL_BASE)) |
1055 |
#define SWI_SYS_RT_SIGRETURN (0xef000000|(TARGET_NR_rt_sigreturn + ARM_SYSCALL_BASE)) |
1056 |
|
1057 |
/*
|
1058 |
* For Thumb syscalls, we pass the syscall number via r7. We therefore
|
1059 |
* need two 16-bit instructions.
|
1060 |
*/
|
1061 |
#define SWI_THUMB_SIGRETURN (0xdf00 << 16 | 0x2700 | (TARGET_NR_sigreturn)) |
1062 |
#define SWI_THUMB_RT_SIGRETURN (0xdf00 << 16 | 0x2700 | (TARGET_NR_rt_sigreturn)) |
1063 |
|
1064 |
static const abi_ulong retcodes[4] = { |
1065 |
SWI_SYS_SIGRETURN, SWI_THUMB_SIGRETURN, |
1066 |
SWI_SYS_RT_SIGRETURN, SWI_THUMB_RT_SIGRETURN |
1067 |
}; |
1068 |
|
1069 |
|
1070 |
#define __put_user_error(x,p,e) __put_user(x, p)
|
1071 |
#define __get_user_error(x,p,e) __get_user(x, p)
|
1072 |
|
1073 |
static inline int valid_user_regs(CPUState *regs) |
1074 |
{ |
1075 |
return 1; |
1076 |
} |
1077 |
|
1078 |
static int |
1079 |
setup_sigcontext(struct target_sigcontext *sc, /*struct _fpstate *fpstate,*/ |
1080 |
CPUState *env, abi_ulong mask) |
1081 |
{ |
1082 |
int err = 0; |
1083 |
|
1084 |
__put_user_error(env->regs[0], &sc->arm_r0, err);
|
1085 |
__put_user_error(env->regs[1], &sc->arm_r1, err);
|
1086 |
__put_user_error(env->regs[2], &sc->arm_r2, err);
|
1087 |
__put_user_error(env->regs[3], &sc->arm_r3, err);
|
1088 |
__put_user_error(env->regs[4], &sc->arm_r4, err);
|
1089 |
__put_user_error(env->regs[5], &sc->arm_r5, err);
|
1090 |
__put_user_error(env->regs[6], &sc->arm_r6, err);
|
1091 |
__put_user_error(env->regs[7], &sc->arm_r7, err);
|
1092 |
__put_user_error(env->regs[8], &sc->arm_r8, err);
|
1093 |
__put_user_error(env->regs[9], &sc->arm_r9, err);
|
1094 |
__put_user_error(env->regs[10], &sc->arm_r10, err);
|
1095 |
__put_user_error(env->regs[11], &sc->arm_fp, err);
|
1096 |
__put_user_error(env->regs[12], &sc->arm_ip, err);
|
1097 |
__put_user_error(env->regs[13], &sc->arm_sp, err);
|
1098 |
__put_user_error(env->regs[14], &sc->arm_lr, err);
|
1099 |
__put_user_error(env->regs[15], &sc->arm_pc, err);
|
1100 |
#ifdef TARGET_CONFIG_CPU_32
|
1101 |
__put_user_error(cpsr_read(env), &sc->arm_cpsr, err); |
1102 |
#endif
|
1103 |
|
1104 |
__put_user_error(/* current->thread.trap_no */ 0, &sc->trap_no, err); |
1105 |
__put_user_error(/* current->thread.error_code */ 0, &sc->error_code, err); |
1106 |
__put_user_error(/* current->thread.address */ 0, &sc->fault_address, err); |
1107 |
__put_user_error(mask, &sc->oldmask, err); |
1108 |
|
1109 |
return err;
|
1110 |
} |
1111 |
|
1112 |
static inline abi_ulong |
1113 |
get_sigframe(struct emulated_sigaction *ka, CPUState *regs, int framesize) |
1114 |
{ |
1115 |
unsigned long sp = regs->regs[13]; |
1116 |
|
1117 |
/*
|
1118 |
* This is the X/Open sanctioned signal stack switching.
|
1119 |
*/
|
1120 |
if ((ka->sa.sa_flags & TARGET_SA_ONSTACK) && !sas_ss_flags(sp))
|
1121 |
sp = target_sigaltstack_used.ss_sp + target_sigaltstack_used.ss_size; |
1122 |
/*
|
1123 |
* ATPCS B01 mandates 8-byte alignment
|
1124 |
*/
|
1125 |
return (sp - framesize) & ~7; |
1126 |
} |
1127 |
|
1128 |
static int |
1129 |
setup_return(CPUState *env, struct emulated_sigaction *ka,
|
1130 |
abi_ulong *rc, abi_ulong frame_addr, int usig, abi_ulong rc_addr)
|
1131 |
{ |
1132 |
abi_ulong handler = ka->sa._sa_handler; |
1133 |
abi_ulong retcode; |
1134 |
int thumb = 0; |
1135 |
#if defined(TARGET_CONFIG_CPU_32)
|
1136 |
#if 0
|
1137 |
abi_ulong cpsr = env->cpsr;
|
1138 |
|
1139 |
/*
|
1140 |
* Maybe we need to deliver a 32-bit signal to a 26-bit task.
|
1141 |
*/
|
1142 |
if (ka->sa.sa_flags & SA_THIRTYTWO)
|
1143 |
cpsr = (cpsr & ~MODE_MASK) | USR_MODE;
|
1144 |
|
1145 |
#ifdef CONFIG_ARM_THUMB
|
1146 |
if (elf_hwcap & HWCAP_THUMB) {
|
1147 |
/*
|
1148 |
* The LSB of the handler determines if we're going to
|
1149 |
* be using THUMB or ARM mode for this signal handler.
|
1150 |
*/
|
1151 |
thumb = handler & 1;
|
1152 |
|
1153 |
if (thumb)
|
1154 |
cpsr |= T_BIT;
|
1155 |
else
|
1156 |
cpsr &= ~T_BIT;
|
1157 |
}
|
1158 |
#endif /* CONFIG_ARM_THUMB */
|
1159 |
#endif /* 0 */ |
1160 |
#endif /* TARGET_CONFIG_CPU_32 */ |
1161 |
|
1162 |
if (ka->sa.sa_flags & TARGET_SA_RESTORER) {
|
1163 |
retcode = ka->sa.sa_restorer; |
1164 |
} else {
|
1165 |
unsigned int idx = thumb; |
1166 |
|
1167 |
if (ka->sa.sa_flags & TARGET_SA_SIGINFO)
|
1168 |
idx += 2;
|
1169 |
|
1170 |
if (__put_user(retcodes[idx], rc))
|
1171 |
return 1; |
1172 |
#if 0
|
1173 |
flush_icache_range((abi_ulong)rc,
|
1174 |
(abi_ulong)(rc + 1));
|
1175 |
#endif
|
1176 |
retcode = rc_addr + thumb; |
1177 |
} |
1178 |
|
1179 |
env->regs[0] = usig;
|
1180 |
env->regs[13] = frame_addr;
|
1181 |
env->regs[14] = retcode;
|
1182 |
env->regs[15] = handler & (thumb ? ~1 : ~3); |
1183 |
|
1184 |
#if 0
|
1185 |
#ifdef TARGET_CONFIG_CPU_32
|
1186 |
env->cpsr = cpsr;
|
1187 |
#endif
|
1188 |
#endif
|
1189 |
|
1190 |
return 0; |
1191 |
} |
1192 |
|
1193 |
/* compare linux/arch/arm/kernel/signal.c:setup_frame() */
|
1194 |
static void setup_frame(int usig, struct emulated_sigaction *ka, |
1195 |
target_sigset_t *set, CPUState *regs) |
1196 |
{ |
1197 |
struct sigframe *frame;
|
1198 |
abi_ulong frame_addr = get_sigframe(ka, regs, sizeof(*frame));
|
1199 |
int i, err = 0; |
1200 |
|
1201 |
if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) |
1202 |
return;
|
1203 |
|
1204 |
err |= setup_sigcontext(&frame->sc, /*&frame->fpstate,*/ regs, set->sig[0]); |
1205 |
|
1206 |
for(i = 1; i < TARGET_NSIG_WORDS; i++) { |
1207 |
if (__put_user(set->sig[i], &frame->extramask[i - 1])) |
1208 |
goto end;
|
1209 |
} |
1210 |
|
1211 |
if (err == 0) |
1212 |
err = setup_return(regs, ka, &frame->retcode, frame_addr, usig, |
1213 |
frame_addr + offsetof(struct sigframe, retcode));
|
1214 |
|
1215 |
end:
|
1216 |
unlock_user_struct(frame, frame_addr, 1);
|
1217 |
// return err;
|
1218 |
} |
1219 |
|
1220 |
/* compare linux/arch/arm/kernel/signal.c:setup_rt_frame() */
|
1221 |
static void setup_rt_frame(int usig, struct emulated_sigaction *ka, |
1222 |
target_siginfo_t *info, |
1223 |
target_sigset_t *set, CPUState *env) |
1224 |
{ |
1225 |
struct rt_sigframe *frame;
|
1226 |
abi_ulong frame_addr = get_sigframe(ka, env, sizeof(*frame));
|
1227 |
struct target_sigaltstack stack;
|
1228 |
int i, err = 0; |
1229 |
abi_ulong info_addr, uc_addr; |
1230 |
|
1231 |
if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) |
1232 |
return /* 1 */; |
1233 |
|
1234 |
info_addr = frame_addr + offsetof(struct rt_sigframe, info);
|
1235 |
__put_user_error(info_addr, &frame->pinfo, err); |
1236 |
uc_addr = frame_addr + offsetof(struct rt_sigframe, uc);
|
1237 |
__put_user_error(uc_addr, &frame->puc, err); |
1238 |
err |= copy_siginfo_to_user(&frame->info, info); |
1239 |
|
1240 |
/* Clear all the bits of the ucontext we don't use. */
|
1241 |
memset(&frame->uc, 0, offsetof(struct target_ucontext, tuc_mcontext)); |
1242 |
|
1243 |
memset(&stack, 0, sizeof(stack)); |
1244 |
__put_user(target_sigaltstack_used.ss_sp, &stack.ss_sp); |
1245 |
__put_user(target_sigaltstack_used.ss_size, &stack.ss_size); |
1246 |
__put_user(sas_ss_flags(get_sp_from_cpustate(env)), &stack.ss_flags); |
1247 |
memcpy(&frame->uc.tuc_stack, &stack, sizeof(stack));
|
1248 |
|
1249 |
err |= setup_sigcontext(&frame->uc.tuc_mcontext, /*&frame->fpstate,*/
|
1250 |
env, set->sig[0]);
|
1251 |
for(i = 0; i < TARGET_NSIG_WORDS; i++) { |
1252 |
if (__put_user(set->sig[i], &frame->uc.tuc_sigmask.sig[i]))
|
1253 |
goto end;
|
1254 |
} |
1255 |
|
1256 |
if (err == 0) |
1257 |
err = setup_return(env, ka, &frame->retcode, frame_addr, usig, |
1258 |
frame_addr + offsetof(struct rt_sigframe, retcode));
|
1259 |
|
1260 |
if (err == 0) { |
1261 |
/*
|
1262 |
* For realtime signals we must also set the second and third
|
1263 |
* arguments for the signal handler.
|
1264 |
* -- Peter Maydell <pmaydell@chiark.greenend.org.uk> 2000-12-06
|
1265 |
*/
|
1266 |
env->regs[1] = info_addr;
|
1267 |
env->regs[2] = uc_addr;
|
1268 |
} |
1269 |
|
1270 |
end:
|
1271 |
unlock_user_struct(frame, frame_addr, 1);
|
1272 |
|
1273 |
// return err;
|
1274 |
} |
1275 |
|
1276 |
static int |
1277 |
restore_sigcontext(CPUState *env, struct target_sigcontext *sc)
|
1278 |
{ |
1279 |
int err = 0; |
1280 |
uint32_t cpsr; |
1281 |
|
1282 |
__get_user_error(env->regs[0], &sc->arm_r0, err);
|
1283 |
__get_user_error(env->regs[1], &sc->arm_r1, err);
|
1284 |
__get_user_error(env->regs[2], &sc->arm_r2, err);
|
1285 |
__get_user_error(env->regs[3], &sc->arm_r3, err);
|
1286 |
__get_user_error(env->regs[4], &sc->arm_r4, err);
|
1287 |
__get_user_error(env->regs[5], &sc->arm_r5, err);
|
1288 |
__get_user_error(env->regs[6], &sc->arm_r6, err);
|
1289 |
__get_user_error(env->regs[7], &sc->arm_r7, err);
|
1290 |
__get_user_error(env->regs[8], &sc->arm_r8, err);
|
1291 |
__get_user_error(env->regs[9], &sc->arm_r9, err);
|
1292 |
__get_user_error(env->regs[10], &sc->arm_r10, err);
|
1293 |
__get_user_error(env->regs[11], &sc->arm_fp, err);
|
1294 |
__get_user_error(env->regs[12], &sc->arm_ip, err);
|
1295 |
__get_user_error(env->regs[13], &sc->arm_sp, err);
|
1296 |
__get_user_error(env->regs[14], &sc->arm_lr, err);
|
1297 |
__get_user_error(env->regs[15], &sc->arm_pc, err);
|
1298 |
#ifdef TARGET_CONFIG_CPU_32
|
1299 |
__get_user_error(cpsr, &sc->arm_cpsr, err); |
1300 |
cpsr_write(env, cpsr, 0xffffffff);
|
1301 |
#endif
|
1302 |
|
1303 |
err |= !valid_user_regs(env); |
1304 |
|
1305 |
return err;
|
1306 |
} |
1307 |
|
1308 |
long do_sigreturn(CPUState *env)
|
1309 |
{ |
1310 |
abi_ulong frame_addr; |
1311 |
struct sigframe *frame;
|
1312 |
target_sigset_t set; |
1313 |
sigset_t host_set; |
1314 |
int i;
|
1315 |
|
1316 |
/*
|
1317 |
* Since we stacked the signal on a 64-bit boundary,
|
1318 |
* then 'sp' should be word aligned here. If it's
|
1319 |
* not, then the user is trying to mess with us.
|
1320 |
*/
|
1321 |
if (env->regs[13] & 7) |
1322 |
goto badframe;
|
1323 |
|
1324 |
frame_addr = env->regs[13];
|
1325 |
if (!lock_user_struct(VERIFY_READ, frame, frame_addr, 1)) |
1326 |
goto badframe;
|
1327 |
|
1328 |
if (__get_user(set.sig[0], &frame->sc.oldmask)) |
1329 |
goto badframe;
|
1330 |
for(i = 1; i < TARGET_NSIG_WORDS; i++) { |
1331 |
if (__get_user(set.sig[i], &frame->extramask[i - 1])) |
1332 |
goto badframe;
|
1333 |
} |
1334 |
|
1335 |
target_to_host_sigset_internal(&host_set, &set); |
1336 |
sigprocmask(SIG_SETMASK, &host_set, NULL);
|
1337 |
|
1338 |
if (restore_sigcontext(env, &frame->sc))
|
1339 |
goto badframe;
|
1340 |
|
1341 |
#if 0
|
1342 |
/* Send SIGTRAP if we're single-stepping */
|
1343 |
if (ptrace_cancel_bpt(current))
|
1344 |
send_sig(SIGTRAP, current, 1);
|
1345 |
#endif
|
1346 |
unlock_user_struct(frame, frame_addr, 0);
|
1347 |
return env->regs[0]; |
1348 |
|
1349 |
badframe:
|
1350 |
unlock_user_struct(frame, frame_addr, 0);
|
1351 |
force_sig(SIGSEGV /* , current */);
|
1352 |
return 0; |
1353 |
} |
1354 |
|
1355 |
long do_rt_sigreturn(CPUState *env)
|
1356 |
{ |
1357 |
abi_ulong frame_addr; |
1358 |
struct rt_sigframe *frame;
|
1359 |
sigset_t host_set; |
1360 |
|
1361 |
/*
|
1362 |
* Since we stacked the signal on a 64-bit boundary,
|
1363 |
* then 'sp' should be word aligned here. If it's
|
1364 |
* not, then the user is trying to mess with us.
|
1365 |
*/
|
1366 |
if (env->regs[13] & 7) |
1367 |
goto badframe;
|
1368 |
|
1369 |
frame_addr = env->regs[13];
|
1370 |
if (!lock_user_struct(VERIFY_READ, frame, frame_addr, 1)) |
1371 |
goto badframe;
|
1372 |
|
1373 |
target_to_host_sigset(&host_set, &frame->uc.tuc_sigmask); |
1374 |
sigprocmask(SIG_SETMASK, &host_set, NULL);
|
1375 |
|
1376 |
if (restore_sigcontext(env, &frame->uc.tuc_mcontext))
|
1377 |
goto badframe;
|
1378 |
|
1379 |
if (do_sigaltstack(frame_addr + offsetof(struct rt_sigframe, uc.tuc_stack), 0, get_sp_from_cpustate(env)) == -EFAULT) |
1380 |
goto badframe;
|
1381 |
|
1382 |
#if 0
|
1383 |
/* Send SIGTRAP if we're single-stepping */
|
1384 |
if (ptrace_cancel_bpt(current))
|
1385 |
send_sig(SIGTRAP, current, 1);
|
1386 |
#endif
|
1387 |
unlock_user_struct(frame, frame_addr, 0);
|
1388 |
return env->regs[0]; |
1389 |
|
1390 |
badframe:
|
1391 |
unlock_user_struct(frame, frame_addr, 0);
|
1392 |
force_sig(SIGSEGV /* , current */);
|
1393 |
return 0; |
1394 |
} |
1395 |
|
1396 |
#elif defined(TARGET_SPARC)
|
1397 |
|
1398 |
#define __SUNOS_MAXWIN 31 |
1399 |
|
1400 |
/* This is what SunOS does, so shall I. */
|
1401 |
struct target_sigcontext {
|
1402 |
abi_ulong sigc_onstack; /* state to restore */
|
1403 |
|
1404 |
abi_ulong sigc_mask; /* sigmask to restore */
|
1405 |
abi_ulong sigc_sp; /* stack pointer */
|
1406 |
abi_ulong sigc_pc; /* program counter */
|
1407 |
abi_ulong sigc_npc; /* next program counter */
|
1408 |
abi_ulong sigc_psr; /* for condition codes etc */
|
1409 |
abi_ulong sigc_g1; /* User uses these two registers */
|
1410 |
abi_ulong sigc_o0; /* within the trampoline code. */
|
1411 |
|
1412 |
/* Now comes information regarding the users window set
|
1413 |
* at the time of the signal.
|
1414 |
*/
|
1415 |
abi_ulong sigc_oswins; /* outstanding windows */
|
1416 |
|
1417 |
/* stack ptrs for each regwin buf */
|
1418 |
char *sigc_spbuf[__SUNOS_MAXWIN];
|
1419 |
|
1420 |
/* Windows to restore after signal */
|
1421 |
struct {
|
1422 |
abi_ulong locals[8];
|
1423 |
abi_ulong ins[8];
|
1424 |
} sigc_wbuf[__SUNOS_MAXWIN]; |
1425 |
}; |
1426 |
/* A Sparc stack frame */
|
1427 |
struct sparc_stackf {
|
1428 |
abi_ulong locals[8];
|
1429 |
abi_ulong ins[6];
|
1430 |
struct sparc_stackf *fp;
|
1431 |
abi_ulong callers_pc; |
1432 |
char *structptr;
|
1433 |
abi_ulong xargs[6];
|
1434 |
abi_ulong xxargs[1];
|
1435 |
}; |
1436 |
|
1437 |
typedef struct { |
1438 |
struct {
|
1439 |
abi_ulong psr; |
1440 |
abi_ulong pc; |
1441 |
abi_ulong npc; |
1442 |
abi_ulong y; |
1443 |
abi_ulong u_regs[16]; /* globals and ins */ |
1444 |
} si_regs; |
1445 |
int si_mask;
|
1446 |
} __siginfo_t; |
1447 |
|
1448 |
typedef struct { |
1449 |
unsigned long si_float_regs [32]; |
1450 |
unsigned long si_fsr; |
1451 |
unsigned long si_fpqdepth; |
1452 |
struct {
|
1453 |
unsigned long *insn_addr; |
1454 |
unsigned long insn; |
1455 |
} si_fpqueue [16];
|
1456 |
} qemu_siginfo_fpu_t; |
1457 |
|
1458 |
|
1459 |
struct target_signal_frame {
|
1460 |
struct sparc_stackf ss;
|
1461 |
__siginfo_t info; |
1462 |
abi_ulong fpu_save; |
1463 |
abi_ulong insns[2] __attribute__ ((aligned (8))); |
1464 |
abi_ulong extramask[TARGET_NSIG_WORDS - 1];
|
1465 |
abi_ulong extra_size; /* Should be 0 */
|
1466 |
qemu_siginfo_fpu_t fpu_state; |
1467 |
}; |
1468 |
struct target_rt_signal_frame {
|
1469 |
struct sparc_stackf ss;
|
1470 |
siginfo_t info; |
1471 |
abi_ulong regs[20];
|
1472 |
sigset_t mask; |
1473 |
abi_ulong fpu_save; |
1474 |
unsigned int insns[2]; |
1475 |
stack_t stack; |
1476 |
unsigned int extra_size; /* Should be 0 */ |
1477 |
qemu_siginfo_fpu_t fpu_state; |
1478 |
}; |
1479 |
|
1480 |
#define UREG_O0 16 |
1481 |
#define UREG_O6 22 |
1482 |
#define UREG_I0 0 |
1483 |
#define UREG_I1 1 |
1484 |
#define UREG_I2 2 |
1485 |
#define UREG_I3 3 |
1486 |
#define UREG_I4 4 |
1487 |
#define UREG_I5 5 |
1488 |
#define UREG_I6 6 |
1489 |
#define UREG_I7 7 |
1490 |
#define UREG_L0 8 |
1491 |
#define UREG_FP UREG_I6
|
1492 |
#define UREG_SP UREG_O6
|
1493 |
|
1494 |
static inline abi_ulong get_sigframe(struct emulated_sigaction *sa, |
1495 |
CPUState *env, unsigned long framesize) |
1496 |
{ |
1497 |
abi_ulong sp; |
1498 |
|
1499 |
sp = env->regwptr[UREG_FP]; |
1500 |
|
1501 |
/* This is the X/Open sanctioned signal stack switching. */
|
1502 |
if (sa->sa.sa_flags & TARGET_SA_ONSTACK) {
|
1503 |
if (!on_sig_stack(sp)
|
1504 |
&& !((target_sigaltstack_used.ss_sp + target_sigaltstack_used.ss_size) & 7))
|
1505 |
sp = target_sigaltstack_used.ss_sp + target_sigaltstack_used.ss_size; |
1506 |
} |
1507 |
return sp - framesize;
|
1508 |
} |
1509 |
|
1510 |
static int |
1511 |
setup___siginfo(__siginfo_t *si, CPUState *env, abi_ulong mask) |
1512 |
{ |
1513 |
int err = 0, i; |
1514 |
|
1515 |
err |= __put_user(env->psr, &si->si_regs.psr); |
1516 |
err |= __put_user(env->pc, &si->si_regs.pc); |
1517 |
err |= __put_user(env->npc, &si->si_regs.npc); |
1518 |
err |= __put_user(env->y, &si->si_regs.y); |
1519 |
for (i=0; i < 8; i++) { |
1520 |
err |= __put_user(env->gregs[i], &si->si_regs.u_regs[i]); |
1521 |
} |
1522 |
for (i=0; i < 8; i++) { |
1523 |
err |= __put_user(env->regwptr[UREG_I0 + i], &si->si_regs.u_regs[i+8]);
|
1524 |
} |
1525 |
err |= __put_user(mask, &si->si_mask); |
1526 |
return err;
|
1527 |
} |
1528 |
|
1529 |
#if 0
|
1530 |
static int
|
1531 |
setup_sigcontext(struct target_sigcontext *sc, /*struct _fpstate *fpstate,*/
|
1532 |
CPUState *env, unsigned long mask)
|
1533 |
{
|
1534 |
int err = 0;
|
1535 |
|
1536 |
err |= __put_user(mask, &sc->sigc_mask);
|
1537 |
err |= __put_user(env->regwptr[UREG_SP], &sc->sigc_sp);
|
1538 |
err |= __put_user(env->pc, &sc->sigc_pc);
|
1539 |
err |= __put_user(env->npc, &sc->sigc_npc);
|
1540 |
err |= __put_user(env->psr, &sc->sigc_psr);
|
1541 |
err |= __put_user(env->gregs[1], &sc->sigc_g1);
|
1542 |
err |= __put_user(env->regwptr[UREG_O0], &sc->sigc_o0);
|
1543 |
|
1544 |
return err;
|
1545 |
}
|
1546 |
#endif
|
1547 |
#define NF_ALIGNEDSZ (((sizeof(struct target_signal_frame) + 7) & (~7))) |
1548 |
|
1549 |
static void setup_frame(int sig, struct emulated_sigaction *ka, |
1550 |
target_sigset_t *set, CPUState *env) |
1551 |
{ |
1552 |
abi_ulong sf_addr; |
1553 |
struct target_signal_frame *sf;
|
1554 |
int sigframe_size, err, i;
|
1555 |
|
1556 |
/* 1. Make sure everything is clean */
|
1557 |
//synchronize_user_stack();
|
1558 |
|
1559 |
sigframe_size = NF_ALIGNEDSZ; |
1560 |
sf_addr = get_sigframe(ka, env, sigframe_size); |
1561 |
|
1562 |
sf = lock_user(VERIFY_WRITE, sf_addr, |
1563 |
sizeof(struct target_signal_frame), 0); |
1564 |
if (!sf)
|
1565 |
goto sigsegv;
|
1566 |
|
1567 |
//fprintf(stderr, "sf: %x pc %x fp %x sp %x\n", sf, env->pc, env->regwptr[UREG_FP], env->regwptr[UREG_SP]);
|
1568 |
#if 0
|
1569 |
if (invalid_frame_pointer(sf, sigframe_size))
|
1570 |
goto sigill_and_return;
|
1571 |
#endif
|
1572 |
/* 2. Save the current process state */
|
1573 |
err = setup___siginfo(&sf->info, env, set->sig[0]);
|
1574 |
err |= __put_user(0, &sf->extra_size);
|
1575 |
|
1576 |
//err |= save_fpu_state(regs, &sf->fpu_state);
|
1577 |
//err |= __put_user(&sf->fpu_state, &sf->fpu_save);
|
1578 |
|
1579 |
err |= __put_user(set->sig[0], &sf->info.si_mask);
|
1580 |
for (i = 0; i < TARGET_NSIG_WORDS - 1; i++) { |
1581 |
err |= __put_user(set->sig[i + 1], &sf->extramask[i]);
|
1582 |
} |
1583 |
|
1584 |
for (i = 0; i < 8; i++) { |
1585 |
err |= __put_user(env->regwptr[i + UREG_L0], &sf->ss.locals[i]); |
1586 |
} |
1587 |
for (i = 0; i < 8; i++) { |
1588 |
err |= __put_user(env->regwptr[i + UREG_I0], &sf->ss.ins[i]); |
1589 |
} |
1590 |
if (err)
|
1591 |
goto sigsegv;
|
1592 |
|
1593 |
/* 3. signal handler back-trampoline and parameters */
|
1594 |
env->regwptr[UREG_FP] = sf_addr; |
1595 |
env->regwptr[UREG_I0] = sig; |
1596 |
env->regwptr[UREG_I1] = sf_addr + |
1597 |
offsetof(struct target_signal_frame, info);
|
1598 |
env->regwptr[UREG_I2] = sf_addr + |
1599 |
offsetof(struct target_signal_frame, info);
|
1600 |
|
1601 |
/* 4. signal handler */
|
1602 |
env->pc = ka->sa._sa_handler; |
1603 |
env->npc = (env->pc + 4);
|
1604 |
/* 5. return to kernel instructions */
|
1605 |
if (ka->sa.sa_restorer)
|
1606 |
env->regwptr[UREG_I7] = ka->sa.sa_restorer; |
1607 |
else {
|
1608 |
uint32_t val32; |
1609 |
|
1610 |
env->regwptr[UREG_I7] = sf_addr + |
1611 |
offsetof(struct target_signal_frame, insns) - 2 * 4; |
1612 |
|
1613 |
/* mov __NR_sigreturn, %g1 */
|
1614 |
val32 = 0x821020d8;
|
1615 |
err |= __put_user(val32, &sf->insns[0]);
|
1616 |
|
1617 |
/* t 0x10 */
|
1618 |
val32 = 0x91d02010;
|
1619 |
err |= __put_user(val32, &sf->insns[1]);
|
1620 |
if (err)
|
1621 |
goto sigsegv;
|
1622 |
|
1623 |
/* Flush instruction space. */
|
1624 |
//flush_sig_insns(current->mm, (unsigned long) &(sf->insns[0]));
|
1625 |
// tb_flush(env);
|
1626 |
} |
1627 |
unlock_user(sf, sf_addr, sizeof(struct target_signal_frame)); |
1628 |
return;
|
1629 |
#if 0
|
1630 |
sigill_and_return:
|
1631 |
force_sig(TARGET_SIGILL);
|
1632 |
#endif
|
1633 |
sigsegv:
|
1634 |
//fprintf(stderr, "force_sig\n");
|
1635 |
unlock_user(sf, sf_addr, sizeof(struct target_signal_frame)); |
1636 |
force_sig(TARGET_SIGSEGV); |
1637 |
} |
1638 |
static inline int |
1639 |
restore_fpu_state(CPUState *env, qemu_siginfo_fpu_t *fpu) |
1640 |
{ |
1641 |
int err;
|
1642 |
#if 0
|
1643 |
#ifdef CONFIG_SMP
|
1644 |
if (current->flags & PF_USEDFPU)
|
1645 |
regs->psr &= ~PSR_EF;
|
1646 |
#else
|
1647 |
if (current == last_task_used_math) {
|
1648 |
last_task_used_math = 0;
|
1649 |
regs->psr &= ~PSR_EF; |
1650 |
} |
1651 |
#endif
|
1652 |
current->used_math = 1;
|
1653 |
current->flags &= ~PF_USEDFPU; |
1654 |
#endif
|
1655 |
#if 0
|
1656 |
if (verify_area (VERIFY_READ, fpu, sizeof(*fpu)))
|
1657 |
return -EFAULT;
|
1658 |
#endif
|
1659 |
|
1660 |
#if 0
|
1661 |
/* XXX: incorrect */
|
1662 |
err = __copy_from_user(&env->fpr[0], &fpu->si_float_regs[0],
|
1663 |
(sizeof(unsigned long) * 32));
|
1664 |
#endif
|
1665 |
err |= __get_user(env->fsr, &fpu->si_fsr); |
1666 |
#if 0
|
1667 |
err |= __get_user(current->thread.fpqdepth, &fpu->si_fpqdepth);
|
1668 |
if (current->thread.fpqdepth != 0)
|
1669 |
err |= __copy_from_user(¤t->thread.fpqueue[0],
|
1670 |
&fpu->si_fpqueue[0],
|
1671 |
((sizeof(unsigned long) +
|
1672 |
(sizeof(unsigned long *)))*16));
|
1673 |
#endif
|
1674 |
return err;
|
1675 |
} |
1676 |
|
1677 |
|
1678 |
static void setup_rt_frame(int sig, struct emulated_sigaction *ka, |
1679 |
target_siginfo_t *info, |
1680 |
target_sigset_t *set, CPUState *env) |
1681 |
{ |
1682 |
fprintf(stderr, "setup_rt_frame: not implemented\n");
|
1683 |
} |
1684 |
|
1685 |
long do_sigreturn(CPUState *env)
|
1686 |
{ |
1687 |
abi_ulong sf_addr; |
1688 |
struct target_signal_frame *sf;
|
1689 |
uint32_t up_psr, pc, npc; |
1690 |
target_sigset_t set; |
1691 |
sigset_t host_set; |
1692 |
abi_ulong fpu_save_addr; |
1693 |
int err, i;
|
1694 |
|
1695 |
sf_addr = env->regwptr[UREG_FP]; |
1696 |
if (!lock_user_struct(VERIFY_READ, sf, sf_addr, 1)) |
1697 |
goto segv_and_exit;
|
1698 |
#if 0
|
1699 |
fprintf(stderr, "sigreturn\n");
|
1700 |
fprintf(stderr, "sf: %x pc %x fp %x sp %x\n", sf, env->pc, env->regwptr[UREG_FP], env->regwptr[UREG_SP]);
|
1701 |
#endif
|
1702 |
//cpu_dump_state(env, stderr, fprintf, 0);
|
1703 |
|
1704 |
/* 1. Make sure we are not getting garbage from the user */
|
1705 |
|
1706 |
if (sf_addr & 3) |
1707 |
goto segv_and_exit;
|
1708 |
|
1709 |
err = __get_user(pc, &sf->info.si_regs.pc); |
1710 |
err |= __get_user(npc, &sf->info.si_regs.npc); |
1711 |
|
1712 |
if ((pc | npc) & 3) |
1713 |
goto segv_and_exit;
|
1714 |
|
1715 |
/* 2. Restore the state */
|
1716 |
err |= __get_user(up_psr, &sf->info.si_regs.psr); |
1717 |
|
1718 |
/* User can only change condition codes and FPU enabling in %psr. */
|
1719 |
env->psr = (up_psr & (PSR_ICC /* | PSR_EF */))
|
1720 |
| (env->psr & ~(PSR_ICC /* | PSR_EF */));
|
1721 |
|
1722 |
env->pc = pc; |
1723 |
env->npc = npc; |
1724 |
err |= __get_user(env->y, &sf->info.si_regs.y); |
1725 |
for (i=0; i < 8; i++) { |
1726 |
err |= __get_user(env->gregs[i], &sf->info.si_regs.u_regs[i]); |
1727 |
} |
1728 |
for (i=0; i < 8; i++) { |
1729 |
err |= __get_user(env->regwptr[i + UREG_I0], &sf->info.si_regs.u_regs[i+8]);
|
1730 |
} |
1731 |
|
1732 |
err |= __get_user(fpu_save_addr, &sf->fpu_save); |
1733 |
|
1734 |
//if (fpu_save)
|
1735 |
// err |= restore_fpu_state(env, fpu_save);
|
1736 |
|
1737 |
/* This is pretty much atomic, no amount locking would prevent
|
1738 |
* the races which exist anyways.
|
1739 |
*/
|
1740 |
err |= __get_user(set.sig[0], &sf->info.si_mask);
|
1741 |
for(i = 1; i < TARGET_NSIG_WORDS; i++) { |
1742 |
err |= (__get_user(set.sig[i], &sf->extramask[i - 1]));
|
1743 |
} |
1744 |
|
1745 |
target_to_host_sigset_internal(&host_set, &set); |
1746 |
sigprocmask(SIG_SETMASK, &host_set, NULL);
|
1747 |
|
1748 |
if (err)
|
1749 |
goto segv_and_exit;
|
1750 |
unlock_user_struct(sf, sf_addr, 0);
|
1751 |
return env->regwptr[0]; |
1752 |
|
1753 |
segv_and_exit:
|
1754 |
unlock_user_struct(sf, sf_addr, 0);
|
1755 |
force_sig(TARGET_SIGSEGV); |
1756 |
} |
1757 |
|
1758 |
long do_rt_sigreturn(CPUState *env)
|
1759 |
{ |
1760 |
fprintf(stderr, "do_rt_sigreturn: not implemented\n");
|
1761 |
return -TARGET_ENOSYS;
|
1762 |
} |
1763 |
|
1764 |
#if defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
|
1765 |
#define MC_TSTATE 0 |
1766 |
#define MC_PC 1 |
1767 |
#define MC_NPC 2 |
1768 |
#define MC_Y 3 |
1769 |
#define MC_G1 4 |
1770 |
#define MC_G2 5 |
1771 |
#define MC_G3 6 |
1772 |
#define MC_G4 7 |
1773 |
#define MC_G5 8 |
1774 |
#define MC_G6 9 |
1775 |
#define MC_G7 10 |
1776 |
#define MC_O0 11 |
1777 |
#define MC_O1 12 |
1778 |
#define MC_O2 13 |
1779 |
#define MC_O3 14 |
1780 |
#define MC_O4 15 |
1781 |
#define MC_O5 16 |
1782 |
#define MC_O6 17 |
1783 |
#define MC_O7 18 |
1784 |
#define MC_NGREG 19 |
1785 |
|
1786 |
typedef abi_ulong target_mc_greg_t;
|
1787 |
typedef target_mc_greg_t target_mc_gregset_t[MC_NGREG];
|
1788 |
|
1789 |
struct target_mc_fq {
|
1790 |
abi_ulong *mcfq_addr; |
1791 |
uint32_t mcfq_insn; |
1792 |
}; |
1793 |
|
1794 |
struct target_mc_fpu {
|
1795 |
union {
|
1796 |
uint32_t sregs[32];
|
1797 |
uint64_t dregs[32];
|
1798 |
//uint128_t qregs[16];
|
1799 |
} mcfpu_fregs; |
1800 |
abi_ulong mcfpu_fsr; |
1801 |
abi_ulong mcfpu_fprs; |
1802 |
abi_ulong mcfpu_gsr; |
1803 |
struct target_mc_fq *mcfpu_fq;
|
1804 |
unsigned char mcfpu_qcnt; |
1805 |
unsigned char mcfpu_qentsz; |
1806 |
unsigned char mcfpu_enab; |
1807 |
}; |
1808 |
typedef struct target_mc_fpu target_mc_fpu_t; |
1809 |
|
1810 |
typedef struct { |
1811 |
target_mc_gregset_t mc_gregs; |
1812 |
target_mc_greg_t mc_fp; |
1813 |
target_mc_greg_t mc_i7; |
1814 |
target_mc_fpu_t mc_fpregs; |
1815 |
} target_mcontext_t; |
1816 |
|
1817 |
struct target_ucontext {
|
1818 |
struct target_ucontext *uc_link;
|
1819 |
abi_ulong uc_flags; |
1820 |
target_sigset_t uc_sigmask; |
1821 |
target_mcontext_t uc_mcontext; |
1822 |
}; |
1823 |
|
1824 |
/* A V9 register window */
|
1825 |
struct target_reg_window {
|
1826 |
abi_ulong locals[8];
|
1827 |
abi_ulong ins[8];
|
1828 |
}; |
1829 |
|
1830 |
#define TARGET_STACK_BIAS 2047 |
1831 |
|
1832 |
/* {set, get}context() needed for 64-bit SparcLinux userland. */
|
1833 |
void sparc64_set_context(CPUSPARCState *env)
|
1834 |
{ |
1835 |
abi_ulong ucp_addr; |
1836 |
struct target_ucontext *ucp;
|
1837 |
target_mc_gregset_t *grp; |
1838 |
abi_ulong pc, npc, tstate; |
1839 |
abi_ulong fp, i7, w_addr; |
1840 |
unsigned char fenab; |
1841 |
int err;
|
1842 |
unsigned int i; |
1843 |
|
1844 |
ucp_addr = env->regwptr[UREG_I0]; |
1845 |
if (!lock_user_struct(VERIFY_READ, ucp, ucp_addr, 1)) |
1846 |
goto do_sigsegv;
|
1847 |
grp = &ucp->uc_mcontext.mc_gregs; |
1848 |
err = __get_user(pc, &((*grp)[MC_PC])); |
1849 |
err |= __get_user(npc, &((*grp)[MC_NPC])); |
1850 |
if (err || ((pc | npc) & 3)) |
1851 |
goto do_sigsegv;
|
1852 |
if (env->regwptr[UREG_I1]) {
|
1853 |
target_sigset_t target_set; |
1854 |
sigset_t set; |
1855 |
|
1856 |
if (TARGET_NSIG_WORDS == 1) { |
1857 |
if (__get_user(target_set.sig[0], &ucp->uc_sigmask.sig[0])) |
1858 |
goto do_sigsegv;
|
1859 |
} else {
|
1860 |
abi_ulong *src, *dst; |
1861 |
src = ucp->uc_sigmask.sig; |
1862 |
dst = target_set.sig; |
1863 |
for (i = 0; i < sizeof(target_sigset_t) / sizeof(abi_ulong); |
1864 |
i++, dst++, src++) |
1865 |
err |= __get_user(*dst, src); |
1866 |
if (err)
|
1867 |
goto do_sigsegv;
|
1868 |
} |
1869 |
target_to_host_sigset_internal(&set, &target_set); |
1870 |
sigprocmask(SIG_SETMASK, &set, NULL);
|
1871 |
} |
1872 |
env->pc = pc; |
1873 |
env->npc = npc; |
1874 |
err |= __get_user(env->y, &((*grp)[MC_Y])); |
1875 |
err |= __get_user(tstate, &((*grp)[MC_TSTATE])); |
1876 |
env->asi = (tstate >> 24) & 0xff; |
1877 |
PUT_CCR(env, tstate >> 32);
|
1878 |
PUT_CWP64(env, tstate & 0x1f);
|
1879 |
err |= __get_user(env->gregs[1], (&(*grp)[MC_G1]));
|
1880 |
err |= __get_user(env->gregs[2], (&(*grp)[MC_G2]));
|
1881 |
err |= __get_user(env->gregs[3], (&(*grp)[MC_G3]));
|
1882 |
err |= __get_user(env->gregs[4], (&(*grp)[MC_G4]));
|
1883 |
err |= __get_user(env->gregs[5], (&(*grp)[MC_G5]));
|
1884 |
err |= __get_user(env->gregs[6], (&(*grp)[MC_G6]));
|
1885 |
err |= __get_user(env->gregs[7], (&(*grp)[MC_G7]));
|
1886 |
err |= __get_user(env->regwptr[UREG_I0], (&(*grp)[MC_O0])); |
1887 |
err |= __get_user(env->regwptr[UREG_I1], (&(*grp)[MC_O1])); |
1888 |
err |= __get_user(env->regwptr[UREG_I2], (&(*grp)[MC_O2])); |
1889 |
err |= __get_user(env->regwptr[UREG_I3], (&(*grp)[MC_O3])); |
1890 |
err |= __get_user(env->regwptr[UREG_I4], (&(*grp)[MC_O4])); |
1891 |
err |= __get_user(env->regwptr[UREG_I5], (&(*grp)[MC_O5])); |
1892 |
err |= __get_user(env->regwptr[UREG_I6], (&(*grp)[MC_O6])); |
1893 |
err |= __get_user(env->regwptr[UREG_I7], (&(*grp)[MC_O7])); |
1894 |
|
1895 |
err |= __get_user(fp, &(ucp->uc_mcontext.mc_fp)); |
1896 |
err |= __get_user(i7, &(ucp->uc_mcontext.mc_i7)); |
1897 |
|
1898 |
w_addr = TARGET_STACK_BIAS+env->regwptr[UREG_I6]; |
1899 |
if (put_user(fp, w_addr + offsetof(struct target_reg_window, ins[6]), |
1900 |
abi_ulong) != 0)
|
1901 |
goto do_sigsegv;
|
1902 |
if (put_user(i7, w_addr + offsetof(struct target_reg_window, ins[7]), |
1903 |
abi_ulong) != 0)
|
1904 |
goto do_sigsegv;
|
1905 |
err |= __get_user(fenab, &(ucp->uc_mcontext.mc_fpregs.mcfpu_enab)); |
1906 |
err |= __get_user(env->fprs, &(ucp->uc_mcontext.mc_fpregs.mcfpu_fprs)); |
1907 |
{ |
1908 |
uint32_t *src, *dst; |
1909 |
src = ucp->uc_mcontext.mc_fpregs.mcfpu_fregs.sregs; |
1910 |
dst = env->fpr; |
1911 |
/* XXX: check that the CPU storage is the same as user context */
|
1912 |
for (i = 0; i < 64; i++, dst++, src++) |
1913 |
err |= __get_user(*dst, src); |
1914 |
} |
1915 |
err |= __get_user(env->fsr, |
1916 |
&(ucp->uc_mcontext.mc_fpregs.mcfpu_fsr)); |
1917 |
err |= __get_user(env->gsr, |
1918 |
&(ucp->uc_mcontext.mc_fpregs.mcfpu_gsr)); |
1919 |
if (err)
|
1920 |
goto do_sigsegv;
|
1921 |
unlock_user_struct(ucp, ucp_addr, 0);
|
1922 |
return;
|
1923 |
do_sigsegv:
|
1924 |
unlock_user_struct(ucp, ucp_addr, 0);
|
1925 |
force_sig(SIGSEGV); |
1926 |
} |
1927 |
|
1928 |
void sparc64_get_context(CPUSPARCState *env)
|
1929 |
{ |
1930 |
abi_ulong ucp_addr; |
1931 |
struct target_ucontext *ucp;
|
1932 |
target_mc_gregset_t *grp; |
1933 |
target_mcontext_t *mcp; |
1934 |
abi_ulong fp, i7, w_addr; |
1935 |
int err;
|
1936 |
unsigned int i; |
1937 |
target_sigset_t target_set; |
1938 |
sigset_t set; |
1939 |
|
1940 |
ucp_addr = env->regwptr[UREG_I0]; |
1941 |
if (!lock_user_struct(VERIFY_WRITE, ucp, ucp_addr, 0)) |
1942 |
goto do_sigsegv;
|
1943 |
|
1944 |
mcp = &ucp->uc_mcontext; |
1945 |
grp = &mcp->mc_gregs; |
1946 |
|
1947 |
/* Skip over the trap instruction, first. */
|
1948 |
env->pc = env->npc; |
1949 |
env->npc += 4;
|
1950 |
|
1951 |
err = 0;
|
1952 |
|
1953 |
sigprocmask(0, NULL, &set); |
1954 |
host_to_target_sigset_internal(&target_set, &set); |
1955 |
if (TARGET_NSIG_WORDS == 1) { |
1956 |
err |= __put_user(target_set.sig[0],
|
1957 |
(abi_ulong *)&ucp->uc_sigmask); |
1958 |
} else {
|
1959 |
abi_ulong *src, *dst; |
1960 |
src = target_set.sig; |
1961 |
dst = ucp->uc_sigmask.sig; |
1962 |
for (i = 0; i < sizeof(target_sigset_t) / sizeof(abi_ulong); |
1963 |
i++, dst++, src++) |
1964 |
err |= __put_user(*src, dst); |
1965 |
if (err)
|
1966 |
goto do_sigsegv;
|
1967 |
} |
1968 |
|
1969 |
/* XXX: tstate must be saved properly */
|
1970 |
// err |= __put_user(env->tstate, &((*grp)[MC_TSTATE]));
|
1971 |
err |= __put_user(env->pc, &((*grp)[MC_PC])); |
1972 |
err |= __put_user(env->npc, &((*grp)[MC_NPC])); |
1973 |
err |= __put_user(env->y, &((*grp)[MC_Y])); |
1974 |
err |= __put_user(env->gregs[1], &((*grp)[MC_G1]));
|
1975 |
err |= __put_user(env->gregs[2], &((*grp)[MC_G2]));
|
1976 |
err |= __put_user(env->gregs[3], &((*grp)[MC_G3]));
|
1977 |
err |= __put_user(env->gregs[4], &((*grp)[MC_G4]));
|
1978 |
err |= __put_user(env->gregs[5], &((*grp)[MC_G5]));
|
1979 |
err |= __put_user(env->gregs[6], &((*grp)[MC_G6]));
|
1980 |
err |= __put_user(env->gregs[7], &((*grp)[MC_G7]));
|
1981 |
err |= __put_user(env->regwptr[UREG_I0], &((*grp)[MC_O0])); |
1982 |
err |= __put_user(env->regwptr[UREG_I1], &((*grp)[MC_O1])); |
1983 |
err |= __put_user(env->regwptr[UREG_I2], &((*grp)[MC_O2])); |
1984 |
err |= __put_user(env->regwptr[UREG_I3], &((*grp)[MC_O3])); |
1985 |
err |= __put_user(env->regwptr[UREG_I4], &((*grp)[MC_O4])); |
1986 |
err |= __put_user(env->regwptr[UREG_I5], &((*grp)[MC_O5])); |
1987 |
err |= __put_user(env->regwptr[UREG_I6], &((*grp)[MC_O6])); |
1988 |
err |= __put_user(env->regwptr[UREG_I7], &((*grp)[MC_O7])); |
1989 |
|
1990 |
w_addr = TARGET_STACK_BIAS+env->regwptr[UREG_I6]; |
1991 |
fp = i7 = 0;
|
1992 |
if (get_user(fp, w_addr + offsetof(struct target_reg_window, ins[6]), |
1993 |
abi_ulong) != 0)
|
1994 |
goto do_sigsegv;
|
1995 |
if (get_user(i7, w_addr + offsetof(struct target_reg_window, ins[7]), |
1996 |
abi_ulong) != 0)
|
1997 |
goto do_sigsegv;
|
1998 |
err |= __put_user(fp, &(mcp->mc_fp)); |
1999 |
err |= __put_user(i7, &(mcp->mc_i7)); |
2000 |
|
2001 |
{ |
2002 |
uint32_t *src, *dst; |
2003 |
src = env->fpr; |
2004 |
dst = ucp->uc_mcontext.mc_fpregs.mcfpu_fregs.sregs; |
2005 |
/* XXX: check that the CPU storage is the same as user context */
|
2006 |
for (i = 0; i < 64; i++, dst++, src++) |
2007 |
err |= __put_user(*src, dst); |
2008 |
} |
2009 |
err |= __put_user(env->fsr, &(mcp->mc_fpregs.mcfpu_fsr)); |
2010 |
err |= __put_user(env->gsr, &(mcp->mc_fpregs.mcfpu_gsr)); |
2011 |
err |= __put_user(env->fprs, &(mcp->mc_fpregs.mcfpu_fprs)); |
2012 |
|
2013 |
if (err)
|
2014 |
goto do_sigsegv;
|
2015 |
unlock_user_struct(ucp, ucp_addr, 1);
|
2016 |
return;
|
2017 |
do_sigsegv:
|
2018 |
unlock_user_struct(ucp, ucp_addr, 1);
|
2019 |
force_sig(SIGSEGV); |
2020 |
} |
2021 |
#endif
|
2022 |
#elif defined(TARGET_ABI_MIPSN64)
|
2023 |
|
2024 |
# warning signal handling not implemented
|
2025 |
|
2026 |
static void setup_frame(int sig, struct emulated_sigaction *ka, |
2027 |
target_sigset_t *set, CPUState *env) |
2028 |
{ |
2029 |
fprintf(stderr, "setup_frame: not implemented\n");
|
2030 |
} |
2031 |
|
2032 |
static void setup_rt_frame(int sig, struct emulated_sigaction *ka, |
2033 |
target_siginfo_t *info, |
2034 |
target_sigset_t *set, CPUState *env) |
2035 |
{ |
2036 |
fprintf(stderr, "setup_rt_frame: not implemented\n");
|
2037 |
} |
2038 |
|
2039 |
long do_sigreturn(CPUState *env)
|
2040 |
{ |
2041 |
fprintf(stderr, "do_sigreturn: not implemented\n");
|
2042 |
return -TARGET_ENOSYS;
|
2043 |
} |
2044 |
|
2045 |
long do_rt_sigreturn(CPUState *env)
|
2046 |
{ |
2047 |
fprintf(stderr, "do_rt_sigreturn: not implemented\n");
|
2048 |
return -TARGET_ENOSYS;
|
2049 |
} |
2050 |
|
2051 |
#elif defined(TARGET_ABI_MIPSN32)
|
2052 |
|
2053 |
# warning signal handling not implemented
|
2054 |
|
2055 |
static void setup_frame(int sig, struct emulated_sigaction *ka, |
2056 |
target_sigset_t *set, CPUState *env) |
2057 |
{ |
2058 |
fprintf(stderr, "setup_frame: not implemented\n");
|
2059 |
} |
2060 |
|
2061 |
static void setup_rt_frame(int sig, struct emulated_sigaction *ka, |
2062 |
target_siginfo_t *info, |
2063 |
target_sigset_t *set, CPUState *env) |
2064 |
{ |
2065 |
fprintf(stderr, "setup_rt_frame: not implemented\n");
|
2066 |
} |
2067 |
|
2068 |
long do_sigreturn(CPUState *env)
|
2069 |
{ |
2070 |
fprintf(stderr, "do_sigreturn: not implemented\n");
|
2071 |
return -TARGET_ENOSYS;
|
2072 |
} |
2073 |
|
2074 |
long do_rt_sigreturn(CPUState *env)
|
2075 |
{ |
2076 |
fprintf(stderr, "do_rt_sigreturn: not implemented\n");
|
2077 |
return -TARGET_ENOSYS;
|
2078 |
} |
2079 |
|
2080 |
#elif defined(TARGET_ABI_MIPSO32)
|
2081 |
|
2082 |
struct target_sigcontext {
|
2083 |
uint32_t sc_regmask; /* Unused */
|
2084 |
uint32_t sc_status; |
2085 |
uint64_t sc_pc; |
2086 |
uint64_t sc_regs[32];
|
2087 |
uint64_t sc_fpregs[32];
|
2088 |
uint32_t sc_ownedfp; /* Unused */
|
2089 |
uint32_t sc_fpc_csr; |
2090 |
uint32_t sc_fpc_eir; /* Unused */
|
2091 |
uint32_t sc_used_math; |
2092 |
uint32_t sc_dsp; /* dsp status, was sc_ssflags */
|
2093 |
uint64_t sc_mdhi; |
2094 |
uint64_t sc_mdlo; |
2095 |
target_ulong sc_hi1; /* Was sc_cause */
|
2096 |
target_ulong sc_lo1; /* Was sc_badvaddr */
|
2097 |
target_ulong sc_hi2; /* Was sc_sigset[4] */
|
2098 |
target_ulong sc_lo2; |
2099 |
target_ulong sc_hi3; |
2100 |
target_ulong sc_lo3; |
2101 |
}; |
2102 |
|
2103 |
struct sigframe {
|
2104 |
uint32_t sf_ass[4]; /* argument save space for o32 */ |
2105 |
uint32_t sf_code[2]; /* signal trampoline */ |
2106 |
struct target_sigcontext sf_sc;
|
2107 |
target_sigset_t sf_mask; |
2108 |
}; |
2109 |
|
2110 |
/* Install trampoline to jump back from signal handler */
|
2111 |
static inline int install_sigtramp(unsigned int *tramp, unsigned int syscall) |
2112 |
{ |
2113 |
int err;
|
2114 |
|
2115 |
/*
|
2116 |
* Set up the return code ...
|
2117 |
*
|
2118 |
* li v0, __NR__foo_sigreturn
|
2119 |
* syscall
|
2120 |
*/
|
2121 |
|
2122 |
err = __put_user(0x24020000 + syscall, tramp + 0); |
2123 |
err |= __put_user(0x0000000c , tramp + 1); |
2124 |
/* flush_cache_sigtramp((unsigned long) tramp); */
|
2125 |
return err;
|
2126 |
} |
2127 |
|
2128 |
static inline int |
2129 |
setup_sigcontext(CPUState *regs, struct target_sigcontext *sc)
|
2130 |
{ |
2131 |
int err = 0; |
2132 |
|
2133 |
err |= __put_user(regs->PC[regs->current_tc], &sc->sc_pc); |
2134 |
|
2135 |
#define save_gp_reg(i) do { \ |
2136 |
err |= __put_user(regs->gpr[i][regs->current_tc], &sc->sc_regs[i]); \ |
2137 |
} while(0) |
2138 |
__put_user(0, &sc->sc_regs[0]); save_gp_reg(1); save_gp_reg(2); |
2139 |
save_gp_reg(3); save_gp_reg(4); save_gp_reg(5); save_gp_reg(6); |
2140 |
save_gp_reg(7); save_gp_reg(8); save_gp_reg(9); save_gp_reg(10); |
2141 |
save_gp_reg(11); save_gp_reg(12); save_gp_reg(13); save_gp_reg(14); |
2142 |
save_gp_reg(15); save_gp_reg(16); save_gp_reg(17); save_gp_reg(18); |
2143 |
save_gp_reg(19); save_gp_reg(20); save_gp_reg(21); save_gp_reg(22); |
2144 |
save_gp_reg(23); save_gp_reg(24); save_gp_reg(25); save_gp_reg(26); |
2145 |
save_gp_reg(27); save_gp_reg(28); save_gp_reg(29); save_gp_reg(30); |
2146 |
save_gp_reg(31);
|
2147 |
#undef save_gp_reg
|
2148 |
|
2149 |
err |= __put_user(regs->HI[0][regs->current_tc], &sc->sc_mdhi);
|
2150 |
err |= __put_user(regs->LO[0][regs->current_tc], &sc->sc_mdlo);
|
2151 |
|
2152 |
/* Not used yet, but might be useful if we ever have DSP suppport */
|
2153 |
#if 0
|
2154 |
if (cpu_has_dsp) {
|
2155 |
err |= __put_user(mfhi1(), &sc->sc_hi1);
|
2156 |
err |= __put_user(mflo1(), &sc->sc_lo1);
|
2157 |
err |= __put_user(mfhi2(), &sc->sc_hi2);
|
2158 |
err |= __put_user(mflo2(), &sc->sc_lo2);
|
2159 |
err |= __put_user(mfhi3(), &sc->sc_hi3);
|
2160 |
err |= __put_user(mflo3(), &sc->sc_lo3);
|
2161 |
err |= __put_user(rddsp(DSP_MASK), &sc->sc_dsp);
|
2162 |
}
|
2163 |
/* same with 64 bit */
|
2164 |
#ifdef CONFIG_64BIT
|
2165 |
err |= __put_user(regs->hi, &sc->sc_hi[0]);
|
2166 |
err |= __put_user(regs->lo, &sc->sc_lo[0]);
|
2167 |
if (cpu_has_dsp) {
|
2168 |
err |= __put_user(mfhi1(), &sc->sc_hi[1]);
|
2169 |
err |= __put_user(mflo1(), &sc->sc_lo[1]);
|
2170 |
err |= __put_user(mfhi2(), &sc->sc_hi[2]);
|
2171 |
err |= __put_user(mflo2(), &sc->sc_lo[2]);
|
2172 |
err |= __put_user(mfhi3(), &sc->sc_hi[3]);
|
2173 |
err |= __put_user(mflo3(), &sc->sc_lo[3]);
|
2174 |
err |= __put_user(rddsp(DSP_MASK), &sc->sc_dsp);
|
2175 |
}
|
2176 |
#endif
|
2177 |
#endif
|
2178 |
|
2179 |
#if 0
|
2180 |
err |= __put_user(!!used_math(), &sc->sc_used_math);
|
2181 |
|
2182 |
if (!used_math())
|
2183 |
goto out;
|
2184 |
|
2185 |
/*
|
2186 |
* Save FPU state to signal context. Signal handler will "inherit"
|
2187 |
* current FPU state.
|
2188 |
*/
|
2189 |
preempt_disable();
|
2190 |
|
2191 |
if (!is_fpu_owner()) {
|
2192 |
own_fpu();
|
2193 |
restore_fp(current);
|
2194 |
}
|
2195 |
err |= save_fp_context(sc);
|
2196 |
|
2197 |
preempt_enable();
|
2198 |
out:
|
2199 |
#endif
|
2200 |
return err;
|
2201 |
} |
2202 |
|
2203 |
static inline int |
2204 |
restore_sigcontext(CPUState *regs, struct target_sigcontext *sc)
|
2205 |
{ |
2206 |
int err = 0; |
2207 |
|
2208 |
err |= __get_user(regs->CP0_EPC, &sc->sc_pc); |
2209 |
|
2210 |
err |= __get_user(regs->HI[0][regs->current_tc], &sc->sc_mdhi);
|
2211 |
err |= __get_user(regs->LO[0][regs->current_tc], &sc->sc_mdlo);
|
2212 |
|
2213 |
#define restore_gp_reg(i) do { \ |
2214 |
err |= __get_user(regs->gpr[i][regs->current_tc], &sc->sc_regs[i]); \ |
2215 |
} while(0) |
2216 |
restore_gp_reg( 1); restore_gp_reg( 2); restore_gp_reg( 3); |
2217 |
restore_gp_reg( 4); restore_gp_reg( 5); restore_gp_reg( 6); |
2218 |
restore_gp_reg( 7); restore_gp_reg( 8); restore_gp_reg( 9); |
2219 |
restore_gp_reg(10); restore_gp_reg(11); restore_gp_reg(12); |
2220 |
restore_gp_reg(13); restore_gp_reg(14); restore_gp_reg(15); |
2221 |
restore_gp_reg(16); restore_gp_reg(17); restore_gp_reg(18); |
2222 |
restore_gp_reg(19); restore_gp_reg(20); restore_gp_reg(21); |
2223 |
restore_gp_reg(22); restore_gp_reg(23); restore_gp_reg(24); |
2224 |
restore_gp_reg(25); restore_gp_reg(26); restore_gp_reg(27); |
2225 |
restore_gp_reg(28); restore_gp_reg(29); restore_gp_reg(30); |
2226 |
restore_gp_reg(31);
|
2227 |
#undef restore_gp_reg
|
2228 |
|
2229 |
#if 0
|
2230 |
if (cpu_has_dsp) {
|
2231 |
err |= __get_user(treg, &sc->sc_hi1); mthi1(treg);
|
2232 |
err |= __get_user(treg, &sc->sc_lo1); mtlo1(treg);
|
2233 |
err |= __get_user(treg, &sc->sc_hi2); mthi2(treg);
|
2234 |
err |= __get_user(treg, &sc->sc_lo2); mtlo2(treg);
|
2235 |
err |= __get_user(treg, &sc->sc_hi3); mthi3(treg);
|
2236 |
err |= __get_user(treg, &sc->sc_lo3); mtlo3(treg);
|
2237 |
err |= __get_user(treg, &sc->sc_dsp); wrdsp(treg, DSP_MASK);
|
2238 |
}
|
2239 |
#ifdef CONFIG_64BIT
|
2240 |
err |= __get_user(regs->hi, &sc->sc_hi[0]);
|
2241 |
err |= __get_user(regs->lo, &sc->sc_lo[0]);
|
2242 |
if (cpu_has_dsp) {
|
2243 |
err |= __get_user(treg, &sc->sc_hi[1]); mthi1(treg);
|
2244 |
err |= __get_user(treg, &sc->sc_lo[1]); mthi1(treg);
|
2245 |
err |= __get_user(treg, &sc->sc_hi[2]); mthi2(treg);
|
2246 |
err |= __get_user(treg, &sc->sc_lo[2]); mthi2(treg);
|
2247 |
err |= __get_user(treg, &sc->sc_hi[3]); mthi3(treg);
|
2248 |
err |= __get_user(treg, &sc->sc_lo[3]); mthi3(treg);
|
2249 |
err |= __get_user(treg, &sc->sc_dsp); wrdsp(treg, DSP_MASK);
|
2250 |
}
|
2251 |
#endif
|
2252 |
|
2253 |
err |= __get_user(used_math, &sc->sc_used_math); |
2254 |
conditional_used_math(used_math); |
2255 |
|
2256 |
preempt_disable(); |
2257 |
|
2258 |
if (used_math()) {
|
2259 |
/* restore fpu context if we have used it before */
|
2260 |
own_fpu(); |
2261 |
err |= restore_fp_context(sc); |
2262 |
} else {
|
2263 |
/* signal handler may have used FPU. Give it up. */
|
2264 |
lose_fpu(); |
2265 |
} |
2266 |
|
2267 |
preempt_enable(); |
2268 |
#endif
|
2269 |
return err;
|
2270 |
} |
2271 |
/*
|
2272 |
* Determine which stack to use..
|
2273 |
*/
|
2274 |
static inline abi_ulong |
2275 |
get_sigframe(struct emulated_sigaction *ka, CPUState *regs, size_t frame_size)
|
2276 |
{ |
2277 |
unsigned long sp; |
2278 |
|
2279 |
/* Default to using normal stack */
|
2280 |
sp = regs->gpr[29][regs->current_tc];
|
2281 |
|
2282 |
/*
|
2283 |
* FPU emulator may have it's own trampoline active just
|
2284 |
* above the user stack, 16-bytes before the next lowest
|
2285 |
* 16 byte boundary. Try to avoid trashing it.
|
2286 |
*/
|
2287 |
sp -= 32;
|
2288 |
|
2289 |
/* This is the X/Open sanctioned signal stack switching. */
|
2290 |
if ((ka->sa.sa_flags & TARGET_SA_ONSTACK) && (sas_ss_flags (sp) == 0)) { |
2291 |
sp = target_sigaltstack_used.ss_sp + target_sigaltstack_used.ss_size; |
2292 |
} |
2293 |
|
2294 |
return (sp - frame_size) & ~7; |
2295 |
} |
2296 |
|
2297 |
/* compare linux/arch/mips/kernel/signal.c:setup_frame() */
|
2298 |
static void setup_frame(int sig, struct emulated_sigaction * ka, |
2299 |
target_sigset_t *set, CPUState *regs) |
2300 |
{ |
2301 |
struct sigframe *frame;
|
2302 |
abi_ulong frame_addr; |
2303 |
int i;
|
2304 |
|
2305 |
frame_addr = get_sigframe(ka, regs, sizeof(*frame));
|
2306 |
if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) |
2307 |
goto give_sigsegv;
|
2308 |
|
2309 |
install_sigtramp(frame->sf_code, TARGET_NR_sigreturn); |
2310 |
|
2311 |
if(setup_sigcontext(regs, &frame->sf_sc))
|
2312 |
goto give_sigsegv;
|
2313 |
|
2314 |
for(i = 0; i < TARGET_NSIG_WORDS; i++) { |
2315 |
if(__put_user(set->sig[i], &frame->sf_mask.sig[i]))
|
2316 |
goto give_sigsegv;
|
2317 |
} |
2318 |
|
2319 |
/*
|
2320 |
* Arguments to signal handler:
|
2321 |
*
|
2322 |
* a0 = signal number
|
2323 |
* a1 = 0 (should be cause)
|
2324 |
* a2 = pointer to struct sigcontext
|
2325 |
*
|
2326 |
* $25 and PC point to the signal handler, $29 points to the
|
2327 |
* struct sigframe.
|
2328 |
*/
|
2329 |
regs->gpr[ 4][regs->current_tc] = sig;
|
2330 |
regs->gpr[ 5][regs->current_tc] = 0; |
2331 |
regs->gpr[ 6][regs->current_tc] = frame_addr + offsetof(struct sigframe, sf_sc); |
2332 |
regs->gpr[29][regs->current_tc] = frame_addr;
|
2333 |
regs->gpr[31][regs->current_tc] = frame_addr + offsetof(struct sigframe, sf_code); |
2334 |
/* The original kernel code sets CP0_EPC to the handler
|
2335 |
* since it returns to userland using eret
|
2336 |
* we cannot do this here, and we must set PC directly */
|
2337 |
regs->PC[regs->current_tc] = regs->gpr[25][regs->current_tc] = ka->sa._sa_handler;
|
2338 |
unlock_user_struct(frame, frame_addr, 1);
|
2339 |
return;
|
2340 |
|
2341 |
give_sigsegv:
|
2342 |
unlock_user_struct(frame, frame_addr, 1);
|
2343 |
force_sig(TARGET_SIGSEGV/*, current*/);
|
2344 |
return;
|
2345 |
} |
2346 |
|
2347 |
long do_sigreturn(CPUState *regs)
|
2348 |
{ |
2349 |
struct sigframe *frame;
|
2350 |
abi_ulong frame_addr; |
2351 |
sigset_t blocked; |
2352 |
target_sigset_t target_set; |
2353 |
int i;
|
2354 |
|
2355 |
#if defined(DEBUG_SIGNAL)
|
2356 |
fprintf(stderr, "do_sigreturn\n");
|
2357 |
#endif
|
2358 |
frame_addr = regs->gpr[29][regs->current_tc];
|
2359 |
if (!lock_user_struct(VERIFY_READ, frame, frame_addr, 1)) |
2360 |
goto badframe;
|
2361 |
|
2362 |
for(i = 0; i < TARGET_NSIG_WORDS; i++) { |
2363 |
if(__get_user(target_set.sig[i], &frame->sf_mask.sig[i]))
|
2364 |
goto badframe;
|
2365 |
} |
2366 |
|
2367 |
target_to_host_sigset_internal(&blocked, &target_set); |
2368 |
sigprocmask(SIG_SETMASK, &blocked, NULL);
|
2369 |
|
2370 |
if (restore_sigcontext(regs, &frame->sf_sc))
|
2371 |
goto badframe;
|
2372 |
|
2373 |
#if 0
|
2374 |
/*
|
2375 |
* Don't let your children do this ...
|
2376 |
*/
|
2377 |
__asm__ __volatile__(
|
2378 |
"move\t$29, %0\n\t"
|
2379 |
"j\tsyscall_exit"
|
2380 |
:/* no outputs */
|
2381 |
:"r" (®s));
|
2382 |
/* Unreached */
|
2383 |
#endif
|
2384 |
|
2385 |
regs->PC[regs->current_tc] = regs->CP0_EPC; |
2386 |
/* I am not sure this is right, but it seems to work
|
2387 |
* maybe a problem with nested signals ? */
|
2388 |
regs->CP0_EPC = 0;
|
2389 |
return 0; |
2390 |
|
2391 |
badframe:
|
2392 |
force_sig(TARGET_SIGSEGV/*, current*/);
|
2393 |
return 0; |
2394 |
} |
2395 |
|
2396 |
static void setup_rt_frame(int sig, struct emulated_sigaction *ka, |
2397 |
target_siginfo_t *info, |
2398 |
target_sigset_t *set, CPUState *env) |
2399 |
{ |
2400 |
fprintf(stderr, "setup_rt_frame: not implemented\n");
|
2401 |
} |
2402 |
|
2403 |
long do_rt_sigreturn(CPUState *env)
|
2404 |
{ |
2405 |
fprintf(stderr, "do_rt_sigreturn: not implemented\n");
|
2406 |
return -TARGET_ENOSYS;
|
2407 |
} |
2408 |
|
2409 |
#else
|
2410 |
|
2411 |
static void setup_frame(int sig, struct emulated_sigaction *ka, |
2412 |
target_sigset_t *set, CPUState *env) |
2413 |
{ |
2414 |
fprintf(stderr, "setup_frame: not implemented\n");
|
2415 |
} |
2416 |
|
2417 |
static void setup_rt_frame(int sig, struct emulated_sigaction *ka, |
2418 |
target_siginfo_t *info, |
2419 |
target_sigset_t *set, CPUState *env) |
2420 |
{ |
2421 |
fprintf(stderr, "setup_rt_frame: not implemented\n");
|
2422 |
} |
2423 |
|
2424 |
long do_sigreturn(CPUState *env)
|
2425 |
{ |
2426 |
fprintf(stderr, "do_sigreturn: not implemented\n");
|
2427 |
return -TARGET_ENOSYS;
|
2428 |
} |
2429 |
|
2430 |
long do_rt_sigreturn(CPUState *env)
|
2431 |
{ |
2432 |
fprintf(stderr, "do_rt_sigreturn: not implemented\n");
|
2433 |
return -TARGET_ENOSYS;
|
2434 |
} |
2435 |
|
2436 |
#endif
|
2437 |
|
2438 |
void process_pending_signals(void *cpu_env) |
2439 |
{ |
2440 |
int sig;
|
2441 |
abi_ulong handler; |
2442 |
sigset_t set, old_set; |
2443 |
target_sigset_t target_old_set; |
2444 |
struct emulated_sigaction *k;
|
2445 |
struct sigqueue *q;
|
2446 |
|
2447 |
if (!signal_pending)
|
2448 |
return;
|
2449 |
|
2450 |
k = sigact_table; |
2451 |
for(sig = 1; sig <= TARGET_NSIG; sig++) { |
2452 |
if (k->pending)
|
2453 |
goto handle_signal;
|
2454 |
k++; |
2455 |
} |
2456 |
/* if no signal is pending, just return */
|
2457 |
signal_pending = 0;
|
2458 |
return;
|
2459 |
|
2460 |
handle_signal:
|
2461 |
#ifdef DEBUG_SIGNAL
|
2462 |
fprintf(stderr, "qemu: process signal %d\n", sig);
|
2463 |
#endif
|
2464 |
/* dequeue signal */
|
2465 |
q = k->first; |
2466 |
k->first = q->next; |
2467 |
if (!k->first)
|
2468 |
k->pending = 0;
|
2469 |
|
2470 |
sig = gdb_handlesig (cpu_env, sig); |
2471 |
if (!sig) {
|
2472 |
fprintf (stderr, "Lost signal\n");
|
2473 |
abort(); |
2474 |
} |
2475 |
|
2476 |
handler = k->sa._sa_handler; |
2477 |
if (handler == TARGET_SIG_DFL) {
|
2478 |
/* default handler : ignore some signal. The other are fatal */
|
2479 |
if (sig != TARGET_SIGCHLD &&
|
2480 |
sig != TARGET_SIGURG && |
2481 |
sig != TARGET_SIGWINCH) { |
2482 |
force_sig(sig); |
2483 |
} |
2484 |
} else if (handler == TARGET_SIG_IGN) { |
2485 |
/* ignore sig */
|
2486 |
} else if (handler == TARGET_SIG_ERR) { |
2487 |
force_sig(sig); |
2488 |
} else {
|
2489 |
/* compute the blocked signals during the handler execution */
|
2490 |
target_to_host_sigset(&set, &k->sa.sa_mask); |
2491 |
/* SA_NODEFER indicates that the current signal should not be
|
2492 |
blocked during the handler */
|
2493 |
if (!(k->sa.sa_flags & TARGET_SA_NODEFER))
|
2494 |
sigaddset(&set, target_to_host_signal(sig)); |
2495 |
|
2496 |
/* block signals in the handler using Linux */
|
2497 |
sigprocmask(SIG_BLOCK, &set, &old_set); |
2498 |
/* save the previous blocked signal state to restore it at the
|
2499 |
end of the signal execution (see do_sigreturn) */
|
2500 |
host_to_target_sigset_internal(&target_old_set, &old_set); |
2501 |
|
2502 |
/* if the CPU is in VM86 mode, we restore the 32 bit values */
|
2503 |
#if defined(TARGET_I386) && !defined(TARGET_X86_64)
|
2504 |
{ |
2505 |
CPUX86State *env = cpu_env; |
2506 |
if (env->eflags & VM_MASK)
|
2507 |
save_v86_state(env); |
2508 |
} |
2509 |
#endif
|
2510 |
/* prepare the stack frame of the virtual CPU */
|
2511 |
if (k->sa.sa_flags & TARGET_SA_SIGINFO)
|
2512 |
setup_rt_frame(sig, k, &q->info, &target_old_set, cpu_env); |
2513 |
else
|
2514 |
setup_frame(sig, k, &target_old_set, cpu_env); |
2515 |
if (k->sa.sa_flags & TARGET_SA_RESETHAND)
|
2516 |
k->sa._sa_handler = TARGET_SIG_DFL; |
2517 |
} |
2518 |
if (q != &k->info)
|
2519 |
free_sigqueue(q); |
2520 |
} |