2 * Emulation of Linux signals
4 * Copyright (c) 2003 Fabrice Bellard
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.
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.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
26 #include <sys/ucontext.h>
27 #include <sys/resource.h>
30 #include "qemu-common.h"
31 #include "target_signal.h"
33 //#define DEBUG_SIGNAL
35 static struct target_sigaltstack target_sigaltstack_used
= {
38 .ss_flags
= TARGET_SS_DISABLE
,
41 static struct target_sigaction sigact_table
[TARGET_NSIG
];
43 static void host_signal_handler(int host_signum
, siginfo_t
*info
,
46 static uint8_t host_to_target_signal_table
[_NSIG
] = {
47 [SIGHUP
] = TARGET_SIGHUP
,
48 [SIGINT
] = TARGET_SIGINT
,
49 [SIGQUIT
] = TARGET_SIGQUIT
,
50 [SIGILL
] = TARGET_SIGILL
,
51 [SIGTRAP
] = TARGET_SIGTRAP
,
52 [SIGABRT
] = TARGET_SIGABRT
,
53 /* [SIGIOT] = TARGET_SIGIOT,*/
54 [SIGBUS
] = TARGET_SIGBUS
,
55 [SIGFPE
] = TARGET_SIGFPE
,
56 [SIGKILL
] = TARGET_SIGKILL
,
57 [SIGUSR1
] = TARGET_SIGUSR1
,
58 [SIGSEGV
] = TARGET_SIGSEGV
,
59 [SIGUSR2
] = TARGET_SIGUSR2
,
60 [SIGPIPE
] = TARGET_SIGPIPE
,
61 [SIGALRM
] = TARGET_SIGALRM
,
62 [SIGTERM
] = TARGET_SIGTERM
,
64 [SIGSTKFLT
] = TARGET_SIGSTKFLT
,
66 [SIGCHLD
] = TARGET_SIGCHLD
,
67 [SIGCONT
] = TARGET_SIGCONT
,
68 [SIGSTOP
] = TARGET_SIGSTOP
,
69 [SIGTSTP
] = TARGET_SIGTSTP
,
70 [SIGTTIN
] = TARGET_SIGTTIN
,
71 [SIGTTOU
] = TARGET_SIGTTOU
,
72 [SIGURG
] = TARGET_SIGURG
,
73 [SIGXCPU
] = TARGET_SIGXCPU
,
74 [SIGXFSZ
] = TARGET_SIGXFSZ
,
75 [SIGVTALRM
] = TARGET_SIGVTALRM
,
76 [SIGPROF
] = TARGET_SIGPROF
,
77 [SIGWINCH
] = TARGET_SIGWINCH
,
78 [SIGIO
] = TARGET_SIGIO
,
79 [SIGPWR
] = TARGET_SIGPWR
,
80 [SIGSYS
] = TARGET_SIGSYS
,
81 /* next signals stay the same */
82 /* Nasty hack: Reverse SIGRTMIN and SIGRTMAX to avoid overlap with
83 host libpthread signals. This assumes no one actually uses SIGRTMAX :-/
84 To fix this properly we need to do manual signal delivery multiplexed
85 over a single host signal. */
86 [__SIGRTMIN
] = __SIGRTMAX
,
87 [__SIGRTMAX
] = __SIGRTMIN
,
89 static uint8_t target_to_host_signal_table
[_NSIG
];
91 static inline int on_sig_stack(unsigned long sp
)
93 return (sp
- target_sigaltstack_used
.ss_sp
94 < target_sigaltstack_used
.ss_size
);
97 static inline int sas_ss_flags(unsigned long sp
)
99 return (target_sigaltstack_used
.ss_size
== 0 ? SS_DISABLE
100 : on_sig_stack(sp
) ? SS_ONSTACK
: 0);
103 int host_to_target_signal(int sig
)
107 return host_to_target_signal_table
[sig
];
110 int target_to_host_signal(int sig
)
114 return target_to_host_signal_table
[sig
];
117 static inline void target_sigemptyset(target_sigset_t
*set
)
119 memset(set
, 0, sizeof(*set
));
122 static inline void target_sigaddset(target_sigset_t
*set
, int signum
)
125 abi_ulong mask
= (abi_ulong
)1 << (signum
% TARGET_NSIG_BPW
);
126 set
->sig
[signum
/ TARGET_NSIG_BPW
] |= mask
;
129 static inline int target_sigismember(const target_sigset_t
*set
, int signum
)
132 abi_ulong mask
= (abi_ulong
)1 << (signum
% TARGET_NSIG_BPW
);
133 return ((set
->sig
[signum
/ TARGET_NSIG_BPW
] & mask
) != 0);
136 static void host_to_target_sigset_internal(target_sigset_t
*d
,
140 target_sigemptyset(d
);
141 for (i
= 1; i
<= TARGET_NSIG
; i
++) {
142 if (sigismember(s
, i
)) {
143 target_sigaddset(d
, host_to_target_signal(i
));
148 void host_to_target_sigset(target_sigset_t
*d
, const sigset_t
*s
)
153 host_to_target_sigset_internal(&d1
, s
);
154 for(i
= 0;i
< TARGET_NSIG_WORDS
; i
++)
155 d
->sig
[i
] = tswapal(d1
.sig
[i
]);
158 static void target_to_host_sigset_internal(sigset_t
*d
,
159 const target_sigset_t
*s
)
163 for (i
= 1; i
<= TARGET_NSIG
; i
++) {
164 if (target_sigismember(s
, i
)) {
165 sigaddset(d
, target_to_host_signal(i
));
170 void target_to_host_sigset(sigset_t
*d
, const target_sigset_t
*s
)
175 for(i
= 0;i
< TARGET_NSIG_WORDS
; i
++)
176 s1
.sig
[i
] = tswapal(s
->sig
[i
]);
177 target_to_host_sigset_internal(d
, &s1
);
180 void host_to_target_old_sigset(abi_ulong
*old_sigset
,
181 const sigset_t
*sigset
)
184 host_to_target_sigset(&d
, sigset
);
185 *old_sigset
= d
.sig
[0];
188 void target_to_host_old_sigset(sigset_t
*sigset
,
189 const abi_ulong
*old_sigset
)
194 d
.sig
[0] = *old_sigset
;
195 for(i
= 1;i
< TARGET_NSIG_WORDS
; i
++)
197 target_to_host_sigset(sigset
, &d
);
200 /* siginfo conversion */
202 static inline void host_to_target_siginfo_noswap(target_siginfo_t
*tinfo
,
203 const siginfo_t
*info
)
205 int sig
= host_to_target_signal(info
->si_signo
);
206 tinfo
->si_signo
= sig
;
208 tinfo
->si_code
= info
->si_code
;
210 if (sig
== TARGET_SIGILL
|| sig
== TARGET_SIGFPE
|| sig
== TARGET_SIGSEGV
211 || sig
== TARGET_SIGBUS
|| sig
== TARGET_SIGTRAP
) {
212 /* Should never come here, but who knows. The information for
213 the target is irrelevant. */
214 tinfo
->_sifields
._sigfault
._addr
= 0;
215 } else if (sig
== TARGET_SIGIO
) {
216 tinfo
->_sifields
._sigpoll
._band
= info
->si_band
;
217 tinfo
->_sifields
._sigpoll
._fd
= info
->si_fd
;
218 } else if (sig
== TARGET_SIGCHLD
) {
219 tinfo
->_sifields
._sigchld
._pid
= info
->si_pid
;
220 tinfo
->_sifields
._sigchld
._uid
= info
->si_uid
;
221 tinfo
->_sifields
._sigchld
._status
222 = host_to_target_waitstatus(info
->si_status
);
223 tinfo
->_sifields
._sigchld
._utime
= info
->si_utime
;
224 tinfo
->_sifields
._sigchld
._stime
= info
->si_stime
;
225 } else if (sig
>= TARGET_SIGRTMIN
) {
226 tinfo
->_sifields
._rt
._pid
= info
->si_pid
;
227 tinfo
->_sifields
._rt
._uid
= info
->si_uid
;
228 /* XXX: potential problem if 64 bit */
229 tinfo
->_sifields
._rt
._sigval
.sival_ptr
230 = (abi_ulong
)(unsigned long)info
->si_value
.sival_ptr
;
234 static void tswap_siginfo(target_siginfo_t
*tinfo
,
235 const target_siginfo_t
*info
)
237 int sig
= info
->si_signo
;
238 tinfo
->si_signo
= tswap32(sig
);
239 tinfo
->si_errno
= tswap32(info
->si_errno
);
240 tinfo
->si_code
= tswap32(info
->si_code
);
242 if (sig
== TARGET_SIGILL
|| sig
== TARGET_SIGFPE
|| sig
== TARGET_SIGSEGV
243 || sig
== TARGET_SIGBUS
|| sig
== TARGET_SIGTRAP
) {
244 tinfo
->_sifields
._sigfault
._addr
245 = tswapal(info
->_sifields
._sigfault
._addr
);
246 } else if (sig
== TARGET_SIGIO
) {
247 tinfo
->_sifields
._sigpoll
._band
248 = tswap32(info
->_sifields
._sigpoll
._band
);
249 tinfo
->_sifields
._sigpoll
._fd
= tswap32(info
->_sifields
._sigpoll
._fd
);
250 } else if (sig
== TARGET_SIGCHLD
) {
251 tinfo
->_sifields
._sigchld
._pid
252 = tswap32(info
->_sifields
._sigchld
._pid
);
253 tinfo
->_sifields
._sigchld
._uid
254 = tswap32(info
->_sifields
._sigchld
._uid
);
255 tinfo
->_sifields
._sigchld
._status
256 = tswap32(info
->_sifields
._sigchld
._status
);
257 tinfo
->_sifields
._sigchld
._utime
258 = tswapal(info
->_sifields
._sigchld
._utime
);
259 tinfo
->_sifields
._sigchld
._stime
260 = tswapal(info
->_sifields
._sigchld
._stime
);
261 } else if (sig
>= TARGET_SIGRTMIN
) {
262 tinfo
->_sifields
._rt
._pid
= tswap32(info
->_sifields
._rt
._pid
);
263 tinfo
->_sifields
._rt
._uid
= tswap32(info
->_sifields
._rt
._uid
);
264 tinfo
->_sifields
._rt
._sigval
.sival_ptr
265 = tswapal(info
->_sifields
._rt
._sigval
.sival_ptr
);
270 void host_to_target_siginfo(target_siginfo_t
*tinfo
, const siginfo_t
*info
)
272 host_to_target_siginfo_noswap(tinfo
, info
);
273 tswap_siginfo(tinfo
, tinfo
);
276 /* XXX: we support only POSIX RT signals are used. */
277 /* XXX: find a solution for 64 bit (additional malloced data is needed) */
278 void target_to_host_siginfo(siginfo_t
*info
, const target_siginfo_t
*tinfo
)
280 info
->si_signo
= tswap32(tinfo
->si_signo
);
281 info
->si_errno
= tswap32(tinfo
->si_errno
);
282 info
->si_code
= tswap32(tinfo
->si_code
);
283 info
->si_pid
= tswap32(tinfo
->_sifields
._rt
._pid
);
284 info
->si_uid
= tswap32(tinfo
->_sifields
._rt
._uid
);
285 info
->si_value
.sival_ptr
=
286 (void *)(long)tswapal(tinfo
->_sifields
._rt
._sigval
.sival_ptr
);
289 static int fatal_signal (int sig
)
294 case TARGET_SIGWINCH
:
295 /* Ignored by default. */
302 /* Job control signals. */
309 /* returns 1 if given signal should dump core if not handled */
310 static int core_dump_signal(int sig
)
326 void signal_init(void)
328 struct sigaction act
;
329 struct sigaction oact
;
333 /* generate signal conversion tables */
334 for(i
= 1; i
< _NSIG
; i
++) {
335 if (host_to_target_signal_table
[i
] == 0)
336 host_to_target_signal_table
[i
] = i
;
338 for(i
= 1; i
< _NSIG
; i
++) {
339 j
= host_to_target_signal_table
[i
];
340 target_to_host_signal_table
[j
] = i
;
343 /* set all host signal handlers. ALL signals are blocked during
344 the handlers to serialize them. */
345 memset(sigact_table
, 0, sizeof(sigact_table
));
347 sigfillset(&act
.sa_mask
);
348 act
.sa_flags
= SA_SIGINFO
;
349 act
.sa_sigaction
= host_signal_handler
;
350 for(i
= 1; i
<= TARGET_NSIG
; i
++) {
351 host_sig
= target_to_host_signal(i
);
352 sigaction(host_sig
, NULL
, &oact
);
353 if (oact
.sa_sigaction
== (void *)SIG_IGN
) {
354 sigact_table
[i
- 1]._sa_handler
= TARGET_SIG_IGN
;
355 } else if (oact
.sa_sigaction
== (void *)SIG_DFL
) {
356 sigact_table
[i
- 1]._sa_handler
= TARGET_SIG_DFL
;
358 /* If there's already a handler installed then something has
359 gone horribly wrong, so don't even try to handle that case. */
360 /* Install some handlers for our own use. We need at least
361 SIGSEGV and SIGBUS, to detect exceptions. We can not just
362 trap all signals because it affects syscall interrupt
363 behavior. But do trap all default-fatal signals. */
364 if (fatal_signal (i
))
365 sigaction(host_sig
, &act
, NULL
);
369 /* signal queue handling */
371 static inline struct sigqueue
*alloc_sigqueue(CPUArchState
*env
)
373 TaskState
*ts
= env
->opaque
;
374 struct sigqueue
*q
= ts
->first_free
;
377 ts
->first_free
= q
->next
;
381 static inline void free_sigqueue(CPUArchState
*env
, struct sigqueue
*q
)
383 TaskState
*ts
= env
->opaque
;
384 q
->next
= ts
->first_free
;
388 /* abort execution with signal */
389 static void QEMU_NORETURN
force_sig(int target_sig
)
391 TaskState
*ts
= (TaskState
*)thread_env
->opaque
;
392 int host_sig
, core_dumped
= 0;
393 struct sigaction act
;
394 host_sig
= target_to_host_signal(target_sig
);
395 gdb_signalled(thread_env
, target_sig
);
397 /* dump core if supported by target binary format */
398 if (core_dump_signal(target_sig
) && (ts
->bprm
->core_dump
!= NULL
)) {
401 ((*ts
->bprm
->core_dump
)(target_sig
, thread_env
) == 0);
404 /* we already dumped the core of target process, we don't want
405 * a coredump of qemu itself */
406 struct rlimit nodump
;
407 getrlimit(RLIMIT_CORE
, &nodump
);
409 setrlimit(RLIMIT_CORE
, &nodump
);
410 (void) fprintf(stderr
, "qemu: uncaught target signal %d (%s) - %s\n",
411 target_sig
, strsignal(host_sig
), "core dumped" );
414 /* The proper exit code for dying from an uncaught signal is
415 * -<signal>. The kernel doesn't allow exit() or _exit() to pass
416 * a negative value. To get the proper exit code we need to
417 * actually die from an uncaught signal. Here the default signal
418 * handler is installed, we send ourself a signal and we wait for
420 sigfillset(&act
.sa_mask
);
421 act
.sa_handler
= SIG_DFL
;
422 sigaction(host_sig
, &act
, NULL
);
424 /* For some reason raise(host_sig) doesn't send the signal when
425 * statically linked on x86-64. */
426 kill(getpid(), host_sig
);
428 /* Make sure the signal isn't masked (just reuse the mask inside
430 sigdelset(&act
.sa_mask
, host_sig
);
431 sigsuspend(&act
.sa_mask
);
437 /* queue a signal so that it will be send to the virtual CPU as soon
439 int queue_signal(CPUArchState
*env
, int sig
, target_siginfo_t
*info
)
441 TaskState
*ts
= env
->opaque
;
442 struct emulated_sigtable
*k
;
443 struct sigqueue
*q
, **pq
;
447 #if defined(DEBUG_SIGNAL)
448 fprintf(stderr
, "queue_signal: sig=%d\n",
451 k
= &ts
->sigtab
[sig
- 1];
452 queue
= gdb_queuesig ();
453 handler
= sigact_table
[sig
- 1]._sa_handler
;
454 if (!queue
&& handler
== TARGET_SIG_DFL
) {
455 if (sig
== TARGET_SIGTSTP
|| sig
== TARGET_SIGTTIN
|| sig
== TARGET_SIGTTOU
) {
456 kill(getpid(),SIGSTOP
);
459 /* default handler : ignore some signal. The other are fatal */
460 if (sig
!= TARGET_SIGCHLD
&&
461 sig
!= TARGET_SIGURG
&&
462 sig
!= TARGET_SIGWINCH
&&
463 sig
!= TARGET_SIGCONT
) {
466 return 0; /* indicate ignored */
468 } else if (!queue
&& handler
== TARGET_SIG_IGN
) {
471 } else if (!queue
&& handler
== TARGET_SIG_ERR
) {
475 if (sig
< TARGET_SIGRTMIN
) {
476 /* if non real time signal, we queue exactly one signal */
486 q
= alloc_sigqueue(env
);
497 /* signal that a new signal is pending */
498 ts
->signal_pending
= 1;
499 return 1; /* indicates that the signal was queued */
503 static void host_signal_handler(int host_signum
, siginfo_t
*info
,
507 target_siginfo_t tinfo
;
509 /* the CPU emulator uses some host signals to detect exceptions,
510 we forward to it some signals */
511 if ((host_signum
== SIGSEGV
|| host_signum
== SIGBUS
)
512 && info
->si_code
> 0) {
513 if (cpu_signal_handler(host_signum
, info
, puc
))
517 /* get target signal number */
518 sig
= host_to_target_signal(host_signum
);
519 if (sig
< 1 || sig
> TARGET_NSIG
)
521 #if defined(DEBUG_SIGNAL)
522 fprintf(stderr
, "qemu: got signal %d\n", sig
);
524 host_to_target_siginfo_noswap(&tinfo
, info
);
525 if (queue_signal(thread_env
, sig
, &tinfo
) == 1) {
526 /* interrupt the virtual CPU as soon as possible */
527 cpu_exit(thread_env
);
531 /* do_sigaltstack() returns target values and errnos. */
532 /* compare linux/kernel/signal.c:do_sigaltstack() */
533 abi_long
do_sigaltstack(abi_ulong uss_addr
, abi_ulong uoss_addr
, abi_ulong sp
)
536 struct target_sigaltstack oss
;
538 /* XXX: test errors */
541 __put_user(target_sigaltstack_used
.ss_sp
, &oss
.ss_sp
);
542 __put_user(target_sigaltstack_used
.ss_size
, &oss
.ss_size
);
543 __put_user(sas_ss_flags(sp
), &oss
.ss_flags
);
548 struct target_sigaltstack
*uss
;
549 struct target_sigaltstack ss
;
551 ret
= -TARGET_EFAULT
;
552 if (!lock_user_struct(VERIFY_READ
, uss
, uss_addr
, 1)
553 || __get_user(ss
.ss_sp
, &uss
->ss_sp
)
554 || __get_user(ss
.ss_size
, &uss
->ss_size
)
555 || __get_user(ss
.ss_flags
, &uss
->ss_flags
))
557 unlock_user_struct(uss
, uss_addr
, 0);
560 if (on_sig_stack(sp
))
563 ret
= -TARGET_EINVAL
;
564 if (ss
.ss_flags
!= TARGET_SS_DISABLE
565 && ss
.ss_flags
!= TARGET_SS_ONSTACK
569 if (ss
.ss_flags
== TARGET_SS_DISABLE
) {
573 ret
= -TARGET_ENOMEM
;
574 if (ss
.ss_size
< MINSIGSTKSZ
)
578 target_sigaltstack_used
.ss_sp
= ss
.ss_sp
;
579 target_sigaltstack_used
.ss_size
= ss
.ss_size
;
583 ret
= -TARGET_EFAULT
;
584 if (copy_to_user(uoss_addr
, &oss
, sizeof(oss
)))
593 /* do_sigaction() return host values and errnos */
594 int do_sigaction(int sig
, const struct target_sigaction
*act
,
595 struct target_sigaction
*oact
)
597 struct target_sigaction
*k
;
598 struct sigaction act1
;
602 if (sig
< 1 || sig
> TARGET_NSIG
|| sig
== TARGET_SIGKILL
|| sig
== TARGET_SIGSTOP
)
604 k
= &sigact_table
[sig
- 1];
605 #if defined(DEBUG_SIGNAL)
606 fprintf(stderr
, "sigaction sig=%d act=0x%p, oact=0x%p\n",
610 __put_user(k
->_sa_handler
, &oact
->_sa_handler
);
611 __put_user(k
->sa_flags
, &oact
->sa_flags
);
612 #if !defined(TARGET_MIPS)
613 __put_user(k
->sa_restorer
, &oact
->sa_restorer
);
616 oact
->sa_mask
= k
->sa_mask
;
619 /* FIXME: This is not threadsafe. */
620 __get_user(k
->_sa_handler
, &act
->_sa_handler
);
621 __get_user(k
->sa_flags
, &act
->sa_flags
);
622 #if !defined(TARGET_MIPS)
623 __get_user(k
->sa_restorer
, &act
->sa_restorer
);
625 /* To be swapped in target_to_host_sigset. */
626 k
->sa_mask
= act
->sa_mask
;
628 /* we update the host linux signal state */
629 host_sig
= target_to_host_signal(sig
);
630 if (host_sig
!= SIGSEGV
&& host_sig
!= SIGBUS
) {
631 sigfillset(&act1
.sa_mask
);
632 act1
.sa_flags
= SA_SIGINFO
;
633 if (k
->sa_flags
& TARGET_SA_RESTART
)
634 act1
.sa_flags
|= SA_RESTART
;
635 /* NOTE: it is important to update the host kernel signal
636 ignore state to avoid getting unexpected interrupted
638 if (k
->_sa_handler
== TARGET_SIG_IGN
) {
639 act1
.sa_sigaction
= (void *)SIG_IGN
;
640 } else if (k
->_sa_handler
== TARGET_SIG_DFL
) {
641 if (fatal_signal (sig
))
642 act1
.sa_sigaction
= host_signal_handler
;
644 act1
.sa_sigaction
= (void *)SIG_DFL
;
646 act1
.sa_sigaction
= host_signal_handler
;
648 ret
= sigaction(host_sig
, &act1
, NULL
);
654 static inline int copy_siginfo_to_user(target_siginfo_t
*tinfo
,
655 const target_siginfo_t
*info
)
657 tswap_siginfo(tinfo
, info
);
661 static inline int current_exec_domain_sig(int sig
)
663 return /* current->exec_domain && current->exec_domain->signal_invmap
664 && sig < 32 ? current->exec_domain->signal_invmap[sig] : */ sig
;
667 #if defined(TARGET_I386) && TARGET_ABI_BITS == 32
669 /* from the Linux kernel */
671 struct target_fpreg
{
672 uint16_t significand
[4];
676 struct target_fpxreg
{
677 uint16_t significand
[4];
682 struct target_xmmreg
{
683 abi_ulong element
[4];
686 struct target_fpstate
{
687 /* Regular FPU environment */
695 struct target_fpreg _st
[8];
697 uint16_t magic
; /* 0xffff = regular FPU data only */
699 /* FXSR FPU environment */
700 abi_ulong _fxsr_env
[6]; /* FXSR FPU env is ignored */
703 struct target_fpxreg _fxsr_st
[8]; /* FXSR FPU reg data is ignored */
704 struct target_xmmreg _xmm
[8];
705 abi_ulong padding
[56];
708 #define X86_FXSR_MAGIC 0x0000
710 struct target_sigcontext
{
728 abi_ulong esp_at_signal
;
730 abi_ulong fpstate
; /* pointer */
735 struct target_ucontext
{
738 target_stack_t tuc_stack
;
739 struct target_sigcontext tuc_mcontext
;
740 target_sigset_t tuc_sigmask
; /* mask last for extensibility */
747 struct target_sigcontext sc
;
748 struct target_fpstate fpstate
;
749 abi_ulong extramask
[TARGET_NSIG_WORDS
-1];
759 struct target_siginfo info
;
760 struct target_ucontext uc
;
761 struct target_fpstate fpstate
;
766 * Set up a signal frame.
769 /* XXX: save x87 state */
771 setup_sigcontext(struct target_sigcontext
*sc
, struct target_fpstate
*fpstate
,
772 CPUX86State
*env
, abi_ulong mask
, abi_ulong fpstate_addr
)
777 /* already locked in setup_frame() */
778 err
|= __put_user(env
->segs
[R_GS
].selector
, (unsigned int *)&sc
->gs
);
779 err
|= __put_user(env
->segs
[R_FS
].selector
, (unsigned int *)&sc
->fs
);
780 err
|= __put_user(env
->segs
[R_ES
].selector
, (unsigned int *)&sc
->es
);
781 err
|= __put_user(env
->segs
[R_DS
].selector
, (unsigned int *)&sc
->ds
);
782 err
|= __put_user(env
->regs
[R_EDI
], &sc
->edi
);
783 err
|= __put_user(env
->regs
[R_ESI
], &sc
->esi
);
784 err
|= __put_user(env
->regs
[R_EBP
], &sc
->ebp
);
785 err
|= __put_user(env
->regs
[R_ESP
], &sc
->esp
);
786 err
|= __put_user(env
->regs
[R_EBX
], &sc
->ebx
);
787 err
|= __put_user(env
->regs
[R_EDX
], &sc
->edx
);
788 err
|= __put_user(env
->regs
[R_ECX
], &sc
->ecx
);
789 err
|= __put_user(env
->regs
[R_EAX
], &sc
->eax
);
790 err
|= __put_user(env
->exception_index
, &sc
->trapno
);
791 err
|= __put_user(env
->error_code
, &sc
->err
);
792 err
|= __put_user(env
->eip
, &sc
->eip
);
793 err
|= __put_user(env
->segs
[R_CS
].selector
, (unsigned int *)&sc
->cs
);
794 err
|= __put_user(env
->eflags
, &sc
->eflags
);
795 err
|= __put_user(env
->regs
[R_ESP
], &sc
->esp_at_signal
);
796 err
|= __put_user(env
->segs
[R_SS
].selector
, (unsigned int *)&sc
->ss
);
798 cpu_x86_fsave(env
, fpstate_addr
, 1);
799 fpstate
->status
= fpstate
->sw
;
801 err
|= __put_user(magic
, &fpstate
->magic
);
802 err
|= __put_user(fpstate_addr
, &sc
->fpstate
);
804 /* non-iBCS2 extensions.. */
805 err
|= __put_user(mask
, &sc
->oldmask
);
806 err
|= __put_user(env
->cr
[2], &sc
->cr2
);
811 * Determine which stack to use..
814 static inline abi_ulong
815 get_sigframe(struct target_sigaction
*ka
, CPUX86State
*env
, size_t frame_size
)
819 /* Default to using normal stack */
820 esp
= env
->regs
[R_ESP
];
821 /* This is the X/Open sanctioned signal stack switching. */
822 if (ka
->sa_flags
& TARGET_SA_ONSTACK
) {
823 if (sas_ss_flags(esp
) == 0)
824 esp
= target_sigaltstack_used
.ss_sp
+ target_sigaltstack_used
.ss_size
;
827 /* This is the legacy signal stack switching. */
829 if ((env
->segs
[R_SS
].selector
& 0xffff) != __USER_DS
&&
830 !(ka
->sa_flags
& TARGET_SA_RESTORER
) &&
832 esp
= (unsigned long) ka
->sa_restorer
;
834 return (esp
- frame_size
) & -8ul;
837 /* compare linux/arch/i386/kernel/signal.c:setup_frame() */
838 static void setup_frame(int sig
, struct target_sigaction
*ka
,
839 target_sigset_t
*set
, CPUX86State
*env
)
841 abi_ulong frame_addr
;
842 struct sigframe
*frame
;
845 frame_addr
= get_sigframe(ka
, env
, sizeof(*frame
));
847 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0))
850 err
|= __put_user(current_exec_domain_sig(sig
),
855 setup_sigcontext(&frame
->sc
, &frame
->fpstate
, env
, set
->sig
[0],
856 frame_addr
+ offsetof(struct sigframe
, fpstate
));
860 for(i
= 1; i
< TARGET_NSIG_WORDS
; i
++) {
861 if (__put_user(set
->sig
[i
], &frame
->extramask
[i
- 1]))
865 /* Set up to return from userspace. If provided, use a stub
866 already in userspace. */
867 if (ka
->sa_flags
& TARGET_SA_RESTORER
) {
868 err
|= __put_user(ka
->sa_restorer
, &frame
->pretcode
);
871 abi_ulong retcode_addr
;
872 retcode_addr
= frame_addr
+ offsetof(struct sigframe
, retcode
);
873 err
|= __put_user(retcode_addr
, &frame
->pretcode
);
874 /* This is popl %eax ; movl $,%eax ; int $0x80 */
876 err
|= __put_user(val16
, (uint16_t *)(frame
->retcode
+0));
877 err
|= __put_user(TARGET_NR_sigreturn
, (int *)(frame
->retcode
+2));
879 err
|= __put_user(val16
, (uint16_t *)(frame
->retcode
+6));
885 /* Set up registers for signal handler */
886 env
->regs
[R_ESP
] = frame_addr
;
887 env
->eip
= ka
->_sa_handler
;
889 cpu_x86_load_seg(env
, R_DS
, __USER_DS
);
890 cpu_x86_load_seg(env
, R_ES
, __USER_DS
);
891 cpu_x86_load_seg(env
, R_SS
, __USER_DS
);
892 cpu_x86_load_seg(env
, R_CS
, __USER_CS
);
893 env
->eflags
&= ~TF_MASK
;
895 unlock_user_struct(frame
, frame_addr
, 1);
900 unlock_user_struct(frame
, frame_addr
, 1);
901 if (sig
== TARGET_SIGSEGV
)
902 ka
->_sa_handler
= TARGET_SIG_DFL
;
903 force_sig(TARGET_SIGSEGV
/* , current */);
906 /* compare linux/arch/i386/kernel/signal.c:setup_rt_frame() */
907 static void setup_rt_frame(int sig
, struct target_sigaction
*ka
,
908 target_siginfo_t
*info
,
909 target_sigset_t
*set
, CPUX86State
*env
)
911 abi_ulong frame_addr
, addr
;
912 struct rt_sigframe
*frame
;
915 frame_addr
= get_sigframe(ka
, env
, sizeof(*frame
));
917 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0))
920 err
|= __put_user(current_exec_domain_sig(sig
),
922 addr
= frame_addr
+ offsetof(struct rt_sigframe
, info
);
923 err
|= __put_user(addr
, &frame
->pinfo
);
924 addr
= frame_addr
+ offsetof(struct rt_sigframe
, uc
);
925 err
|= __put_user(addr
, &frame
->puc
);
926 err
|= copy_siginfo_to_user(&frame
->info
, info
);
930 /* Create the ucontext. */
931 err
|= __put_user(0, &frame
->uc
.tuc_flags
);
932 err
|= __put_user(0, &frame
->uc
.tuc_link
);
933 err
|= __put_user(target_sigaltstack_used
.ss_sp
,
934 &frame
->uc
.tuc_stack
.ss_sp
);
935 err
|= __put_user(sas_ss_flags(get_sp_from_cpustate(env
)),
936 &frame
->uc
.tuc_stack
.ss_flags
);
937 err
|= __put_user(target_sigaltstack_used
.ss_size
,
938 &frame
->uc
.tuc_stack
.ss_size
);
939 err
|= setup_sigcontext(&frame
->uc
.tuc_mcontext
, &frame
->fpstate
,
941 frame_addr
+ offsetof(struct rt_sigframe
, fpstate
));
942 for(i
= 0; i
< TARGET_NSIG_WORDS
; i
++) {
943 if (__put_user(set
->sig
[i
], &frame
->uc
.tuc_sigmask
.sig
[i
]))
947 /* Set up to return from userspace. If provided, use a stub
948 already in userspace. */
949 if (ka
->sa_flags
& TARGET_SA_RESTORER
) {
950 err
|= __put_user(ka
->sa_restorer
, &frame
->pretcode
);
953 addr
= frame_addr
+ offsetof(struct rt_sigframe
, retcode
);
954 err
|= __put_user(addr
, &frame
->pretcode
);
955 /* This is movl $,%eax ; int $0x80 */
956 err
|= __put_user(0xb8, (char *)(frame
->retcode
+0));
957 err
|= __put_user(TARGET_NR_rt_sigreturn
, (int *)(frame
->retcode
+1));
959 err
|= __put_user(val16
, (uint16_t *)(frame
->retcode
+5));
965 /* Set up registers for signal handler */
966 env
->regs
[R_ESP
] = frame_addr
;
967 env
->eip
= ka
->_sa_handler
;
969 cpu_x86_load_seg(env
, R_DS
, __USER_DS
);
970 cpu_x86_load_seg(env
, R_ES
, __USER_DS
);
971 cpu_x86_load_seg(env
, R_SS
, __USER_DS
);
972 cpu_x86_load_seg(env
, R_CS
, __USER_CS
);
973 env
->eflags
&= ~TF_MASK
;
975 unlock_user_struct(frame
, frame_addr
, 1);
980 unlock_user_struct(frame
, frame_addr
, 1);
981 if (sig
== TARGET_SIGSEGV
)
982 ka
->_sa_handler
= TARGET_SIG_DFL
;
983 force_sig(TARGET_SIGSEGV
/* , current */);
987 restore_sigcontext(CPUX86State
*env
, struct target_sigcontext
*sc
, int *peax
)
989 unsigned int err
= 0;
990 abi_ulong fpstate_addr
;
991 unsigned int tmpflags
;
993 cpu_x86_load_seg(env
, R_GS
, tswap16(sc
->gs
));
994 cpu_x86_load_seg(env
, R_FS
, tswap16(sc
->fs
));
995 cpu_x86_load_seg(env
, R_ES
, tswap16(sc
->es
));
996 cpu_x86_load_seg(env
, R_DS
, tswap16(sc
->ds
));
998 env
->regs
[R_EDI
] = tswapl(sc
->edi
);
999 env
->regs
[R_ESI
] = tswapl(sc
->esi
);
1000 env
->regs
[R_EBP
] = tswapl(sc
->ebp
);
1001 env
->regs
[R_ESP
] = tswapl(sc
->esp
);
1002 env
->regs
[R_EBX
] = tswapl(sc
->ebx
);
1003 env
->regs
[R_EDX
] = tswapl(sc
->edx
);
1004 env
->regs
[R_ECX
] = tswapl(sc
->ecx
);
1005 env
->eip
= tswapl(sc
->eip
);
1007 cpu_x86_load_seg(env
, R_CS
, lduw_p(&sc
->cs
) | 3);
1008 cpu_x86_load_seg(env
, R_SS
, lduw_p(&sc
->ss
) | 3);
1010 tmpflags
= tswapl(sc
->eflags
);
1011 env
->eflags
= (env
->eflags
& ~0x40DD5) | (tmpflags
& 0x40DD5);
1012 // regs->orig_eax = -1; /* disable syscall checks */
1014 fpstate_addr
= tswapl(sc
->fpstate
);
1015 if (fpstate_addr
!= 0) {
1016 if (!access_ok(VERIFY_READ
, fpstate_addr
,
1017 sizeof(struct target_fpstate
)))
1019 cpu_x86_frstor(env
, fpstate_addr
, 1);
1022 *peax
= tswapl(sc
->eax
);
1028 long do_sigreturn(CPUX86State
*env
)
1030 struct sigframe
*frame
;
1031 abi_ulong frame_addr
= env
->regs
[R_ESP
] - 8;
1032 target_sigset_t target_set
;
1036 #if defined(DEBUG_SIGNAL)
1037 fprintf(stderr
, "do_sigreturn\n");
1039 if (!lock_user_struct(VERIFY_READ
, frame
, frame_addr
, 1))
1041 /* set blocked signals */
1042 if (__get_user(target_set
.sig
[0], &frame
->sc
.oldmask
))
1044 for(i
= 1; i
< TARGET_NSIG_WORDS
; i
++) {
1045 if (__get_user(target_set
.sig
[i
], &frame
->extramask
[i
- 1]))
1049 target_to_host_sigset_internal(&set
, &target_set
);
1050 sigprocmask(SIG_SETMASK
, &set
, NULL
);
1052 /* restore registers */
1053 if (restore_sigcontext(env
, &frame
->sc
, &eax
))
1055 unlock_user_struct(frame
, frame_addr
, 0);
1059 unlock_user_struct(frame
, frame_addr
, 0);
1060 force_sig(TARGET_SIGSEGV
);
1064 long do_rt_sigreturn(CPUX86State
*env
)
1066 abi_ulong frame_addr
;
1067 struct rt_sigframe
*frame
;
1071 frame_addr
= env
->regs
[R_ESP
] - 4;
1072 if (!lock_user_struct(VERIFY_READ
, frame
, frame_addr
, 1))
1074 target_to_host_sigset(&set
, &frame
->uc
.tuc_sigmask
);
1075 sigprocmask(SIG_SETMASK
, &set
, NULL
);
1077 if (restore_sigcontext(env
, &frame
->uc
.tuc_mcontext
, &eax
))
1080 if (do_sigaltstack(frame_addr
+ offsetof(struct rt_sigframe
, uc
.tuc_stack
), 0,
1081 get_sp_from_cpustate(env
)) == -EFAULT
)
1084 unlock_user_struct(frame
, frame_addr
, 0);
1088 unlock_user_struct(frame
, frame_addr
, 0);
1089 force_sig(TARGET_SIGSEGV
);
1093 #elif defined(TARGET_ARM)
1095 struct target_sigcontext
{
1097 abi_ulong error_code
;
1116 abi_ulong fault_address
;
1119 struct target_ucontext_v1
{
1120 abi_ulong tuc_flags
;
1122 target_stack_t tuc_stack
;
1123 struct target_sigcontext tuc_mcontext
;
1124 target_sigset_t tuc_sigmask
; /* mask last for extensibility */
1127 struct target_ucontext_v2
{
1128 abi_ulong tuc_flags
;
1130 target_stack_t tuc_stack
;
1131 struct target_sigcontext tuc_mcontext
;
1132 target_sigset_t tuc_sigmask
; /* mask last for extensibility */
1133 char __unused
[128 - sizeof(target_sigset_t
)];
1134 abi_ulong tuc_regspace
[128] __attribute__((__aligned__(8)));
1137 struct target_user_vfp
{
1138 uint64_t fpregs
[32];
1142 struct target_user_vfp_exc
{
1148 struct target_vfp_sigframe
{
1151 struct target_user_vfp ufp
;
1152 struct target_user_vfp_exc ufp_exc
;
1153 } __attribute__((__aligned__(8)));
1155 struct target_iwmmxt_sigframe
{
1159 /* Note that not all the coprocessor control registers are stored here */
1166 } __attribute__((__aligned__(8)));
1168 #define TARGET_VFP_MAGIC 0x56465001
1169 #define TARGET_IWMMXT_MAGIC 0x12ef842a
1173 struct target_sigcontext sc
;
1174 abi_ulong extramask
[TARGET_NSIG_WORDS
-1];
1180 struct target_ucontext_v2 uc
;
1184 struct rt_sigframe_v1
1188 struct target_siginfo info
;
1189 struct target_ucontext_v1 uc
;
1193 struct rt_sigframe_v2
1195 struct target_siginfo info
;
1196 struct target_ucontext_v2 uc
;
1200 #define TARGET_CONFIG_CPU_32 1
1203 * For ARM syscalls, we encode the syscall number into the instruction.
1205 #define SWI_SYS_SIGRETURN (0xef000000|(TARGET_NR_sigreturn + ARM_SYSCALL_BASE))
1206 #define SWI_SYS_RT_SIGRETURN (0xef000000|(TARGET_NR_rt_sigreturn + ARM_SYSCALL_BASE))
1209 * For Thumb syscalls, we pass the syscall number via r7. We therefore
1210 * need two 16-bit instructions.
1212 #define SWI_THUMB_SIGRETURN (0xdf00 << 16 | 0x2700 | (TARGET_NR_sigreturn))
1213 #define SWI_THUMB_RT_SIGRETURN (0xdf00 << 16 | 0x2700 | (TARGET_NR_rt_sigreturn))
1215 static const abi_ulong retcodes
[4] = {
1216 SWI_SYS_SIGRETURN
, SWI_THUMB_SIGRETURN
,
1217 SWI_SYS_RT_SIGRETURN
, SWI_THUMB_RT_SIGRETURN
1221 #define __get_user_error(x,p,e) __get_user(x, p)
1223 static inline int valid_user_regs(CPUARMState
*regs
)
1229 setup_sigcontext(struct target_sigcontext
*sc
, /*struct _fpstate *fpstate,*/
1230 CPUARMState
*env
, abi_ulong mask
)
1232 __put_user(env
->regs
[0], &sc
->arm_r0
);
1233 __put_user(env
->regs
[1], &sc
->arm_r1
);
1234 __put_user(env
->regs
[2], &sc
->arm_r2
);
1235 __put_user(env
->regs
[3], &sc
->arm_r3
);
1236 __put_user(env
->regs
[4], &sc
->arm_r4
);
1237 __put_user(env
->regs
[5], &sc
->arm_r5
);
1238 __put_user(env
->regs
[6], &sc
->arm_r6
);
1239 __put_user(env
->regs
[7], &sc
->arm_r7
);
1240 __put_user(env
->regs
[8], &sc
->arm_r8
);
1241 __put_user(env
->regs
[9], &sc
->arm_r9
);
1242 __put_user(env
->regs
[10], &sc
->arm_r10
);
1243 __put_user(env
->regs
[11], &sc
->arm_fp
);
1244 __put_user(env
->regs
[12], &sc
->arm_ip
);
1245 __put_user(env
->regs
[13], &sc
->arm_sp
);
1246 __put_user(env
->regs
[14], &sc
->arm_lr
);
1247 __put_user(env
->regs
[15], &sc
->arm_pc
);
1248 #ifdef TARGET_CONFIG_CPU_32
1249 __put_user(cpsr_read(env
), &sc
->arm_cpsr
);
1252 __put_user(/* current->thread.trap_no */ 0, &sc
->trap_no
);
1253 __put_user(/* current->thread.error_code */ 0, &sc
->error_code
);
1254 __put_user(/* current->thread.address */ 0, &sc
->fault_address
);
1255 __put_user(mask
, &sc
->oldmask
);
1258 static inline abi_ulong
1259 get_sigframe(struct target_sigaction
*ka
, CPUARMState
*regs
, int framesize
)
1261 unsigned long sp
= regs
->regs
[13];
1264 * This is the X/Open sanctioned signal stack switching.
1266 if ((ka
->sa_flags
& TARGET_SA_ONSTACK
) && !sas_ss_flags(sp
))
1267 sp
= target_sigaltstack_used
.ss_sp
+ target_sigaltstack_used
.ss_size
;
1269 * ATPCS B01 mandates 8-byte alignment
1271 return (sp
- framesize
) & ~7;
1275 setup_return(CPUARMState
*env
, struct target_sigaction
*ka
,
1276 abi_ulong
*rc
, abi_ulong frame_addr
, int usig
, abi_ulong rc_addr
)
1278 abi_ulong handler
= ka
->_sa_handler
;
1280 int thumb
= handler
& 1;
1281 uint32_t cpsr
= cpsr_read(env
);
1290 if (ka
->sa_flags
& TARGET_SA_RESTORER
) {
1291 retcode
= ka
->sa_restorer
;
1293 unsigned int idx
= thumb
;
1295 if (ka
->sa_flags
& TARGET_SA_SIGINFO
)
1298 if (__put_user(retcodes
[idx
], rc
))
1301 retcode
= rc_addr
+ thumb
;
1304 env
->regs
[0] = usig
;
1305 env
->regs
[13] = frame_addr
;
1306 env
->regs
[14] = retcode
;
1307 env
->regs
[15] = handler
& (thumb
? ~1 : ~3);
1308 cpsr_write(env
, cpsr
, 0xffffffff);
1313 static abi_ulong
*setup_sigframe_v2_vfp(abi_ulong
*regspace
, CPUARMState
*env
)
1316 struct target_vfp_sigframe
*vfpframe
;
1317 vfpframe
= (struct target_vfp_sigframe
*)regspace
;
1318 __put_user(TARGET_VFP_MAGIC
, &vfpframe
->magic
);
1319 __put_user(sizeof(*vfpframe
), &vfpframe
->size
);
1320 for (i
= 0; i
< 32; i
++) {
1321 __put_user(float64_val(env
->vfp
.regs
[i
]), &vfpframe
->ufp
.fpregs
[i
]);
1323 __put_user(vfp_get_fpscr(env
), &vfpframe
->ufp
.fpscr
);
1324 __put_user(env
->vfp
.xregs
[ARM_VFP_FPEXC
], &vfpframe
->ufp_exc
.fpexc
);
1325 __put_user(env
->vfp
.xregs
[ARM_VFP_FPINST
], &vfpframe
->ufp_exc
.fpinst
);
1326 __put_user(env
->vfp
.xregs
[ARM_VFP_FPINST2
], &vfpframe
->ufp_exc
.fpinst2
);
1327 return (abi_ulong
*)(vfpframe
+1);
1330 static abi_ulong
*setup_sigframe_v2_iwmmxt(abi_ulong
*regspace
,
1334 struct target_iwmmxt_sigframe
*iwmmxtframe
;
1335 iwmmxtframe
= (struct target_iwmmxt_sigframe
*)regspace
;
1336 __put_user(TARGET_IWMMXT_MAGIC
, &iwmmxtframe
->magic
);
1337 __put_user(sizeof(*iwmmxtframe
), &iwmmxtframe
->size
);
1338 for (i
= 0; i
< 16; i
++) {
1339 __put_user(env
->iwmmxt
.regs
[i
], &iwmmxtframe
->regs
[i
]);
1341 __put_user(env
->vfp
.xregs
[ARM_IWMMXT_wCSSF
], &iwmmxtframe
->wcssf
);
1342 __put_user(env
->vfp
.xregs
[ARM_IWMMXT_wCASF
], &iwmmxtframe
->wcssf
);
1343 __put_user(env
->vfp
.xregs
[ARM_IWMMXT_wCGR0
], &iwmmxtframe
->wcgr0
);
1344 __put_user(env
->vfp
.xregs
[ARM_IWMMXT_wCGR1
], &iwmmxtframe
->wcgr1
);
1345 __put_user(env
->vfp
.xregs
[ARM_IWMMXT_wCGR2
], &iwmmxtframe
->wcgr2
);
1346 __put_user(env
->vfp
.xregs
[ARM_IWMMXT_wCGR3
], &iwmmxtframe
->wcgr3
);
1347 return (abi_ulong
*)(iwmmxtframe
+1);
1350 static void setup_sigframe_v2(struct target_ucontext_v2
*uc
,
1351 target_sigset_t
*set
, CPUARMState
*env
)
1353 struct target_sigaltstack stack
;
1355 abi_ulong
*regspace
;
1357 /* Clear all the bits of the ucontext we don't use. */
1358 memset(uc
, 0, offsetof(struct target_ucontext_v2
, tuc_mcontext
));
1360 memset(&stack
, 0, sizeof(stack
));
1361 __put_user(target_sigaltstack_used
.ss_sp
, &stack
.ss_sp
);
1362 __put_user(target_sigaltstack_used
.ss_size
, &stack
.ss_size
);
1363 __put_user(sas_ss_flags(get_sp_from_cpustate(env
)), &stack
.ss_flags
);
1364 memcpy(&uc
->tuc_stack
, &stack
, sizeof(stack
));
1366 setup_sigcontext(&uc
->tuc_mcontext
, env
, set
->sig
[0]);
1367 /* Save coprocessor signal frame. */
1368 regspace
= uc
->tuc_regspace
;
1369 if (arm_feature(env
, ARM_FEATURE_VFP
)) {
1370 regspace
= setup_sigframe_v2_vfp(regspace
, env
);
1372 if (arm_feature(env
, ARM_FEATURE_IWMMXT
)) {
1373 regspace
= setup_sigframe_v2_iwmmxt(regspace
, env
);
1376 /* Write terminating magic word */
1377 __put_user(0, regspace
);
1379 for(i
= 0; i
< TARGET_NSIG_WORDS
; i
++) {
1380 __put_user(set
->sig
[i
], &uc
->tuc_sigmask
.sig
[i
]);
1384 /* compare linux/arch/arm/kernel/signal.c:setup_frame() */
1385 static void setup_frame_v1(int usig
, struct target_sigaction
*ka
,
1386 target_sigset_t
*set
, CPUARMState
*regs
)
1388 struct sigframe_v1
*frame
;
1389 abi_ulong frame_addr
= get_sigframe(ka
, regs
, sizeof(*frame
));
1392 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0))
1395 setup_sigcontext(&frame
->sc
, regs
, set
->sig
[0]);
1397 for(i
= 1; i
< TARGET_NSIG_WORDS
; i
++) {
1398 if (__put_user(set
->sig
[i
], &frame
->extramask
[i
- 1]))
1402 setup_return(regs
, ka
, &frame
->retcode
, frame_addr
, usig
,
1403 frame_addr
+ offsetof(struct sigframe_v1
, retcode
));
1406 unlock_user_struct(frame
, frame_addr
, 1);
1409 static void setup_frame_v2(int usig
, struct target_sigaction
*ka
,
1410 target_sigset_t
*set
, CPUARMState
*regs
)
1412 struct sigframe_v2
*frame
;
1413 abi_ulong frame_addr
= get_sigframe(ka
, regs
, sizeof(*frame
));
1415 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0))
1418 setup_sigframe_v2(&frame
->uc
, set
, regs
);
1420 setup_return(regs
, ka
, &frame
->retcode
, frame_addr
, usig
,
1421 frame_addr
+ offsetof(struct sigframe_v2
, retcode
));
1423 unlock_user_struct(frame
, frame_addr
, 1);
1426 static void setup_frame(int usig
, struct target_sigaction
*ka
,
1427 target_sigset_t
*set
, CPUARMState
*regs
)
1429 if (get_osversion() >= 0x020612) {
1430 setup_frame_v2(usig
, ka
, set
, regs
);
1432 setup_frame_v1(usig
, ka
, set
, regs
);
1436 /* compare linux/arch/arm/kernel/signal.c:setup_rt_frame() */
1437 static void setup_rt_frame_v1(int usig
, struct target_sigaction
*ka
,
1438 target_siginfo_t
*info
,
1439 target_sigset_t
*set
, CPUARMState
*env
)
1441 struct rt_sigframe_v1
*frame
;
1442 abi_ulong frame_addr
= get_sigframe(ka
, env
, sizeof(*frame
));
1443 struct target_sigaltstack stack
;
1445 abi_ulong info_addr
, uc_addr
;
1447 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0))
1450 info_addr
= frame_addr
+ offsetof(struct rt_sigframe_v1
, info
);
1451 __put_user(info_addr
, &frame
->pinfo
);
1452 uc_addr
= frame_addr
+ offsetof(struct rt_sigframe_v1
, uc
);
1453 __put_user(uc_addr
, &frame
->puc
);
1454 copy_siginfo_to_user(&frame
->info
, info
);
1456 /* Clear all the bits of the ucontext we don't use. */
1457 memset(&frame
->uc
, 0, offsetof(struct target_ucontext_v1
, tuc_mcontext
));
1459 memset(&stack
, 0, sizeof(stack
));
1460 __put_user(target_sigaltstack_used
.ss_sp
, &stack
.ss_sp
);
1461 __put_user(target_sigaltstack_used
.ss_size
, &stack
.ss_size
);
1462 __put_user(sas_ss_flags(get_sp_from_cpustate(env
)), &stack
.ss_flags
);
1463 memcpy(&frame
->uc
.tuc_stack
, &stack
, sizeof(stack
));
1465 setup_sigcontext(&frame
->uc
.tuc_mcontext
, env
, set
->sig
[0]);
1466 for(i
= 0; i
< TARGET_NSIG_WORDS
; i
++) {
1467 if (__put_user(set
->sig
[i
], &frame
->uc
.tuc_sigmask
.sig
[i
]))
1471 setup_return(env
, ka
, &frame
->retcode
, frame_addr
, usig
,
1472 frame_addr
+ offsetof(struct rt_sigframe_v1
, retcode
));
1474 env
->regs
[1] = info_addr
;
1475 env
->regs
[2] = uc_addr
;
1478 unlock_user_struct(frame
, frame_addr
, 1);
1481 static void setup_rt_frame_v2(int usig
, struct target_sigaction
*ka
,
1482 target_siginfo_t
*info
,
1483 target_sigset_t
*set
, CPUARMState
*env
)
1485 struct rt_sigframe_v2
*frame
;
1486 abi_ulong frame_addr
= get_sigframe(ka
, env
, sizeof(*frame
));
1487 abi_ulong info_addr
, uc_addr
;
1489 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0))
1492 info_addr
= frame_addr
+ offsetof(struct rt_sigframe_v2
, info
);
1493 uc_addr
= frame_addr
+ offsetof(struct rt_sigframe_v2
, uc
);
1494 copy_siginfo_to_user(&frame
->info
, info
);
1496 setup_sigframe_v2(&frame
->uc
, set
, env
);
1498 setup_return(env
, ka
, &frame
->retcode
, frame_addr
, usig
,
1499 frame_addr
+ offsetof(struct rt_sigframe_v2
, retcode
));
1501 env
->regs
[1] = info_addr
;
1502 env
->regs
[2] = uc_addr
;
1504 unlock_user_struct(frame
, frame_addr
, 1);
1507 static void setup_rt_frame(int usig
, struct target_sigaction
*ka
,
1508 target_siginfo_t
*info
,
1509 target_sigset_t
*set
, CPUARMState
*env
)
1511 if (get_osversion() >= 0x020612) {
1512 setup_rt_frame_v2(usig
, ka
, info
, set
, env
);
1514 setup_rt_frame_v1(usig
, ka
, info
, set
, env
);
1519 restore_sigcontext(CPUARMState
*env
, struct target_sigcontext
*sc
)
1524 __get_user_error(env
->regs
[0], &sc
->arm_r0
, err
);
1525 __get_user_error(env
->regs
[1], &sc
->arm_r1
, err
);
1526 __get_user_error(env
->regs
[2], &sc
->arm_r2
, err
);
1527 __get_user_error(env
->regs
[3], &sc
->arm_r3
, err
);
1528 __get_user_error(env
->regs
[4], &sc
->arm_r4
, err
);
1529 __get_user_error(env
->regs
[5], &sc
->arm_r5
, err
);
1530 __get_user_error(env
->regs
[6], &sc
->arm_r6
, err
);
1531 __get_user_error(env
->regs
[7], &sc
->arm_r7
, err
);
1532 __get_user_error(env
->regs
[8], &sc
->arm_r8
, err
);
1533 __get_user_error(env
->regs
[9], &sc
->arm_r9
, err
);
1534 __get_user_error(env
->regs
[10], &sc
->arm_r10
, err
);
1535 __get_user_error(env
->regs
[11], &sc
->arm_fp
, err
);
1536 __get_user_error(env
->regs
[12], &sc
->arm_ip
, err
);
1537 __get_user_error(env
->regs
[13], &sc
->arm_sp
, err
);
1538 __get_user_error(env
->regs
[14], &sc
->arm_lr
, err
);
1539 __get_user_error(env
->regs
[15], &sc
->arm_pc
, err
);
1540 #ifdef TARGET_CONFIG_CPU_32
1541 __get_user_error(cpsr
, &sc
->arm_cpsr
, err
);
1542 cpsr_write(env
, cpsr
, CPSR_USER
| CPSR_EXEC
);
1545 err
|= !valid_user_regs(env
);
1550 static long do_sigreturn_v1(CPUARMState
*env
)
1552 abi_ulong frame_addr
;
1553 struct sigframe_v1
*frame
;
1554 target_sigset_t set
;
1559 * Since we stacked the signal on a 64-bit boundary,
1560 * then 'sp' should be word aligned here. If it's
1561 * not, then the user is trying to mess with us.
1563 if (env
->regs
[13] & 7)
1566 frame_addr
= env
->regs
[13];
1567 if (!lock_user_struct(VERIFY_READ
, frame
, frame_addr
, 1))
1570 if (__get_user(set
.sig
[0], &frame
->sc
.oldmask
))
1572 for(i
= 1; i
< TARGET_NSIG_WORDS
; i
++) {
1573 if (__get_user(set
.sig
[i
], &frame
->extramask
[i
- 1]))
1577 target_to_host_sigset_internal(&host_set
, &set
);
1578 sigprocmask(SIG_SETMASK
, &host_set
, NULL
);
1580 if (restore_sigcontext(env
, &frame
->sc
))
1584 /* Send SIGTRAP if we're single-stepping */
1585 if (ptrace_cancel_bpt(current
))
1586 send_sig(SIGTRAP
, current
, 1);
1588 unlock_user_struct(frame
, frame_addr
, 0);
1589 return env
->regs
[0];
1592 unlock_user_struct(frame
, frame_addr
, 0);
1593 force_sig(TARGET_SIGSEGV
/* , current */);
1597 static abi_ulong
*restore_sigframe_v2_vfp(CPUARMState
*env
, abi_ulong
*regspace
)
1600 abi_ulong magic
, sz
;
1601 uint32_t fpscr
, fpexc
;
1602 struct target_vfp_sigframe
*vfpframe
;
1603 vfpframe
= (struct target_vfp_sigframe
*)regspace
;
1605 __get_user(magic
, &vfpframe
->magic
);
1606 __get_user(sz
, &vfpframe
->size
);
1607 if (magic
!= TARGET_VFP_MAGIC
|| sz
!= sizeof(*vfpframe
)) {
1610 for (i
= 0; i
< 32; i
++) {
1611 __get_user(float64_val(env
->vfp
.regs
[i
]), &vfpframe
->ufp
.fpregs
[i
]);
1613 __get_user(fpscr
, &vfpframe
->ufp
.fpscr
);
1614 vfp_set_fpscr(env
, fpscr
);
1615 __get_user(fpexc
, &vfpframe
->ufp_exc
.fpexc
);
1616 /* Sanitise FPEXC: ensure VFP is enabled, FPINST2 is invalid
1617 * and the exception flag is cleared
1620 fpexc
&= ~((1 << 31) | (1 << 28));
1621 env
->vfp
.xregs
[ARM_VFP_FPEXC
] = fpexc
;
1622 __get_user(env
->vfp
.xregs
[ARM_VFP_FPINST
], &vfpframe
->ufp_exc
.fpinst
);
1623 __get_user(env
->vfp
.xregs
[ARM_VFP_FPINST2
], &vfpframe
->ufp_exc
.fpinst2
);
1624 return (abi_ulong
*)(vfpframe
+ 1);
1627 static abi_ulong
*restore_sigframe_v2_iwmmxt(CPUARMState
*env
,
1628 abi_ulong
*regspace
)
1631 abi_ulong magic
, sz
;
1632 struct target_iwmmxt_sigframe
*iwmmxtframe
;
1633 iwmmxtframe
= (struct target_iwmmxt_sigframe
*)regspace
;
1635 __get_user(magic
, &iwmmxtframe
->magic
);
1636 __get_user(sz
, &iwmmxtframe
->size
);
1637 if (magic
!= TARGET_IWMMXT_MAGIC
|| sz
!= sizeof(*iwmmxtframe
)) {
1640 for (i
= 0; i
< 16; i
++) {
1641 __get_user(env
->iwmmxt
.regs
[i
], &iwmmxtframe
->regs
[i
]);
1643 __get_user(env
->vfp
.xregs
[ARM_IWMMXT_wCSSF
], &iwmmxtframe
->wcssf
);
1644 __get_user(env
->vfp
.xregs
[ARM_IWMMXT_wCASF
], &iwmmxtframe
->wcssf
);
1645 __get_user(env
->vfp
.xregs
[ARM_IWMMXT_wCGR0
], &iwmmxtframe
->wcgr0
);
1646 __get_user(env
->vfp
.xregs
[ARM_IWMMXT_wCGR1
], &iwmmxtframe
->wcgr1
);
1647 __get_user(env
->vfp
.xregs
[ARM_IWMMXT_wCGR2
], &iwmmxtframe
->wcgr2
);
1648 __get_user(env
->vfp
.xregs
[ARM_IWMMXT_wCGR3
], &iwmmxtframe
->wcgr3
);
1649 return (abi_ulong
*)(iwmmxtframe
+ 1);
1652 static int do_sigframe_return_v2(CPUARMState
*env
, target_ulong frame_addr
,
1653 struct target_ucontext_v2
*uc
)
1656 abi_ulong
*regspace
;
1658 target_to_host_sigset(&host_set
, &uc
->tuc_sigmask
);
1659 sigprocmask(SIG_SETMASK
, &host_set
, NULL
);
1661 if (restore_sigcontext(env
, &uc
->tuc_mcontext
))
1664 /* Restore coprocessor signal frame */
1665 regspace
= uc
->tuc_regspace
;
1666 if (arm_feature(env
, ARM_FEATURE_VFP
)) {
1667 regspace
= restore_sigframe_v2_vfp(env
, regspace
);
1672 if (arm_feature(env
, ARM_FEATURE_IWMMXT
)) {
1673 regspace
= restore_sigframe_v2_iwmmxt(env
, regspace
);
1679 if (do_sigaltstack(frame_addr
+ offsetof(struct target_ucontext_v2
, tuc_stack
), 0, get_sp_from_cpustate(env
)) == -EFAULT
)
1683 /* Send SIGTRAP if we're single-stepping */
1684 if (ptrace_cancel_bpt(current
))
1685 send_sig(SIGTRAP
, current
, 1);
1691 static long do_sigreturn_v2(CPUARMState
*env
)
1693 abi_ulong frame_addr
;
1694 struct sigframe_v2
*frame
;
1697 * Since we stacked the signal on a 64-bit boundary,
1698 * then 'sp' should be word aligned here. If it's
1699 * not, then the user is trying to mess with us.
1701 if (env
->regs
[13] & 7)
1704 frame_addr
= env
->regs
[13];
1705 if (!lock_user_struct(VERIFY_READ
, frame
, frame_addr
, 1))
1708 if (do_sigframe_return_v2(env
, frame_addr
, &frame
->uc
))
1711 unlock_user_struct(frame
, frame_addr
, 0);
1712 return env
->regs
[0];
1715 unlock_user_struct(frame
, frame_addr
, 0);
1716 force_sig(TARGET_SIGSEGV
/* , current */);
1720 long do_sigreturn(CPUARMState
*env
)
1722 if (get_osversion() >= 0x020612) {
1723 return do_sigreturn_v2(env
);
1725 return do_sigreturn_v1(env
);
1729 static long do_rt_sigreturn_v1(CPUARMState
*env
)
1731 abi_ulong frame_addr
;
1732 struct rt_sigframe_v1
*frame
;
1736 * Since we stacked the signal on a 64-bit boundary,
1737 * then 'sp' should be word aligned here. If it's
1738 * not, then the user is trying to mess with us.
1740 if (env
->regs
[13] & 7)
1743 frame_addr
= env
->regs
[13];
1744 if (!lock_user_struct(VERIFY_READ
, frame
, frame_addr
, 1))
1747 target_to_host_sigset(&host_set
, &frame
->uc
.tuc_sigmask
);
1748 sigprocmask(SIG_SETMASK
, &host_set
, NULL
);
1750 if (restore_sigcontext(env
, &frame
->uc
.tuc_mcontext
))
1753 if (do_sigaltstack(frame_addr
+ offsetof(struct rt_sigframe_v1
, uc
.tuc_stack
), 0, get_sp_from_cpustate(env
)) == -EFAULT
)
1757 /* Send SIGTRAP if we're single-stepping */
1758 if (ptrace_cancel_bpt(current
))
1759 send_sig(SIGTRAP
, current
, 1);
1761 unlock_user_struct(frame
, frame_addr
, 0);
1762 return env
->regs
[0];
1765 unlock_user_struct(frame
, frame_addr
, 0);
1766 force_sig(TARGET_SIGSEGV
/* , current */);
1770 static long do_rt_sigreturn_v2(CPUARMState
*env
)
1772 abi_ulong frame_addr
;
1773 struct rt_sigframe_v2
*frame
;
1776 * Since we stacked the signal on a 64-bit boundary,
1777 * then 'sp' should be word aligned here. If it's
1778 * not, then the user is trying to mess with us.
1780 if (env
->regs
[13] & 7)
1783 frame_addr
= env
->regs
[13];
1784 if (!lock_user_struct(VERIFY_READ
, frame
, frame_addr
, 1))
1787 if (do_sigframe_return_v2(env
, frame_addr
, &frame
->uc
))
1790 unlock_user_struct(frame
, frame_addr
, 0);
1791 return env
->regs
[0];
1794 unlock_user_struct(frame
, frame_addr
, 0);
1795 force_sig(TARGET_SIGSEGV
/* , current */);
1799 long do_rt_sigreturn(CPUARMState
*env
)
1801 if (get_osversion() >= 0x020612) {
1802 return do_rt_sigreturn_v2(env
);
1804 return do_rt_sigreturn_v1(env
);
1808 #elif defined(TARGET_SPARC)
1810 #define __SUNOS_MAXWIN 31
1812 /* This is what SunOS does, so shall I. */
1813 struct target_sigcontext
{
1814 abi_ulong sigc_onstack
; /* state to restore */
1816 abi_ulong sigc_mask
; /* sigmask to restore */
1817 abi_ulong sigc_sp
; /* stack pointer */
1818 abi_ulong sigc_pc
; /* program counter */
1819 abi_ulong sigc_npc
; /* next program counter */
1820 abi_ulong sigc_psr
; /* for condition codes etc */
1821 abi_ulong sigc_g1
; /* User uses these two registers */
1822 abi_ulong sigc_o0
; /* within the trampoline code. */
1824 /* Now comes information regarding the users window set
1825 * at the time of the signal.
1827 abi_ulong sigc_oswins
; /* outstanding windows */
1829 /* stack ptrs for each regwin buf */
1830 char *sigc_spbuf
[__SUNOS_MAXWIN
];
1832 /* Windows to restore after signal */
1834 abi_ulong locals
[8];
1836 } sigc_wbuf
[__SUNOS_MAXWIN
];
1838 /* A Sparc stack frame */
1839 struct sparc_stackf
{
1840 abi_ulong locals
[8];
1842 /* It's simpler to treat fp and callers_pc as elements of ins[]
1843 * since we never need to access them ourselves.
1847 abi_ulong xxargs
[1];
1856 abi_ulong u_regs
[16]; /* globals and ins */
1862 abi_ulong si_float_regs
[32];
1863 unsigned long si_fsr
;
1864 unsigned long si_fpqdepth
;
1866 unsigned long *insn_addr
;
1869 } qemu_siginfo_fpu_t
;
1872 struct target_signal_frame
{
1873 struct sparc_stackf ss
;
1876 abi_ulong insns
[2] __attribute__ ((aligned (8)));
1877 abi_ulong extramask
[TARGET_NSIG_WORDS
- 1];
1878 abi_ulong extra_size
; /* Should be 0 */
1879 qemu_siginfo_fpu_t fpu_state
;
1881 struct target_rt_signal_frame
{
1882 struct sparc_stackf ss
;
1887 unsigned int insns
[2];
1889 unsigned int extra_size
; /* Should be 0 */
1890 qemu_siginfo_fpu_t fpu_state
;
1904 #define UREG_FP UREG_I6
1905 #define UREG_SP UREG_O6
1907 static inline abi_ulong
get_sigframe(struct target_sigaction
*sa
,
1909 unsigned long framesize
)
1913 sp
= env
->regwptr
[UREG_FP
];
1915 /* This is the X/Open sanctioned signal stack switching. */
1916 if (sa
->sa_flags
& TARGET_SA_ONSTACK
) {
1917 if (!on_sig_stack(sp
)
1918 && !((target_sigaltstack_used
.ss_sp
+ target_sigaltstack_used
.ss_size
) & 7))
1919 sp
= target_sigaltstack_used
.ss_sp
+ target_sigaltstack_used
.ss_size
;
1921 return sp
- framesize
;
1925 setup___siginfo(__siginfo_t
*si
, CPUSPARCState
*env
, abi_ulong mask
)
1929 err
|= __put_user(env
->psr
, &si
->si_regs
.psr
);
1930 err
|= __put_user(env
->pc
, &si
->si_regs
.pc
);
1931 err
|= __put_user(env
->npc
, &si
->si_regs
.npc
);
1932 err
|= __put_user(env
->y
, &si
->si_regs
.y
);
1933 for (i
=0; i
< 8; i
++) {
1934 err
|= __put_user(env
->gregs
[i
], &si
->si_regs
.u_regs
[i
]);
1936 for (i
=0; i
< 8; i
++) {
1937 err
|= __put_user(env
->regwptr
[UREG_I0
+ i
], &si
->si_regs
.u_regs
[i
+8]);
1939 err
|= __put_user(mask
, &si
->si_mask
);
1945 setup_sigcontext(struct target_sigcontext
*sc
, /*struct _fpstate *fpstate,*/
1946 CPUSPARCState
*env
, unsigned long mask
)
1950 err
|= __put_user(mask
, &sc
->sigc_mask
);
1951 err
|= __put_user(env
->regwptr
[UREG_SP
], &sc
->sigc_sp
);
1952 err
|= __put_user(env
->pc
, &sc
->sigc_pc
);
1953 err
|= __put_user(env
->npc
, &sc
->sigc_npc
);
1954 err
|= __put_user(env
->psr
, &sc
->sigc_psr
);
1955 err
|= __put_user(env
->gregs
[1], &sc
->sigc_g1
);
1956 err
|= __put_user(env
->regwptr
[UREG_O0
], &sc
->sigc_o0
);
1961 #define NF_ALIGNEDSZ (((sizeof(struct target_signal_frame) + 7) & (~7)))
1963 static void setup_frame(int sig
, struct target_sigaction
*ka
,
1964 target_sigset_t
*set
, CPUSPARCState
*env
)
1967 struct target_signal_frame
*sf
;
1968 int sigframe_size
, err
, i
;
1970 /* 1. Make sure everything is clean */
1971 //synchronize_user_stack();
1973 sigframe_size
= NF_ALIGNEDSZ
;
1974 sf_addr
= get_sigframe(ka
, env
, sigframe_size
);
1976 sf
= lock_user(VERIFY_WRITE
, sf_addr
,
1977 sizeof(struct target_signal_frame
), 0);
1981 //fprintf(stderr, "sf: %x pc %x fp %x sp %x\n", sf, env->pc, env->regwptr[UREG_FP], env->regwptr[UREG_SP]);
1983 if (invalid_frame_pointer(sf
, sigframe_size
))
1984 goto sigill_and_return
;
1986 /* 2. Save the current process state */
1987 err
= setup___siginfo(&sf
->info
, env
, set
->sig
[0]);
1988 err
|= __put_user(0, &sf
->extra_size
);
1990 //err |= save_fpu_state(regs, &sf->fpu_state);
1991 //err |= __put_user(&sf->fpu_state, &sf->fpu_save);
1993 err
|= __put_user(set
->sig
[0], &sf
->info
.si_mask
);
1994 for (i
= 0; i
< TARGET_NSIG_WORDS
- 1; i
++) {
1995 err
|= __put_user(set
->sig
[i
+ 1], &sf
->extramask
[i
]);
1998 for (i
= 0; i
< 8; i
++) {
1999 err
|= __put_user(env
->regwptr
[i
+ UREG_L0
], &sf
->ss
.locals
[i
]);
2001 for (i
= 0; i
< 8; i
++) {
2002 err
|= __put_user(env
->regwptr
[i
+ UREG_I0
], &sf
->ss
.ins
[i
]);
2007 /* 3. signal handler back-trampoline and parameters */
2008 env
->regwptr
[UREG_FP
] = sf_addr
;
2009 env
->regwptr
[UREG_I0
] = sig
;
2010 env
->regwptr
[UREG_I1
] = sf_addr
+
2011 offsetof(struct target_signal_frame
, info
);
2012 env
->regwptr
[UREG_I2
] = sf_addr
+
2013 offsetof(struct target_signal_frame
, info
);
2015 /* 4. signal handler */
2016 env
->pc
= ka
->_sa_handler
;
2017 env
->npc
= (env
->pc
+ 4);
2018 /* 5. return to kernel instructions */
2019 if (ka
->sa_restorer
)
2020 env
->regwptr
[UREG_I7
] = ka
->sa_restorer
;
2024 env
->regwptr
[UREG_I7
] = sf_addr
+
2025 offsetof(struct target_signal_frame
, insns
) - 2 * 4;
2027 /* mov __NR_sigreturn, %g1 */
2029 err
|= __put_user(val32
, &sf
->insns
[0]);
2033 err
|= __put_user(val32
, &sf
->insns
[1]);
2037 /* Flush instruction space. */
2038 //flush_sig_insns(current->mm, (unsigned long) &(sf->insns[0]));
2041 unlock_user(sf
, sf_addr
, sizeof(struct target_signal_frame
));
2045 force_sig(TARGET_SIGILL
);
2048 //fprintf(stderr, "force_sig\n");
2049 unlock_user(sf
, sf_addr
, sizeof(struct target_signal_frame
));
2050 force_sig(TARGET_SIGSEGV
);
2053 restore_fpu_state(CPUSPARCState
*env
, qemu_siginfo_fpu_t
*fpu
)
2058 if (current
->flags
& PF_USEDFPU
)
2059 regs
->psr
&= ~PSR_EF
;
2061 if (current
== last_task_used_math
) {
2062 last_task_used_math
= 0;
2063 regs
->psr
&= ~PSR_EF
;
2066 current
->used_math
= 1;
2067 current
->flags
&= ~PF_USEDFPU
;
2070 if (verify_area (VERIFY_READ
, fpu
, sizeof(*fpu
)))
2074 /* XXX: incorrect */
2075 err
= copy_from_user(&env
->fpr
[0], fpu
->si_float_regs
[0],
2076 (sizeof(abi_ulong
) * 32));
2077 err
|= __get_user(env
->fsr
, &fpu
->si_fsr
);
2079 err
|= __get_user(current
->thread
.fpqdepth
, &fpu
->si_fpqdepth
);
2080 if (current
->thread
.fpqdepth
!= 0)
2081 err
|= __copy_from_user(¤t
->thread
.fpqueue
[0],
2082 &fpu
->si_fpqueue
[0],
2083 ((sizeof(unsigned long) +
2084 (sizeof(unsigned long *)))*16));
2090 static void setup_rt_frame(int sig
, struct target_sigaction
*ka
,
2091 target_siginfo_t
*info
,
2092 target_sigset_t
*set
, CPUSPARCState
*env
)
2094 fprintf(stderr
, "setup_rt_frame: not implemented\n");
2097 long do_sigreturn(CPUSPARCState
*env
)
2100 struct target_signal_frame
*sf
;
2101 uint32_t up_psr
, pc
, npc
;
2102 target_sigset_t set
;
2106 sf_addr
= env
->regwptr
[UREG_FP
];
2107 if (!lock_user_struct(VERIFY_READ
, sf
, sf_addr
, 1))
2110 fprintf(stderr
, "sigreturn\n");
2111 fprintf(stderr
, "sf: %x pc %x fp %x sp %x\n", sf
, env
->pc
, env
->regwptr
[UREG_FP
], env
->regwptr
[UREG_SP
]);
2113 //cpu_dump_state(env, stderr, fprintf, 0);
2115 /* 1. Make sure we are not getting garbage from the user */
2120 err
= __get_user(pc
, &sf
->info
.si_regs
.pc
);
2121 err
|= __get_user(npc
, &sf
->info
.si_regs
.npc
);
2126 /* 2. Restore the state */
2127 err
|= __get_user(up_psr
, &sf
->info
.si_regs
.psr
);
2129 /* User can only change condition codes and FPU enabling in %psr. */
2130 env
->psr
= (up_psr
& (PSR_ICC
/* | PSR_EF */))
2131 | (env
->psr
& ~(PSR_ICC
/* | PSR_EF */));
2135 err
|= __get_user(env
->y
, &sf
->info
.si_regs
.y
);
2136 for (i
=0; i
< 8; i
++) {
2137 err
|= __get_user(env
->gregs
[i
], &sf
->info
.si_regs
.u_regs
[i
]);
2139 for (i
=0; i
< 8; i
++) {
2140 err
|= __get_user(env
->regwptr
[i
+ UREG_I0
], &sf
->info
.si_regs
.u_regs
[i
+8]);
2143 /* FIXME: implement FPU save/restore:
2144 * __get_user(fpu_save, &sf->fpu_save);
2146 * err |= restore_fpu_state(env, fpu_save);
2149 /* This is pretty much atomic, no amount locking would prevent
2150 * the races which exist anyways.
2152 err
|= __get_user(set
.sig
[0], &sf
->info
.si_mask
);
2153 for(i
= 1; i
< TARGET_NSIG_WORDS
; i
++) {
2154 err
|= (__get_user(set
.sig
[i
], &sf
->extramask
[i
- 1]));
2157 target_to_host_sigset_internal(&host_set
, &set
);
2158 sigprocmask(SIG_SETMASK
, &host_set
, NULL
);
2162 unlock_user_struct(sf
, sf_addr
, 0);
2163 return env
->regwptr
[0];
2166 unlock_user_struct(sf
, sf_addr
, 0);
2167 force_sig(TARGET_SIGSEGV
);
2170 long do_rt_sigreturn(CPUSPARCState
*env
)
2172 fprintf(stderr
, "do_rt_sigreturn: not implemented\n");
2173 return -TARGET_ENOSYS
;
2176 #if defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
2198 typedef abi_ulong target_mc_greg_t
;
2199 typedef target_mc_greg_t target_mc_gregset_t
[MC_NGREG
];
2201 struct target_mc_fq
{
2202 abi_ulong
*mcfq_addr
;
2206 struct target_mc_fpu
{
2210 //uint128_t qregs[16];
2212 abi_ulong mcfpu_fsr
;
2213 abi_ulong mcfpu_fprs
;
2214 abi_ulong mcfpu_gsr
;
2215 struct target_mc_fq
*mcfpu_fq
;
2216 unsigned char mcfpu_qcnt
;
2217 unsigned char mcfpu_qentsz
;
2218 unsigned char mcfpu_enab
;
2220 typedef struct target_mc_fpu target_mc_fpu_t
;
2223 target_mc_gregset_t mc_gregs
;
2224 target_mc_greg_t mc_fp
;
2225 target_mc_greg_t mc_i7
;
2226 target_mc_fpu_t mc_fpregs
;
2227 } target_mcontext_t
;
2229 struct target_ucontext
{
2230 struct target_ucontext
*tuc_link
;
2231 abi_ulong tuc_flags
;
2232 target_sigset_t tuc_sigmask
;
2233 target_mcontext_t tuc_mcontext
;
2236 /* A V9 register window */
2237 struct target_reg_window
{
2238 abi_ulong locals
[8];
2242 #define TARGET_STACK_BIAS 2047
2244 /* {set, get}context() needed for 64-bit SparcLinux userland. */
2245 void sparc64_set_context(CPUSPARCState
*env
)
2248 struct target_ucontext
*ucp
;
2249 target_mc_gregset_t
*grp
;
2250 abi_ulong pc
, npc
, tstate
;
2251 abi_ulong fp
, i7
, w_addr
;
2255 ucp_addr
= env
->regwptr
[UREG_I0
];
2256 if (!lock_user_struct(VERIFY_READ
, ucp
, ucp_addr
, 1))
2258 grp
= &ucp
->tuc_mcontext
.mc_gregs
;
2259 err
= __get_user(pc
, &((*grp
)[MC_PC
]));
2260 err
|= __get_user(npc
, &((*grp
)[MC_NPC
]));
2261 if (err
|| ((pc
| npc
) & 3))
2263 if (env
->regwptr
[UREG_I1
]) {
2264 target_sigset_t target_set
;
2267 if (TARGET_NSIG_WORDS
== 1) {
2268 if (__get_user(target_set
.sig
[0], &ucp
->tuc_sigmask
.sig
[0]))
2271 abi_ulong
*src
, *dst
;
2272 src
= ucp
->tuc_sigmask
.sig
;
2273 dst
= target_set
.sig
;
2274 for (i
= 0; i
< sizeof(target_sigset_t
) / sizeof(abi_ulong
);
2276 err
|= __get_user(*dst
, src
);
2280 target_to_host_sigset_internal(&set
, &target_set
);
2281 sigprocmask(SIG_SETMASK
, &set
, NULL
);
2285 err
|= __get_user(env
->y
, &((*grp
)[MC_Y
]));
2286 err
|= __get_user(tstate
, &((*grp
)[MC_TSTATE
]));
2287 env
->asi
= (tstate
>> 24) & 0xff;
2288 cpu_put_ccr(env
, tstate
>> 32);
2289 cpu_put_cwp64(env
, tstate
& 0x1f);
2290 err
|= __get_user(env
->gregs
[1], (&(*grp
)[MC_G1
]));
2291 err
|= __get_user(env
->gregs
[2], (&(*grp
)[MC_G2
]));
2292 err
|= __get_user(env
->gregs
[3], (&(*grp
)[MC_G3
]));
2293 err
|= __get_user(env
->gregs
[4], (&(*grp
)[MC_G4
]));
2294 err
|= __get_user(env
->gregs
[5], (&(*grp
)[MC_G5
]));
2295 err
|= __get_user(env
->gregs
[6], (&(*grp
)[MC_G6
]));
2296 err
|= __get_user(env
->gregs
[7], (&(*grp
)[MC_G7
]));
2297 err
|= __get_user(env
->regwptr
[UREG_I0
], (&(*grp
)[MC_O0
]));
2298 err
|= __get_user(env
->regwptr
[UREG_I1
], (&(*grp
)[MC_O1
]));
2299 err
|= __get_user(env
->regwptr
[UREG_I2
], (&(*grp
)[MC_O2
]));
2300 err
|= __get_user(env
->regwptr
[UREG_I3
], (&(*grp
)[MC_O3
]));
2301 err
|= __get_user(env
->regwptr
[UREG_I4
], (&(*grp
)[MC_O4
]));
2302 err
|= __get_user(env
->regwptr
[UREG_I5
], (&(*grp
)[MC_O5
]));
2303 err
|= __get_user(env
->regwptr
[UREG_I6
], (&(*grp
)[MC_O6
]));
2304 err
|= __get_user(env
->regwptr
[UREG_I7
], (&(*grp
)[MC_O7
]));
2306 err
|= __get_user(fp
, &(ucp
->tuc_mcontext
.mc_fp
));
2307 err
|= __get_user(i7
, &(ucp
->tuc_mcontext
.mc_i7
));
2309 w_addr
= TARGET_STACK_BIAS
+env
->regwptr
[UREG_I6
];
2310 if (put_user(fp
, w_addr
+ offsetof(struct target_reg_window
, ins
[6]),
2313 if (put_user(i7
, w_addr
+ offsetof(struct target_reg_window
, ins
[7]),
2316 /* FIXME this does not match how the kernel handles the FPU in
2317 * its sparc64_set_context implementation. In particular the FPU
2318 * is only restored if fenab is non-zero in:
2319 * __get_user(fenab, &(ucp->tuc_mcontext.mc_fpregs.mcfpu_enab));
2321 err
|= __get_user(env
->fprs
, &(ucp
->tuc_mcontext
.mc_fpregs
.mcfpu_fprs
));
2323 uint32_t *src
= ucp
->tuc_mcontext
.mc_fpregs
.mcfpu_fregs
.sregs
;
2324 for (i
= 0; i
< 64; i
++, src
++) {
2326 err
|= __get_user(env
->fpr
[i
/2].l
.lower
, src
);
2328 err
|= __get_user(env
->fpr
[i
/2].l
.upper
, src
);
2332 err
|= __get_user(env
->fsr
,
2333 &(ucp
->tuc_mcontext
.mc_fpregs
.mcfpu_fsr
));
2334 err
|= __get_user(env
->gsr
,
2335 &(ucp
->tuc_mcontext
.mc_fpregs
.mcfpu_gsr
));
2338 unlock_user_struct(ucp
, ucp_addr
, 0);
2341 unlock_user_struct(ucp
, ucp_addr
, 0);
2342 force_sig(TARGET_SIGSEGV
);
2345 void sparc64_get_context(CPUSPARCState
*env
)
2348 struct target_ucontext
*ucp
;
2349 target_mc_gregset_t
*grp
;
2350 target_mcontext_t
*mcp
;
2351 abi_ulong fp
, i7
, w_addr
;
2354 target_sigset_t target_set
;
2357 ucp_addr
= env
->regwptr
[UREG_I0
];
2358 if (!lock_user_struct(VERIFY_WRITE
, ucp
, ucp_addr
, 0))
2361 mcp
= &ucp
->tuc_mcontext
;
2362 grp
= &mcp
->mc_gregs
;
2364 /* Skip over the trap instruction, first. */
2370 sigprocmask(0, NULL
, &set
);
2371 host_to_target_sigset_internal(&target_set
, &set
);
2372 if (TARGET_NSIG_WORDS
== 1) {
2373 err
|= __put_user(target_set
.sig
[0],
2374 (abi_ulong
*)&ucp
->tuc_sigmask
);
2376 abi_ulong
*src
, *dst
;
2377 src
= target_set
.sig
;
2378 dst
= ucp
->tuc_sigmask
.sig
;
2379 for (i
= 0; i
< sizeof(target_sigset_t
) / sizeof(abi_ulong
);
2381 err
|= __put_user(*src
, dst
);
2386 /* XXX: tstate must be saved properly */
2387 // err |= __put_user(env->tstate, &((*grp)[MC_TSTATE]));
2388 err
|= __put_user(env
->pc
, &((*grp
)[MC_PC
]));
2389 err
|= __put_user(env
->npc
, &((*grp
)[MC_NPC
]));
2390 err
|= __put_user(env
->y
, &((*grp
)[MC_Y
]));
2391 err
|= __put_user(env
->gregs
[1], &((*grp
)[MC_G1
]));
2392 err
|= __put_user(env
->gregs
[2], &((*grp
)[MC_G2
]));
2393 err
|= __put_user(env
->gregs
[3], &((*grp
)[MC_G3
]));
2394 err
|= __put_user(env
->gregs
[4], &((*grp
)[MC_G4
]));
2395 err
|= __put_user(env
->gregs
[5], &((*grp
)[MC_G5
]));
2396 err
|= __put_user(env
->gregs
[6], &((*grp
)[MC_G6
]));
2397 err
|= __put_user(env
->gregs
[7], &((*grp
)[MC_G7
]));
2398 err
|= __put_user(env
->regwptr
[UREG_I0
], &((*grp
)[MC_O0
]));
2399 err
|= __put_user(env
->regwptr
[UREG_I1
], &((*grp
)[MC_O1
]));
2400 err
|= __put_user(env
->regwptr
[UREG_I2
], &((*grp
)[MC_O2
]));
2401 err
|= __put_user(env
->regwptr
[UREG_I3
], &((*grp
)[MC_O3
]));
2402 err
|= __put_user(env
->regwptr
[UREG_I4
], &((*grp
)[MC_O4
]));
2403 err
|= __put_user(env
->regwptr
[UREG_I5
], &((*grp
)[MC_O5
]));
2404 err
|= __put_user(env
->regwptr
[UREG_I6
], &((*grp
)[MC_O6
]));
2405 err
|= __put_user(env
->regwptr
[UREG_I7
], &((*grp
)[MC_O7
]));
2407 w_addr
= TARGET_STACK_BIAS
+env
->regwptr
[UREG_I6
];
2409 if (get_user(fp
, w_addr
+ offsetof(struct target_reg_window
, ins
[6]),
2412 if (get_user(i7
, w_addr
+ offsetof(struct target_reg_window
, ins
[7]),
2415 err
|= __put_user(fp
, &(mcp
->mc_fp
));
2416 err
|= __put_user(i7
, &(mcp
->mc_i7
));
2419 uint32_t *dst
= ucp
->tuc_mcontext
.mc_fpregs
.mcfpu_fregs
.sregs
;
2420 for (i
= 0; i
< 64; i
++, dst
++) {
2422 err
|= __put_user(env
->fpr
[i
/2].l
.lower
, dst
);
2424 err
|= __put_user(env
->fpr
[i
/2].l
.upper
, dst
);
2428 err
|= __put_user(env
->fsr
, &(mcp
->mc_fpregs
.mcfpu_fsr
));
2429 err
|= __put_user(env
->gsr
, &(mcp
->mc_fpregs
.mcfpu_gsr
));
2430 err
|= __put_user(env
->fprs
, &(mcp
->mc_fpregs
.mcfpu_fprs
));
2434 unlock_user_struct(ucp
, ucp_addr
, 1);
2437 unlock_user_struct(ucp
, ucp_addr
, 1);
2438 force_sig(TARGET_SIGSEGV
);
2441 #elif defined(TARGET_MIPS) || defined(TARGET_MIPS64)
2443 # if defined(TARGET_ABI_MIPSO32)
2444 struct target_sigcontext
{
2445 uint32_t sc_regmask
; /* Unused */
2448 uint64_t sc_regs
[32];
2449 uint64_t sc_fpregs
[32];
2450 uint32_t sc_ownedfp
; /* Unused */
2451 uint32_t sc_fpc_csr
;
2452 uint32_t sc_fpc_eir
; /* Unused */
2453 uint32_t sc_used_math
;
2454 uint32_t sc_dsp
; /* dsp status, was sc_ssflags */
2458 target_ulong sc_hi1
; /* Was sc_cause */
2459 target_ulong sc_lo1
; /* Was sc_badvaddr */
2460 target_ulong sc_hi2
; /* Was sc_sigset[4] */
2461 target_ulong sc_lo2
;
2462 target_ulong sc_hi3
;
2463 target_ulong sc_lo3
;
2465 # else /* N32 || N64 */
2466 struct target_sigcontext
{
2467 uint64_t sc_regs
[32];
2468 uint64_t sc_fpregs
[32];
2478 uint32_t sc_fpc_csr
;
2479 uint32_t sc_used_math
;
2481 uint32_t sc_reserved
;
2486 uint32_t sf_ass
[4]; /* argument save space for o32 */
2487 uint32_t sf_code
[2]; /* signal trampoline */
2488 struct target_sigcontext sf_sc
;
2489 target_sigset_t sf_mask
;
2492 struct target_ucontext
{
2493 target_ulong tuc_flags
;
2494 target_ulong tuc_link
;
2495 target_stack_t tuc_stack
;
2497 struct target_sigcontext tuc_mcontext
;
2498 target_sigset_t tuc_sigmask
;
2501 struct target_rt_sigframe
{
2502 uint32_t rs_ass
[4]; /* argument save space for o32 */
2503 uint32_t rs_code
[2]; /* signal trampoline */
2504 struct target_siginfo rs_info
;
2505 struct target_ucontext rs_uc
;
2508 /* Install trampoline to jump back from signal handler */
2509 static inline int install_sigtramp(unsigned int *tramp
, unsigned int syscall
)
2514 * Set up the return code ...
2516 * li v0, __NR__foo_sigreturn
2520 err
|= __put_user(0x24020000 + syscall
, tramp
+ 0);
2521 err
|= __put_user(0x0000000c , tramp
+ 1);
2526 setup_sigcontext(CPUMIPSState
*regs
, struct target_sigcontext
*sc
)
2531 err
|= __put_user(exception_resume_pc(regs
), &sc
->sc_pc
);
2532 regs
->hflags
&= ~MIPS_HFLAG_BMASK
;
2534 __put_user(0, &sc
->sc_regs
[0]);
2535 for (i
= 1; i
< 32; ++i
) {
2536 err
|= __put_user(regs
->active_tc
.gpr
[i
], &sc
->sc_regs
[i
]);
2539 err
|= __put_user(regs
->active_tc
.HI
[0], &sc
->sc_mdhi
);
2540 err
|= __put_user(regs
->active_tc
.LO
[0], &sc
->sc_mdlo
);
2542 /* Rather than checking for dsp existence, always copy. The storage
2543 would just be garbage otherwise. */
2544 err
|= __put_user(regs
->active_tc
.HI
[1], &sc
->sc_hi1
);
2545 err
|= __put_user(regs
->active_tc
.HI
[2], &sc
->sc_hi2
);
2546 err
|= __put_user(regs
->active_tc
.HI
[3], &sc
->sc_hi3
);
2547 err
|= __put_user(regs
->active_tc
.LO
[1], &sc
->sc_lo1
);
2548 err
|= __put_user(regs
->active_tc
.LO
[2], &sc
->sc_lo2
);
2549 err
|= __put_user(regs
->active_tc
.LO
[3], &sc
->sc_lo3
);
2551 uint32_t dsp
= cpu_rddsp(0x3ff, regs
);
2552 err
|= __put_user(dsp
, &sc
->sc_dsp
);
2555 err
|= __put_user(1, &sc
->sc_used_math
);
2557 for (i
= 0; i
< 32; ++i
) {
2558 err
|= __put_user(regs
->active_fpu
.fpr
[i
].d
, &sc
->sc_fpregs
[i
]);
2565 restore_sigcontext(CPUMIPSState
*regs
, struct target_sigcontext
*sc
)
2570 err
|= __get_user(regs
->CP0_EPC
, &sc
->sc_pc
);
2572 err
|= __get_user(regs
->active_tc
.HI
[0], &sc
->sc_mdhi
);
2573 err
|= __get_user(regs
->active_tc
.LO
[0], &sc
->sc_mdlo
);
2575 for (i
= 1; i
< 32; ++i
) {
2576 err
|= __get_user(regs
->active_tc
.gpr
[i
], &sc
->sc_regs
[i
]);
2579 err
|= __get_user(regs
->active_tc
.HI
[1], &sc
->sc_hi1
);
2580 err
|= __get_user(regs
->active_tc
.HI
[2], &sc
->sc_hi2
);
2581 err
|= __get_user(regs
->active_tc
.HI
[3], &sc
->sc_hi3
);
2582 err
|= __get_user(regs
->active_tc
.LO
[1], &sc
->sc_lo1
);
2583 err
|= __get_user(regs
->active_tc
.LO
[2], &sc
->sc_lo2
);
2584 err
|= __get_user(regs
->active_tc
.LO
[3], &sc
->sc_lo3
);
2587 err
|= __get_user(dsp
, &sc
->sc_dsp
);
2588 cpu_wrdsp(dsp
, 0x3ff, regs
);
2591 for (i
= 0; i
< 32; ++i
) {
2592 err
|= __get_user(regs
->active_fpu
.fpr
[i
].d
, &sc
->sc_fpregs
[i
]);
2599 * Determine which stack to use..
2601 static inline abi_ulong
2602 get_sigframe(struct target_sigaction
*ka
, CPUMIPSState
*regs
, size_t frame_size
)
2606 /* Default to using normal stack */
2607 sp
= regs
->active_tc
.gpr
[29];
2610 * FPU emulator may have its own trampoline active just
2611 * above the user stack, 16-bytes before the next lowest
2612 * 16 byte boundary. Try to avoid trashing it.
2616 /* This is the X/Open sanctioned signal stack switching. */
2617 if ((ka
->sa_flags
& TARGET_SA_ONSTACK
) && (sas_ss_flags (sp
) == 0)) {
2618 sp
= target_sigaltstack_used
.ss_sp
+ target_sigaltstack_used
.ss_size
;
2621 return (sp
- frame_size
) & ~7;
2624 static void mips_set_hflags_isa_mode_from_pc(CPUMIPSState
*env
)
2626 if (env
->insn_flags
& (ASE_MIPS16
| ASE_MICROMIPS
)) {
2627 env
->hflags
&= ~MIPS_HFLAG_M16
;
2628 env
->hflags
|= (env
->active_tc
.PC
& 1) << MIPS_HFLAG_M16_SHIFT
;
2629 env
->active_tc
.PC
&= ~(target_ulong
) 1;
2633 # if defined(TARGET_ABI_MIPSO32)
2634 /* compare linux/arch/mips/kernel/signal.c:setup_frame() */
2635 static void setup_frame(int sig
, struct target_sigaction
* ka
,
2636 target_sigset_t
*set
, CPUMIPSState
*regs
)
2638 struct sigframe
*frame
;
2639 abi_ulong frame_addr
;
2642 frame_addr
= get_sigframe(ka
, regs
, sizeof(*frame
));
2643 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0))
2646 install_sigtramp(frame
->sf_code
, TARGET_NR_sigreturn
);
2648 if(setup_sigcontext(regs
, &frame
->sf_sc
))
2651 for(i
= 0; i
< TARGET_NSIG_WORDS
; i
++) {
2652 if(__put_user(set
->sig
[i
], &frame
->sf_mask
.sig
[i
]))
2657 * Arguments to signal handler:
2659 * a0 = signal number
2660 * a1 = 0 (should be cause)
2661 * a2 = pointer to struct sigcontext
2663 * $25 and PC point to the signal handler, $29 points to the
2666 regs
->active_tc
.gpr
[ 4] = sig
;
2667 regs
->active_tc
.gpr
[ 5] = 0;
2668 regs
->active_tc
.gpr
[ 6] = frame_addr
+ offsetof(struct sigframe
, sf_sc
);
2669 regs
->active_tc
.gpr
[29] = frame_addr
;
2670 regs
->active_tc
.gpr
[31] = frame_addr
+ offsetof(struct sigframe
, sf_code
);
2671 /* The original kernel code sets CP0_EPC to the handler
2672 * since it returns to userland using eret
2673 * we cannot do this here, and we must set PC directly */
2674 regs
->active_tc
.PC
= regs
->active_tc
.gpr
[25] = ka
->_sa_handler
;
2675 mips_set_hflags_isa_mode_from_pc(regs
);
2676 unlock_user_struct(frame
, frame_addr
, 1);
2680 unlock_user_struct(frame
, frame_addr
, 1);
2681 force_sig(TARGET_SIGSEGV
/*, current*/);
2684 long do_sigreturn(CPUMIPSState
*regs
)
2686 struct sigframe
*frame
;
2687 abi_ulong frame_addr
;
2689 target_sigset_t target_set
;
2692 #if defined(DEBUG_SIGNAL)
2693 fprintf(stderr
, "do_sigreturn\n");
2695 frame_addr
= regs
->active_tc
.gpr
[29];
2696 if (!lock_user_struct(VERIFY_READ
, frame
, frame_addr
, 1))
2699 for(i
= 0; i
< TARGET_NSIG_WORDS
; i
++) {
2700 if(__get_user(target_set
.sig
[i
], &frame
->sf_mask
.sig
[i
]))
2704 target_to_host_sigset_internal(&blocked
, &target_set
);
2705 sigprocmask(SIG_SETMASK
, &blocked
, NULL
);
2707 if (restore_sigcontext(regs
, &frame
->sf_sc
))
2712 * Don't let your children do this ...
2714 __asm__
__volatile__(
2722 regs
->active_tc
.PC
= regs
->CP0_EPC
;
2723 mips_set_hflags_isa_mode_from_pc(regs
);
2724 /* I am not sure this is right, but it seems to work
2725 * maybe a problem with nested signals ? */
2727 return -TARGET_QEMU_ESIGRETURN
;
2730 force_sig(TARGET_SIGSEGV
/*, current*/);
2735 static void setup_rt_frame(int sig
, struct target_sigaction
*ka
,
2736 target_siginfo_t
*info
,
2737 target_sigset_t
*set
, CPUMIPSState
*env
)
2739 struct target_rt_sigframe
*frame
;
2740 abi_ulong frame_addr
;
2743 frame_addr
= get_sigframe(ka
, env
, sizeof(*frame
));
2744 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0))
2747 install_sigtramp(frame
->rs_code
, TARGET_NR_rt_sigreturn
);
2749 copy_siginfo_to_user(&frame
->rs_info
, info
);
2751 __put_user(0, &frame
->rs_uc
.tuc_flags
);
2752 __put_user(0, &frame
->rs_uc
.tuc_link
);
2753 __put_user(target_sigaltstack_used
.ss_sp
, &frame
->rs_uc
.tuc_stack
.ss_sp
);
2754 __put_user(target_sigaltstack_used
.ss_size
, &frame
->rs_uc
.tuc_stack
.ss_size
);
2755 __put_user(sas_ss_flags(get_sp_from_cpustate(env
)),
2756 &frame
->rs_uc
.tuc_stack
.ss_flags
);
2758 setup_sigcontext(env
, &frame
->rs_uc
.tuc_mcontext
);
2760 for(i
= 0; i
< TARGET_NSIG_WORDS
; i
++) {
2761 __put_user(set
->sig
[i
], &frame
->rs_uc
.tuc_sigmask
.sig
[i
]);
2765 * Arguments to signal handler:
2767 * a0 = signal number
2768 * a1 = pointer to siginfo_t
2769 * a2 = pointer to struct ucontext
2771 * $25 and PC point to the signal handler, $29 points to the
2774 env
->active_tc
.gpr
[ 4] = sig
;
2775 env
->active_tc
.gpr
[ 5] = frame_addr
2776 + offsetof(struct target_rt_sigframe
, rs_info
);
2777 env
->active_tc
.gpr
[ 6] = frame_addr
2778 + offsetof(struct target_rt_sigframe
, rs_uc
);
2779 env
->active_tc
.gpr
[29] = frame_addr
;
2780 env
->active_tc
.gpr
[31] = frame_addr
2781 + offsetof(struct target_rt_sigframe
, rs_code
);
2782 /* The original kernel code sets CP0_EPC to the handler
2783 * since it returns to userland using eret
2784 * we cannot do this here, and we must set PC directly */
2785 env
->active_tc
.PC
= env
->active_tc
.gpr
[25] = ka
->_sa_handler
;
2786 mips_set_hflags_isa_mode_from_pc(env
);
2787 unlock_user_struct(frame
, frame_addr
, 1);
2791 unlock_user_struct(frame
, frame_addr
, 1);
2792 force_sig(TARGET_SIGSEGV
/*, current*/);
2795 long do_rt_sigreturn(CPUMIPSState
*env
)
2797 struct target_rt_sigframe
*frame
;
2798 abi_ulong frame_addr
;
2801 #if defined(DEBUG_SIGNAL)
2802 fprintf(stderr
, "do_rt_sigreturn\n");
2804 frame_addr
= env
->active_tc
.gpr
[29];
2805 if (!lock_user_struct(VERIFY_READ
, frame
, frame_addr
, 1))
2808 target_to_host_sigset(&blocked
, &frame
->rs_uc
.tuc_sigmask
);
2809 sigprocmask(SIG_SETMASK
, &blocked
, NULL
);
2811 if (restore_sigcontext(env
, &frame
->rs_uc
.tuc_mcontext
))
2814 if (do_sigaltstack(frame_addr
+
2815 offsetof(struct target_rt_sigframe
, rs_uc
.tuc_stack
),
2816 0, get_sp_from_cpustate(env
)) == -EFAULT
)
2819 env
->active_tc
.PC
= env
->CP0_EPC
;
2820 mips_set_hflags_isa_mode_from_pc(env
);
2821 /* I am not sure this is right, but it seems to work
2822 * maybe a problem with nested signals ? */
2824 return -TARGET_QEMU_ESIGRETURN
;
2827 force_sig(TARGET_SIGSEGV
/*, current*/);
2831 #elif defined(TARGET_SH4)
2834 * code and data structures from linux kernel:
2835 * include/asm-sh/sigcontext.h
2836 * arch/sh/kernel/signal.c
2839 struct target_sigcontext
{
2840 target_ulong oldmask
;
2843 target_ulong sc_gregs
[16];
2847 target_ulong sc_gbr
;
2848 target_ulong sc_mach
;
2849 target_ulong sc_macl
;
2852 target_ulong sc_fpregs
[16];
2853 target_ulong sc_xfpregs
[16];
2854 unsigned int sc_fpscr
;
2855 unsigned int sc_fpul
;
2856 unsigned int sc_ownedfp
;
2859 struct target_sigframe
2861 struct target_sigcontext sc
;
2862 target_ulong extramask
[TARGET_NSIG_WORDS
-1];
2863 uint16_t retcode
[3];
2867 struct target_ucontext
{
2868 target_ulong tuc_flags
;
2869 struct target_ucontext
*tuc_link
;
2870 target_stack_t tuc_stack
;
2871 struct target_sigcontext tuc_mcontext
;
2872 target_sigset_t tuc_sigmask
; /* mask last for extensibility */
2875 struct target_rt_sigframe
2877 struct target_siginfo info
;
2878 struct target_ucontext uc
;
2879 uint16_t retcode
[3];
2883 #define MOVW(n) (0x9300|((n)-2)) /* Move mem word at PC+n to R3 */
2884 #define TRAP_NOARG 0xc310 /* Syscall w/no args (NR in R3) SH3/4 */
2886 static abi_ulong
get_sigframe(struct target_sigaction
*ka
,
2887 unsigned long sp
, size_t frame_size
)
2889 if ((ka
->sa_flags
& TARGET_SA_ONSTACK
) && (sas_ss_flags(sp
) == 0)) {
2890 sp
= target_sigaltstack_used
.ss_sp
+ target_sigaltstack_used
.ss_size
;
2893 return (sp
- frame_size
) & -8ul;
2896 static int setup_sigcontext(struct target_sigcontext
*sc
,
2897 CPUSH4State
*regs
, unsigned long mask
)
2902 #define COPY(x) err |= __put_user(regs->x, &sc->sc_##x)
2903 COPY(gregs
[0]); COPY(gregs
[1]);
2904 COPY(gregs
[2]); COPY(gregs
[3]);
2905 COPY(gregs
[4]); COPY(gregs
[5]);
2906 COPY(gregs
[6]); COPY(gregs
[7]);
2907 COPY(gregs
[8]); COPY(gregs
[9]);
2908 COPY(gregs
[10]); COPY(gregs
[11]);
2909 COPY(gregs
[12]); COPY(gregs
[13]);
2910 COPY(gregs
[14]); COPY(gregs
[15]);
2911 COPY(gbr
); COPY(mach
);
2912 COPY(macl
); COPY(pr
);
2916 for (i
=0; i
<16; i
++) {
2917 err
|= __put_user(regs
->fregs
[i
], &sc
->sc_fpregs
[i
]);
2919 err
|= __put_user(regs
->fpscr
, &sc
->sc_fpscr
);
2920 err
|= __put_user(regs
->fpul
, &sc
->sc_fpul
);
2922 /* non-iBCS2 extensions.. */
2923 err
|= __put_user(mask
, &sc
->oldmask
);
2928 static int restore_sigcontext(CPUSH4State
*regs
, struct target_sigcontext
*sc
,
2931 unsigned int err
= 0;
2934 #define COPY(x) err |= __get_user(regs->x, &sc->sc_##x)
2936 COPY(gregs
[2]); COPY(gregs
[3]);
2937 COPY(gregs
[4]); COPY(gregs
[5]);
2938 COPY(gregs
[6]); COPY(gregs
[7]);
2939 COPY(gregs
[8]); COPY(gregs
[9]);
2940 COPY(gregs
[10]); COPY(gregs
[11]);
2941 COPY(gregs
[12]); COPY(gregs
[13]);
2942 COPY(gregs
[14]); COPY(gregs
[15]);
2943 COPY(gbr
); COPY(mach
);
2944 COPY(macl
); COPY(pr
);
2948 for (i
=0; i
<16; i
++) {
2949 err
|= __get_user(regs
->fregs
[i
], &sc
->sc_fpregs
[i
]);
2951 err
|= __get_user(regs
->fpscr
, &sc
->sc_fpscr
);
2952 err
|= __get_user(regs
->fpul
, &sc
->sc_fpul
);
2954 regs
->tra
= -1; /* disable syscall checks */
2955 err
|= __get_user(*r0_p
, &sc
->sc_gregs
[0]);
2959 static void setup_frame(int sig
, struct target_sigaction
*ka
,
2960 target_sigset_t
*set
, CPUSH4State
*regs
)
2962 struct target_sigframe
*frame
;
2963 abi_ulong frame_addr
;
2968 frame_addr
= get_sigframe(ka
, regs
->gregs
[15], sizeof(*frame
));
2969 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0))
2972 signal
= current_exec_domain_sig(sig
);
2974 err
|= setup_sigcontext(&frame
->sc
, regs
, set
->sig
[0]);
2976 for (i
= 0; i
< TARGET_NSIG_WORDS
- 1; i
++) {
2977 err
|= __put_user(set
->sig
[i
+ 1], &frame
->extramask
[i
]);
2980 /* Set up to return from userspace. If provided, use a stub
2981 already in userspace. */
2982 if (ka
->sa_flags
& TARGET_SA_RESTORER
) {
2983 regs
->pr
= (unsigned long) ka
->sa_restorer
;
2985 /* Generate return code (system call to sigreturn) */
2986 err
|= __put_user(MOVW(2), &frame
->retcode
[0]);
2987 err
|= __put_user(TRAP_NOARG
, &frame
->retcode
[1]);
2988 err
|= __put_user((TARGET_NR_sigreturn
), &frame
->retcode
[2]);
2989 regs
->pr
= (unsigned long) frame
->retcode
;
2995 /* Set up registers for signal handler */
2996 regs
->gregs
[15] = frame_addr
;
2997 regs
->gregs
[4] = signal
; /* Arg for signal handler */
2999 regs
->gregs
[6] = frame_addr
+= offsetof(typeof(*frame
), sc
);
3000 regs
->pc
= (unsigned long) ka
->_sa_handler
;
3002 unlock_user_struct(frame
, frame_addr
, 1);
3006 unlock_user_struct(frame
, frame_addr
, 1);
3007 force_sig(TARGET_SIGSEGV
);
3010 static void setup_rt_frame(int sig
, struct target_sigaction
*ka
,
3011 target_siginfo_t
*info
,
3012 target_sigset_t
*set
, CPUSH4State
*regs
)
3014 struct target_rt_sigframe
*frame
;
3015 abi_ulong frame_addr
;
3020 frame_addr
= get_sigframe(ka
, regs
->gregs
[15], sizeof(*frame
));
3021 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0))
3024 signal
= current_exec_domain_sig(sig
);
3026 err
|= copy_siginfo_to_user(&frame
->info
, info
);
3028 /* Create the ucontext. */
3029 err
|= __put_user(0, &frame
->uc
.tuc_flags
);
3030 err
|= __put_user(0, (unsigned long *)&frame
->uc
.tuc_link
);
3031 err
|= __put_user((unsigned long)target_sigaltstack_used
.ss_sp
,
3032 &frame
->uc
.tuc_stack
.ss_sp
);
3033 err
|= __put_user(sas_ss_flags(regs
->gregs
[15]),
3034 &frame
->uc
.tuc_stack
.ss_flags
);
3035 err
|= __put_user(target_sigaltstack_used
.ss_size
,
3036 &frame
->uc
.tuc_stack
.ss_size
);
3037 err
|= setup_sigcontext(&frame
->uc
.tuc_mcontext
,
3039 for(i
= 0; i
< TARGET_NSIG_WORDS
; i
++) {
3040 err
|= __put_user(set
->sig
[i
], &frame
->uc
.tuc_sigmask
.sig
[i
]);
3043 /* Set up to return from userspace. If provided, use a stub
3044 already in userspace. */
3045 if (ka
->sa_flags
& TARGET_SA_RESTORER
) {
3046 regs
->pr
= (unsigned long) ka
->sa_restorer
;
3048 /* Generate return code (system call to sigreturn) */
3049 err
|= __put_user(MOVW(2), &frame
->retcode
[0]);
3050 err
|= __put_user(TRAP_NOARG
, &frame
->retcode
[1]);
3051 err
|= __put_user((TARGET_NR_rt_sigreturn
), &frame
->retcode
[2]);
3052 regs
->pr
= (unsigned long) frame
->retcode
;
3058 /* Set up registers for signal handler */
3059 regs
->gregs
[15] = frame_addr
;
3060 regs
->gregs
[4] = signal
; /* Arg for signal handler */
3061 regs
->gregs
[5] = frame_addr
+ offsetof(typeof(*frame
), info
);
3062 regs
->gregs
[6] = frame_addr
+ offsetof(typeof(*frame
), uc
);
3063 regs
->pc
= (unsigned long) ka
->_sa_handler
;
3065 unlock_user_struct(frame
, frame_addr
, 1);
3069 unlock_user_struct(frame
, frame_addr
, 1);
3070 force_sig(TARGET_SIGSEGV
);
3073 long do_sigreturn(CPUSH4State
*regs
)
3075 struct target_sigframe
*frame
;
3076 abi_ulong frame_addr
;
3078 target_sigset_t target_set
;
3083 #if defined(DEBUG_SIGNAL)
3084 fprintf(stderr
, "do_sigreturn\n");
3086 frame_addr
= regs
->gregs
[15];
3087 if (!lock_user_struct(VERIFY_READ
, frame
, frame_addr
, 1))
3090 err
|= __get_user(target_set
.sig
[0], &frame
->sc
.oldmask
);
3091 for(i
= 1; i
< TARGET_NSIG_WORDS
; i
++) {
3092 err
|= (__get_user(target_set
.sig
[i
], &frame
->extramask
[i
- 1]));
3098 target_to_host_sigset_internal(&blocked
, &target_set
);
3099 sigprocmask(SIG_SETMASK
, &blocked
, NULL
);
3101 if (restore_sigcontext(regs
, &frame
->sc
, &r0
))
3104 unlock_user_struct(frame
, frame_addr
, 0);
3108 unlock_user_struct(frame
, frame_addr
, 0);
3109 force_sig(TARGET_SIGSEGV
);
3113 long do_rt_sigreturn(CPUSH4State
*regs
)
3115 struct target_rt_sigframe
*frame
;
3116 abi_ulong frame_addr
;
3120 #if defined(DEBUG_SIGNAL)
3121 fprintf(stderr
, "do_rt_sigreturn\n");
3123 frame_addr
= regs
->gregs
[15];
3124 if (!lock_user_struct(VERIFY_READ
, frame
, frame_addr
, 1))
3127 target_to_host_sigset(&blocked
, &frame
->uc
.tuc_sigmask
);
3128 sigprocmask(SIG_SETMASK
, &blocked
, NULL
);
3130 if (restore_sigcontext(regs
, &frame
->uc
.tuc_mcontext
, &r0
))
3133 if (do_sigaltstack(frame_addr
+
3134 offsetof(struct target_rt_sigframe
, uc
.tuc_stack
),
3135 0, get_sp_from_cpustate(regs
)) == -EFAULT
)
3138 unlock_user_struct(frame
, frame_addr
, 0);
3142 unlock_user_struct(frame
, frame_addr
, 0);
3143 force_sig(TARGET_SIGSEGV
);
3146 #elif defined(TARGET_MICROBLAZE)
3148 struct target_sigcontext
{
3149 struct target_pt_regs regs
; /* needs to be first */
3153 struct target_stack_t
{
3156 unsigned int ss_size
;
3159 struct target_ucontext
{
3160 abi_ulong tuc_flags
;
3162 struct target_stack_t tuc_stack
;
3163 struct target_sigcontext tuc_mcontext
;
3164 uint32_t tuc_extramask
[TARGET_NSIG_WORDS
- 1];
3167 /* Signal frames. */
3168 struct target_signal_frame
{
3169 struct target_ucontext uc
;
3170 uint32_t extramask
[TARGET_NSIG_WORDS
- 1];
3174 struct rt_signal_frame
{
3180 static void setup_sigcontext(struct target_sigcontext
*sc
, CPUMBState
*env
)
3182 __put_user(env
->regs
[0], &sc
->regs
.r0
);
3183 __put_user(env
->regs
[1], &sc
->regs
.r1
);
3184 __put_user(env
->regs
[2], &sc
->regs
.r2
);
3185 __put_user(env
->regs
[3], &sc
->regs
.r3
);
3186 __put_user(env
->regs
[4], &sc
->regs
.r4
);
3187 __put_user(env
->regs
[5], &sc
->regs
.r5
);
3188 __put_user(env
->regs
[6], &sc
->regs
.r6
);
3189 __put_user(env
->regs
[7], &sc
->regs
.r7
);
3190 __put_user(env
->regs
[8], &sc
->regs
.r8
);
3191 __put_user(env
->regs
[9], &sc
->regs
.r9
);
3192 __put_user(env
->regs
[10], &sc
->regs
.r10
);
3193 __put_user(env
->regs
[11], &sc
->regs
.r11
);
3194 __put_user(env
->regs
[12], &sc
->regs
.r12
);
3195 __put_user(env
->regs
[13], &sc
->regs
.r13
);
3196 __put_user(env
->regs
[14], &sc
->regs
.r14
);
3197 __put_user(env
->regs
[15], &sc
->regs
.r15
);
3198 __put_user(env
->regs
[16], &sc
->regs
.r16
);
3199 __put_user(env
->regs
[17], &sc
->regs
.r17
);
3200 __put_user(env
->regs
[18], &sc
->regs
.r18
);
3201 __put_user(env
->regs
[19], &sc
->regs
.r19
);
3202 __put_user(env
->regs
[20], &sc
->regs
.r20
);
3203 __put_user(env
->regs
[21], &sc
->regs
.r21
);
3204 __put_user(env
->regs
[22], &sc
->regs
.r22
);
3205 __put_user(env
->regs
[23], &sc
->regs
.r23
);
3206 __put_user(env
->regs
[24], &sc
->regs
.r24
);
3207 __put_user(env
->regs
[25], &sc
->regs
.r25
);
3208 __put_user(env
->regs
[26], &sc
->regs
.r26
);
3209 __put_user(env
->regs
[27], &sc
->regs
.r27
);
3210 __put_user(env
->regs
[28], &sc
->regs
.r28
);
3211 __put_user(env
->regs
[29], &sc
->regs
.r29
);
3212 __put_user(env
->regs
[30], &sc
->regs
.r30
);
3213 __put_user(env
->regs
[31], &sc
->regs
.r31
);
3214 __put_user(env
->sregs
[SR_PC
], &sc
->regs
.pc
);
3217 static void restore_sigcontext(struct target_sigcontext
*sc
, CPUMBState
*env
)
3219 __get_user(env
->regs
[0], &sc
->regs
.r0
);
3220 __get_user(env
->regs
[1], &sc
->regs
.r1
);
3221 __get_user(env
->regs
[2], &sc
->regs
.r2
);
3222 __get_user(env
->regs
[3], &sc
->regs
.r3
);
3223 __get_user(env
->regs
[4], &sc
->regs
.r4
);
3224 __get_user(env
->regs
[5], &sc
->regs
.r5
);
3225 __get_user(env
->regs
[6], &sc
->regs
.r6
);
3226 __get_user(env
->regs
[7], &sc
->regs
.r7
);
3227 __get_user(env
->regs
[8], &sc
->regs
.r8
);
3228 __get_user(env
->regs
[9], &sc
->regs
.r9
);
3229 __get_user(env
->regs
[10], &sc
->regs
.r10
);
3230 __get_user(env
->regs
[11], &sc
->regs
.r11
);
3231 __get_user(env
->regs
[12], &sc
->regs
.r12
);
3232 __get_user(env
->regs
[13], &sc
->regs
.r13
);
3233 __get_user(env
->regs
[14], &sc
->regs
.r14
);
3234 __get_user(env
->regs
[15], &sc
->regs
.r15
);
3235 __get_user(env
->regs
[16], &sc
->regs
.r16
);
3236 __get_user(env
->regs
[17], &sc
->regs
.r17
);
3237 __get_user(env
->regs
[18], &sc
->regs
.r18
);
3238 __get_user(env
->regs
[19], &sc
->regs
.r19
);
3239 __get_user(env
->regs
[20], &sc
->regs
.r20
);
3240 __get_user(env
->regs
[21], &sc
->regs
.r21
);
3241 __get_user(env
->regs
[22], &sc
->regs
.r22
);
3242 __get_user(env
->regs
[23], &sc
->regs
.r23
);
3243 __get_user(env
->regs
[24], &sc
->regs
.r24
);
3244 __get_user(env
->regs
[25], &sc
->regs
.r25
);
3245 __get_user(env
->regs
[26], &sc
->regs
.r26
);
3246 __get_user(env
->regs
[27], &sc
->regs
.r27
);
3247 __get_user(env
->regs
[28], &sc
->regs
.r28
);
3248 __get_user(env
->regs
[29], &sc
->regs
.r29
);
3249 __get_user(env
->regs
[30], &sc
->regs
.r30
);
3250 __get_user(env
->regs
[31], &sc
->regs
.r31
);
3251 __get_user(env
->sregs
[SR_PC
], &sc
->regs
.pc
);
3254 static abi_ulong
get_sigframe(struct target_sigaction
*ka
,
3255 CPUMBState
*env
, int frame_size
)
3257 abi_ulong sp
= env
->regs
[1];
3259 if ((ka
->sa_flags
& SA_ONSTACK
) != 0 && !on_sig_stack(sp
))
3260 sp
= target_sigaltstack_used
.ss_sp
+ target_sigaltstack_used
.ss_size
;
3262 return ((sp
- frame_size
) & -8UL);
3265 static void setup_frame(int sig
, struct target_sigaction
*ka
,
3266 target_sigset_t
*set
, CPUMBState
*env
)
3268 struct target_signal_frame
*frame
;
3269 abi_ulong frame_addr
;
3273 frame_addr
= get_sigframe(ka
, env
, sizeof *frame
);
3274 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0))
3277 /* Save the mask. */
3278 err
|= __put_user(set
->sig
[0], &frame
->uc
.tuc_mcontext
.oldmask
);
3282 for(i
= 1; i
< TARGET_NSIG_WORDS
; i
++) {
3283 if (__put_user(set
->sig
[i
], &frame
->extramask
[i
- 1]))
3287 setup_sigcontext(&frame
->uc
.tuc_mcontext
, env
);
3289 /* Set up to return from userspace. If provided, use a stub
3290 already in userspace. */
3291 /* minus 8 is offset to cater for "rtsd r15,8" offset */
3292 if (ka
->sa_flags
& TARGET_SA_RESTORER
) {
3293 env
->regs
[15] = ((unsigned long)ka
->sa_restorer
)-8;
3296 /* Note, these encodings are _big endian_! */
3297 /* addi r12, r0, __NR_sigreturn */
3298 t
= 0x31800000UL
| TARGET_NR_sigreturn
;
3299 err
|= __put_user(t
, frame
->tramp
+ 0);
3302 err
|= __put_user(t
, frame
->tramp
+ 1);
3304 /* Return from sighandler will jump to the tramp.
3305 Negative 8 offset because return is rtsd r15, 8 */
3306 env
->regs
[15] = ((unsigned long)frame
->tramp
) - 8;
3312 /* Set up registers for signal handler */
3313 env
->regs
[1] = frame_addr
;
3314 /* Signal handler args: */
3315 env
->regs
[5] = sig
; /* Arg 0: signum */
3317 /* arg 1: sigcontext */
3318 env
->regs
[7] = frame_addr
+= offsetof(typeof(*frame
), uc
);
3320 /* Offset of 4 to handle microblaze rtid r14, 0 */
3321 env
->sregs
[SR_PC
] = (unsigned long)ka
->_sa_handler
;
3323 unlock_user_struct(frame
, frame_addr
, 1);
3326 unlock_user_struct(frame
, frame_addr
, 1);
3327 force_sig(TARGET_SIGSEGV
);
3330 static void setup_rt_frame(int sig
, struct target_sigaction
*ka
,
3331 target_siginfo_t
*info
,
3332 target_sigset_t
*set
, CPUMBState
*env
)
3334 fprintf(stderr
, "Microblaze setup_rt_frame: not implemented\n");
3337 long do_sigreturn(CPUMBState
*env
)
3339 struct target_signal_frame
*frame
;
3340 abi_ulong frame_addr
;
3341 target_sigset_t target_set
;
3345 frame_addr
= env
->regs
[R_SP
];
3346 /* Make sure the guest isn't playing games. */
3347 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 1))
3350 /* Restore blocked signals */
3351 if (__get_user(target_set
.sig
[0], &frame
->uc
.tuc_mcontext
.oldmask
))
3353 for(i
= 1; i
< TARGET_NSIG_WORDS
; i
++) {
3354 if (__get_user(target_set
.sig
[i
], &frame
->extramask
[i
- 1]))
3357 target_to_host_sigset_internal(&set
, &target_set
);
3358 sigprocmask(SIG_SETMASK
, &set
, NULL
);
3360 restore_sigcontext(&frame
->uc
.tuc_mcontext
, env
);
3361 /* We got here through a sigreturn syscall, our path back is via an
3362 rtb insn so setup r14 for that. */
3363 env
->regs
[14] = env
->sregs
[SR_PC
];
3365 unlock_user_struct(frame
, frame_addr
, 0);
3366 return env
->regs
[10];
3368 unlock_user_struct(frame
, frame_addr
, 0);
3369 force_sig(TARGET_SIGSEGV
);
3372 long do_rt_sigreturn(CPUMBState
*env
)
3374 fprintf(stderr
, "Microblaze do_rt_sigreturn: not implemented\n");
3375 return -TARGET_ENOSYS
;
3378 #elif defined(TARGET_CRIS)
3380 struct target_sigcontext
{
3381 struct target_pt_regs regs
; /* needs to be first */
3383 uint32_t usp
; /* usp before stacking this gunk on it */
3386 /* Signal frames. */
3387 struct target_signal_frame
{
3388 struct target_sigcontext sc
;
3389 uint32_t extramask
[TARGET_NSIG_WORDS
- 1];
3390 uint8_t retcode
[8]; /* Trampoline code. */
3393 struct rt_signal_frame
{
3398 uint8_t retcode
[8]; /* Trampoline code. */
3401 static void setup_sigcontext(struct target_sigcontext
*sc
, CPUCRISState
*env
)
3403 __put_user(env
->regs
[0], &sc
->regs
.r0
);
3404 __put_user(env
->regs
[1], &sc
->regs
.r1
);
3405 __put_user(env
->regs
[2], &sc
->regs
.r2
);
3406 __put_user(env
->regs
[3], &sc
->regs
.r3
);
3407 __put_user(env
->regs
[4], &sc
->regs
.r4
);
3408 __put_user(env
->regs
[5], &sc
->regs
.r5
);
3409 __put_user(env
->regs
[6], &sc
->regs
.r6
);
3410 __put_user(env
->regs
[7], &sc
->regs
.r7
);
3411 __put_user(env
->regs
[8], &sc
->regs
.r8
);
3412 __put_user(env
->regs
[9], &sc
->regs
.r9
);
3413 __put_user(env
->regs
[10], &sc
->regs
.r10
);
3414 __put_user(env
->regs
[11], &sc
->regs
.r11
);
3415 __put_user(env
->regs
[12], &sc
->regs
.r12
);
3416 __put_user(env
->regs
[13], &sc
->regs
.r13
);
3417 __put_user(env
->regs
[14], &sc
->usp
);
3418 __put_user(env
->regs
[15], &sc
->regs
.acr
);
3419 __put_user(env
->pregs
[PR_MOF
], &sc
->regs
.mof
);
3420 __put_user(env
->pregs
[PR_SRP
], &sc
->regs
.srp
);
3421 __put_user(env
->pc
, &sc
->regs
.erp
);
3424 static void restore_sigcontext(struct target_sigcontext
*sc
, CPUCRISState
*env
)
3426 __get_user(env
->regs
[0], &sc
->regs
.r0
);
3427 __get_user(env
->regs
[1], &sc
->regs
.r1
);
3428 __get_user(env
->regs
[2], &sc
->regs
.r2
);
3429 __get_user(env
->regs
[3], &sc
->regs
.r3
);
3430 __get_user(env
->regs
[4], &sc
->regs
.r4
);
3431 __get_user(env
->regs
[5], &sc
->regs
.r5
);
3432 __get_user(env
->regs
[6], &sc
->regs
.r6
);
3433 __get_user(env
->regs
[7], &sc
->regs
.r7
);
3434 __get_user(env
->regs
[8], &sc
->regs
.r8
);
3435 __get_user(env
->regs
[9], &sc
->regs
.r9
);
3436 __get_user(env
->regs
[10], &sc
->regs
.r10
);
3437 __get_user(env
->regs
[11], &sc
->regs
.r11
);
3438 __get_user(env
->regs
[12], &sc
->regs
.r12
);
3439 __get_user(env
->regs
[13], &sc
->regs
.r13
);
3440 __get_user(env
->regs
[14], &sc
->usp
);
3441 __get_user(env
->regs
[15], &sc
->regs
.acr
);
3442 __get_user(env
->pregs
[PR_MOF
], &sc
->regs
.mof
);
3443 __get_user(env
->pregs
[PR_SRP
], &sc
->regs
.srp
);
3444 __get_user(env
->pc
, &sc
->regs
.erp
);
3447 static abi_ulong
get_sigframe(CPUCRISState
*env
, int framesize
)
3450 /* Align the stack downwards to 4. */
3451 sp
= (env
->regs
[R_SP
] & ~3);
3452 return sp
- framesize
;
3455 static void setup_frame(int sig
, struct target_sigaction
*ka
,
3456 target_sigset_t
*set
, CPUCRISState
*env
)
3458 struct target_signal_frame
*frame
;
3459 abi_ulong frame_addr
;
3463 frame_addr
= get_sigframe(env
, sizeof *frame
);
3464 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0))
3468 * The CRIS signal return trampoline. A real linux/CRIS kernel doesn't
3469 * use this trampoline anymore but it sets it up for GDB.
3470 * In QEMU, using the trampoline simplifies things a bit so we use it.
3472 * This is movu.w __NR_sigreturn, r9; break 13;
3474 err
|= __put_user(0x9c5f, frame
->retcode
+0);
3475 err
|= __put_user(TARGET_NR_sigreturn
,
3477 err
|= __put_user(0xe93d, frame
->retcode
+4);
3479 /* Save the mask. */
3480 err
|= __put_user(set
->sig
[0], &frame
->sc
.oldmask
);
3484 for(i
= 1; i
< TARGET_NSIG_WORDS
; i
++) {
3485 if (__put_user(set
->sig
[i
], &frame
->extramask
[i
- 1]))
3489 setup_sigcontext(&frame
->sc
, env
);
3491 /* Move the stack and setup the arguments for the handler. */
3492 env
->regs
[R_SP
] = frame_addr
;
3493 env
->regs
[10] = sig
;
3494 env
->pc
= (unsigned long) ka
->_sa_handler
;
3495 /* Link SRP so the guest returns through the trampoline. */
3496 env
->pregs
[PR_SRP
] = frame_addr
+ offsetof(typeof(*frame
), retcode
);
3498 unlock_user_struct(frame
, frame_addr
, 1);
3501 unlock_user_struct(frame
, frame_addr
, 1);
3502 force_sig(TARGET_SIGSEGV
);
3505 static void setup_rt_frame(int sig
, struct target_sigaction
*ka
,
3506 target_siginfo_t
*info
,
3507 target_sigset_t
*set
, CPUCRISState
*env
)
3509 fprintf(stderr
, "CRIS setup_rt_frame: not implemented\n");
3512 long do_sigreturn(CPUCRISState
*env
)
3514 struct target_signal_frame
*frame
;
3515 abi_ulong frame_addr
;
3516 target_sigset_t target_set
;
3520 frame_addr
= env
->regs
[R_SP
];
3521 /* Make sure the guest isn't playing games. */
3522 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 1))
3525 /* Restore blocked signals */
3526 if (__get_user(target_set
.sig
[0], &frame
->sc
.oldmask
))
3528 for(i
= 1; i
< TARGET_NSIG_WORDS
; i
++) {
3529 if (__get_user(target_set
.sig
[i
], &frame
->extramask
[i
- 1]))
3532 target_to_host_sigset_internal(&set
, &target_set
);
3533 sigprocmask(SIG_SETMASK
, &set
, NULL
);
3535 restore_sigcontext(&frame
->sc
, env
);
3536 unlock_user_struct(frame
, frame_addr
, 0);
3537 return env
->regs
[10];
3539 unlock_user_struct(frame
, frame_addr
, 0);
3540 force_sig(TARGET_SIGSEGV
);
3543 long do_rt_sigreturn(CPUCRISState
*env
)
3545 fprintf(stderr
, "CRIS do_rt_sigreturn: not implemented\n");
3546 return -TARGET_ENOSYS
;
3549 #elif defined(TARGET_OPENRISC)
3551 struct target_sigcontext
{
3552 struct target_pt_regs regs
;
3557 struct target_ucontext
{
3558 abi_ulong tuc_flags
;
3560 target_stack_t tuc_stack
;
3561 struct target_sigcontext tuc_mcontext
;
3562 target_sigset_t tuc_sigmask
; /* mask last for extensibility */
3565 struct target_rt_sigframe
{
3568 struct target_siginfo info
;
3569 struct target_sigcontext sc
;
3570 struct target_ucontext uc
;
3571 unsigned char retcode
[16]; /* trampoline code */
3574 /* This is the asm-generic/ucontext.h version */
3576 static int restore_sigcontext(CPUOpenRISCState
*regs
,
3577 struct target_sigcontext
*sc
)
3579 unsigned int err
= 0;
3580 unsigned long old_usp
;
3582 /* Alwys make any pending restarted system call return -EINTR */
3583 current_thread_info()->restart_block
.fn
= do_no_restart_syscall
;
3585 /* restore the regs from &sc->regs (same as sc, since regs is first)
3586 * (sc is already checked for VERIFY_READ since the sigframe was
3587 * checked in sys_sigreturn previously)
3590 if (copy_from_user(regs
, &sc
, sizeof(struct target_pt_regs
))) {
3594 /* make sure the U-flag is set so user-mode cannot fool us */
3598 /* restore the old USP as it was before we stacked the sc etc.
3599 * (we cannot just pop the sigcontext since we aligned the sp and
3600 * stuff after pushing it)
3603 err
|= __get_user(old_usp
, &sc
->usp
);
3604 phx_signal("old_usp 0x%lx", old_usp
);
3606 __PHX__ REALLY
/* ??? */
3608 regs
->gpr
[1] = old_usp
;
3610 /* TODO: the other ports use regs->orig_XX to disable syscall checks
3611 * after this completes, but we don't use that mechanism. maybe we can
3622 /* Set up a signal frame. */
3624 static int setup_sigcontext(struct target_sigcontext
*sc
,
3625 CPUOpenRISCState
*regs
,
3629 unsigned long usp
= regs
->gpr
[1];
3631 /* copy the regs. they are first in sc so we can use sc directly */
3633 /*err |= copy_to_user(&sc, regs, sizeof(struct target_pt_regs));*/
3635 /* Set the frametype to CRIS_FRAME_NORMAL for the execution of
3636 the signal handler. The frametype will be restored to its previous
3637 value in restore_sigcontext. */
3638 /*regs->frametype = CRIS_FRAME_NORMAL;*/
3640 /* then some other stuff */
3641 err
|= __put_user(mask
, &sc
->oldmask
);
3642 err
|= __put_user(usp
, &sc
->usp
); return err
;
3645 static inline unsigned long align_sigframe(unsigned long sp
)
3652 static inline abi_ulong
get_sigframe(struct target_sigaction
*ka
,
3653 CPUOpenRISCState
*regs
,
3656 unsigned long sp
= regs
->gpr
[1];
3657 int onsigstack
= on_sig_stack(sp
);
3660 /* This is the X/Open sanctioned signal stack switching. */
3661 if ((ka
->sa_flags
& SA_ONSTACK
) != 0 && !onsigstack
) {
3662 sp
= target_sigaltstack_used
.ss_sp
+ target_sigaltstack_used
.ss_size
;
3665 sp
= align_sigframe(sp
- frame_size
);
3668 * If we are on the alternate signal stack and would overflow it, don't.
3669 * Return an always-bogus address instead so we will die with SIGSEGV.
3672 if (onsigstack
&& !likely(on_sig_stack(sp
))) {
3679 static void setup_frame(int sig
, struct target_sigaction
*ka
,
3680 target_sigset_t
*set
, CPUOpenRISCState
*env
)
3682 qemu_log("Not implement.\n");
3685 static void setup_rt_frame(int sig
, struct target_sigaction
*ka
,
3686 target_siginfo_t
*info
,
3687 target_sigset_t
*set
, CPUOpenRISCState
*env
)
3690 abi_ulong frame_addr
;
3691 unsigned long return_ip
;
3692 struct target_rt_sigframe
*frame
;
3693 abi_ulong info_addr
, uc_addr
;
3695 frame_addr
= get_sigframe(ka
, env
, sizeof *frame
);
3697 frame_addr
= get_sigframe(ka
, env
, sizeof(*frame
));
3698 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0)) {
3702 info_addr
= frame_addr
+ offsetof(struct target_rt_sigframe
, info
);
3703 err
|= __put_user(info_addr
, &frame
->pinfo
);
3704 uc_addr
= frame_addr
+ offsetof(struct target_rt_sigframe
, uc
);
3705 err
|= __put_user(uc_addr
, &frame
->puc
);
3707 if (ka
->sa_flags
& SA_SIGINFO
) {
3708 err
|= copy_siginfo_to_user(&frame
->info
, info
);
3714 /*err |= __clear_user(&frame->uc, offsetof(struct ucontext, uc_mcontext));*/
3715 err
|= __put_user(0, &frame
->uc
.tuc_flags
);
3716 err
|= __put_user(0, &frame
->uc
.tuc_link
);
3717 err
|= __put_user(target_sigaltstack_used
.ss_sp
,
3718 &frame
->uc
.tuc_stack
.ss_sp
);
3719 err
|= __put_user(sas_ss_flags(env
->gpr
[1]), &frame
->uc
.tuc_stack
.ss_flags
);
3720 err
|= __put_user(target_sigaltstack_used
.ss_size
,
3721 &frame
->uc
.tuc_stack
.ss_size
);
3722 err
|= setup_sigcontext(&frame
->sc
, env
, set
->sig
[0]);
3724 /*err |= copy_to_user(frame->uc.tuc_sigmask, set, sizeof(*set));*/
3730 /* trampoline - the desired return ip is the retcode itself */
3731 return_ip
= (unsigned long)&frame
->retcode
;
3732 /* This is l.ori r11,r0,__NR_sigreturn, l.sys 1 */
3733 err
|= __put_user(0xa960, (short *)(frame
->retcode
+ 0));
3734 err
|= __put_user(TARGET_NR_rt_sigreturn
, (short *)(frame
->retcode
+ 2));
3735 err
|= __put_user(0x20000001, (unsigned long *)(frame
->retcode
+ 4));
3736 err
|= __put_user(0x15000000, (unsigned long *)(frame
->retcode
+ 8));
3742 /* TODO what is the current->exec_domain stuff and invmap ? */
3744 /* Set up registers for signal handler */
3745 env
->pc
= (unsigned long)ka
->_sa_handler
; /* what we enter NOW */
3746 env
->gpr
[9] = (unsigned long)return_ip
; /* what we enter LATER */
3747 env
->gpr
[3] = (unsigned long)sig
; /* arg 1: signo */
3748 env
->gpr
[4] = (unsigned long)&frame
->info
; /* arg 2: (siginfo_t*) */
3749 env
->gpr
[5] = (unsigned long)&frame
->uc
; /* arg 3: ucontext */
3751 /* actually move the usp to reflect the stacked frame */
3752 env
->gpr
[1] = (unsigned long)frame
;
3757 unlock_user_struct(frame
, frame_addr
, 1);
3758 if (sig
== TARGET_SIGSEGV
) {
3759 ka
->_sa_handler
= TARGET_SIG_DFL
;
3761 force_sig(TARGET_SIGSEGV
);
3764 long do_sigreturn(CPUOpenRISCState
*env
)
3767 qemu_log("do_sigreturn: not implemented\n");
3768 return -TARGET_ENOSYS
;
3771 long do_rt_sigreturn(CPUOpenRISCState
*env
)
3773 qemu_log("do_rt_sigreturn: not implemented\n");
3774 return -TARGET_ENOSYS
;
3776 /* TARGET_OPENRISC */
3778 #elif defined(TARGET_S390X)
3780 #define __NUM_GPRS 16
3781 #define __NUM_FPRS 16
3782 #define __NUM_ACRS 16
3784 #define S390_SYSCALL_SIZE 2
3785 #define __SIGNAL_FRAMESIZE 160 /* FIXME: 31-bit mode -> 96 */
3787 #define _SIGCONTEXT_NSIG 64
3788 #define _SIGCONTEXT_NSIG_BPW 64 /* FIXME: 31-bit mode -> 32 */
3789 #define _SIGCONTEXT_NSIG_WORDS (_SIGCONTEXT_NSIG / _SIGCONTEXT_NSIG_BPW)
3790 #define _SIGMASK_COPY_SIZE (sizeof(unsigned long)*_SIGCONTEXT_NSIG_WORDS)
3791 #define PSW_ADDR_AMODE 0x0000000000000000UL /* 0x80000000UL for 31-bit */
3792 #define S390_SYSCALL_OPCODE ((uint16_t)0x0a00)
3796 target_ulong gprs
[__NUM_GPRS
];
3797 unsigned int acrs
[__NUM_ACRS
];
3798 } target_s390_regs_common
;
3802 double fprs
[__NUM_FPRS
];
3803 } target_s390_fp_regs
;
3806 target_s390_regs_common regs
;
3807 target_s390_fp_regs fpregs
;
3810 struct target_sigcontext
{
3811 target_ulong oldmask
[_SIGCONTEXT_NSIG_WORDS
];
3812 target_sigregs
*sregs
;
3816 uint8_t callee_used_stack
[__SIGNAL_FRAMESIZE
];
3817 struct target_sigcontext sc
;
3818 target_sigregs sregs
;
3820 uint8_t retcode
[S390_SYSCALL_SIZE
];
3823 struct target_ucontext
{
3824 target_ulong tuc_flags
;
3825 struct target_ucontext
*tuc_link
;
3826 target_stack_t tuc_stack
;
3827 target_sigregs tuc_mcontext
;
3828 target_sigset_t tuc_sigmask
; /* mask last for extensibility */
3832 uint8_t callee_used_stack
[__SIGNAL_FRAMESIZE
];
3833 uint8_t retcode
[S390_SYSCALL_SIZE
];
3834 struct target_siginfo info
;
3835 struct target_ucontext uc
;
3838 static inline abi_ulong
3839 get_sigframe(struct target_sigaction
*ka
, CPUS390XState
*env
, size_t frame_size
)
3843 /* Default to using normal stack */
3846 /* This is the X/Open sanctioned signal stack switching. */
3847 if (ka
->sa_flags
& TARGET_SA_ONSTACK
) {
3848 if (!sas_ss_flags(sp
)) {
3849 sp
= target_sigaltstack_used
.ss_sp
+
3850 target_sigaltstack_used
.ss_size
;
3854 /* This is the legacy signal stack switching. */
3855 else if (/* FIXME !user_mode(regs) */ 0 &&
3856 !(ka
->sa_flags
& TARGET_SA_RESTORER
) &&
3858 sp
= (abi_ulong
) ka
->sa_restorer
;
3861 return (sp
- frame_size
) & -8ul;
3864 static void save_sigregs(CPUS390XState
*env
, target_sigregs
*sregs
)
3867 //save_access_regs(current->thread.acrs); FIXME
3869 /* Copy a 'clean' PSW mask to the user to avoid leaking
3870 information about whether PER is currently on. */
3871 __put_user(env
->psw
.mask
, &sregs
->regs
.psw
.mask
);
3872 __put_user(env
->psw
.addr
, &sregs
->regs
.psw
.addr
);
3873 for (i
= 0; i
< 16; i
++) {
3874 __put_user(env
->regs
[i
], &sregs
->regs
.gprs
[i
]);
3876 for (i
= 0; i
< 16; i
++) {
3877 __put_user(env
->aregs
[i
], &sregs
->regs
.acrs
[i
]);
3880 * We have to store the fp registers to current->thread.fp_regs
3881 * to merge them with the emulated registers.
3883 //save_fp_regs(¤t->thread.fp_regs); FIXME
3884 for (i
= 0; i
< 16; i
++) {
3885 __put_user(env
->fregs
[i
].ll
, &sregs
->fpregs
.fprs
[i
]);
3889 static void setup_frame(int sig
, struct target_sigaction
*ka
,
3890 target_sigset_t
*set
, CPUS390XState
*env
)
3893 abi_ulong frame_addr
;
3895 frame_addr
= get_sigframe(ka
, env
, sizeof(*frame
));
3896 qemu_log("%s: frame_addr 0x%llx\n", __FUNCTION__
,
3897 (unsigned long long)frame_addr
);
3898 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0)) {
3902 qemu_log("%s: 1\n", __FUNCTION__
);
3903 if (__put_user(set
->sig
[0], &frame
->sc
.oldmask
[0])) {
3907 save_sigregs(env
, &frame
->sregs
);
3909 __put_user((abi_ulong
)(unsigned long)&frame
->sregs
,
3910 (abi_ulong
*)&frame
->sc
.sregs
);
3912 /* Set up to return from userspace. If provided, use a stub
3913 already in userspace. */
3914 if (ka
->sa_flags
& TARGET_SA_RESTORER
) {
3915 env
->regs
[14] = (unsigned long)
3916 ka
->sa_restorer
| PSW_ADDR_AMODE
;
3918 env
->regs
[14] = (unsigned long)
3919 frame
->retcode
| PSW_ADDR_AMODE
;
3920 if (__put_user(S390_SYSCALL_OPCODE
| TARGET_NR_sigreturn
,
3921 (uint16_t *)(frame
->retcode
)))
3925 /* Set up backchain. */
3926 if (__put_user(env
->regs
[15], (abi_ulong
*) frame
)) {
3930 /* Set up registers for signal handler */
3931 env
->regs
[15] = frame_addr
;
3932 env
->psw
.addr
= (target_ulong
) ka
->_sa_handler
| PSW_ADDR_AMODE
;
3934 env
->regs
[2] = sig
; //map_signal(sig);
3935 env
->regs
[3] = frame_addr
+= offsetof(typeof(*frame
), sc
);
3937 /* We forgot to include these in the sigcontext.
3938 To avoid breaking binary compatibility, they are passed as args. */
3939 env
->regs
[4] = 0; // FIXME: no clue... current->thread.trap_no;
3940 env
->regs
[5] = 0; // FIXME: no clue... current->thread.prot_addr;
3942 /* Place signal number on stack to allow backtrace from handler. */
3943 if (__put_user(env
->regs
[2], (int *) &frame
->signo
)) {
3946 unlock_user_struct(frame
, frame_addr
, 1);
3950 qemu_log("%s: give_sigsegv\n", __FUNCTION__
);
3951 unlock_user_struct(frame
, frame_addr
, 1);
3952 force_sig(TARGET_SIGSEGV
);
3955 static void setup_rt_frame(int sig
, struct target_sigaction
*ka
,
3956 target_siginfo_t
*info
,
3957 target_sigset_t
*set
, CPUS390XState
*env
)
3961 abi_ulong frame_addr
;
3963 frame_addr
= get_sigframe(ka
, env
, sizeof *frame
);
3964 qemu_log("%s: frame_addr 0x%llx\n", __FUNCTION__
,
3965 (unsigned long long)frame_addr
);
3966 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0)) {
3970 qemu_log("%s: 1\n", __FUNCTION__
);
3971 if (copy_siginfo_to_user(&frame
->info
, info
)) {
3975 /* Create the ucontext. */
3976 __put_user(0, &frame
->uc
.tuc_flags
);
3977 __put_user((abi_ulong
)0, (abi_ulong
*)&frame
->uc
.tuc_link
);
3978 __put_user(target_sigaltstack_used
.ss_sp
, &frame
->uc
.tuc_stack
.ss_sp
);
3979 __put_user(sas_ss_flags(get_sp_from_cpustate(env
)),
3980 &frame
->uc
.tuc_stack
.ss_flags
);
3981 __put_user(target_sigaltstack_used
.ss_size
, &frame
->uc
.tuc_stack
.ss_size
);
3982 save_sigregs(env
, &frame
->uc
.tuc_mcontext
);
3983 for (i
= 0; i
< TARGET_NSIG_WORDS
; i
++) {
3984 __put_user((abi_ulong
)set
->sig
[i
],
3985 (abi_ulong
*)&frame
->uc
.tuc_sigmask
.sig
[i
]);
3988 /* Set up to return from userspace. If provided, use a stub
3989 already in userspace. */
3990 if (ka
->sa_flags
& TARGET_SA_RESTORER
) {
3991 env
->regs
[14] = (unsigned long) ka
->sa_restorer
| PSW_ADDR_AMODE
;
3993 env
->regs
[14] = (unsigned long) frame
->retcode
| PSW_ADDR_AMODE
;
3994 if (__put_user(S390_SYSCALL_OPCODE
| TARGET_NR_rt_sigreturn
,
3995 (uint16_t *)(frame
->retcode
))) {
4000 /* Set up backchain. */
4001 if (__put_user(env
->regs
[15], (abi_ulong
*) frame
)) {
4005 /* Set up registers for signal handler */
4006 env
->regs
[15] = frame_addr
;
4007 env
->psw
.addr
= (target_ulong
) ka
->_sa_handler
| PSW_ADDR_AMODE
;
4009 env
->regs
[2] = sig
; //map_signal(sig);
4010 env
->regs
[3] = frame_addr
+ offsetof(typeof(*frame
), info
);
4011 env
->regs
[4] = frame_addr
+ offsetof(typeof(*frame
), uc
);
4015 qemu_log("%s: give_sigsegv\n", __FUNCTION__
);
4016 unlock_user_struct(frame
, frame_addr
, 1);
4017 force_sig(TARGET_SIGSEGV
);
4021 restore_sigregs(CPUS390XState
*env
, target_sigregs
*sc
)
4026 for (i
= 0; i
< 16; i
++) {
4027 err
|= __get_user(env
->regs
[i
], &sc
->regs
.gprs
[i
]);
4030 err
|= __get_user(env
->psw
.mask
, &sc
->regs
.psw
.mask
);
4031 qemu_log("%s: sc->regs.psw.addr 0x%llx env->psw.addr 0x%llx\n",
4032 __FUNCTION__
, (unsigned long long)sc
->regs
.psw
.addr
,
4033 (unsigned long long)env
->psw
.addr
);
4034 err
|= __get_user(env
->psw
.addr
, &sc
->regs
.psw
.addr
);
4035 /* FIXME: 31-bit -> | PSW_ADDR_AMODE */
4037 for (i
= 0; i
< 16; i
++) {
4038 err
|= __get_user(env
->aregs
[i
], &sc
->regs
.acrs
[i
]);
4040 for (i
= 0; i
< 16; i
++) {
4041 err
|= __get_user(env
->fregs
[i
].ll
, &sc
->fpregs
.fprs
[i
]);
4047 long do_sigreturn(CPUS390XState
*env
)
4050 abi_ulong frame_addr
= env
->regs
[15];
4051 qemu_log("%s: frame_addr 0x%llx\n", __FUNCTION__
,
4052 (unsigned long long)frame_addr
);
4053 target_sigset_t target_set
;
4056 if (!lock_user_struct(VERIFY_READ
, frame
, frame_addr
, 1)) {
4059 if (__get_user(target_set
.sig
[0], &frame
->sc
.oldmask
[0])) {
4063 target_to_host_sigset_internal(&set
, &target_set
);
4064 sigprocmask(SIG_SETMASK
, &set
, NULL
); /* ~_BLOCKABLE? */
4066 if (restore_sigregs(env
, &frame
->sregs
)) {
4070 unlock_user_struct(frame
, frame_addr
, 0);
4071 return env
->regs
[2];
4074 unlock_user_struct(frame
, frame_addr
, 0);
4075 force_sig(TARGET_SIGSEGV
);
4079 long do_rt_sigreturn(CPUS390XState
*env
)
4082 abi_ulong frame_addr
= env
->regs
[15];
4083 qemu_log("%s: frame_addr 0x%llx\n", __FUNCTION__
,
4084 (unsigned long long)frame_addr
);
4087 if (!lock_user_struct(VERIFY_READ
, frame
, frame_addr
, 1)) {
4090 target_to_host_sigset(&set
, &frame
->uc
.tuc_sigmask
);
4092 sigprocmask(SIG_SETMASK
, &set
, NULL
); /* ~_BLOCKABLE? */
4094 if (restore_sigregs(env
, &frame
->uc
.tuc_mcontext
)) {
4098 if (do_sigaltstack(frame_addr
+ offsetof(rt_sigframe
, uc
.tuc_stack
), 0,
4099 get_sp_from_cpustate(env
)) == -EFAULT
) {
4102 unlock_user_struct(frame
, frame_addr
, 0);
4103 return env
->regs
[2];
4106 unlock_user_struct(frame
, frame_addr
, 0);
4107 force_sig(TARGET_SIGSEGV
);
4111 #elif defined(TARGET_PPC) && !defined(TARGET_PPC64)
4113 /* FIXME: Many of the structures are defined for both PPC and PPC64, but
4114 the signal handling is different enough that we haven't implemented
4115 support for PPC64 yet. Hence the restriction above.
4117 There are various #if'd blocks for code for TARGET_PPC64. These
4118 blocks should go away so that we can successfully run 32-bit and
4119 64-bit binaries on a QEMU configured for PPC64. */
4121 /* Size of dummy stack frame allocated when calling signal handler.
4122 See arch/powerpc/include/asm/ptrace.h. */
4123 #if defined(TARGET_PPC64)
4124 #define SIGNAL_FRAMESIZE 128
4126 #define SIGNAL_FRAMESIZE 64
4129 /* See arch/powerpc/include/asm/sigcontext.h. */
4130 struct target_sigcontext
{
4131 target_ulong _unused
[4];
4133 #if defined(TARGET_PPC64)
4136 target_ulong handler
;
4137 target_ulong oldmask
;
4138 target_ulong regs
; /* struct pt_regs __user * */
4139 /* TODO: PPC64 includes extra bits here. */
4142 /* Indices for target_mcontext.mc_gregs, below.
4143 See arch/powerpc/include/asm/ptrace.h for details. */
4179 TARGET_PT_ORIG_R3
= 34,
4184 /* Yes, there are two registers with #39. One is 64-bit only. */
4186 TARGET_PT_SOFTE
= 39,
4187 TARGET_PT_TRAP
= 40,
4189 TARGET_PT_DSISR
= 42,
4190 TARGET_PT_RESULT
= 43,
4191 TARGET_PT_REGS_COUNT
= 44
4194 /* See arch/powerpc/include/asm/ucontext.h. Only used for 32-bit PPC;
4195 on 64-bit PPC, sigcontext and mcontext are one and the same. */
4196 struct target_mcontext
{
4197 target_ulong mc_gregs
[48];
4198 /* Includes fpscr. */
4199 uint64_t mc_fregs
[33];
4200 target_ulong mc_pad
[2];
4201 /* We need to handle Altivec and SPE at the same time, which no
4202 kernel needs to do. Fortunately, the kernel defines this bit to
4203 be Altivec-register-large all the time, rather than trying to
4204 twiddle it based on the specific platform. */
4206 /* SPE vector registers. One extra for SPEFSCR. */
4208 /* Altivec vector registers. The packing of VSCR and VRSAVE
4209 varies depending on whether we're PPC64 or not: PPC64 splits
4210 them apart; PPC32 stuffs them together. */
4211 #if defined(TARGET_PPC64)
4212 #define QEMU_NVRREG 34
4214 #define QEMU_NVRREG 33
4216 ppc_avr_t altivec
[QEMU_NVRREG
];
4218 } mc_vregs
__attribute__((__aligned__(16)));
4221 struct target_ucontext
{
4222 target_ulong tuc_flags
;
4223 target_ulong tuc_link
; /* struct ucontext __user * */
4224 struct target_sigaltstack tuc_stack
;
4225 #if !defined(TARGET_PPC64)
4227 target_ulong tuc_regs
; /* struct mcontext __user *
4228 points to uc_mcontext field */
4230 target_sigset_t tuc_sigmask
;
4231 #if defined(TARGET_PPC64)
4232 target_sigset_t unused
[15]; /* Allow for uc_sigmask growth */
4233 struct target_sigcontext tuc_mcontext
;
4235 int32_t tuc_maskext
[30];
4236 int32_t tuc_pad2
[3];
4237 struct target_mcontext tuc_mcontext
;
4241 /* See arch/powerpc/kernel/signal_32.c. */
4242 struct target_sigframe
{
4243 struct target_sigcontext sctx
;
4244 struct target_mcontext mctx
;
4248 struct target_rt_sigframe
{
4249 struct target_siginfo info
;
4250 struct target_ucontext uc
;
4254 /* We use the mc_pad field for the signal return trampoline. */
4255 #define tramp mc_pad
4257 /* See arch/powerpc/kernel/signal.c. */
4258 static target_ulong
get_sigframe(struct target_sigaction
*ka
,
4262 target_ulong oldsp
, newsp
;
4264 oldsp
= env
->gpr
[1];
4266 if ((ka
->sa_flags
& TARGET_SA_ONSTACK
) &&
4267 (sas_ss_flags(oldsp
) == 0)) {
4268 oldsp
= (target_sigaltstack_used
.ss_sp
4269 + target_sigaltstack_used
.ss_size
);
4272 newsp
= (oldsp
- frame_size
) & ~0xFUL
;
4277 static int save_user_regs(CPUPPCState
*env
, struct target_mcontext
*frame
,
4280 target_ulong msr
= env
->msr
;
4282 target_ulong ccr
= 0;
4284 /* In general, the kernel attempts to be intelligent about what it
4285 needs to save for Altivec/FP/SPE registers. We don't care that
4286 much, so we just go ahead and save everything. */
4288 /* Save general registers. */
4289 for (i
= 0; i
< ARRAY_SIZE(env
->gpr
); i
++) {
4290 if (__put_user(env
->gpr
[i
], &frame
->mc_gregs
[i
])) {
4294 if (__put_user(env
->nip
, &frame
->mc_gregs
[TARGET_PT_NIP
])
4295 || __put_user(env
->ctr
, &frame
->mc_gregs
[TARGET_PT_CTR
])
4296 || __put_user(env
->lr
, &frame
->mc_gregs
[TARGET_PT_LNK
])
4297 || __put_user(env
->xer
, &frame
->mc_gregs
[TARGET_PT_XER
]))
4300 for (i
= 0; i
< ARRAY_SIZE(env
->crf
); i
++) {
4301 ccr
|= env
->crf
[i
] << (32 - ((i
+ 1) * 4));
4303 if (__put_user(ccr
, &frame
->mc_gregs
[TARGET_PT_CCR
]))
4306 /* Save Altivec registers if necessary. */
4307 if (env
->insns_flags
& PPC_ALTIVEC
) {
4308 for (i
= 0; i
< ARRAY_SIZE(env
->avr
); i
++) {
4309 ppc_avr_t
*avr
= &env
->avr
[i
];
4310 ppc_avr_t
*vreg
= &frame
->mc_vregs
.altivec
[i
];
4312 if (__put_user(avr
->u64
[0], &vreg
->u64
[0]) ||
4313 __put_user(avr
->u64
[1], &vreg
->u64
[1])) {
4317 /* Set MSR_VR in the saved MSR value to indicate that
4318 frame->mc_vregs contains valid data. */
4320 if (__put_user((uint32_t)env
->spr
[SPR_VRSAVE
],
4321 &frame
->mc_vregs
.altivec
[32].u32
[3]))
4325 /* Save floating point registers. */
4326 if (env
->insns_flags
& PPC_FLOAT
) {
4327 for (i
= 0; i
< ARRAY_SIZE(env
->fpr
); i
++) {
4328 if (__put_user(env
->fpr
[i
], &frame
->mc_fregs
[i
])) {
4332 if (__put_user((uint64_t) env
->fpscr
, &frame
->mc_fregs
[32]))
4336 /* Save SPE registers. The kernel only saves the high half. */
4337 if (env
->insns_flags
& PPC_SPE
) {
4338 #if defined(TARGET_PPC64)
4339 for (i
= 0; i
< ARRAY_SIZE(env
->gpr
); i
++) {
4340 if (__put_user(env
->gpr
[i
] >> 32, &frame
->mc_vregs
.spe
[i
])) {
4345 for (i
= 0; i
< ARRAY_SIZE(env
->gprh
); i
++) {
4346 if (__put_user(env
->gprh
[i
], &frame
->mc_vregs
.spe
[i
])) {
4351 /* Set MSR_SPE in the saved MSR value to indicate that
4352 frame->mc_vregs contains valid data. */
4354 if (__put_user(env
->spe_fscr
, &frame
->mc_vregs
.spe
[32]))
4359 if (__put_user(msr
, &frame
->mc_gregs
[TARGET_PT_MSR
]))
4362 /* Set up the sigreturn trampoline: li r0,sigret; sc. */
4364 if (__put_user(0x38000000UL
| sigret
, &frame
->tramp
[0]) ||
4365 __put_user(0x44000002UL
, &frame
->tramp
[1])) {
4373 static int restore_user_regs(CPUPPCState
*env
,
4374 struct target_mcontext
*frame
, int sig
)
4376 target_ulong save_r2
= 0;
4383 save_r2
= env
->gpr
[2];
4386 /* Restore general registers. */
4387 for (i
= 0; i
< ARRAY_SIZE(env
->gpr
); i
++) {
4388 if (__get_user(env
->gpr
[i
], &frame
->mc_gregs
[i
])) {
4392 if (__get_user(env
->nip
, &frame
->mc_gregs
[TARGET_PT_NIP
])
4393 || __get_user(env
->ctr
, &frame
->mc_gregs
[TARGET_PT_CTR
])
4394 || __get_user(env
->lr
, &frame
->mc_gregs
[TARGET_PT_LNK
])
4395 || __get_user(env
->xer
, &frame
->mc_gregs
[TARGET_PT_XER
]))
4397 if (__get_user(ccr
, &frame
->mc_gregs
[TARGET_PT_CCR
]))
4400 for (i
= 0; i
< ARRAY_SIZE(env
->crf
); i
++) {
4401 env
->crf
[i
] = (ccr
>> (32 - ((i
+ 1) * 4))) & 0xf;
4405 env
->gpr
[2] = save_r2
;
4408 if (__get_user(msr
, &frame
->mc_gregs
[TARGET_PT_MSR
]))
4411 /* If doing signal return, restore the previous little-endian mode. */
4413 env
->msr
= (env
->msr
& ~MSR_LE
) | (msr
& MSR_LE
);
4415 /* Restore Altivec registers if necessary. */
4416 if (env
->insns_flags
& PPC_ALTIVEC
) {
4417 for (i
= 0; i
< ARRAY_SIZE(env
->avr
); i
++) {
4418 ppc_avr_t
*avr
= &env
->avr
[i
];
4419 ppc_avr_t
*vreg
= &frame
->mc_vregs
.altivec
[i
];
4421 if (__get_user(avr
->u64
[0], &vreg
->u64
[0]) ||
4422 __get_user(avr
->u64
[1], &vreg
->u64
[1])) {
4426 /* Set MSR_VEC in the saved MSR value to indicate that
4427 frame->mc_vregs contains valid data. */
4428 if (__get_user(env
->spr
[SPR_VRSAVE
],
4429 (target_ulong
*)(&frame
->mc_vregs
.altivec
[32].u32
[3])))
4433 /* Restore floating point registers. */
4434 if (env
->insns_flags
& PPC_FLOAT
) {
4436 for (i
= 0; i
< ARRAY_SIZE(env
->fpr
); i
++) {
4437 if (__get_user(env
->fpr
[i
], &frame
->mc_fregs
[i
])) {
4441 if (__get_user(fpscr
, &frame
->mc_fregs
[32]))
4443 env
->fpscr
= (uint32_t) fpscr
;
4446 /* Save SPE registers. The kernel only saves the high half. */
4447 if (env
->insns_flags
& PPC_SPE
) {
4448 #if defined(TARGET_PPC64)
4449 for (i
= 0; i
< ARRAY_SIZE(env
->gpr
); i
++) {
4452 if (__get_user(hi
, &frame
->mc_vregs
.spe
[i
])) {
4455 env
->gpr
[i
] = ((uint64_t)hi
<< 32) | ((uint32_t) env
->gpr
[i
]);
4458 for (i
= 0; i
< ARRAY_SIZE(env
->gprh
); i
++) {
4459 if (__get_user(env
->gprh
[i
], &frame
->mc_vregs
.spe
[i
])) {
4464 if (__get_user(env
->spe_fscr
, &frame
->mc_vregs
.spe
[32]))
4471 static void setup_frame(int sig
, struct target_sigaction
*ka
,
4472 target_sigset_t
*set
, CPUPPCState
*env
)
4474 struct target_sigframe
*frame
;
4475 struct target_sigcontext
*sc
;
4476 target_ulong frame_addr
, newsp
;
4480 frame_addr
= get_sigframe(ka
, env
, sizeof(*frame
));
4481 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 1))
4485 signal
= current_exec_domain_sig(sig
);
4487 err
|= __put_user(ka
->_sa_handler
, &sc
->handler
);
4488 err
|= __put_user(set
->sig
[0], &sc
->oldmask
);
4489 #if defined(TARGET_PPC64)
4490 err
|= __put_user(set
->sig
[0] >> 32, &sc
->_unused
[3]);
4492 err
|= __put_user(set
->sig
[1], &sc
->_unused
[3]);
4494 err
|= __put_user(h2g(&frame
->mctx
), &sc
->regs
);
4495 err
|= __put_user(sig
, &sc
->signal
);
4497 /* Save user regs. */
4498 err
|= save_user_regs(env
, &frame
->mctx
, TARGET_NR_sigreturn
);
4500 /* The kernel checks for the presence of a VDSO here. We don't
4501 emulate a vdso, so use a sigreturn system call. */
4502 env
->lr
= (target_ulong
) h2g(frame
->mctx
.tramp
);
4504 /* Turn off all fp exceptions. */
4507 /* Create a stack frame for the caller of the handler. */
4508 newsp
= frame_addr
- SIGNAL_FRAMESIZE
;
4509 err
|= put_user(env
->gpr
[1], newsp
, target_ulong
);
4514 /* Set up registers for signal handler. */
4515 env
->gpr
[1] = newsp
;
4516 env
->gpr
[3] = signal
;
4517 env
->gpr
[4] = frame_addr
+ offsetof(struct target_sigframe
, sctx
);
4518 env
->nip
= (target_ulong
) ka
->_sa_handler
;
4519 /* Signal handlers are entered in big-endian mode. */
4520 env
->msr
&= ~MSR_LE
;
4522 unlock_user_struct(frame
, frame_addr
, 1);
4526 unlock_user_struct(frame
, frame_addr
, 1);
4527 qemu_log("segfaulting from setup_frame\n");
4528 force_sig(TARGET_SIGSEGV
);
4531 static void setup_rt_frame(int sig
, struct target_sigaction
*ka
,
4532 target_siginfo_t
*info
,
4533 target_sigset_t
*set
, CPUPPCState
*env
)
4535 struct target_rt_sigframe
*rt_sf
;
4536 struct target_mcontext
*frame
;
4537 target_ulong rt_sf_addr
, newsp
= 0;
4541 rt_sf_addr
= get_sigframe(ka
, env
, sizeof(*rt_sf
));
4542 if (!lock_user_struct(VERIFY_WRITE
, rt_sf
, rt_sf_addr
, 1))
4545 signal
= current_exec_domain_sig(sig
);
4547 err
|= copy_siginfo_to_user(&rt_sf
->info
, info
);
4549 err
|= __put_user(0, &rt_sf
->uc
.tuc_flags
);
4550 err
|= __put_user(0, &rt_sf
->uc
.tuc_link
);
4551 err
|= __put_user((target_ulong
)target_sigaltstack_used
.ss_sp
,
4552 &rt_sf
->uc
.tuc_stack
.ss_sp
);
4553 err
|= __put_user(sas_ss_flags(env
->gpr
[1]),
4554 &rt_sf
->uc
.tuc_stack
.ss_flags
);
4555 err
|= __put_user(target_sigaltstack_used
.ss_size
,
4556 &rt_sf
->uc
.tuc_stack
.ss_size
);
4557 err
|= __put_user(h2g (&rt_sf
->uc
.tuc_mcontext
),
4558 &rt_sf
->uc
.tuc_regs
);
4559 for(i
= 0; i
< TARGET_NSIG_WORDS
; i
++) {
4560 err
|= __put_user(set
->sig
[i
], &rt_sf
->uc
.tuc_sigmask
.sig
[i
]);
4563 frame
= &rt_sf
->uc
.tuc_mcontext
;
4564 err
|= save_user_regs(env
, frame
, TARGET_NR_rt_sigreturn
);
4566 /* The kernel checks for the presence of a VDSO here. We don't
4567 emulate a vdso, so use a sigreturn system call. */
4568 env
->lr
= (target_ulong
) h2g(frame
->tramp
);
4570 /* Turn off all fp exceptions. */
4573 /* Create a stack frame for the caller of the handler. */
4574 newsp
= rt_sf_addr
- (SIGNAL_FRAMESIZE
+ 16);
4575 err
|= __put_user(env
->gpr
[1], (target_ulong
*)(uintptr_t) newsp
);
4580 /* Set up registers for signal handler. */
4581 env
->gpr
[1] = newsp
;
4582 env
->gpr
[3] = (target_ulong
) signal
;
4583 env
->gpr
[4] = (target_ulong
) h2g(&rt_sf
->info
);
4584 env
->gpr
[5] = (target_ulong
) h2g(&rt_sf
->uc
);
4585 env
->gpr
[6] = (target_ulong
) h2g(rt_sf
);
4586 env
->nip
= (target_ulong
) ka
->_sa_handler
;
4587 /* Signal handlers are entered in big-endian mode. */
4588 env
->msr
&= ~MSR_LE
;
4590 unlock_user_struct(rt_sf
, rt_sf_addr
, 1);
4594 unlock_user_struct(rt_sf
, rt_sf_addr
, 1);
4595 qemu_log("segfaulting from setup_rt_frame\n");
4596 force_sig(TARGET_SIGSEGV
);
4600 long do_sigreturn(CPUPPCState
*env
)
4602 struct target_sigcontext
*sc
= NULL
;
4603 struct target_mcontext
*sr
= NULL
;
4604 target_ulong sr_addr
, sc_addr
;
4606 target_sigset_t set
;
4608 sc_addr
= env
->gpr
[1] + SIGNAL_FRAMESIZE
;
4609 if (!lock_user_struct(VERIFY_READ
, sc
, sc_addr
, 1))
4612 #if defined(TARGET_PPC64)
4613 set
.sig
[0] = sc
->oldmask
+ ((long)(sc
->_unused
[3]) << 32);
4615 if(__get_user(set
.sig
[0], &sc
->oldmask
) ||
4616 __get_user(set
.sig
[1], &sc
->_unused
[3]))
4619 target_to_host_sigset_internal(&blocked
, &set
);
4620 sigprocmask(SIG_SETMASK
, &blocked
, NULL
);
4622 if (__get_user(sr_addr
, &sc
->regs
))
4624 if (!lock_user_struct(VERIFY_READ
, sr
, sr_addr
, 1))
4626 if (restore_user_regs(env
, sr
, 1))
4629 unlock_user_struct(sr
, sr_addr
, 1);
4630 unlock_user_struct(sc
, sc_addr
, 1);
4631 return -TARGET_QEMU_ESIGRETURN
;
4634 unlock_user_struct(sr
, sr_addr
, 1);
4635 unlock_user_struct(sc
, sc_addr
, 1);
4636 qemu_log("segfaulting from do_sigreturn\n");
4637 force_sig(TARGET_SIGSEGV
);
4641 /* See arch/powerpc/kernel/signal_32.c. */
4642 static int do_setcontext(struct target_ucontext
*ucp
, CPUPPCState
*env
, int sig
)
4644 struct target_mcontext
*mcp
;
4645 target_ulong mcp_addr
;
4647 target_sigset_t set
;
4649 if (copy_from_user(&set
, h2g(ucp
) + offsetof(struct target_ucontext
, tuc_sigmask
),
4653 #if defined(TARGET_PPC64)
4654 fprintf (stderr
, "do_setcontext: not implemented\n");
4657 if (__get_user(mcp_addr
, &ucp
->tuc_regs
))
4660 if (!lock_user_struct(VERIFY_READ
, mcp
, mcp_addr
, 1))
4663 target_to_host_sigset_internal(&blocked
, &set
);
4664 sigprocmask(SIG_SETMASK
, &blocked
, NULL
);
4665 if (restore_user_regs(env
, mcp
, sig
))
4668 unlock_user_struct(mcp
, mcp_addr
, 1);
4672 unlock_user_struct(mcp
, mcp_addr
, 1);
4677 long do_rt_sigreturn(CPUPPCState
*env
)
4679 struct target_rt_sigframe
*rt_sf
= NULL
;
4680 target_ulong rt_sf_addr
;
4682 rt_sf_addr
= env
->gpr
[1] + SIGNAL_FRAMESIZE
+ 16;
4683 if (!lock_user_struct(VERIFY_READ
, rt_sf
, rt_sf_addr
, 1))
4686 if (do_setcontext(&rt_sf
->uc
, env
, 1))
4689 do_sigaltstack(rt_sf_addr
4690 + offsetof(struct target_rt_sigframe
, uc
.tuc_stack
),
4693 unlock_user_struct(rt_sf
, rt_sf_addr
, 1);
4694 return -TARGET_QEMU_ESIGRETURN
;
4697 unlock_user_struct(rt_sf
, rt_sf_addr
, 1);
4698 qemu_log("segfaulting from do_rt_sigreturn\n");
4699 force_sig(TARGET_SIGSEGV
);
4703 #elif defined(TARGET_M68K)
4705 struct target_sigcontext
{
4712 unsigned short sc_sr
;
4716 struct target_sigframe
4723 abi_ulong extramask
[TARGET_NSIG_WORDS
-1];
4724 struct target_sigcontext sc
;
4727 typedef int target_greg_t
;
4728 #define TARGET_NGREG 18
4729 typedef target_greg_t target_gregset_t
[TARGET_NGREG
];
4731 typedef struct target_fpregset
{
4734 } target_fpregset_t
;
4736 struct target_mcontext
{
4738 target_gregset_t gregs
;
4739 target_fpregset_t fpregs
;
4742 #define TARGET_MCONTEXT_VERSION 2
4744 struct target_ucontext
{
4745 abi_ulong tuc_flags
;
4747 target_stack_t tuc_stack
;
4748 struct target_mcontext tuc_mcontext
;
4749 abi_long tuc_filler
[80];
4750 target_sigset_t tuc_sigmask
;
4753 struct target_rt_sigframe
4760 struct target_siginfo info
;
4761 struct target_ucontext uc
;
4765 setup_sigcontext(struct target_sigcontext
*sc
, CPUM68KState
*env
,
4770 err
|= __put_user(mask
, &sc
->sc_mask
);
4771 err
|= __put_user(env
->aregs
[7], &sc
->sc_usp
);
4772 err
|= __put_user(env
->dregs
[0], &sc
->sc_d0
);
4773 err
|= __put_user(env
->dregs
[1], &sc
->sc_d1
);
4774 err
|= __put_user(env
->aregs
[0], &sc
->sc_a0
);
4775 err
|= __put_user(env
->aregs
[1], &sc
->sc_a1
);
4776 err
|= __put_user(env
->sr
, &sc
->sc_sr
);
4777 err
|= __put_user(env
->pc
, &sc
->sc_pc
);
4783 restore_sigcontext(CPUM68KState
*env
, struct target_sigcontext
*sc
, int *pd0
)
4788 err
|= __get_user(env
->aregs
[7], &sc
->sc_usp
);
4789 err
|= __get_user(env
->dregs
[1], &sc
->sc_d1
);
4790 err
|= __get_user(env
->aregs
[0], &sc
->sc_a0
);
4791 err
|= __get_user(env
->aregs
[1], &sc
->sc_a1
);
4792 err
|= __get_user(env
->pc
, &sc
->sc_pc
);
4793 err
|= __get_user(temp
, &sc
->sc_sr
);
4794 env
->sr
= (env
->sr
& 0xff00) | (temp
& 0xff);
4796 *pd0
= tswapl(sc
->sc_d0
);
4802 * Determine which stack to use..
4804 static inline abi_ulong
4805 get_sigframe(struct target_sigaction
*ka
, CPUM68KState
*regs
,
4810 sp
= regs
->aregs
[7];
4812 /* This is the X/Open sanctioned signal stack switching. */
4813 if ((ka
->sa_flags
& TARGET_SA_ONSTACK
) && (sas_ss_flags (sp
) == 0)) {
4814 sp
= target_sigaltstack_used
.ss_sp
+ target_sigaltstack_used
.ss_size
;
4817 return ((sp
- frame_size
) & -8UL);
4820 static void setup_frame(int sig
, struct target_sigaction
*ka
,
4821 target_sigset_t
*set
, CPUM68KState
*env
)
4823 struct target_sigframe
*frame
;
4824 abi_ulong frame_addr
;
4825 abi_ulong retcode_addr
;
4830 frame_addr
= get_sigframe(ka
, env
, sizeof *frame
);
4831 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0))
4834 err
|= __put_user(sig
, &frame
->sig
);
4836 sc_addr
= frame_addr
+ offsetof(struct target_sigframe
, sc
);
4837 err
|= __put_user(sc_addr
, &frame
->psc
);
4839 err
|= setup_sigcontext(&frame
->sc
, env
, set
->sig
[0]);
4843 for(i
= 1; i
< TARGET_NSIG_WORDS
; i
++) {
4844 if (__put_user(set
->sig
[i
], &frame
->extramask
[i
- 1]))
4848 /* Set up to return from userspace. */
4850 retcode_addr
= frame_addr
+ offsetof(struct target_sigframe
, retcode
);
4851 err
|= __put_user(retcode_addr
, &frame
->pretcode
);
4853 /* moveq #,d0; trap #0 */
4855 err
|= __put_user(0x70004e40 + (TARGET_NR_sigreturn
<< 16),
4856 (long *)(frame
->retcode
));
4861 /* Set up to return from userspace */
4863 env
->aregs
[7] = frame_addr
;
4864 env
->pc
= ka
->_sa_handler
;
4866 unlock_user_struct(frame
, frame_addr
, 1);
4870 unlock_user_struct(frame
, frame_addr
, 1);
4871 force_sig(TARGET_SIGSEGV
);
4874 static inline int target_rt_setup_ucontext(struct target_ucontext
*uc
,
4877 target_greg_t
*gregs
= uc
->tuc_mcontext
.gregs
;
4880 err
= __put_user(TARGET_MCONTEXT_VERSION
, &uc
->tuc_mcontext
.version
);
4881 err
|= __put_user(env
->dregs
[0], &gregs
[0]);
4882 err
|= __put_user(env
->dregs
[1], &gregs
[1]);
4883 err
|= __put_user(env
->dregs
[2], &gregs
[2]);
4884 err
|= __put_user(env
->dregs
[3], &gregs
[3]);
4885 err
|= __put_user(env
->dregs
[4], &gregs
[4]);
4886 err
|= __put_user(env
->dregs
[5], &gregs
[5]);
4887 err
|= __put_user(env
->dregs
[6], &gregs
[6]);
4888 err
|= __put_user(env
->dregs
[7], &gregs
[7]);
4889 err
|= __put_user(env
->aregs
[0], &gregs
[8]);
4890 err
|= __put_user(env
->aregs
[1], &gregs
[9]);
4891 err
|= __put_user(env
->aregs
[2], &gregs
[10]);
4892 err
|= __put_user(env
->aregs
[3], &gregs
[11]);
4893 err
|= __put_user(env
->aregs
[4], &gregs
[12]);
4894 err
|= __put_user(env
->aregs
[5], &gregs
[13]);
4895 err
|= __put_user(env
->aregs
[6], &gregs
[14]);
4896 err
|= __put_user(env
->aregs
[7], &gregs
[15]);
4897 err
|= __put_user(env
->pc
, &gregs
[16]);
4898 err
|= __put_user(env
->sr
, &gregs
[17]);
4903 static inline int target_rt_restore_ucontext(CPUM68KState
*env
,
4904 struct target_ucontext
*uc
,
4909 target_greg_t
*gregs
= uc
->tuc_mcontext
.gregs
;
4911 err
= __get_user(temp
, &uc
->tuc_mcontext
.version
);
4912 if (temp
!= TARGET_MCONTEXT_VERSION
)
4915 /* restore passed registers */
4916 err
|= __get_user(env
->dregs
[0], &gregs
[0]);
4917 err
|= __get_user(env
->dregs
[1], &gregs
[1]);
4918 err
|= __get_user(env
->dregs
[2], &gregs
[2]);
4919 err
|= __get_user(env
->dregs
[3], &gregs
[3]);
4920 err
|= __get_user(env
->dregs
[4], &gregs
[4]);
4921 err
|= __get_user(env
->dregs
[5], &gregs
[5]);
4922 err
|= __get_user(env
->dregs
[6], &gregs
[6]);
4923 err
|= __get_user(env
->dregs
[7], &gregs
[7]);
4924 err
|= __get_user(env
->aregs
[0], &gregs
[8]);
4925 err
|= __get_user(env
->aregs
[1], &gregs
[9]);
4926 err
|= __get_user(env
->aregs
[2], &gregs
[10]);
4927 err
|= __get_user(env
->aregs
[3], &gregs
[11]);
4928 err
|= __get_user(env
->aregs
[4], &gregs
[12]);
4929 err
|= __get_user(env
->aregs
[5], &gregs
[13]);
4930 err
|= __get_user(env
->aregs
[6], &gregs
[14]);
4931 err
|= __get_user(env
->aregs
[7], &gregs
[15]);
4932 err
|= __get_user(env
->pc
, &gregs
[16]);
4933 err
|= __get_user(temp
, &gregs
[17]);
4934 env
->sr
= (env
->sr
& 0xff00) | (temp
& 0xff);
4936 *pd0
= env
->dregs
[0];
4943 static void setup_rt_frame(int sig
, struct target_sigaction
*ka
,
4944 target_siginfo_t
*info
,
4945 target_sigset_t
*set
, CPUM68KState
*env
)
4947 struct target_rt_sigframe
*frame
;
4948 abi_ulong frame_addr
;
4949 abi_ulong retcode_addr
;
4950 abi_ulong info_addr
;
4955 frame_addr
= get_sigframe(ka
, env
, sizeof *frame
);
4956 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0))
4959 err
|= __put_user(sig
, &frame
->sig
);
4961 info_addr
= frame_addr
+ offsetof(struct target_rt_sigframe
, info
);
4962 err
|= __put_user(info_addr
, &frame
->pinfo
);
4964 uc_addr
= frame_addr
+ offsetof(struct target_rt_sigframe
, uc
);
4965 err
|= __put_user(uc_addr
, &frame
->puc
);
4967 err
|= copy_siginfo_to_user(&frame
->info
, info
);
4969 /* Create the ucontext */
4971 err
|= __put_user(0, &frame
->uc
.tuc_flags
);
4972 err
|= __put_user(0, &frame
->uc
.tuc_link
);
4973 err
|= __put_user(target_sigaltstack_used
.ss_sp
,
4974 &frame
->uc
.tuc_stack
.ss_sp
);
4975 err
|= __put_user(sas_ss_flags(env
->aregs
[7]),
4976 &frame
->uc
.tuc_stack
.ss_flags
);
4977 err
|= __put_user(target_sigaltstack_used
.ss_size
,
4978 &frame
->uc
.tuc_stack
.ss_size
);
4979 err
|= target_rt_setup_ucontext(&frame
->uc
, env
);
4984 for(i
= 0; i
< TARGET_NSIG_WORDS
; i
++) {
4985 if (__put_user(set
->sig
[i
], &frame
->uc
.tuc_sigmask
.sig
[i
]))
4989 /* Set up to return from userspace. */
4991 retcode_addr
= frame_addr
+ offsetof(struct target_sigframe
, retcode
);
4992 err
|= __put_user(retcode_addr
, &frame
->pretcode
);
4994 /* moveq #,d0; notb d0; trap #0 */
4996 err
|= __put_user(0x70004600 + ((TARGET_NR_rt_sigreturn
^ 0xff) << 16),
4997 (long *)(frame
->retcode
+ 0));
4998 err
|= __put_user(0x4e40, (short *)(frame
->retcode
+ 4));
5003 /* Set up to return from userspace */
5005 env
->aregs
[7] = frame_addr
;
5006 env
->pc
= ka
->_sa_handler
;
5008 unlock_user_struct(frame
, frame_addr
, 1);
5012 unlock_user_struct(frame
, frame_addr
, 1);
5013 force_sig(TARGET_SIGSEGV
);
5016 long do_sigreturn(CPUM68KState
*env
)
5018 struct target_sigframe
*frame
;
5019 abi_ulong frame_addr
= env
->aregs
[7] - 4;
5020 target_sigset_t target_set
;
5024 if (!lock_user_struct(VERIFY_READ
, frame
, frame_addr
, 1))
5027 /* set blocked signals */
5029 if (__get_user(target_set
.sig
[0], &frame
->sc
.sc_mask
))
5032 for(i
= 1; i
< TARGET_NSIG_WORDS
; i
++) {
5033 if (__get_user(target_set
.sig
[i
], &frame
->extramask
[i
- 1]))
5037 target_to_host_sigset_internal(&set
, &target_set
);
5038 sigprocmask(SIG_SETMASK
, &set
, NULL
);
5040 /* restore registers */
5042 if (restore_sigcontext(env
, &frame
->sc
, &d0
))
5045 unlock_user_struct(frame
, frame_addr
, 0);
5049 unlock_user_struct(frame
, frame_addr
, 0);
5050 force_sig(TARGET_SIGSEGV
);
5054 long do_rt_sigreturn(CPUM68KState
*env
)
5056 struct target_rt_sigframe
*frame
;
5057 abi_ulong frame_addr
= env
->aregs
[7] - 4;
5058 target_sigset_t target_set
;
5062 if (!lock_user_struct(VERIFY_READ
, frame
, frame_addr
, 1))
5065 target_to_host_sigset_internal(&set
, &target_set
);
5066 sigprocmask(SIG_SETMASK
, &set
, NULL
);
5068 /* restore registers */
5070 if (target_rt_restore_ucontext(env
, &frame
->uc
, &d0
))
5073 if (do_sigaltstack(frame_addr
+
5074 offsetof(struct target_rt_sigframe
, uc
.tuc_stack
),
5075 0, get_sp_from_cpustate(env
)) == -EFAULT
)
5078 unlock_user_struct(frame
, frame_addr
, 0);
5082 unlock_user_struct(frame
, frame_addr
, 0);
5083 force_sig(TARGET_SIGSEGV
);
5087 #elif defined(TARGET_ALPHA)
5089 struct target_sigcontext
{
5090 abi_long sc_onstack
;
5094 abi_long sc_regs
[32];
5095 abi_long sc_ownedfp
;
5096 abi_long sc_fpregs
[32];
5098 abi_ulong sc_fp_control
;
5099 abi_ulong sc_reserved1
;
5100 abi_ulong sc_reserved2
;
5103 abi_ulong sc_traparg_a0
;
5104 abi_ulong sc_traparg_a1
;
5105 abi_ulong sc_traparg_a2
;
5106 abi_ulong sc_fp_trap_pc
;
5107 abi_ulong sc_fp_trigger_sum
;
5108 abi_ulong sc_fp_trigger_inst
;
5111 struct target_ucontext
{
5112 abi_ulong tuc_flags
;
5114 abi_ulong tuc_osf_sigmask
;
5115 target_stack_t tuc_stack
;
5116 struct target_sigcontext tuc_mcontext
;
5117 target_sigset_t tuc_sigmask
;
5120 struct target_sigframe
{
5121 struct target_sigcontext sc
;
5122 unsigned int retcode
[3];
5125 struct target_rt_sigframe
{
5126 target_siginfo_t info
;
5127 struct target_ucontext uc
;
5128 unsigned int retcode
[3];
5131 #define INSN_MOV_R30_R16 0x47fe0410
5132 #define INSN_LDI_R0 0x201f0000
5133 #define INSN_CALLSYS 0x00000083
5135 static int setup_sigcontext(struct target_sigcontext
*sc
, CPUAlphaState
*env
,
5136 abi_ulong frame_addr
, target_sigset_t
*set
)
5140 err
|= __put_user(on_sig_stack(frame_addr
), &sc
->sc_onstack
);
5141 err
|= __put_user(set
->sig
[0], &sc
->sc_mask
);
5142 err
|= __put_user(env
->pc
, &sc
->sc_pc
);
5143 err
|= __put_user(8, &sc
->sc_ps
);
5145 for (i
= 0; i
< 31; ++i
) {
5146 err
|= __put_user(env
->ir
[i
], &sc
->sc_regs
[i
]);
5148 err
|= __put_user(0, &sc
->sc_regs
[31]);
5150 for (i
= 0; i
< 31; ++i
) {
5151 err
|= __put_user(env
->fir
[i
], &sc
->sc_fpregs
[i
]);
5153 err
|= __put_user(0, &sc
->sc_fpregs
[31]);
5154 err
|= __put_user(cpu_alpha_load_fpcr(env
), &sc
->sc_fpcr
);
5156 err
|= __put_user(0, &sc
->sc_traparg_a0
); /* FIXME */
5157 err
|= __put_user(0, &sc
->sc_traparg_a1
); /* FIXME */
5158 err
|= __put_user(0, &sc
->sc_traparg_a2
); /* FIXME */
5163 static int restore_sigcontext(CPUAlphaState
*env
,
5164 struct target_sigcontext
*sc
)
5169 err
|= __get_user(env
->pc
, &sc
->sc_pc
);
5171 for (i
= 0; i
< 31; ++i
) {
5172 err
|= __get_user(env
->ir
[i
], &sc
->sc_regs
[i
]);
5174 for (i
= 0; i
< 31; ++i
) {
5175 err
|= __get_user(env
->fir
[i
], &sc
->sc_fpregs
[i
]);
5178 err
|= __get_user(fpcr
, &sc
->sc_fpcr
);
5179 cpu_alpha_store_fpcr(env
, fpcr
);
5184 static inline abi_ulong
get_sigframe(struct target_sigaction
*sa
,
5186 unsigned long framesize
)
5188 abi_ulong sp
= env
->ir
[IR_SP
];
5190 /* This is the X/Open sanctioned signal stack switching. */
5191 if ((sa
->sa_flags
& TARGET_SA_ONSTACK
) != 0 && !sas_ss_flags(sp
)) {
5192 sp
= target_sigaltstack_used
.ss_sp
+ target_sigaltstack_used
.ss_size
;
5194 return (sp
- framesize
) & -32;
5197 static void setup_frame(int sig
, struct target_sigaction
*ka
,
5198 target_sigset_t
*set
, CPUAlphaState
*env
)
5200 abi_ulong frame_addr
, r26
;
5201 struct target_sigframe
*frame
;
5204 frame_addr
= get_sigframe(ka
, env
, sizeof(*frame
));
5205 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0)) {
5209 err
|= setup_sigcontext(&frame
->sc
, env
, frame_addr
, set
);
5211 if (ka
->sa_restorer
) {
5212 r26
= ka
->sa_restorer
;
5214 err
|= __put_user(INSN_MOV_R30_R16
, &frame
->retcode
[0]);
5215 err
|= __put_user(INSN_LDI_R0
+ TARGET_NR_sigreturn
,
5216 &frame
->retcode
[1]);
5217 err
|= __put_user(INSN_CALLSYS
, &frame
->retcode
[2]);
5222 unlock_user_struct(frame
, frame_addr
, 1);
5226 if (sig
== TARGET_SIGSEGV
) {
5227 ka
->_sa_handler
= TARGET_SIG_DFL
;
5229 force_sig(TARGET_SIGSEGV
);
5232 env
->ir
[IR_RA
] = r26
;
5233 env
->ir
[IR_PV
] = env
->pc
= ka
->_sa_handler
;
5234 env
->ir
[IR_A0
] = sig
;
5236 env
->ir
[IR_A2
] = frame_addr
+ offsetof(struct target_sigframe
, sc
);
5237 env
->ir
[IR_SP
] = frame_addr
;
5240 static void setup_rt_frame(int sig
, struct target_sigaction
*ka
,
5241 target_siginfo_t
*info
,
5242 target_sigset_t
*set
, CPUAlphaState
*env
)
5244 abi_ulong frame_addr
, r26
;
5245 struct target_rt_sigframe
*frame
;
5248 frame_addr
= get_sigframe(ka
, env
, sizeof(*frame
));
5249 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0)) {
5253 err
|= copy_siginfo_to_user(&frame
->info
, info
);
5255 err
|= __put_user(0, &frame
->uc
.tuc_flags
);
5256 err
|= __put_user(0, &frame
->uc
.tuc_link
);
5257 err
|= __put_user(set
->sig
[0], &frame
->uc
.tuc_osf_sigmask
);
5258 err
|= __put_user(target_sigaltstack_used
.ss_sp
,
5259 &frame
->uc
.tuc_stack
.ss_sp
);
5260 err
|= __put_user(sas_ss_flags(env
->ir
[IR_SP
]),
5261 &frame
->uc
.tuc_stack
.ss_flags
);
5262 err
|= __put_user(target_sigaltstack_used
.ss_size
,
5263 &frame
->uc
.tuc_stack
.ss_size
);
5264 err
|= setup_sigcontext(&frame
->uc
.tuc_mcontext
, env
, frame_addr
, set
);
5265 for (i
= 0; i
< TARGET_NSIG_WORDS
; ++i
) {
5266 err
|= __put_user(set
->sig
[i
], &frame
->uc
.tuc_sigmask
.sig
[i
]);
5269 if (ka
->sa_restorer
) {
5270 r26
= ka
->sa_restorer
;
5272 err
|= __put_user(INSN_MOV_R30_R16
, &frame
->retcode
[0]);
5273 err
|= __put_user(INSN_LDI_R0
+ TARGET_NR_rt_sigreturn
,
5274 &frame
->retcode
[1]);
5275 err
|= __put_user(INSN_CALLSYS
, &frame
->retcode
[2]);
5282 if (sig
== TARGET_SIGSEGV
) {
5283 ka
->_sa_handler
= TARGET_SIG_DFL
;
5285 force_sig(TARGET_SIGSEGV
);
5288 env
->ir
[IR_RA
] = r26
;
5289 env
->ir
[IR_PV
] = env
->pc
= ka
->_sa_handler
;
5290 env
->ir
[IR_A0
] = sig
;
5291 env
->ir
[IR_A1
] = frame_addr
+ offsetof(struct target_rt_sigframe
, info
);
5292 env
->ir
[IR_A2
] = frame_addr
+ offsetof(struct target_rt_sigframe
, uc
);
5293 env
->ir
[IR_SP
] = frame_addr
;
5296 long do_sigreturn(CPUAlphaState
*env
)
5298 struct target_sigcontext
*sc
;
5299 abi_ulong sc_addr
= env
->ir
[IR_A0
];
5300 target_sigset_t target_set
;
5303 if (!lock_user_struct(VERIFY_READ
, sc
, sc_addr
, 1)) {
5307 target_sigemptyset(&target_set
);
5308 if (__get_user(target_set
.sig
[0], &sc
->sc_mask
)) {
5312 target_to_host_sigset_internal(&set
, &target_set
);
5313 sigprocmask(SIG_SETMASK
, &set
, NULL
);
5315 if (restore_sigcontext(env
, sc
)) {
5318 unlock_user_struct(sc
, sc_addr
, 0);
5319 return env
->ir
[IR_V0
];
5322 unlock_user_struct(sc
, sc_addr
, 0);
5323 force_sig(TARGET_SIGSEGV
);
5326 long do_rt_sigreturn(CPUAlphaState
*env
)
5328 abi_ulong frame_addr
= env
->ir
[IR_A0
];
5329 struct target_rt_sigframe
*frame
;
5332 if (!lock_user_struct(VERIFY_READ
, frame
, frame_addr
, 1)) {
5335 target_to_host_sigset(&set
, &frame
->uc
.tuc_sigmask
);
5336 sigprocmask(SIG_SETMASK
, &set
, NULL
);
5338 if (restore_sigcontext(env
, &frame
->uc
.tuc_mcontext
)) {
5341 if (do_sigaltstack(frame_addr
+ offsetof(struct target_rt_sigframe
,
5343 0, env
->ir
[IR_SP
]) == -EFAULT
) {
5347 unlock_user_struct(frame
, frame_addr
, 0);
5348 return env
->ir
[IR_V0
];
5352 unlock_user_struct(frame
, frame_addr
, 0);
5353 force_sig(TARGET_SIGSEGV
);
5358 static void setup_frame(int sig
, struct target_sigaction
*ka
,
5359 target_sigset_t
*set
, CPUArchState
*env
)
5361 fprintf(stderr
, "setup_frame: not implemented\n");
5364 static void setup_rt_frame(int sig
, struct target_sigaction
*ka
,
5365 target_siginfo_t
*info
,
5366 target_sigset_t
*set
, CPUArchState
*env
)
5368 fprintf(stderr
, "setup_rt_frame: not implemented\n");
5371 long do_sigreturn(CPUArchState
*env
)
5373 fprintf(stderr
, "do_sigreturn: not implemented\n");
5374 return -TARGET_ENOSYS
;
5377 long do_rt_sigreturn(CPUArchState
*env
)
5379 fprintf(stderr
, "do_rt_sigreturn: not implemented\n");
5380 return -TARGET_ENOSYS
;
5385 void process_pending_signals(CPUArchState
*cpu_env
)
5389 sigset_t set
, old_set
;
5390 target_sigset_t target_old_set
;
5391 struct emulated_sigtable
*k
;
5392 struct target_sigaction
*sa
;
5394 TaskState
*ts
= cpu_env
->opaque
;
5396 if (!ts
->signal_pending
)
5399 /* FIXME: This is not threadsafe. */
5401 for(sig
= 1; sig
<= TARGET_NSIG
; sig
++) {
5406 /* if no signal is pending, just return */
5407 ts
->signal_pending
= 0;
5412 fprintf(stderr
, "qemu: process signal %d\n", sig
);
5414 /* dequeue signal */
5420 sig
= gdb_handlesig (cpu_env
, sig
);
5423 handler
= TARGET_SIG_IGN
;
5425 sa
= &sigact_table
[sig
- 1];
5426 handler
= sa
->_sa_handler
;
5429 if (handler
== TARGET_SIG_DFL
) {
5430 /* default handler : ignore some signal. The other are job control or fatal */
5431 if (sig
== TARGET_SIGTSTP
|| sig
== TARGET_SIGTTIN
|| sig
== TARGET_SIGTTOU
) {
5432 kill(getpid(),SIGSTOP
);
5433 } else if (sig
!= TARGET_SIGCHLD
&&
5434 sig
!= TARGET_SIGURG
&&
5435 sig
!= TARGET_SIGWINCH
&&
5436 sig
!= TARGET_SIGCONT
) {
5439 } else if (handler
== TARGET_SIG_IGN
) {
5441 } else if (handler
== TARGET_SIG_ERR
) {
5444 /* compute the blocked signals during the handler execution */
5445 target_to_host_sigset(&set
, &sa
->sa_mask
);
5446 /* SA_NODEFER indicates that the current signal should not be
5447 blocked during the handler */
5448 if (!(sa
->sa_flags
& TARGET_SA_NODEFER
))
5449 sigaddset(&set
, target_to_host_signal(sig
));
5451 /* block signals in the handler using Linux */
5452 sigprocmask(SIG_BLOCK
, &set
, &old_set
);
5453 /* save the previous blocked signal state to restore it at the
5454 end of the signal execution (see do_sigreturn) */
5455 host_to_target_sigset_internal(&target_old_set
, &old_set
);
5457 /* if the CPU is in VM86 mode, we restore the 32 bit values */
5458 #if defined(TARGET_I386) && !defined(TARGET_X86_64)
5460 CPUX86State
*env
= cpu_env
;
5461 if (env
->eflags
& VM_MASK
)
5462 save_v86_state(env
);
5465 /* prepare the stack frame of the virtual CPU */
5466 #if defined(TARGET_ABI_MIPSN32) || defined(TARGET_ABI_MIPSN64)
5467 /* These targets do not have traditional signals. */
5468 setup_rt_frame(sig
, sa
, &q
->info
, &target_old_set
, cpu_env
);
5470 if (sa
->sa_flags
& TARGET_SA_SIGINFO
)
5471 setup_rt_frame(sig
, sa
, &q
->info
, &target_old_set
, cpu_env
);
5473 setup_frame(sig
, sa
, &target_old_set
, cpu_env
);
5475 if (sa
->sa_flags
& TARGET_SA_RESETHAND
)
5476 sa
->_sa_handler
= TARGET_SIG_DFL
;
5479 free_sigqueue(cpu_env
, q
);