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_ABI_MIPSN64)
2443 # warning signal handling not implemented
2445 static void setup_frame(int sig
, struct target_sigaction
*ka
,
2446 target_sigset_t
*set
, CPUMIPSState
*env
)
2448 fprintf(stderr
, "setup_frame: not implemented\n");
2451 static void setup_rt_frame(int sig
, struct target_sigaction
*ka
,
2452 target_siginfo_t
*info
,
2453 target_sigset_t
*set
, CPUMIPSState
*env
)
2455 fprintf(stderr
, "setup_rt_frame: not implemented\n");
2458 long do_sigreturn(CPUMIPSState
*env
)
2460 fprintf(stderr
, "do_sigreturn: not implemented\n");
2461 return -TARGET_ENOSYS
;
2464 long do_rt_sigreturn(CPUMIPSState
*env
)
2466 fprintf(stderr
, "do_rt_sigreturn: not implemented\n");
2467 return -TARGET_ENOSYS
;
2470 #elif defined(TARGET_ABI_MIPSN32)
2472 # warning signal handling not implemented
2474 static void setup_frame(int sig
, struct target_sigaction
*ka
,
2475 target_sigset_t
*set
, CPUMIPSState
*env
)
2477 fprintf(stderr
, "setup_frame: not implemented\n");
2480 static void setup_rt_frame(int sig
, struct target_sigaction
*ka
,
2481 target_siginfo_t
*info
,
2482 target_sigset_t
*set
, CPUMIPSState
*env
)
2484 fprintf(stderr
, "setup_rt_frame: not implemented\n");
2487 long do_sigreturn(CPUMIPSState
*env
)
2489 fprintf(stderr
, "do_sigreturn: not implemented\n");
2490 return -TARGET_ENOSYS
;
2493 long do_rt_sigreturn(CPUMIPSState
*env
)
2495 fprintf(stderr
, "do_rt_sigreturn: not implemented\n");
2496 return -TARGET_ENOSYS
;
2499 #elif defined(TARGET_ABI_MIPSO32)
2501 struct target_sigcontext
{
2502 uint32_t sc_regmask
; /* Unused */
2505 uint64_t sc_regs
[32];
2506 uint64_t sc_fpregs
[32];
2507 uint32_t sc_ownedfp
; /* Unused */
2508 uint32_t sc_fpc_csr
;
2509 uint32_t sc_fpc_eir
; /* Unused */
2510 uint32_t sc_used_math
;
2511 uint32_t sc_dsp
; /* dsp status, was sc_ssflags */
2515 target_ulong sc_hi1
; /* Was sc_cause */
2516 target_ulong sc_lo1
; /* Was sc_badvaddr */
2517 target_ulong sc_hi2
; /* Was sc_sigset[4] */
2518 target_ulong sc_lo2
;
2519 target_ulong sc_hi3
;
2520 target_ulong sc_lo3
;
2524 uint32_t sf_ass
[4]; /* argument save space for o32 */
2525 uint32_t sf_code
[2]; /* signal trampoline */
2526 struct target_sigcontext sf_sc
;
2527 target_sigset_t sf_mask
;
2530 struct target_ucontext
{
2531 target_ulong tuc_flags
;
2532 target_ulong tuc_link
;
2533 target_stack_t tuc_stack
;
2535 struct target_sigcontext tuc_mcontext
;
2536 target_sigset_t tuc_sigmask
;
2539 struct target_rt_sigframe
{
2540 uint32_t rs_ass
[4]; /* argument save space for o32 */
2541 uint32_t rs_code
[2]; /* signal trampoline */
2542 struct target_siginfo rs_info
;
2543 struct target_ucontext rs_uc
;
2546 /* Install trampoline to jump back from signal handler */
2547 static inline int install_sigtramp(unsigned int *tramp
, unsigned int syscall
)
2552 * Set up the return code ...
2554 * li v0, __NR__foo_sigreturn
2558 err
= __put_user(0x24020000 + syscall
, tramp
+ 0);
2559 err
|= __put_user(0x0000000c , tramp
+ 1);
2560 /* flush_cache_sigtramp((unsigned long) tramp); */
2565 setup_sigcontext(CPUMIPSState
*regs
, struct target_sigcontext
*sc
)
2569 err
|= __put_user(regs
->active_tc
.PC
, &sc
->sc_pc
);
2571 #define save_gp_reg(i) do { \
2572 err |= __put_user(regs->active_tc.gpr[i], &sc->sc_regs[i]); \
2574 __put_user(0, &sc
->sc_regs
[0]); save_gp_reg(1); save_gp_reg(2);
2575 save_gp_reg(3); save_gp_reg(4); save_gp_reg(5); save_gp_reg(6);
2576 save_gp_reg(7); save_gp_reg(8); save_gp_reg(9); save_gp_reg(10);
2577 save_gp_reg(11); save_gp_reg(12); save_gp_reg(13); save_gp_reg(14);
2578 save_gp_reg(15); save_gp_reg(16); save_gp_reg(17); save_gp_reg(18);
2579 save_gp_reg(19); save_gp_reg(20); save_gp_reg(21); save_gp_reg(22);
2580 save_gp_reg(23); save_gp_reg(24); save_gp_reg(25); save_gp_reg(26);
2581 save_gp_reg(27); save_gp_reg(28); save_gp_reg(29); save_gp_reg(30);
2585 err
|= __put_user(regs
->active_tc
.HI
[0], &sc
->sc_mdhi
);
2586 err
|= __put_user(regs
->active_tc
.LO
[0], &sc
->sc_mdlo
);
2588 /* Not used yet, but might be useful if we ever have DSP suppport */
2591 err
|= __put_user(mfhi1(), &sc
->sc_hi1
);
2592 err
|= __put_user(mflo1(), &sc
->sc_lo1
);
2593 err
|= __put_user(mfhi2(), &sc
->sc_hi2
);
2594 err
|= __put_user(mflo2(), &sc
->sc_lo2
);
2595 err
|= __put_user(mfhi3(), &sc
->sc_hi3
);
2596 err
|= __put_user(mflo3(), &sc
->sc_lo3
);
2597 err
|= __put_user(rddsp(DSP_MASK
), &sc
->sc_dsp
);
2599 /* same with 64 bit */
2601 err
|= __put_user(regs
->hi
, &sc
->sc_hi
[0]);
2602 err
|= __put_user(regs
->lo
, &sc
->sc_lo
[0]);
2604 err
|= __put_user(mfhi1(), &sc
->sc_hi
[1]);
2605 err
|= __put_user(mflo1(), &sc
->sc_lo
[1]);
2606 err
|= __put_user(mfhi2(), &sc
->sc_hi
[2]);
2607 err
|= __put_user(mflo2(), &sc
->sc_lo
[2]);
2608 err
|= __put_user(mfhi3(), &sc
->sc_hi
[3]);
2609 err
|= __put_user(mflo3(), &sc
->sc_lo
[3]);
2610 err
|= __put_user(rddsp(DSP_MASK
), &sc
->sc_dsp
);
2616 err
|= __put_user(!!used_math(), &sc
->sc_used_math
);
2622 * Save FPU state to signal context. Signal handler will "inherit"
2623 * current FPU state.
2627 if (!is_fpu_owner()) {
2629 restore_fp(current
);
2631 err
|= save_fp_context(sc
);
2640 restore_sigcontext(CPUMIPSState
*regs
, struct target_sigcontext
*sc
)
2644 err
|= __get_user(regs
->CP0_EPC
, &sc
->sc_pc
);
2646 err
|= __get_user(regs
->active_tc
.HI
[0], &sc
->sc_mdhi
);
2647 err
|= __get_user(regs
->active_tc
.LO
[0], &sc
->sc_mdlo
);
2649 #define restore_gp_reg(i) do { \
2650 err |= __get_user(regs->active_tc.gpr[i], &sc->sc_regs[i]); \
2652 restore_gp_reg( 1); restore_gp_reg( 2); restore_gp_reg( 3);
2653 restore_gp_reg( 4); restore_gp_reg( 5); restore_gp_reg( 6);
2654 restore_gp_reg( 7); restore_gp_reg( 8); restore_gp_reg( 9);
2655 restore_gp_reg(10); restore_gp_reg(11); restore_gp_reg(12);
2656 restore_gp_reg(13); restore_gp_reg(14); restore_gp_reg(15);
2657 restore_gp_reg(16); restore_gp_reg(17); restore_gp_reg(18);
2658 restore_gp_reg(19); restore_gp_reg(20); restore_gp_reg(21);
2659 restore_gp_reg(22); restore_gp_reg(23); restore_gp_reg(24);
2660 restore_gp_reg(25); restore_gp_reg(26); restore_gp_reg(27);
2661 restore_gp_reg(28); restore_gp_reg(29); restore_gp_reg(30);
2663 #undef restore_gp_reg
2667 err
|= __get_user(treg
, &sc
->sc_hi1
); mthi1(treg
);
2668 err
|= __get_user(treg
, &sc
->sc_lo1
); mtlo1(treg
);
2669 err
|= __get_user(treg
, &sc
->sc_hi2
); mthi2(treg
);
2670 err
|= __get_user(treg
, &sc
->sc_lo2
); mtlo2(treg
);
2671 err
|= __get_user(treg
, &sc
->sc_hi3
); mthi3(treg
);
2672 err
|= __get_user(treg
, &sc
->sc_lo3
); mtlo3(treg
);
2673 err
|= __get_user(treg
, &sc
->sc_dsp
); wrdsp(treg
, DSP_MASK
);
2676 err
|= __get_user(regs
->hi
, &sc
->sc_hi
[0]);
2677 err
|= __get_user(regs
->lo
, &sc
->sc_lo
[0]);
2679 err
|= __get_user(treg
, &sc
->sc_hi
[1]); mthi1(treg
);
2680 err
|= __get_user(treg
, &sc
->sc_lo
[1]); mthi1(treg
);
2681 err
|= __get_user(treg
, &sc
->sc_hi
[2]); mthi2(treg
);
2682 err
|= __get_user(treg
, &sc
->sc_lo
[2]); mthi2(treg
);
2683 err
|= __get_user(treg
, &sc
->sc_hi
[3]); mthi3(treg
);
2684 err
|= __get_user(treg
, &sc
->sc_lo
[3]); mthi3(treg
);
2685 err
|= __get_user(treg
, &sc
->sc_dsp
); wrdsp(treg
, DSP_MASK
);
2689 err
|= __get_user(used_math
, &sc
->sc_used_math
);
2690 conditional_used_math(used_math
);
2695 /* restore fpu context if we have used it before */
2697 err
|= restore_fp_context(sc
);
2699 /* signal handler may have used FPU. Give it up. */
2708 * Determine which stack to use..
2710 static inline abi_ulong
2711 get_sigframe(struct target_sigaction
*ka
, CPUMIPSState
*regs
, size_t frame_size
)
2715 /* Default to using normal stack */
2716 sp
= regs
->active_tc
.gpr
[29];
2719 * FPU emulator may have its own trampoline active just
2720 * above the user stack, 16-bytes before the next lowest
2721 * 16 byte boundary. Try to avoid trashing it.
2725 /* This is the X/Open sanctioned signal stack switching. */
2726 if ((ka
->sa_flags
& TARGET_SA_ONSTACK
) && (sas_ss_flags (sp
) == 0)) {
2727 sp
= target_sigaltstack_used
.ss_sp
+ target_sigaltstack_used
.ss_size
;
2730 return (sp
- frame_size
) & ~7;
2733 /* compare linux/arch/mips/kernel/signal.c:setup_frame() */
2734 static void setup_frame(int sig
, struct target_sigaction
* ka
,
2735 target_sigset_t
*set
, CPUMIPSState
*regs
)
2737 struct sigframe
*frame
;
2738 abi_ulong frame_addr
;
2741 frame_addr
= get_sigframe(ka
, regs
, sizeof(*frame
));
2742 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0))
2745 install_sigtramp(frame
->sf_code
, TARGET_NR_sigreturn
);
2747 if(setup_sigcontext(regs
, &frame
->sf_sc
))
2750 for(i
= 0; i
< TARGET_NSIG_WORDS
; i
++) {
2751 if(__put_user(set
->sig
[i
], &frame
->sf_mask
.sig
[i
]))
2756 * Arguments to signal handler:
2758 * a0 = signal number
2759 * a1 = 0 (should be cause)
2760 * a2 = pointer to struct sigcontext
2762 * $25 and PC point to the signal handler, $29 points to the
2765 regs
->active_tc
.gpr
[ 4] = sig
;
2766 regs
->active_tc
.gpr
[ 5] = 0;
2767 regs
->active_tc
.gpr
[ 6] = frame_addr
+ offsetof(struct sigframe
, sf_sc
);
2768 regs
->active_tc
.gpr
[29] = frame_addr
;
2769 regs
->active_tc
.gpr
[31] = frame_addr
+ offsetof(struct sigframe
, sf_code
);
2770 /* The original kernel code sets CP0_EPC to the handler
2771 * since it returns to userland using eret
2772 * we cannot do this here, and we must set PC directly */
2773 regs
->active_tc
.PC
= regs
->active_tc
.gpr
[25] = ka
->_sa_handler
;
2774 unlock_user_struct(frame
, frame_addr
, 1);
2778 unlock_user_struct(frame
, frame_addr
, 1);
2779 force_sig(TARGET_SIGSEGV
/*, current*/);
2782 long do_sigreturn(CPUMIPSState
*regs
)
2784 struct sigframe
*frame
;
2785 abi_ulong frame_addr
;
2787 target_sigset_t target_set
;
2790 #if defined(DEBUG_SIGNAL)
2791 fprintf(stderr
, "do_sigreturn\n");
2793 frame_addr
= regs
->active_tc
.gpr
[29];
2794 if (!lock_user_struct(VERIFY_READ
, frame
, frame_addr
, 1))
2797 for(i
= 0; i
< TARGET_NSIG_WORDS
; i
++) {
2798 if(__get_user(target_set
.sig
[i
], &frame
->sf_mask
.sig
[i
]))
2802 target_to_host_sigset_internal(&blocked
, &target_set
);
2803 sigprocmask(SIG_SETMASK
, &blocked
, NULL
);
2805 if (restore_sigcontext(regs
, &frame
->sf_sc
))
2810 * Don't let your children do this ...
2812 __asm__
__volatile__(
2820 regs
->active_tc
.PC
= regs
->CP0_EPC
;
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 static void setup_rt_frame(int sig
, struct target_sigaction
*ka
,
2832 target_siginfo_t
*info
,
2833 target_sigset_t
*set
, CPUMIPSState
*env
)
2835 struct target_rt_sigframe
*frame
;
2836 abi_ulong frame_addr
;
2839 frame_addr
= get_sigframe(ka
, env
, sizeof(*frame
));
2840 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0))
2843 install_sigtramp(frame
->rs_code
, TARGET_NR_rt_sigreturn
);
2845 copy_siginfo_to_user(&frame
->rs_info
, info
);
2847 __put_user(0, &frame
->rs_uc
.tuc_flags
);
2848 __put_user(0, &frame
->rs_uc
.tuc_link
);
2849 __put_user(target_sigaltstack_used
.ss_sp
, &frame
->rs_uc
.tuc_stack
.ss_sp
);
2850 __put_user(target_sigaltstack_used
.ss_size
, &frame
->rs_uc
.tuc_stack
.ss_size
);
2851 __put_user(sas_ss_flags(get_sp_from_cpustate(env
)),
2852 &frame
->rs_uc
.tuc_stack
.ss_flags
);
2854 setup_sigcontext(env
, &frame
->rs_uc
.tuc_mcontext
);
2856 for(i
= 0; i
< TARGET_NSIG_WORDS
; i
++) {
2857 __put_user(set
->sig
[i
], &frame
->rs_uc
.tuc_sigmask
.sig
[i
]);
2861 * Arguments to signal handler:
2863 * a0 = signal number
2864 * a1 = pointer to siginfo_t
2865 * a2 = pointer to struct ucontext
2867 * $25 and PC point to the signal handler, $29 points to the
2870 env
->active_tc
.gpr
[ 4] = sig
;
2871 env
->active_tc
.gpr
[ 5] = frame_addr
2872 + offsetof(struct target_rt_sigframe
, rs_info
);
2873 env
->active_tc
.gpr
[ 6] = frame_addr
2874 + offsetof(struct target_rt_sigframe
, rs_uc
);
2875 env
->active_tc
.gpr
[29] = frame_addr
;
2876 env
->active_tc
.gpr
[31] = frame_addr
2877 + offsetof(struct target_rt_sigframe
, rs_code
);
2878 /* The original kernel code sets CP0_EPC to the handler
2879 * since it returns to userland using eret
2880 * we cannot do this here, and we must set PC directly */
2881 env
->active_tc
.PC
= env
->active_tc
.gpr
[25] = ka
->_sa_handler
;
2882 unlock_user_struct(frame
, frame_addr
, 1);
2886 unlock_user_struct(frame
, frame_addr
, 1);
2887 force_sig(TARGET_SIGSEGV
/*, current*/);
2890 long do_rt_sigreturn(CPUMIPSState
*env
)
2892 struct target_rt_sigframe
*frame
;
2893 abi_ulong frame_addr
;
2896 #if defined(DEBUG_SIGNAL)
2897 fprintf(stderr
, "do_rt_sigreturn\n");
2899 frame_addr
= env
->active_tc
.gpr
[29];
2900 if (!lock_user_struct(VERIFY_READ
, frame
, frame_addr
, 1))
2903 target_to_host_sigset(&blocked
, &frame
->rs_uc
.tuc_sigmask
);
2904 sigprocmask(SIG_SETMASK
, &blocked
, NULL
);
2906 if (restore_sigcontext(env
, &frame
->rs_uc
.tuc_mcontext
))
2909 if (do_sigaltstack(frame_addr
+
2910 offsetof(struct target_rt_sigframe
, rs_uc
.tuc_stack
),
2911 0, get_sp_from_cpustate(env
)) == -EFAULT
)
2914 env
->active_tc
.PC
= env
->CP0_EPC
;
2915 /* I am not sure this is right, but it seems to work
2916 * maybe a problem with nested signals ? */
2918 return -TARGET_QEMU_ESIGRETURN
;
2921 force_sig(TARGET_SIGSEGV
/*, current*/);
2925 #elif defined(TARGET_SH4)
2928 * code and data structures from linux kernel:
2929 * include/asm-sh/sigcontext.h
2930 * arch/sh/kernel/signal.c
2933 struct target_sigcontext
{
2934 target_ulong oldmask
;
2937 target_ulong sc_gregs
[16];
2941 target_ulong sc_gbr
;
2942 target_ulong sc_mach
;
2943 target_ulong sc_macl
;
2946 target_ulong sc_fpregs
[16];
2947 target_ulong sc_xfpregs
[16];
2948 unsigned int sc_fpscr
;
2949 unsigned int sc_fpul
;
2950 unsigned int sc_ownedfp
;
2953 struct target_sigframe
2955 struct target_sigcontext sc
;
2956 target_ulong extramask
[TARGET_NSIG_WORDS
-1];
2957 uint16_t retcode
[3];
2961 struct target_ucontext
{
2962 target_ulong tuc_flags
;
2963 struct target_ucontext
*tuc_link
;
2964 target_stack_t tuc_stack
;
2965 struct target_sigcontext tuc_mcontext
;
2966 target_sigset_t tuc_sigmask
; /* mask last for extensibility */
2969 struct target_rt_sigframe
2971 struct target_siginfo info
;
2972 struct target_ucontext uc
;
2973 uint16_t retcode
[3];
2977 #define MOVW(n) (0x9300|((n)-2)) /* Move mem word at PC+n to R3 */
2978 #define TRAP_NOARG 0xc310 /* Syscall w/no args (NR in R3) SH3/4 */
2980 static abi_ulong
get_sigframe(struct target_sigaction
*ka
,
2981 unsigned long sp
, size_t frame_size
)
2983 if ((ka
->sa_flags
& TARGET_SA_ONSTACK
) && (sas_ss_flags(sp
) == 0)) {
2984 sp
= target_sigaltstack_used
.ss_sp
+ target_sigaltstack_used
.ss_size
;
2987 return (sp
- frame_size
) & -8ul;
2990 static int setup_sigcontext(struct target_sigcontext
*sc
,
2991 CPUSH4State
*regs
, unsigned long mask
)
2996 #define COPY(x) err |= __put_user(regs->x, &sc->sc_##x)
2997 COPY(gregs
[0]); COPY(gregs
[1]);
2998 COPY(gregs
[2]); COPY(gregs
[3]);
2999 COPY(gregs
[4]); COPY(gregs
[5]);
3000 COPY(gregs
[6]); COPY(gregs
[7]);
3001 COPY(gregs
[8]); COPY(gregs
[9]);
3002 COPY(gregs
[10]); COPY(gregs
[11]);
3003 COPY(gregs
[12]); COPY(gregs
[13]);
3004 COPY(gregs
[14]); COPY(gregs
[15]);
3005 COPY(gbr
); COPY(mach
);
3006 COPY(macl
); COPY(pr
);
3010 for (i
=0; i
<16; i
++) {
3011 err
|= __put_user(regs
->fregs
[i
], &sc
->sc_fpregs
[i
]);
3013 err
|= __put_user(regs
->fpscr
, &sc
->sc_fpscr
);
3014 err
|= __put_user(regs
->fpul
, &sc
->sc_fpul
);
3016 /* non-iBCS2 extensions.. */
3017 err
|= __put_user(mask
, &sc
->oldmask
);
3022 static int restore_sigcontext(CPUSH4State
*regs
, struct target_sigcontext
*sc
,
3025 unsigned int err
= 0;
3028 #define COPY(x) err |= __get_user(regs->x, &sc->sc_##x)
3030 COPY(gregs
[2]); COPY(gregs
[3]);
3031 COPY(gregs
[4]); COPY(gregs
[5]);
3032 COPY(gregs
[6]); COPY(gregs
[7]);
3033 COPY(gregs
[8]); COPY(gregs
[9]);
3034 COPY(gregs
[10]); COPY(gregs
[11]);
3035 COPY(gregs
[12]); COPY(gregs
[13]);
3036 COPY(gregs
[14]); COPY(gregs
[15]);
3037 COPY(gbr
); COPY(mach
);
3038 COPY(macl
); COPY(pr
);
3042 for (i
=0; i
<16; i
++) {
3043 err
|= __get_user(regs
->fregs
[i
], &sc
->sc_fpregs
[i
]);
3045 err
|= __get_user(regs
->fpscr
, &sc
->sc_fpscr
);
3046 err
|= __get_user(regs
->fpul
, &sc
->sc_fpul
);
3048 regs
->tra
= -1; /* disable syscall checks */
3049 err
|= __get_user(*r0_p
, &sc
->sc_gregs
[0]);
3053 static void setup_frame(int sig
, struct target_sigaction
*ka
,
3054 target_sigset_t
*set
, CPUSH4State
*regs
)
3056 struct target_sigframe
*frame
;
3057 abi_ulong frame_addr
;
3062 frame_addr
= get_sigframe(ka
, regs
->gregs
[15], sizeof(*frame
));
3063 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0))
3066 signal
= current_exec_domain_sig(sig
);
3068 err
|= setup_sigcontext(&frame
->sc
, regs
, set
->sig
[0]);
3070 for (i
= 0; i
< TARGET_NSIG_WORDS
- 1; i
++) {
3071 err
|= __put_user(set
->sig
[i
+ 1], &frame
->extramask
[i
]);
3074 /* Set up to return from userspace. If provided, use a stub
3075 already in userspace. */
3076 if (ka
->sa_flags
& TARGET_SA_RESTORER
) {
3077 regs
->pr
= (unsigned long) ka
->sa_restorer
;
3079 /* Generate return code (system call to sigreturn) */
3080 err
|= __put_user(MOVW(2), &frame
->retcode
[0]);
3081 err
|= __put_user(TRAP_NOARG
, &frame
->retcode
[1]);
3082 err
|= __put_user((TARGET_NR_sigreturn
), &frame
->retcode
[2]);
3083 regs
->pr
= (unsigned long) frame
->retcode
;
3089 /* Set up registers for signal handler */
3090 regs
->gregs
[15] = frame_addr
;
3091 regs
->gregs
[4] = signal
; /* Arg for signal handler */
3093 regs
->gregs
[6] = frame_addr
+= offsetof(typeof(*frame
), sc
);
3094 regs
->pc
= (unsigned long) ka
->_sa_handler
;
3096 unlock_user_struct(frame
, frame_addr
, 1);
3100 unlock_user_struct(frame
, frame_addr
, 1);
3101 force_sig(TARGET_SIGSEGV
);
3104 static void setup_rt_frame(int sig
, struct target_sigaction
*ka
,
3105 target_siginfo_t
*info
,
3106 target_sigset_t
*set
, CPUSH4State
*regs
)
3108 struct target_rt_sigframe
*frame
;
3109 abi_ulong frame_addr
;
3114 frame_addr
= get_sigframe(ka
, regs
->gregs
[15], sizeof(*frame
));
3115 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0))
3118 signal
= current_exec_domain_sig(sig
);
3120 err
|= copy_siginfo_to_user(&frame
->info
, info
);
3122 /* Create the ucontext. */
3123 err
|= __put_user(0, &frame
->uc
.tuc_flags
);
3124 err
|= __put_user(0, (unsigned long *)&frame
->uc
.tuc_link
);
3125 err
|= __put_user((unsigned long)target_sigaltstack_used
.ss_sp
,
3126 &frame
->uc
.tuc_stack
.ss_sp
);
3127 err
|= __put_user(sas_ss_flags(regs
->gregs
[15]),
3128 &frame
->uc
.tuc_stack
.ss_flags
);
3129 err
|= __put_user(target_sigaltstack_used
.ss_size
,
3130 &frame
->uc
.tuc_stack
.ss_size
);
3131 err
|= setup_sigcontext(&frame
->uc
.tuc_mcontext
,
3133 for(i
= 0; i
< TARGET_NSIG_WORDS
; i
++) {
3134 err
|= __put_user(set
->sig
[i
], &frame
->uc
.tuc_sigmask
.sig
[i
]);
3137 /* Set up to return from userspace. If provided, use a stub
3138 already in userspace. */
3139 if (ka
->sa_flags
& TARGET_SA_RESTORER
) {
3140 regs
->pr
= (unsigned long) ka
->sa_restorer
;
3142 /* Generate return code (system call to sigreturn) */
3143 err
|= __put_user(MOVW(2), &frame
->retcode
[0]);
3144 err
|= __put_user(TRAP_NOARG
, &frame
->retcode
[1]);
3145 err
|= __put_user((TARGET_NR_rt_sigreturn
), &frame
->retcode
[2]);
3146 regs
->pr
= (unsigned long) frame
->retcode
;
3152 /* Set up registers for signal handler */
3153 regs
->gregs
[15] = frame_addr
;
3154 regs
->gregs
[4] = signal
; /* Arg for signal handler */
3155 regs
->gregs
[5] = frame_addr
+ offsetof(typeof(*frame
), info
);
3156 regs
->gregs
[6] = frame_addr
+ offsetof(typeof(*frame
), uc
);
3157 regs
->pc
= (unsigned long) ka
->_sa_handler
;
3159 unlock_user_struct(frame
, frame_addr
, 1);
3163 unlock_user_struct(frame
, frame_addr
, 1);
3164 force_sig(TARGET_SIGSEGV
);
3167 long do_sigreturn(CPUSH4State
*regs
)
3169 struct target_sigframe
*frame
;
3170 abi_ulong frame_addr
;
3172 target_sigset_t target_set
;
3177 #if defined(DEBUG_SIGNAL)
3178 fprintf(stderr
, "do_sigreturn\n");
3180 frame_addr
= regs
->gregs
[15];
3181 if (!lock_user_struct(VERIFY_READ
, frame
, frame_addr
, 1))
3184 err
|= __get_user(target_set
.sig
[0], &frame
->sc
.oldmask
);
3185 for(i
= 1; i
< TARGET_NSIG_WORDS
; i
++) {
3186 err
|= (__get_user(target_set
.sig
[i
], &frame
->extramask
[i
- 1]));
3192 target_to_host_sigset_internal(&blocked
, &target_set
);
3193 sigprocmask(SIG_SETMASK
, &blocked
, NULL
);
3195 if (restore_sigcontext(regs
, &frame
->sc
, &r0
))
3198 unlock_user_struct(frame
, frame_addr
, 0);
3202 unlock_user_struct(frame
, frame_addr
, 0);
3203 force_sig(TARGET_SIGSEGV
);
3207 long do_rt_sigreturn(CPUSH4State
*regs
)
3209 struct target_rt_sigframe
*frame
;
3210 abi_ulong frame_addr
;
3214 #if defined(DEBUG_SIGNAL)
3215 fprintf(stderr
, "do_rt_sigreturn\n");
3217 frame_addr
= regs
->gregs
[15];
3218 if (!lock_user_struct(VERIFY_READ
, frame
, frame_addr
, 1))
3221 target_to_host_sigset(&blocked
, &frame
->uc
.tuc_sigmask
);
3222 sigprocmask(SIG_SETMASK
, &blocked
, NULL
);
3224 if (restore_sigcontext(regs
, &frame
->uc
.tuc_mcontext
, &r0
))
3227 if (do_sigaltstack(frame_addr
+
3228 offsetof(struct target_rt_sigframe
, uc
.tuc_stack
),
3229 0, get_sp_from_cpustate(regs
)) == -EFAULT
)
3232 unlock_user_struct(frame
, frame_addr
, 0);
3236 unlock_user_struct(frame
, frame_addr
, 0);
3237 force_sig(TARGET_SIGSEGV
);
3240 #elif defined(TARGET_MICROBLAZE)
3242 struct target_sigcontext
{
3243 struct target_pt_regs regs
; /* needs to be first */
3247 struct target_stack_t
{
3250 unsigned int ss_size
;
3253 struct target_ucontext
{
3254 abi_ulong tuc_flags
;
3256 struct target_stack_t tuc_stack
;
3257 struct target_sigcontext tuc_mcontext
;
3258 uint32_t tuc_extramask
[TARGET_NSIG_WORDS
- 1];
3261 /* Signal frames. */
3262 struct target_signal_frame
{
3263 struct target_ucontext uc
;
3264 uint32_t extramask
[TARGET_NSIG_WORDS
- 1];
3268 struct rt_signal_frame
{
3274 static void setup_sigcontext(struct target_sigcontext
*sc
, CPUMBState
*env
)
3276 __put_user(env
->regs
[0], &sc
->regs
.r0
);
3277 __put_user(env
->regs
[1], &sc
->regs
.r1
);
3278 __put_user(env
->regs
[2], &sc
->regs
.r2
);
3279 __put_user(env
->regs
[3], &sc
->regs
.r3
);
3280 __put_user(env
->regs
[4], &sc
->regs
.r4
);
3281 __put_user(env
->regs
[5], &sc
->regs
.r5
);
3282 __put_user(env
->regs
[6], &sc
->regs
.r6
);
3283 __put_user(env
->regs
[7], &sc
->regs
.r7
);
3284 __put_user(env
->regs
[8], &sc
->regs
.r8
);
3285 __put_user(env
->regs
[9], &sc
->regs
.r9
);
3286 __put_user(env
->regs
[10], &sc
->regs
.r10
);
3287 __put_user(env
->regs
[11], &sc
->regs
.r11
);
3288 __put_user(env
->regs
[12], &sc
->regs
.r12
);
3289 __put_user(env
->regs
[13], &sc
->regs
.r13
);
3290 __put_user(env
->regs
[14], &sc
->regs
.r14
);
3291 __put_user(env
->regs
[15], &sc
->regs
.r15
);
3292 __put_user(env
->regs
[16], &sc
->regs
.r16
);
3293 __put_user(env
->regs
[17], &sc
->regs
.r17
);
3294 __put_user(env
->regs
[18], &sc
->regs
.r18
);
3295 __put_user(env
->regs
[19], &sc
->regs
.r19
);
3296 __put_user(env
->regs
[20], &sc
->regs
.r20
);
3297 __put_user(env
->regs
[21], &sc
->regs
.r21
);
3298 __put_user(env
->regs
[22], &sc
->regs
.r22
);
3299 __put_user(env
->regs
[23], &sc
->regs
.r23
);
3300 __put_user(env
->regs
[24], &sc
->regs
.r24
);
3301 __put_user(env
->regs
[25], &sc
->regs
.r25
);
3302 __put_user(env
->regs
[26], &sc
->regs
.r26
);
3303 __put_user(env
->regs
[27], &sc
->regs
.r27
);
3304 __put_user(env
->regs
[28], &sc
->regs
.r28
);
3305 __put_user(env
->regs
[29], &sc
->regs
.r29
);
3306 __put_user(env
->regs
[30], &sc
->regs
.r30
);
3307 __put_user(env
->regs
[31], &sc
->regs
.r31
);
3308 __put_user(env
->sregs
[SR_PC
], &sc
->regs
.pc
);
3311 static void restore_sigcontext(struct target_sigcontext
*sc
, CPUMBState
*env
)
3313 __get_user(env
->regs
[0], &sc
->regs
.r0
);
3314 __get_user(env
->regs
[1], &sc
->regs
.r1
);
3315 __get_user(env
->regs
[2], &sc
->regs
.r2
);
3316 __get_user(env
->regs
[3], &sc
->regs
.r3
);
3317 __get_user(env
->regs
[4], &sc
->regs
.r4
);
3318 __get_user(env
->regs
[5], &sc
->regs
.r5
);
3319 __get_user(env
->regs
[6], &sc
->regs
.r6
);
3320 __get_user(env
->regs
[7], &sc
->regs
.r7
);
3321 __get_user(env
->regs
[8], &sc
->regs
.r8
);
3322 __get_user(env
->regs
[9], &sc
->regs
.r9
);
3323 __get_user(env
->regs
[10], &sc
->regs
.r10
);
3324 __get_user(env
->regs
[11], &sc
->regs
.r11
);
3325 __get_user(env
->regs
[12], &sc
->regs
.r12
);
3326 __get_user(env
->regs
[13], &sc
->regs
.r13
);
3327 __get_user(env
->regs
[14], &sc
->regs
.r14
);
3328 __get_user(env
->regs
[15], &sc
->regs
.r15
);
3329 __get_user(env
->regs
[16], &sc
->regs
.r16
);
3330 __get_user(env
->regs
[17], &sc
->regs
.r17
);
3331 __get_user(env
->regs
[18], &sc
->regs
.r18
);
3332 __get_user(env
->regs
[19], &sc
->regs
.r19
);
3333 __get_user(env
->regs
[20], &sc
->regs
.r20
);
3334 __get_user(env
->regs
[21], &sc
->regs
.r21
);
3335 __get_user(env
->regs
[22], &sc
->regs
.r22
);
3336 __get_user(env
->regs
[23], &sc
->regs
.r23
);
3337 __get_user(env
->regs
[24], &sc
->regs
.r24
);
3338 __get_user(env
->regs
[25], &sc
->regs
.r25
);
3339 __get_user(env
->regs
[26], &sc
->regs
.r26
);
3340 __get_user(env
->regs
[27], &sc
->regs
.r27
);
3341 __get_user(env
->regs
[28], &sc
->regs
.r28
);
3342 __get_user(env
->regs
[29], &sc
->regs
.r29
);
3343 __get_user(env
->regs
[30], &sc
->regs
.r30
);
3344 __get_user(env
->regs
[31], &sc
->regs
.r31
);
3345 __get_user(env
->sregs
[SR_PC
], &sc
->regs
.pc
);
3348 static abi_ulong
get_sigframe(struct target_sigaction
*ka
,
3349 CPUMBState
*env
, int frame_size
)
3351 abi_ulong sp
= env
->regs
[1];
3353 if ((ka
->sa_flags
& SA_ONSTACK
) != 0 && !on_sig_stack(sp
))
3354 sp
= target_sigaltstack_used
.ss_sp
+ target_sigaltstack_used
.ss_size
;
3356 return ((sp
- frame_size
) & -8UL);
3359 static void setup_frame(int sig
, struct target_sigaction
*ka
,
3360 target_sigset_t
*set
, CPUMBState
*env
)
3362 struct target_signal_frame
*frame
;
3363 abi_ulong frame_addr
;
3367 frame_addr
= get_sigframe(ka
, env
, sizeof *frame
);
3368 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0))
3371 /* Save the mask. */
3372 err
|= __put_user(set
->sig
[0], &frame
->uc
.tuc_mcontext
.oldmask
);
3376 for(i
= 1; i
< TARGET_NSIG_WORDS
; i
++) {
3377 if (__put_user(set
->sig
[i
], &frame
->extramask
[i
- 1]))
3381 setup_sigcontext(&frame
->uc
.tuc_mcontext
, env
);
3383 /* Set up to return from userspace. If provided, use a stub
3384 already in userspace. */
3385 /* minus 8 is offset to cater for "rtsd r15,8" offset */
3386 if (ka
->sa_flags
& TARGET_SA_RESTORER
) {
3387 env
->regs
[15] = ((unsigned long)ka
->sa_restorer
)-8;
3390 /* Note, these encodings are _big endian_! */
3391 /* addi r12, r0, __NR_sigreturn */
3392 t
= 0x31800000UL
| TARGET_NR_sigreturn
;
3393 err
|= __put_user(t
, frame
->tramp
+ 0);
3396 err
|= __put_user(t
, frame
->tramp
+ 1);
3398 /* Return from sighandler will jump to the tramp.
3399 Negative 8 offset because return is rtsd r15, 8 */
3400 env
->regs
[15] = ((unsigned long)frame
->tramp
) - 8;
3406 /* Set up registers for signal handler */
3407 env
->regs
[1] = frame_addr
;
3408 /* Signal handler args: */
3409 env
->regs
[5] = sig
; /* Arg 0: signum */
3411 /* arg 1: sigcontext */
3412 env
->regs
[7] = frame_addr
+= offsetof(typeof(*frame
), uc
);
3414 /* Offset of 4 to handle microblaze rtid r14, 0 */
3415 env
->sregs
[SR_PC
] = (unsigned long)ka
->_sa_handler
;
3417 unlock_user_struct(frame
, frame_addr
, 1);
3420 unlock_user_struct(frame
, frame_addr
, 1);
3421 force_sig(TARGET_SIGSEGV
);
3424 static void setup_rt_frame(int sig
, struct target_sigaction
*ka
,
3425 target_siginfo_t
*info
,
3426 target_sigset_t
*set
, CPUMBState
*env
)
3428 fprintf(stderr
, "Microblaze setup_rt_frame: not implemented\n");
3431 long do_sigreturn(CPUMBState
*env
)
3433 struct target_signal_frame
*frame
;
3434 abi_ulong frame_addr
;
3435 target_sigset_t target_set
;
3439 frame_addr
= env
->regs
[R_SP
];
3440 /* Make sure the guest isn't playing games. */
3441 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 1))
3444 /* Restore blocked signals */
3445 if (__get_user(target_set
.sig
[0], &frame
->uc
.tuc_mcontext
.oldmask
))
3447 for(i
= 1; i
< TARGET_NSIG_WORDS
; i
++) {
3448 if (__get_user(target_set
.sig
[i
], &frame
->extramask
[i
- 1]))
3451 target_to_host_sigset_internal(&set
, &target_set
);
3452 sigprocmask(SIG_SETMASK
, &set
, NULL
);
3454 restore_sigcontext(&frame
->uc
.tuc_mcontext
, env
);
3455 /* We got here through a sigreturn syscall, our path back is via an
3456 rtb insn so setup r14 for that. */
3457 env
->regs
[14] = env
->sregs
[SR_PC
];
3459 unlock_user_struct(frame
, frame_addr
, 0);
3460 return env
->regs
[10];
3462 unlock_user_struct(frame
, frame_addr
, 0);
3463 force_sig(TARGET_SIGSEGV
);
3466 long do_rt_sigreturn(CPUMBState
*env
)
3468 fprintf(stderr
, "Microblaze do_rt_sigreturn: not implemented\n");
3469 return -TARGET_ENOSYS
;
3472 #elif defined(TARGET_CRIS)
3474 struct target_sigcontext
{
3475 struct target_pt_regs regs
; /* needs to be first */
3477 uint32_t usp
; /* usp before stacking this gunk on it */
3480 /* Signal frames. */
3481 struct target_signal_frame
{
3482 struct target_sigcontext sc
;
3483 uint32_t extramask
[TARGET_NSIG_WORDS
- 1];
3484 uint8_t retcode
[8]; /* Trampoline code. */
3487 struct rt_signal_frame
{
3492 uint8_t retcode
[8]; /* Trampoline code. */
3495 static void setup_sigcontext(struct target_sigcontext
*sc
, CPUCRISState
*env
)
3497 __put_user(env
->regs
[0], &sc
->regs
.r0
);
3498 __put_user(env
->regs
[1], &sc
->regs
.r1
);
3499 __put_user(env
->regs
[2], &sc
->regs
.r2
);
3500 __put_user(env
->regs
[3], &sc
->regs
.r3
);
3501 __put_user(env
->regs
[4], &sc
->regs
.r4
);
3502 __put_user(env
->regs
[5], &sc
->regs
.r5
);
3503 __put_user(env
->regs
[6], &sc
->regs
.r6
);
3504 __put_user(env
->regs
[7], &sc
->regs
.r7
);
3505 __put_user(env
->regs
[8], &sc
->regs
.r8
);
3506 __put_user(env
->regs
[9], &sc
->regs
.r9
);
3507 __put_user(env
->regs
[10], &sc
->regs
.r10
);
3508 __put_user(env
->regs
[11], &sc
->regs
.r11
);
3509 __put_user(env
->regs
[12], &sc
->regs
.r12
);
3510 __put_user(env
->regs
[13], &sc
->regs
.r13
);
3511 __put_user(env
->regs
[14], &sc
->usp
);
3512 __put_user(env
->regs
[15], &sc
->regs
.acr
);
3513 __put_user(env
->pregs
[PR_MOF
], &sc
->regs
.mof
);
3514 __put_user(env
->pregs
[PR_SRP
], &sc
->regs
.srp
);
3515 __put_user(env
->pc
, &sc
->regs
.erp
);
3518 static void restore_sigcontext(struct target_sigcontext
*sc
, CPUCRISState
*env
)
3520 __get_user(env
->regs
[0], &sc
->regs
.r0
);
3521 __get_user(env
->regs
[1], &sc
->regs
.r1
);
3522 __get_user(env
->regs
[2], &sc
->regs
.r2
);
3523 __get_user(env
->regs
[3], &sc
->regs
.r3
);
3524 __get_user(env
->regs
[4], &sc
->regs
.r4
);
3525 __get_user(env
->regs
[5], &sc
->regs
.r5
);
3526 __get_user(env
->regs
[6], &sc
->regs
.r6
);
3527 __get_user(env
->regs
[7], &sc
->regs
.r7
);
3528 __get_user(env
->regs
[8], &sc
->regs
.r8
);
3529 __get_user(env
->regs
[9], &sc
->regs
.r9
);
3530 __get_user(env
->regs
[10], &sc
->regs
.r10
);
3531 __get_user(env
->regs
[11], &sc
->regs
.r11
);
3532 __get_user(env
->regs
[12], &sc
->regs
.r12
);
3533 __get_user(env
->regs
[13], &sc
->regs
.r13
);
3534 __get_user(env
->regs
[14], &sc
->usp
);
3535 __get_user(env
->regs
[15], &sc
->regs
.acr
);
3536 __get_user(env
->pregs
[PR_MOF
], &sc
->regs
.mof
);
3537 __get_user(env
->pregs
[PR_SRP
], &sc
->regs
.srp
);
3538 __get_user(env
->pc
, &sc
->regs
.erp
);
3541 static abi_ulong
get_sigframe(CPUCRISState
*env
, int framesize
)
3544 /* Align the stack downwards to 4. */
3545 sp
= (env
->regs
[R_SP
] & ~3);
3546 return sp
- framesize
;
3549 static void setup_frame(int sig
, struct target_sigaction
*ka
,
3550 target_sigset_t
*set
, CPUCRISState
*env
)
3552 struct target_signal_frame
*frame
;
3553 abi_ulong frame_addr
;
3557 frame_addr
= get_sigframe(env
, sizeof *frame
);
3558 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0))
3562 * The CRIS signal return trampoline. A real linux/CRIS kernel doesn't
3563 * use this trampoline anymore but it sets it up for GDB.
3564 * In QEMU, using the trampoline simplifies things a bit so we use it.
3566 * This is movu.w __NR_sigreturn, r9; break 13;
3568 err
|= __put_user(0x9c5f, frame
->retcode
+0);
3569 err
|= __put_user(TARGET_NR_sigreturn
,
3571 err
|= __put_user(0xe93d, frame
->retcode
+4);
3573 /* Save the mask. */
3574 err
|= __put_user(set
->sig
[0], &frame
->sc
.oldmask
);
3578 for(i
= 1; i
< TARGET_NSIG_WORDS
; i
++) {
3579 if (__put_user(set
->sig
[i
], &frame
->extramask
[i
- 1]))
3583 setup_sigcontext(&frame
->sc
, env
);
3585 /* Move the stack and setup the arguments for the handler. */
3586 env
->regs
[R_SP
] = frame_addr
;
3587 env
->regs
[10] = sig
;
3588 env
->pc
= (unsigned long) ka
->_sa_handler
;
3589 /* Link SRP so the guest returns through the trampoline. */
3590 env
->pregs
[PR_SRP
] = frame_addr
+ offsetof(typeof(*frame
), retcode
);
3592 unlock_user_struct(frame
, frame_addr
, 1);
3595 unlock_user_struct(frame
, frame_addr
, 1);
3596 force_sig(TARGET_SIGSEGV
);
3599 static void setup_rt_frame(int sig
, struct target_sigaction
*ka
,
3600 target_siginfo_t
*info
,
3601 target_sigset_t
*set
, CPUCRISState
*env
)
3603 fprintf(stderr
, "CRIS setup_rt_frame: not implemented\n");
3606 long do_sigreturn(CPUCRISState
*env
)
3608 struct target_signal_frame
*frame
;
3609 abi_ulong frame_addr
;
3610 target_sigset_t target_set
;
3614 frame_addr
= env
->regs
[R_SP
];
3615 /* Make sure the guest isn't playing games. */
3616 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 1))
3619 /* Restore blocked signals */
3620 if (__get_user(target_set
.sig
[0], &frame
->sc
.oldmask
))
3622 for(i
= 1; i
< TARGET_NSIG_WORDS
; i
++) {
3623 if (__get_user(target_set
.sig
[i
], &frame
->extramask
[i
- 1]))
3626 target_to_host_sigset_internal(&set
, &target_set
);
3627 sigprocmask(SIG_SETMASK
, &set
, NULL
);
3629 restore_sigcontext(&frame
->sc
, env
);
3630 unlock_user_struct(frame
, frame_addr
, 0);
3631 return env
->regs
[10];
3633 unlock_user_struct(frame
, frame_addr
, 0);
3634 force_sig(TARGET_SIGSEGV
);
3637 long do_rt_sigreturn(CPUCRISState
*env
)
3639 fprintf(stderr
, "CRIS do_rt_sigreturn: not implemented\n");
3640 return -TARGET_ENOSYS
;
3643 #elif defined(TARGET_OPENRISC)
3645 struct target_sigcontext
{
3646 struct target_pt_regs regs
;
3651 struct target_ucontext
{
3652 abi_ulong tuc_flags
;
3654 target_stack_t tuc_stack
;
3655 struct target_sigcontext tuc_mcontext
;
3656 target_sigset_t tuc_sigmask
; /* mask last for extensibility */
3659 struct target_rt_sigframe
{
3662 struct target_siginfo info
;
3663 struct target_sigcontext sc
;
3664 struct target_ucontext uc
;
3665 unsigned char retcode
[16]; /* trampoline code */
3668 /* This is the asm-generic/ucontext.h version */
3670 static int restore_sigcontext(CPUOpenRISCState
*regs
,
3671 struct target_sigcontext
*sc
)
3673 unsigned int err
= 0;
3674 unsigned long old_usp
;
3676 /* Alwys make any pending restarted system call return -EINTR */
3677 current_thread_info()->restart_block
.fn
= do_no_restart_syscall
;
3679 /* restore the regs from &sc->regs (same as sc, since regs is first)
3680 * (sc is already checked for VERIFY_READ since the sigframe was
3681 * checked in sys_sigreturn previously)
3684 if (copy_from_user(regs
, &sc
, sizeof(struct target_pt_regs
))) {
3688 /* make sure the U-flag is set so user-mode cannot fool us */
3692 /* restore the old USP as it was before we stacked the sc etc.
3693 * (we cannot just pop the sigcontext since we aligned the sp and
3694 * stuff after pushing it)
3697 err
|= __get_user(old_usp
, &sc
->usp
);
3698 phx_signal("old_usp 0x%lx", old_usp
);
3700 __PHX__ REALLY
/* ??? */
3702 regs
->gpr
[1] = old_usp
;
3704 /* TODO: the other ports use regs->orig_XX to disable syscall checks
3705 * after this completes, but we don't use that mechanism. maybe we can
3716 /* Set up a signal frame. */
3718 static int setup_sigcontext(struct target_sigcontext
*sc
,
3719 CPUOpenRISCState
*regs
,
3723 unsigned long usp
= regs
->gpr
[1];
3725 /* copy the regs. they are first in sc so we can use sc directly */
3727 /*err |= copy_to_user(&sc, regs, sizeof(struct target_pt_regs));*/
3729 /* Set the frametype to CRIS_FRAME_NORMAL for the execution of
3730 the signal handler. The frametype will be restored to its previous
3731 value in restore_sigcontext. */
3732 /*regs->frametype = CRIS_FRAME_NORMAL;*/
3734 /* then some other stuff */
3735 err
|= __put_user(mask
, &sc
->oldmask
);
3736 err
|= __put_user(usp
, &sc
->usp
); return err
;
3739 static inline unsigned long align_sigframe(unsigned long sp
)
3746 static inline abi_ulong
get_sigframe(struct target_sigaction
*ka
,
3747 CPUOpenRISCState
*regs
,
3750 unsigned long sp
= regs
->gpr
[1];
3751 int onsigstack
= on_sig_stack(sp
);
3754 /* This is the X/Open sanctioned signal stack switching. */
3755 if ((ka
->sa_flags
& SA_ONSTACK
) != 0 && !onsigstack
) {
3756 sp
= target_sigaltstack_used
.ss_sp
+ target_sigaltstack_used
.ss_size
;
3759 sp
= align_sigframe(sp
- frame_size
);
3762 * If we are on the alternate signal stack and would overflow it, don't.
3763 * Return an always-bogus address instead so we will die with SIGSEGV.
3766 if (onsigstack
&& !likely(on_sig_stack(sp
))) {
3773 static void setup_frame(int sig
, struct target_sigaction
*ka
,
3774 target_sigset_t
*set
, CPUOpenRISCState
*env
)
3776 qemu_log("Not implement.\n");
3779 static void setup_rt_frame(int sig
, struct target_sigaction
*ka
,
3780 target_siginfo_t
*info
,
3781 target_sigset_t
*set
, CPUOpenRISCState
*env
)
3784 abi_ulong frame_addr
;
3785 unsigned long return_ip
;
3786 struct target_rt_sigframe
*frame
;
3787 abi_ulong info_addr
, uc_addr
;
3789 frame_addr
= get_sigframe(ka
, env
, sizeof *frame
);
3791 frame_addr
= get_sigframe(ka
, env
, sizeof(*frame
));
3792 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0)) {
3796 info_addr
= frame_addr
+ offsetof(struct target_rt_sigframe
, info
);
3797 err
|= __put_user(info_addr
, &frame
->pinfo
);
3798 uc_addr
= frame_addr
+ offsetof(struct target_rt_sigframe
, uc
);
3799 err
|= __put_user(uc_addr
, &frame
->puc
);
3801 if (ka
->sa_flags
& SA_SIGINFO
) {
3802 err
|= copy_siginfo_to_user(&frame
->info
, info
);
3808 /*err |= __clear_user(&frame->uc, offsetof(struct ucontext, uc_mcontext));*/
3809 err
|= __put_user(0, &frame
->uc
.tuc_flags
);
3810 err
|= __put_user(0, &frame
->uc
.tuc_link
);
3811 err
|= __put_user(target_sigaltstack_used
.ss_sp
,
3812 &frame
->uc
.tuc_stack
.ss_sp
);
3813 err
|= __put_user(sas_ss_flags(env
->gpr
[1]), &frame
->uc
.tuc_stack
.ss_flags
);
3814 err
|= __put_user(target_sigaltstack_used
.ss_size
,
3815 &frame
->uc
.tuc_stack
.ss_size
);
3816 err
|= setup_sigcontext(&frame
->sc
, env
, set
->sig
[0]);
3818 /*err |= copy_to_user(frame->uc.tuc_sigmask, set, sizeof(*set));*/
3824 /* trampoline - the desired return ip is the retcode itself */
3825 return_ip
= (unsigned long)&frame
->retcode
;
3826 /* This is l.ori r11,r0,__NR_sigreturn, l.sys 1 */
3827 err
|= __put_user(0xa960, (short *)(frame
->retcode
+ 0));
3828 err
|= __put_user(TARGET_NR_rt_sigreturn
, (short *)(frame
->retcode
+ 2));
3829 err
|= __put_user(0x20000001, (unsigned long *)(frame
->retcode
+ 4));
3830 err
|= __put_user(0x15000000, (unsigned long *)(frame
->retcode
+ 8));
3836 /* TODO what is the current->exec_domain stuff and invmap ? */
3838 /* Set up registers for signal handler */
3839 env
->pc
= (unsigned long)ka
->_sa_handler
; /* what we enter NOW */
3840 env
->gpr
[9] = (unsigned long)return_ip
; /* what we enter LATER */
3841 env
->gpr
[3] = (unsigned long)sig
; /* arg 1: signo */
3842 env
->gpr
[4] = (unsigned long)&frame
->info
; /* arg 2: (siginfo_t*) */
3843 env
->gpr
[5] = (unsigned long)&frame
->uc
; /* arg 3: ucontext */
3845 /* actually move the usp to reflect the stacked frame */
3846 env
->gpr
[1] = (unsigned long)frame
;
3851 unlock_user_struct(frame
, frame_addr
, 1);
3852 if (sig
== TARGET_SIGSEGV
) {
3853 ka
->_sa_handler
= TARGET_SIG_DFL
;
3855 force_sig(TARGET_SIGSEGV
);
3858 long do_sigreturn(CPUOpenRISCState
*env
)
3861 qemu_log("do_sigreturn: not implemented\n");
3862 return -TARGET_ENOSYS
;
3865 long do_rt_sigreturn(CPUOpenRISCState
*env
)
3867 qemu_log("do_rt_sigreturn: not implemented\n");
3868 return -TARGET_ENOSYS
;
3870 /* TARGET_OPENRISC */
3872 #elif defined(TARGET_S390X)
3874 #define __NUM_GPRS 16
3875 #define __NUM_FPRS 16
3876 #define __NUM_ACRS 16
3878 #define S390_SYSCALL_SIZE 2
3879 #define __SIGNAL_FRAMESIZE 160 /* FIXME: 31-bit mode -> 96 */
3881 #define _SIGCONTEXT_NSIG 64
3882 #define _SIGCONTEXT_NSIG_BPW 64 /* FIXME: 31-bit mode -> 32 */
3883 #define _SIGCONTEXT_NSIG_WORDS (_SIGCONTEXT_NSIG / _SIGCONTEXT_NSIG_BPW)
3884 #define _SIGMASK_COPY_SIZE (sizeof(unsigned long)*_SIGCONTEXT_NSIG_WORDS)
3885 #define PSW_ADDR_AMODE 0x0000000000000000UL /* 0x80000000UL for 31-bit */
3886 #define S390_SYSCALL_OPCODE ((uint16_t)0x0a00)
3890 target_ulong gprs
[__NUM_GPRS
];
3891 unsigned int acrs
[__NUM_ACRS
];
3892 } target_s390_regs_common
;
3896 double fprs
[__NUM_FPRS
];
3897 } target_s390_fp_regs
;
3900 target_s390_regs_common regs
;
3901 target_s390_fp_regs fpregs
;
3904 struct target_sigcontext
{
3905 target_ulong oldmask
[_SIGCONTEXT_NSIG_WORDS
];
3906 target_sigregs
*sregs
;
3910 uint8_t callee_used_stack
[__SIGNAL_FRAMESIZE
];
3911 struct target_sigcontext sc
;
3912 target_sigregs sregs
;
3914 uint8_t retcode
[S390_SYSCALL_SIZE
];
3917 struct target_ucontext
{
3918 target_ulong tuc_flags
;
3919 struct target_ucontext
*tuc_link
;
3920 target_stack_t tuc_stack
;
3921 target_sigregs tuc_mcontext
;
3922 target_sigset_t tuc_sigmask
; /* mask last for extensibility */
3926 uint8_t callee_used_stack
[__SIGNAL_FRAMESIZE
];
3927 uint8_t retcode
[S390_SYSCALL_SIZE
];
3928 struct target_siginfo info
;
3929 struct target_ucontext uc
;
3932 static inline abi_ulong
3933 get_sigframe(struct target_sigaction
*ka
, CPUS390XState
*env
, size_t frame_size
)
3937 /* Default to using normal stack */
3940 /* This is the X/Open sanctioned signal stack switching. */
3941 if (ka
->sa_flags
& TARGET_SA_ONSTACK
) {
3942 if (!sas_ss_flags(sp
)) {
3943 sp
= target_sigaltstack_used
.ss_sp
+
3944 target_sigaltstack_used
.ss_size
;
3948 /* This is the legacy signal stack switching. */
3949 else if (/* FIXME !user_mode(regs) */ 0 &&
3950 !(ka
->sa_flags
& TARGET_SA_RESTORER
) &&
3952 sp
= (abi_ulong
) ka
->sa_restorer
;
3955 return (sp
- frame_size
) & -8ul;
3958 static void save_sigregs(CPUS390XState
*env
, target_sigregs
*sregs
)
3961 //save_access_regs(current->thread.acrs); FIXME
3963 /* Copy a 'clean' PSW mask to the user to avoid leaking
3964 information about whether PER is currently on. */
3965 __put_user(env
->psw
.mask
, &sregs
->regs
.psw
.mask
);
3966 __put_user(env
->psw
.addr
, &sregs
->regs
.psw
.addr
);
3967 for (i
= 0; i
< 16; i
++) {
3968 __put_user(env
->regs
[i
], &sregs
->regs
.gprs
[i
]);
3970 for (i
= 0; i
< 16; i
++) {
3971 __put_user(env
->aregs
[i
], &sregs
->regs
.acrs
[i
]);
3974 * We have to store the fp registers to current->thread.fp_regs
3975 * to merge them with the emulated registers.
3977 //save_fp_regs(¤t->thread.fp_regs); FIXME
3978 for (i
= 0; i
< 16; i
++) {
3979 __put_user(env
->fregs
[i
].ll
, &sregs
->fpregs
.fprs
[i
]);
3983 static void setup_frame(int sig
, struct target_sigaction
*ka
,
3984 target_sigset_t
*set
, CPUS390XState
*env
)
3987 abi_ulong frame_addr
;
3989 frame_addr
= get_sigframe(ka
, env
, sizeof(*frame
));
3990 qemu_log("%s: frame_addr 0x%llx\n", __FUNCTION__
,
3991 (unsigned long long)frame_addr
);
3992 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0)) {
3996 qemu_log("%s: 1\n", __FUNCTION__
);
3997 if (__put_user(set
->sig
[0], &frame
->sc
.oldmask
[0])) {
4001 save_sigregs(env
, &frame
->sregs
);
4003 __put_user((abi_ulong
)(unsigned long)&frame
->sregs
,
4004 (abi_ulong
*)&frame
->sc
.sregs
);
4006 /* Set up to return from userspace. If provided, use a stub
4007 already in userspace. */
4008 if (ka
->sa_flags
& TARGET_SA_RESTORER
) {
4009 env
->regs
[14] = (unsigned long)
4010 ka
->sa_restorer
| PSW_ADDR_AMODE
;
4012 env
->regs
[14] = (unsigned long)
4013 frame
->retcode
| PSW_ADDR_AMODE
;
4014 if (__put_user(S390_SYSCALL_OPCODE
| TARGET_NR_sigreturn
,
4015 (uint16_t *)(frame
->retcode
)))
4019 /* Set up backchain. */
4020 if (__put_user(env
->regs
[15], (abi_ulong
*) frame
)) {
4024 /* Set up registers for signal handler */
4025 env
->regs
[15] = frame_addr
;
4026 env
->psw
.addr
= (target_ulong
) ka
->_sa_handler
| PSW_ADDR_AMODE
;
4028 env
->regs
[2] = sig
; //map_signal(sig);
4029 env
->regs
[3] = frame_addr
+= offsetof(typeof(*frame
), sc
);
4031 /* We forgot to include these in the sigcontext.
4032 To avoid breaking binary compatibility, they are passed as args. */
4033 env
->regs
[4] = 0; // FIXME: no clue... current->thread.trap_no;
4034 env
->regs
[5] = 0; // FIXME: no clue... current->thread.prot_addr;
4036 /* Place signal number on stack to allow backtrace from handler. */
4037 if (__put_user(env
->regs
[2], (int *) &frame
->signo
)) {
4040 unlock_user_struct(frame
, frame_addr
, 1);
4044 qemu_log("%s: give_sigsegv\n", __FUNCTION__
);
4045 unlock_user_struct(frame
, frame_addr
, 1);
4046 force_sig(TARGET_SIGSEGV
);
4049 static void setup_rt_frame(int sig
, struct target_sigaction
*ka
,
4050 target_siginfo_t
*info
,
4051 target_sigset_t
*set
, CPUS390XState
*env
)
4055 abi_ulong frame_addr
;
4057 frame_addr
= get_sigframe(ka
, env
, sizeof *frame
);
4058 qemu_log("%s: frame_addr 0x%llx\n", __FUNCTION__
,
4059 (unsigned long long)frame_addr
);
4060 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0)) {
4064 qemu_log("%s: 1\n", __FUNCTION__
);
4065 if (copy_siginfo_to_user(&frame
->info
, info
)) {
4069 /* Create the ucontext. */
4070 __put_user(0, &frame
->uc
.tuc_flags
);
4071 __put_user((abi_ulong
)0, (abi_ulong
*)&frame
->uc
.tuc_link
);
4072 __put_user(target_sigaltstack_used
.ss_sp
, &frame
->uc
.tuc_stack
.ss_sp
);
4073 __put_user(sas_ss_flags(get_sp_from_cpustate(env
)),
4074 &frame
->uc
.tuc_stack
.ss_flags
);
4075 __put_user(target_sigaltstack_used
.ss_size
, &frame
->uc
.tuc_stack
.ss_size
);
4076 save_sigregs(env
, &frame
->uc
.tuc_mcontext
);
4077 for (i
= 0; i
< TARGET_NSIG_WORDS
; i
++) {
4078 __put_user((abi_ulong
)set
->sig
[i
],
4079 (abi_ulong
*)&frame
->uc
.tuc_sigmask
.sig
[i
]);
4082 /* Set up to return from userspace. If provided, use a stub
4083 already in userspace. */
4084 if (ka
->sa_flags
& TARGET_SA_RESTORER
) {
4085 env
->regs
[14] = (unsigned long) ka
->sa_restorer
| PSW_ADDR_AMODE
;
4087 env
->regs
[14] = (unsigned long) frame
->retcode
| PSW_ADDR_AMODE
;
4088 if (__put_user(S390_SYSCALL_OPCODE
| TARGET_NR_rt_sigreturn
,
4089 (uint16_t *)(frame
->retcode
))) {
4094 /* Set up backchain. */
4095 if (__put_user(env
->regs
[15], (abi_ulong
*) frame
)) {
4099 /* Set up registers for signal handler */
4100 env
->regs
[15] = frame_addr
;
4101 env
->psw
.addr
= (target_ulong
) ka
->_sa_handler
| PSW_ADDR_AMODE
;
4103 env
->regs
[2] = sig
; //map_signal(sig);
4104 env
->regs
[3] = frame_addr
+ offsetof(typeof(*frame
), info
);
4105 env
->regs
[4] = frame_addr
+ offsetof(typeof(*frame
), uc
);
4109 qemu_log("%s: give_sigsegv\n", __FUNCTION__
);
4110 unlock_user_struct(frame
, frame_addr
, 1);
4111 force_sig(TARGET_SIGSEGV
);
4115 restore_sigregs(CPUS390XState
*env
, target_sigregs
*sc
)
4120 for (i
= 0; i
< 16; i
++) {
4121 err
|= __get_user(env
->regs
[i
], &sc
->regs
.gprs
[i
]);
4124 err
|= __get_user(env
->psw
.mask
, &sc
->regs
.psw
.mask
);
4125 qemu_log("%s: sc->regs.psw.addr 0x%llx env->psw.addr 0x%llx\n",
4126 __FUNCTION__
, (unsigned long long)sc
->regs
.psw
.addr
,
4127 (unsigned long long)env
->psw
.addr
);
4128 err
|= __get_user(env
->psw
.addr
, &sc
->regs
.psw
.addr
);
4129 /* FIXME: 31-bit -> | PSW_ADDR_AMODE */
4131 for (i
= 0; i
< 16; i
++) {
4132 err
|= __get_user(env
->aregs
[i
], &sc
->regs
.acrs
[i
]);
4134 for (i
= 0; i
< 16; i
++) {
4135 err
|= __get_user(env
->fregs
[i
].ll
, &sc
->fpregs
.fprs
[i
]);
4141 long do_sigreturn(CPUS390XState
*env
)
4144 abi_ulong frame_addr
= env
->regs
[15];
4145 qemu_log("%s: frame_addr 0x%llx\n", __FUNCTION__
,
4146 (unsigned long long)frame_addr
);
4147 target_sigset_t target_set
;
4150 if (!lock_user_struct(VERIFY_READ
, frame
, frame_addr
, 1)) {
4153 if (__get_user(target_set
.sig
[0], &frame
->sc
.oldmask
[0])) {
4157 target_to_host_sigset_internal(&set
, &target_set
);
4158 sigprocmask(SIG_SETMASK
, &set
, NULL
); /* ~_BLOCKABLE? */
4160 if (restore_sigregs(env
, &frame
->sregs
)) {
4164 unlock_user_struct(frame
, frame_addr
, 0);
4165 return env
->regs
[2];
4168 unlock_user_struct(frame
, frame_addr
, 0);
4169 force_sig(TARGET_SIGSEGV
);
4173 long do_rt_sigreturn(CPUS390XState
*env
)
4176 abi_ulong frame_addr
= env
->regs
[15];
4177 qemu_log("%s: frame_addr 0x%llx\n", __FUNCTION__
,
4178 (unsigned long long)frame_addr
);
4181 if (!lock_user_struct(VERIFY_READ
, frame
, frame_addr
, 1)) {
4184 target_to_host_sigset(&set
, &frame
->uc
.tuc_sigmask
);
4186 sigprocmask(SIG_SETMASK
, &set
, NULL
); /* ~_BLOCKABLE? */
4188 if (restore_sigregs(env
, &frame
->uc
.tuc_mcontext
)) {
4192 if (do_sigaltstack(frame_addr
+ offsetof(rt_sigframe
, uc
.tuc_stack
), 0,
4193 get_sp_from_cpustate(env
)) == -EFAULT
) {
4196 unlock_user_struct(frame
, frame_addr
, 0);
4197 return env
->regs
[2];
4200 unlock_user_struct(frame
, frame_addr
, 0);
4201 force_sig(TARGET_SIGSEGV
);
4205 #elif defined(TARGET_PPC) && !defined(TARGET_PPC64)
4207 /* FIXME: Many of the structures are defined for both PPC and PPC64, but
4208 the signal handling is different enough that we haven't implemented
4209 support for PPC64 yet. Hence the restriction above.
4211 There are various #if'd blocks for code for TARGET_PPC64. These
4212 blocks should go away so that we can successfully run 32-bit and
4213 64-bit binaries on a QEMU configured for PPC64. */
4215 /* Size of dummy stack frame allocated when calling signal handler.
4216 See arch/powerpc/include/asm/ptrace.h. */
4217 #if defined(TARGET_PPC64)
4218 #define SIGNAL_FRAMESIZE 128
4220 #define SIGNAL_FRAMESIZE 64
4223 /* See arch/powerpc/include/asm/sigcontext.h. */
4224 struct target_sigcontext
{
4225 target_ulong _unused
[4];
4227 #if defined(TARGET_PPC64)
4230 target_ulong handler
;
4231 target_ulong oldmask
;
4232 target_ulong regs
; /* struct pt_regs __user * */
4233 /* TODO: PPC64 includes extra bits here. */
4236 /* Indices for target_mcontext.mc_gregs, below.
4237 See arch/powerpc/include/asm/ptrace.h for details. */
4273 TARGET_PT_ORIG_R3
= 34,
4278 /* Yes, there are two registers with #39. One is 64-bit only. */
4280 TARGET_PT_SOFTE
= 39,
4281 TARGET_PT_TRAP
= 40,
4283 TARGET_PT_DSISR
= 42,
4284 TARGET_PT_RESULT
= 43,
4285 TARGET_PT_REGS_COUNT
= 44
4288 /* See arch/powerpc/include/asm/ucontext.h. Only used for 32-bit PPC;
4289 on 64-bit PPC, sigcontext and mcontext are one and the same. */
4290 struct target_mcontext
{
4291 target_ulong mc_gregs
[48];
4292 /* Includes fpscr. */
4293 uint64_t mc_fregs
[33];
4294 target_ulong mc_pad
[2];
4295 /* We need to handle Altivec and SPE at the same time, which no
4296 kernel needs to do. Fortunately, the kernel defines this bit to
4297 be Altivec-register-large all the time, rather than trying to
4298 twiddle it based on the specific platform. */
4300 /* SPE vector registers. One extra for SPEFSCR. */
4302 /* Altivec vector registers. The packing of VSCR and VRSAVE
4303 varies depending on whether we're PPC64 or not: PPC64 splits
4304 them apart; PPC32 stuffs them together. */
4305 #if defined(TARGET_PPC64)
4306 #define QEMU_NVRREG 34
4308 #define QEMU_NVRREG 33
4310 ppc_avr_t altivec
[QEMU_NVRREG
];
4312 } mc_vregs
__attribute__((__aligned__(16)));
4315 struct target_ucontext
{
4316 target_ulong tuc_flags
;
4317 target_ulong tuc_link
; /* struct ucontext __user * */
4318 struct target_sigaltstack tuc_stack
;
4319 #if !defined(TARGET_PPC64)
4321 target_ulong tuc_regs
; /* struct mcontext __user *
4322 points to uc_mcontext field */
4324 target_sigset_t tuc_sigmask
;
4325 #if defined(TARGET_PPC64)
4326 target_sigset_t unused
[15]; /* Allow for uc_sigmask growth */
4327 struct target_sigcontext tuc_mcontext
;
4329 int32_t tuc_maskext
[30];
4330 int32_t tuc_pad2
[3];
4331 struct target_mcontext tuc_mcontext
;
4335 /* See arch/powerpc/kernel/signal_32.c. */
4336 struct target_sigframe
{
4337 struct target_sigcontext sctx
;
4338 struct target_mcontext mctx
;
4342 struct target_rt_sigframe
{
4343 struct target_siginfo info
;
4344 struct target_ucontext uc
;
4348 /* We use the mc_pad field for the signal return trampoline. */
4349 #define tramp mc_pad
4351 /* See arch/powerpc/kernel/signal.c. */
4352 static target_ulong
get_sigframe(struct target_sigaction
*ka
,
4356 target_ulong oldsp
, newsp
;
4358 oldsp
= env
->gpr
[1];
4360 if ((ka
->sa_flags
& TARGET_SA_ONSTACK
) &&
4361 (sas_ss_flags(oldsp
) == 0)) {
4362 oldsp
= (target_sigaltstack_used
.ss_sp
4363 + target_sigaltstack_used
.ss_size
);
4366 newsp
= (oldsp
- frame_size
) & ~0xFUL
;
4371 static int save_user_regs(CPUPPCState
*env
, struct target_mcontext
*frame
,
4374 target_ulong msr
= env
->msr
;
4376 target_ulong ccr
= 0;
4378 /* In general, the kernel attempts to be intelligent about what it
4379 needs to save for Altivec/FP/SPE registers. We don't care that
4380 much, so we just go ahead and save everything. */
4382 /* Save general registers. */
4383 for (i
= 0; i
< ARRAY_SIZE(env
->gpr
); i
++) {
4384 if (__put_user(env
->gpr
[i
], &frame
->mc_gregs
[i
])) {
4388 if (__put_user(env
->nip
, &frame
->mc_gregs
[TARGET_PT_NIP
])
4389 || __put_user(env
->ctr
, &frame
->mc_gregs
[TARGET_PT_CTR
])
4390 || __put_user(env
->lr
, &frame
->mc_gregs
[TARGET_PT_LNK
])
4391 || __put_user(env
->xer
, &frame
->mc_gregs
[TARGET_PT_XER
]))
4394 for (i
= 0; i
< ARRAY_SIZE(env
->crf
); i
++) {
4395 ccr
|= env
->crf
[i
] << (32 - ((i
+ 1) * 4));
4397 if (__put_user(ccr
, &frame
->mc_gregs
[TARGET_PT_CCR
]))
4400 /* Save Altivec registers if necessary. */
4401 if (env
->insns_flags
& PPC_ALTIVEC
) {
4402 for (i
= 0; i
< ARRAY_SIZE(env
->avr
); i
++) {
4403 ppc_avr_t
*avr
= &env
->avr
[i
];
4404 ppc_avr_t
*vreg
= &frame
->mc_vregs
.altivec
[i
];
4406 if (__put_user(avr
->u64
[0], &vreg
->u64
[0]) ||
4407 __put_user(avr
->u64
[1], &vreg
->u64
[1])) {
4411 /* Set MSR_VR in the saved MSR value to indicate that
4412 frame->mc_vregs contains valid data. */
4414 if (__put_user((uint32_t)env
->spr
[SPR_VRSAVE
],
4415 &frame
->mc_vregs
.altivec
[32].u32
[3]))
4419 /* Save floating point registers. */
4420 if (env
->insns_flags
& PPC_FLOAT
) {
4421 for (i
= 0; i
< ARRAY_SIZE(env
->fpr
); i
++) {
4422 if (__put_user(env
->fpr
[i
], &frame
->mc_fregs
[i
])) {
4426 if (__put_user((uint64_t) env
->fpscr
, &frame
->mc_fregs
[32]))
4430 /* Save SPE registers. The kernel only saves the high half. */
4431 if (env
->insns_flags
& PPC_SPE
) {
4432 #if defined(TARGET_PPC64)
4433 for (i
= 0; i
< ARRAY_SIZE(env
->gpr
); i
++) {
4434 if (__put_user(env
->gpr
[i
] >> 32, &frame
->mc_vregs
.spe
[i
])) {
4439 for (i
= 0; i
< ARRAY_SIZE(env
->gprh
); i
++) {
4440 if (__put_user(env
->gprh
[i
], &frame
->mc_vregs
.spe
[i
])) {
4445 /* Set MSR_SPE in the saved MSR value to indicate that
4446 frame->mc_vregs contains valid data. */
4448 if (__put_user(env
->spe_fscr
, &frame
->mc_vregs
.spe
[32]))
4453 if (__put_user(msr
, &frame
->mc_gregs
[TARGET_PT_MSR
]))
4456 /* Set up the sigreturn trampoline: li r0,sigret; sc. */
4458 if (__put_user(0x38000000UL
| sigret
, &frame
->tramp
[0]) ||
4459 __put_user(0x44000002UL
, &frame
->tramp
[1])) {
4467 static int restore_user_regs(CPUPPCState
*env
,
4468 struct target_mcontext
*frame
, int sig
)
4470 target_ulong save_r2
= 0;
4477 save_r2
= env
->gpr
[2];
4480 /* Restore general registers. */
4481 for (i
= 0; i
< ARRAY_SIZE(env
->gpr
); i
++) {
4482 if (__get_user(env
->gpr
[i
], &frame
->mc_gregs
[i
])) {
4486 if (__get_user(env
->nip
, &frame
->mc_gregs
[TARGET_PT_NIP
])
4487 || __get_user(env
->ctr
, &frame
->mc_gregs
[TARGET_PT_CTR
])
4488 || __get_user(env
->lr
, &frame
->mc_gregs
[TARGET_PT_LNK
])
4489 || __get_user(env
->xer
, &frame
->mc_gregs
[TARGET_PT_XER
]))
4491 if (__get_user(ccr
, &frame
->mc_gregs
[TARGET_PT_CCR
]))
4494 for (i
= 0; i
< ARRAY_SIZE(env
->crf
); i
++) {
4495 env
->crf
[i
] = (ccr
>> (32 - ((i
+ 1) * 4))) & 0xf;
4499 env
->gpr
[2] = save_r2
;
4502 if (__get_user(msr
, &frame
->mc_gregs
[TARGET_PT_MSR
]))
4505 /* If doing signal return, restore the previous little-endian mode. */
4507 env
->msr
= (env
->msr
& ~MSR_LE
) | (msr
& MSR_LE
);
4509 /* Restore Altivec registers if necessary. */
4510 if (env
->insns_flags
& PPC_ALTIVEC
) {
4511 for (i
= 0; i
< ARRAY_SIZE(env
->avr
); i
++) {
4512 ppc_avr_t
*avr
= &env
->avr
[i
];
4513 ppc_avr_t
*vreg
= &frame
->mc_vregs
.altivec
[i
];
4515 if (__get_user(avr
->u64
[0], &vreg
->u64
[0]) ||
4516 __get_user(avr
->u64
[1], &vreg
->u64
[1])) {
4520 /* Set MSR_VEC in the saved MSR value to indicate that
4521 frame->mc_vregs contains valid data. */
4522 if (__get_user(env
->spr
[SPR_VRSAVE
],
4523 (target_ulong
*)(&frame
->mc_vregs
.altivec
[32].u32
[3])))
4527 /* Restore floating point registers. */
4528 if (env
->insns_flags
& PPC_FLOAT
) {
4530 for (i
= 0; i
< ARRAY_SIZE(env
->fpr
); i
++) {
4531 if (__get_user(env
->fpr
[i
], &frame
->mc_fregs
[i
])) {
4535 if (__get_user(fpscr
, &frame
->mc_fregs
[32]))
4537 env
->fpscr
= (uint32_t) fpscr
;
4540 /* Save SPE registers. The kernel only saves the high half. */
4541 if (env
->insns_flags
& PPC_SPE
) {
4542 #if defined(TARGET_PPC64)
4543 for (i
= 0; i
< ARRAY_SIZE(env
->gpr
); i
++) {
4546 if (__get_user(hi
, &frame
->mc_vregs
.spe
[i
])) {
4549 env
->gpr
[i
] = ((uint64_t)hi
<< 32) | ((uint32_t) env
->gpr
[i
]);
4552 for (i
= 0; i
< ARRAY_SIZE(env
->gprh
); i
++) {
4553 if (__get_user(env
->gprh
[i
], &frame
->mc_vregs
.spe
[i
])) {
4558 if (__get_user(env
->spe_fscr
, &frame
->mc_vregs
.spe
[32]))
4565 static void setup_frame(int sig
, struct target_sigaction
*ka
,
4566 target_sigset_t
*set
, CPUPPCState
*env
)
4568 struct target_sigframe
*frame
;
4569 struct target_sigcontext
*sc
;
4570 target_ulong frame_addr
, newsp
;
4574 frame_addr
= get_sigframe(ka
, env
, sizeof(*frame
));
4575 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 1))
4579 signal
= current_exec_domain_sig(sig
);
4581 err
|= __put_user(ka
->_sa_handler
, &sc
->handler
);
4582 err
|= __put_user(set
->sig
[0], &sc
->oldmask
);
4583 #if defined(TARGET_PPC64)
4584 err
|= __put_user(set
->sig
[0] >> 32, &sc
->_unused
[3]);
4586 err
|= __put_user(set
->sig
[1], &sc
->_unused
[3]);
4588 err
|= __put_user(h2g(&frame
->mctx
), &sc
->regs
);
4589 err
|= __put_user(sig
, &sc
->signal
);
4591 /* Save user regs. */
4592 err
|= save_user_regs(env
, &frame
->mctx
, TARGET_NR_sigreturn
);
4594 /* The kernel checks for the presence of a VDSO here. We don't
4595 emulate a vdso, so use a sigreturn system call. */
4596 env
->lr
= (target_ulong
) h2g(frame
->mctx
.tramp
);
4598 /* Turn off all fp exceptions. */
4601 /* Create a stack frame for the caller of the handler. */
4602 newsp
= frame_addr
- SIGNAL_FRAMESIZE
;
4603 err
|= put_user(env
->gpr
[1], newsp
, target_ulong
);
4608 /* Set up registers for signal handler. */
4609 env
->gpr
[1] = newsp
;
4610 env
->gpr
[3] = signal
;
4611 env
->gpr
[4] = frame_addr
+ offsetof(struct target_sigframe
, sctx
);
4612 env
->nip
= (target_ulong
) ka
->_sa_handler
;
4613 /* Signal handlers are entered in big-endian mode. */
4614 env
->msr
&= ~MSR_LE
;
4616 unlock_user_struct(frame
, frame_addr
, 1);
4620 unlock_user_struct(frame
, frame_addr
, 1);
4621 qemu_log("segfaulting from setup_frame\n");
4622 force_sig(TARGET_SIGSEGV
);
4625 static void setup_rt_frame(int sig
, struct target_sigaction
*ka
,
4626 target_siginfo_t
*info
,
4627 target_sigset_t
*set
, CPUPPCState
*env
)
4629 struct target_rt_sigframe
*rt_sf
;
4630 struct target_mcontext
*frame
;
4631 target_ulong rt_sf_addr
, newsp
= 0;
4635 rt_sf_addr
= get_sigframe(ka
, env
, sizeof(*rt_sf
));
4636 if (!lock_user_struct(VERIFY_WRITE
, rt_sf
, rt_sf_addr
, 1))
4639 signal
= current_exec_domain_sig(sig
);
4641 err
|= copy_siginfo_to_user(&rt_sf
->info
, info
);
4643 err
|= __put_user(0, &rt_sf
->uc
.tuc_flags
);
4644 err
|= __put_user(0, &rt_sf
->uc
.tuc_link
);
4645 err
|= __put_user((target_ulong
)target_sigaltstack_used
.ss_sp
,
4646 &rt_sf
->uc
.tuc_stack
.ss_sp
);
4647 err
|= __put_user(sas_ss_flags(env
->gpr
[1]),
4648 &rt_sf
->uc
.tuc_stack
.ss_flags
);
4649 err
|= __put_user(target_sigaltstack_used
.ss_size
,
4650 &rt_sf
->uc
.tuc_stack
.ss_size
);
4651 err
|= __put_user(h2g (&rt_sf
->uc
.tuc_mcontext
),
4652 &rt_sf
->uc
.tuc_regs
);
4653 for(i
= 0; i
< TARGET_NSIG_WORDS
; i
++) {
4654 err
|= __put_user(set
->sig
[i
], &rt_sf
->uc
.tuc_sigmask
.sig
[i
]);
4657 frame
= &rt_sf
->uc
.tuc_mcontext
;
4658 err
|= save_user_regs(env
, frame
, TARGET_NR_rt_sigreturn
);
4660 /* The kernel checks for the presence of a VDSO here. We don't
4661 emulate a vdso, so use a sigreturn system call. */
4662 env
->lr
= (target_ulong
) h2g(frame
->tramp
);
4664 /* Turn off all fp exceptions. */
4667 /* Create a stack frame for the caller of the handler. */
4668 newsp
= rt_sf_addr
- (SIGNAL_FRAMESIZE
+ 16);
4669 err
|= __put_user(env
->gpr
[1], (target_ulong
*)(uintptr_t) newsp
);
4674 /* Set up registers for signal handler. */
4675 env
->gpr
[1] = newsp
;
4676 env
->gpr
[3] = (target_ulong
) signal
;
4677 env
->gpr
[4] = (target_ulong
) h2g(&rt_sf
->info
);
4678 env
->gpr
[5] = (target_ulong
) h2g(&rt_sf
->uc
);
4679 env
->gpr
[6] = (target_ulong
) h2g(rt_sf
);
4680 env
->nip
= (target_ulong
) ka
->_sa_handler
;
4681 /* Signal handlers are entered in big-endian mode. */
4682 env
->msr
&= ~MSR_LE
;
4684 unlock_user_struct(rt_sf
, rt_sf_addr
, 1);
4688 unlock_user_struct(rt_sf
, rt_sf_addr
, 1);
4689 qemu_log("segfaulting from setup_rt_frame\n");
4690 force_sig(TARGET_SIGSEGV
);
4694 long do_sigreturn(CPUPPCState
*env
)
4696 struct target_sigcontext
*sc
= NULL
;
4697 struct target_mcontext
*sr
= NULL
;
4698 target_ulong sr_addr
, sc_addr
;
4700 target_sigset_t set
;
4702 sc_addr
= env
->gpr
[1] + SIGNAL_FRAMESIZE
;
4703 if (!lock_user_struct(VERIFY_READ
, sc
, sc_addr
, 1))
4706 #if defined(TARGET_PPC64)
4707 set
.sig
[0] = sc
->oldmask
+ ((long)(sc
->_unused
[3]) << 32);
4709 if(__get_user(set
.sig
[0], &sc
->oldmask
) ||
4710 __get_user(set
.sig
[1], &sc
->_unused
[3]))
4713 target_to_host_sigset_internal(&blocked
, &set
);
4714 sigprocmask(SIG_SETMASK
, &blocked
, NULL
);
4716 if (__get_user(sr_addr
, &sc
->regs
))
4718 if (!lock_user_struct(VERIFY_READ
, sr
, sr_addr
, 1))
4720 if (restore_user_regs(env
, sr
, 1))
4723 unlock_user_struct(sr
, sr_addr
, 1);
4724 unlock_user_struct(sc
, sc_addr
, 1);
4725 return -TARGET_QEMU_ESIGRETURN
;
4728 unlock_user_struct(sr
, sr_addr
, 1);
4729 unlock_user_struct(sc
, sc_addr
, 1);
4730 qemu_log("segfaulting from do_sigreturn\n");
4731 force_sig(TARGET_SIGSEGV
);
4735 /* See arch/powerpc/kernel/signal_32.c. */
4736 static int do_setcontext(struct target_ucontext
*ucp
, CPUPPCState
*env
, int sig
)
4738 struct target_mcontext
*mcp
;
4739 target_ulong mcp_addr
;
4741 target_sigset_t set
;
4743 if (copy_from_user(&set
, h2g(ucp
) + offsetof(struct target_ucontext
, tuc_sigmask
),
4747 #if defined(TARGET_PPC64)
4748 fprintf (stderr
, "do_setcontext: not implemented\n");
4751 if (__get_user(mcp_addr
, &ucp
->tuc_regs
))
4754 if (!lock_user_struct(VERIFY_READ
, mcp
, mcp_addr
, 1))
4757 target_to_host_sigset_internal(&blocked
, &set
);
4758 sigprocmask(SIG_SETMASK
, &blocked
, NULL
);
4759 if (restore_user_regs(env
, mcp
, sig
))
4762 unlock_user_struct(mcp
, mcp_addr
, 1);
4766 unlock_user_struct(mcp
, mcp_addr
, 1);
4771 long do_rt_sigreturn(CPUPPCState
*env
)
4773 struct target_rt_sigframe
*rt_sf
= NULL
;
4774 target_ulong rt_sf_addr
;
4776 rt_sf_addr
= env
->gpr
[1] + SIGNAL_FRAMESIZE
+ 16;
4777 if (!lock_user_struct(VERIFY_READ
, rt_sf
, rt_sf_addr
, 1))
4780 if (do_setcontext(&rt_sf
->uc
, env
, 1))
4783 do_sigaltstack(rt_sf_addr
4784 + offsetof(struct target_rt_sigframe
, uc
.tuc_stack
),
4787 unlock_user_struct(rt_sf
, rt_sf_addr
, 1);
4788 return -TARGET_QEMU_ESIGRETURN
;
4791 unlock_user_struct(rt_sf
, rt_sf_addr
, 1);
4792 qemu_log("segfaulting from do_rt_sigreturn\n");
4793 force_sig(TARGET_SIGSEGV
);
4797 #elif defined(TARGET_M68K)
4799 struct target_sigcontext
{
4806 unsigned short sc_sr
;
4810 struct target_sigframe
4817 abi_ulong extramask
[TARGET_NSIG_WORDS
-1];
4818 struct target_sigcontext sc
;
4821 typedef int target_greg_t
;
4822 #define TARGET_NGREG 18
4823 typedef target_greg_t target_gregset_t
[TARGET_NGREG
];
4825 typedef struct target_fpregset
{
4828 } target_fpregset_t
;
4830 struct target_mcontext
{
4832 target_gregset_t gregs
;
4833 target_fpregset_t fpregs
;
4836 #define TARGET_MCONTEXT_VERSION 2
4838 struct target_ucontext
{
4839 abi_ulong tuc_flags
;
4841 target_stack_t tuc_stack
;
4842 struct target_mcontext tuc_mcontext
;
4843 abi_long tuc_filler
[80];
4844 target_sigset_t tuc_sigmask
;
4847 struct target_rt_sigframe
4854 struct target_siginfo info
;
4855 struct target_ucontext uc
;
4859 setup_sigcontext(struct target_sigcontext
*sc
, CPUM68KState
*env
,
4864 err
|= __put_user(mask
, &sc
->sc_mask
);
4865 err
|= __put_user(env
->aregs
[7], &sc
->sc_usp
);
4866 err
|= __put_user(env
->dregs
[0], &sc
->sc_d0
);
4867 err
|= __put_user(env
->dregs
[1], &sc
->sc_d1
);
4868 err
|= __put_user(env
->aregs
[0], &sc
->sc_a0
);
4869 err
|= __put_user(env
->aregs
[1], &sc
->sc_a1
);
4870 err
|= __put_user(env
->sr
, &sc
->sc_sr
);
4871 err
|= __put_user(env
->pc
, &sc
->sc_pc
);
4877 restore_sigcontext(CPUM68KState
*env
, struct target_sigcontext
*sc
, int *pd0
)
4882 err
|= __get_user(env
->aregs
[7], &sc
->sc_usp
);
4883 err
|= __get_user(env
->dregs
[1], &sc
->sc_d1
);
4884 err
|= __get_user(env
->aregs
[0], &sc
->sc_a0
);
4885 err
|= __get_user(env
->aregs
[1], &sc
->sc_a1
);
4886 err
|= __get_user(env
->pc
, &sc
->sc_pc
);
4887 err
|= __get_user(temp
, &sc
->sc_sr
);
4888 env
->sr
= (env
->sr
& 0xff00) | (temp
& 0xff);
4890 *pd0
= tswapl(sc
->sc_d0
);
4896 * Determine which stack to use..
4898 static inline abi_ulong
4899 get_sigframe(struct target_sigaction
*ka
, CPUM68KState
*regs
,
4904 sp
= regs
->aregs
[7];
4906 /* This is the X/Open sanctioned signal stack switching. */
4907 if ((ka
->sa_flags
& TARGET_SA_ONSTACK
) && (sas_ss_flags (sp
) == 0)) {
4908 sp
= target_sigaltstack_used
.ss_sp
+ target_sigaltstack_used
.ss_size
;
4911 return ((sp
- frame_size
) & -8UL);
4914 static void setup_frame(int sig
, struct target_sigaction
*ka
,
4915 target_sigset_t
*set
, CPUM68KState
*env
)
4917 struct target_sigframe
*frame
;
4918 abi_ulong frame_addr
;
4919 abi_ulong retcode_addr
;
4924 frame_addr
= get_sigframe(ka
, env
, sizeof *frame
);
4925 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0))
4928 err
|= __put_user(sig
, &frame
->sig
);
4930 sc_addr
= frame_addr
+ offsetof(struct target_sigframe
, sc
);
4931 err
|= __put_user(sc_addr
, &frame
->psc
);
4933 err
|= setup_sigcontext(&frame
->sc
, env
, set
->sig
[0]);
4937 for(i
= 1; i
< TARGET_NSIG_WORDS
; i
++) {
4938 if (__put_user(set
->sig
[i
], &frame
->extramask
[i
- 1]))
4942 /* Set up to return from userspace. */
4944 retcode_addr
= frame_addr
+ offsetof(struct target_sigframe
, retcode
);
4945 err
|= __put_user(retcode_addr
, &frame
->pretcode
);
4947 /* moveq #,d0; trap #0 */
4949 err
|= __put_user(0x70004e40 + (TARGET_NR_sigreturn
<< 16),
4950 (long *)(frame
->retcode
));
4955 /* Set up to return from userspace */
4957 env
->aregs
[7] = frame_addr
;
4958 env
->pc
= ka
->_sa_handler
;
4960 unlock_user_struct(frame
, frame_addr
, 1);
4964 unlock_user_struct(frame
, frame_addr
, 1);
4965 force_sig(TARGET_SIGSEGV
);
4968 static inline int target_rt_setup_ucontext(struct target_ucontext
*uc
,
4971 target_greg_t
*gregs
= uc
->tuc_mcontext
.gregs
;
4974 err
= __put_user(TARGET_MCONTEXT_VERSION
, &uc
->tuc_mcontext
.version
);
4975 err
|= __put_user(env
->dregs
[0], &gregs
[0]);
4976 err
|= __put_user(env
->dregs
[1], &gregs
[1]);
4977 err
|= __put_user(env
->dregs
[2], &gregs
[2]);
4978 err
|= __put_user(env
->dregs
[3], &gregs
[3]);
4979 err
|= __put_user(env
->dregs
[4], &gregs
[4]);
4980 err
|= __put_user(env
->dregs
[5], &gregs
[5]);
4981 err
|= __put_user(env
->dregs
[6], &gregs
[6]);
4982 err
|= __put_user(env
->dregs
[7], &gregs
[7]);
4983 err
|= __put_user(env
->aregs
[0], &gregs
[8]);
4984 err
|= __put_user(env
->aregs
[1], &gregs
[9]);
4985 err
|= __put_user(env
->aregs
[2], &gregs
[10]);
4986 err
|= __put_user(env
->aregs
[3], &gregs
[11]);
4987 err
|= __put_user(env
->aregs
[4], &gregs
[12]);
4988 err
|= __put_user(env
->aregs
[5], &gregs
[13]);
4989 err
|= __put_user(env
->aregs
[6], &gregs
[14]);
4990 err
|= __put_user(env
->aregs
[7], &gregs
[15]);
4991 err
|= __put_user(env
->pc
, &gregs
[16]);
4992 err
|= __put_user(env
->sr
, &gregs
[17]);
4997 static inline int target_rt_restore_ucontext(CPUM68KState
*env
,
4998 struct target_ucontext
*uc
,
5003 target_greg_t
*gregs
= uc
->tuc_mcontext
.gregs
;
5005 err
= __get_user(temp
, &uc
->tuc_mcontext
.version
);
5006 if (temp
!= TARGET_MCONTEXT_VERSION
)
5009 /* restore passed registers */
5010 err
|= __get_user(env
->dregs
[0], &gregs
[0]);
5011 err
|= __get_user(env
->dregs
[1], &gregs
[1]);
5012 err
|= __get_user(env
->dregs
[2], &gregs
[2]);
5013 err
|= __get_user(env
->dregs
[3], &gregs
[3]);
5014 err
|= __get_user(env
->dregs
[4], &gregs
[4]);
5015 err
|= __get_user(env
->dregs
[5], &gregs
[5]);
5016 err
|= __get_user(env
->dregs
[6], &gregs
[6]);
5017 err
|= __get_user(env
->dregs
[7], &gregs
[7]);
5018 err
|= __get_user(env
->aregs
[0], &gregs
[8]);
5019 err
|= __get_user(env
->aregs
[1], &gregs
[9]);
5020 err
|= __get_user(env
->aregs
[2], &gregs
[10]);
5021 err
|= __get_user(env
->aregs
[3], &gregs
[11]);
5022 err
|= __get_user(env
->aregs
[4], &gregs
[12]);
5023 err
|= __get_user(env
->aregs
[5], &gregs
[13]);
5024 err
|= __get_user(env
->aregs
[6], &gregs
[14]);
5025 err
|= __get_user(env
->aregs
[7], &gregs
[15]);
5026 err
|= __get_user(env
->pc
, &gregs
[16]);
5027 err
|= __get_user(temp
, &gregs
[17]);
5028 env
->sr
= (env
->sr
& 0xff00) | (temp
& 0xff);
5030 *pd0
= env
->dregs
[0];
5037 static void setup_rt_frame(int sig
, struct target_sigaction
*ka
,
5038 target_siginfo_t
*info
,
5039 target_sigset_t
*set
, CPUM68KState
*env
)
5041 struct target_rt_sigframe
*frame
;
5042 abi_ulong frame_addr
;
5043 abi_ulong retcode_addr
;
5044 abi_ulong info_addr
;
5049 frame_addr
= get_sigframe(ka
, env
, sizeof *frame
);
5050 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0))
5053 err
|= __put_user(sig
, &frame
->sig
);
5055 info_addr
= frame_addr
+ offsetof(struct target_rt_sigframe
, info
);
5056 err
|= __put_user(info_addr
, &frame
->pinfo
);
5058 uc_addr
= frame_addr
+ offsetof(struct target_rt_sigframe
, uc
);
5059 err
|= __put_user(uc_addr
, &frame
->puc
);
5061 err
|= copy_siginfo_to_user(&frame
->info
, info
);
5063 /* Create the ucontext */
5065 err
|= __put_user(0, &frame
->uc
.tuc_flags
);
5066 err
|= __put_user(0, &frame
->uc
.tuc_link
);
5067 err
|= __put_user(target_sigaltstack_used
.ss_sp
,
5068 &frame
->uc
.tuc_stack
.ss_sp
);
5069 err
|= __put_user(sas_ss_flags(env
->aregs
[7]),
5070 &frame
->uc
.tuc_stack
.ss_flags
);
5071 err
|= __put_user(target_sigaltstack_used
.ss_size
,
5072 &frame
->uc
.tuc_stack
.ss_size
);
5073 err
|= target_rt_setup_ucontext(&frame
->uc
, env
);
5078 for(i
= 0; i
< TARGET_NSIG_WORDS
; i
++) {
5079 if (__put_user(set
->sig
[i
], &frame
->uc
.tuc_sigmask
.sig
[i
]))
5083 /* Set up to return from userspace. */
5085 retcode_addr
= frame_addr
+ offsetof(struct target_sigframe
, retcode
);
5086 err
|= __put_user(retcode_addr
, &frame
->pretcode
);
5088 /* moveq #,d0; notb d0; trap #0 */
5090 err
|= __put_user(0x70004600 + ((TARGET_NR_rt_sigreturn
^ 0xff) << 16),
5091 (long *)(frame
->retcode
+ 0));
5092 err
|= __put_user(0x4e40, (short *)(frame
->retcode
+ 4));
5097 /* Set up to return from userspace */
5099 env
->aregs
[7] = frame_addr
;
5100 env
->pc
= ka
->_sa_handler
;
5102 unlock_user_struct(frame
, frame_addr
, 1);
5106 unlock_user_struct(frame
, frame_addr
, 1);
5107 force_sig(TARGET_SIGSEGV
);
5110 long do_sigreturn(CPUM68KState
*env
)
5112 struct target_sigframe
*frame
;
5113 abi_ulong frame_addr
= env
->aregs
[7] - 4;
5114 target_sigset_t target_set
;
5118 if (!lock_user_struct(VERIFY_READ
, frame
, frame_addr
, 1))
5121 /* set blocked signals */
5123 if (__get_user(target_set
.sig
[0], &frame
->sc
.sc_mask
))
5126 for(i
= 1; i
< TARGET_NSIG_WORDS
; i
++) {
5127 if (__get_user(target_set
.sig
[i
], &frame
->extramask
[i
- 1]))
5131 target_to_host_sigset_internal(&set
, &target_set
);
5132 sigprocmask(SIG_SETMASK
, &set
, NULL
);
5134 /* restore registers */
5136 if (restore_sigcontext(env
, &frame
->sc
, &d0
))
5139 unlock_user_struct(frame
, frame_addr
, 0);
5143 unlock_user_struct(frame
, frame_addr
, 0);
5144 force_sig(TARGET_SIGSEGV
);
5148 long do_rt_sigreturn(CPUM68KState
*env
)
5150 struct target_rt_sigframe
*frame
;
5151 abi_ulong frame_addr
= env
->aregs
[7] - 4;
5152 target_sigset_t target_set
;
5156 if (!lock_user_struct(VERIFY_READ
, frame
, frame_addr
, 1))
5159 target_to_host_sigset_internal(&set
, &target_set
);
5160 sigprocmask(SIG_SETMASK
, &set
, NULL
);
5162 /* restore registers */
5164 if (target_rt_restore_ucontext(env
, &frame
->uc
, &d0
))
5167 if (do_sigaltstack(frame_addr
+
5168 offsetof(struct target_rt_sigframe
, uc
.tuc_stack
),
5169 0, get_sp_from_cpustate(env
)) == -EFAULT
)
5172 unlock_user_struct(frame
, frame_addr
, 0);
5176 unlock_user_struct(frame
, frame_addr
, 0);
5177 force_sig(TARGET_SIGSEGV
);
5181 #elif defined(TARGET_ALPHA)
5183 struct target_sigcontext
{
5184 abi_long sc_onstack
;
5188 abi_long sc_regs
[32];
5189 abi_long sc_ownedfp
;
5190 abi_long sc_fpregs
[32];
5192 abi_ulong sc_fp_control
;
5193 abi_ulong sc_reserved1
;
5194 abi_ulong sc_reserved2
;
5197 abi_ulong sc_traparg_a0
;
5198 abi_ulong sc_traparg_a1
;
5199 abi_ulong sc_traparg_a2
;
5200 abi_ulong sc_fp_trap_pc
;
5201 abi_ulong sc_fp_trigger_sum
;
5202 abi_ulong sc_fp_trigger_inst
;
5205 struct target_ucontext
{
5206 abi_ulong tuc_flags
;
5208 abi_ulong tuc_osf_sigmask
;
5209 target_stack_t tuc_stack
;
5210 struct target_sigcontext tuc_mcontext
;
5211 target_sigset_t tuc_sigmask
;
5214 struct target_sigframe
{
5215 struct target_sigcontext sc
;
5216 unsigned int retcode
[3];
5219 struct target_rt_sigframe
{
5220 target_siginfo_t info
;
5221 struct target_ucontext uc
;
5222 unsigned int retcode
[3];
5225 #define INSN_MOV_R30_R16 0x47fe0410
5226 #define INSN_LDI_R0 0x201f0000
5227 #define INSN_CALLSYS 0x00000083
5229 static int setup_sigcontext(struct target_sigcontext
*sc
, CPUAlphaState
*env
,
5230 abi_ulong frame_addr
, target_sigset_t
*set
)
5234 err
|= __put_user(on_sig_stack(frame_addr
), &sc
->sc_onstack
);
5235 err
|= __put_user(set
->sig
[0], &sc
->sc_mask
);
5236 err
|= __put_user(env
->pc
, &sc
->sc_pc
);
5237 err
|= __put_user(8, &sc
->sc_ps
);
5239 for (i
= 0; i
< 31; ++i
) {
5240 err
|= __put_user(env
->ir
[i
], &sc
->sc_regs
[i
]);
5242 err
|= __put_user(0, &sc
->sc_regs
[31]);
5244 for (i
= 0; i
< 31; ++i
) {
5245 err
|= __put_user(env
->fir
[i
], &sc
->sc_fpregs
[i
]);
5247 err
|= __put_user(0, &sc
->sc_fpregs
[31]);
5248 err
|= __put_user(cpu_alpha_load_fpcr(env
), &sc
->sc_fpcr
);
5250 err
|= __put_user(0, &sc
->sc_traparg_a0
); /* FIXME */
5251 err
|= __put_user(0, &sc
->sc_traparg_a1
); /* FIXME */
5252 err
|= __put_user(0, &sc
->sc_traparg_a2
); /* FIXME */
5257 static int restore_sigcontext(CPUAlphaState
*env
,
5258 struct target_sigcontext
*sc
)
5263 err
|= __get_user(env
->pc
, &sc
->sc_pc
);
5265 for (i
= 0; i
< 31; ++i
) {
5266 err
|= __get_user(env
->ir
[i
], &sc
->sc_regs
[i
]);
5268 for (i
= 0; i
< 31; ++i
) {
5269 err
|= __get_user(env
->fir
[i
], &sc
->sc_fpregs
[i
]);
5272 err
|= __get_user(fpcr
, &sc
->sc_fpcr
);
5273 cpu_alpha_store_fpcr(env
, fpcr
);
5278 static inline abi_ulong
get_sigframe(struct target_sigaction
*sa
,
5280 unsigned long framesize
)
5282 abi_ulong sp
= env
->ir
[IR_SP
];
5284 /* This is the X/Open sanctioned signal stack switching. */
5285 if ((sa
->sa_flags
& TARGET_SA_ONSTACK
) != 0 && !sas_ss_flags(sp
)) {
5286 sp
= target_sigaltstack_used
.ss_sp
+ target_sigaltstack_used
.ss_size
;
5288 return (sp
- framesize
) & -32;
5291 static void setup_frame(int sig
, struct target_sigaction
*ka
,
5292 target_sigset_t
*set
, CPUAlphaState
*env
)
5294 abi_ulong frame_addr
, r26
;
5295 struct target_sigframe
*frame
;
5298 frame_addr
= get_sigframe(ka
, env
, sizeof(*frame
));
5299 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0)) {
5303 err
|= setup_sigcontext(&frame
->sc
, env
, frame_addr
, set
);
5305 if (ka
->sa_restorer
) {
5306 r26
= ka
->sa_restorer
;
5308 err
|= __put_user(INSN_MOV_R30_R16
, &frame
->retcode
[0]);
5309 err
|= __put_user(INSN_LDI_R0
+ TARGET_NR_sigreturn
,
5310 &frame
->retcode
[1]);
5311 err
|= __put_user(INSN_CALLSYS
, &frame
->retcode
[2]);
5316 unlock_user_struct(frame
, frame_addr
, 1);
5320 if (sig
== TARGET_SIGSEGV
) {
5321 ka
->_sa_handler
= TARGET_SIG_DFL
;
5323 force_sig(TARGET_SIGSEGV
);
5326 env
->ir
[IR_RA
] = r26
;
5327 env
->ir
[IR_PV
] = env
->pc
= ka
->_sa_handler
;
5328 env
->ir
[IR_A0
] = sig
;
5330 env
->ir
[IR_A2
] = frame_addr
+ offsetof(struct target_sigframe
, sc
);
5331 env
->ir
[IR_SP
] = frame_addr
;
5334 static void setup_rt_frame(int sig
, struct target_sigaction
*ka
,
5335 target_siginfo_t
*info
,
5336 target_sigset_t
*set
, CPUAlphaState
*env
)
5338 abi_ulong frame_addr
, r26
;
5339 struct target_rt_sigframe
*frame
;
5342 frame_addr
= get_sigframe(ka
, env
, sizeof(*frame
));
5343 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0)) {
5347 err
|= copy_siginfo_to_user(&frame
->info
, info
);
5349 err
|= __put_user(0, &frame
->uc
.tuc_flags
);
5350 err
|= __put_user(0, &frame
->uc
.tuc_link
);
5351 err
|= __put_user(set
->sig
[0], &frame
->uc
.tuc_osf_sigmask
);
5352 err
|= __put_user(target_sigaltstack_used
.ss_sp
,
5353 &frame
->uc
.tuc_stack
.ss_sp
);
5354 err
|= __put_user(sas_ss_flags(env
->ir
[IR_SP
]),
5355 &frame
->uc
.tuc_stack
.ss_flags
);
5356 err
|= __put_user(target_sigaltstack_used
.ss_size
,
5357 &frame
->uc
.tuc_stack
.ss_size
);
5358 err
|= setup_sigcontext(&frame
->uc
.tuc_mcontext
, env
, frame_addr
, set
);
5359 for (i
= 0; i
< TARGET_NSIG_WORDS
; ++i
) {
5360 err
|= __put_user(set
->sig
[i
], &frame
->uc
.tuc_sigmask
.sig
[i
]);
5363 if (ka
->sa_restorer
) {
5364 r26
= ka
->sa_restorer
;
5366 err
|= __put_user(INSN_MOV_R30_R16
, &frame
->retcode
[0]);
5367 err
|= __put_user(INSN_LDI_R0
+ TARGET_NR_rt_sigreturn
,
5368 &frame
->retcode
[1]);
5369 err
|= __put_user(INSN_CALLSYS
, &frame
->retcode
[2]);
5376 if (sig
== TARGET_SIGSEGV
) {
5377 ka
->_sa_handler
= TARGET_SIG_DFL
;
5379 force_sig(TARGET_SIGSEGV
);
5382 env
->ir
[IR_RA
] = r26
;
5383 env
->ir
[IR_PV
] = env
->pc
= ka
->_sa_handler
;
5384 env
->ir
[IR_A0
] = sig
;
5385 env
->ir
[IR_A1
] = frame_addr
+ offsetof(struct target_rt_sigframe
, info
);
5386 env
->ir
[IR_A2
] = frame_addr
+ offsetof(struct target_rt_sigframe
, uc
);
5387 env
->ir
[IR_SP
] = frame_addr
;
5390 long do_sigreturn(CPUAlphaState
*env
)
5392 struct target_sigcontext
*sc
;
5393 abi_ulong sc_addr
= env
->ir
[IR_A0
];
5394 target_sigset_t target_set
;
5397 if (!lock_user_struct(VERIFY_READ
, sc
, sc_addr
, 1)) {
5401 target_sigemptyset(&target_set
);
5402 if (__get_user(target_set
.sig
[0], &sc
->sc_mask
)) {
5406 target_to_host_sigset_internal(&set
, &target_set
);
5407 sigprocmask(SIG_SETMASK
, &set
, NULL
);
5409 if (restore_sigcontext(env
, sc
)) {
5412 unlock_user_struct(sc
, sc_addr
, 0);
5413 return env
->ir
[IR_V0
];
5416 unlock_user_struct(sc
, sc_addr
, 0);
5417 force_sig(TARGET_SIGSEGV
);
5420 long do_rt_sigreturn(CPUAlphaState
*env
)
5422 abi_ulong frame_addr
= env
->ir
[IR_A0
];
5423 struct target_rt_sigframe
*frame
;
5426 if (!lock_user_struct(VERIFY_READ
, frame
, frame_addr
, 1)) {
5429 target_to_host_sigset(&set
, &frame
->uc
.tuc_sigmask
);
5430 sigprocmask(SIG_SETMASK
, &set
, NULL
);
5432 if (restore_sigcontext(env
, &frame
->uc
.tuc_mcontext
)) {
5435 if (do_sigaltstack(frame_addr
+ offsetof(struct target_rt_sigframe
,
5437 0, env
->ir
[IR_SP
]) == -EFAULT
) {
5441 unlock_user_struct(frame
, frame_addr
, 0);
5442 return env
->ir
[IR_V0
];
5446 unlock_user_struct(frame
, frame_addr
, 0);
5447 force_sig(TARGET_SIGSEGV
);
5452 static void setup_frame(int sig
, struct target_sigaction
*ka
,
5453 target_sigset_t
*set
, CPUArchState
*env
)
5455 fprintf(stderr
, "setup_frame: not implemented\n");
5458 static void setup_rt_frame(int sig
, struct target_sigaction
*ka
,
5459 target_siginfo_t
*info
,
5460 target_sigset_t
*set
, CPUArchState
*env
)
5462 fprintf(stderr
, "setup_rt_frame: not implemented\n");
5465 long do_sigreturn(CPUArchState
*env
)
5467 fprintf(stderr
, "do_sigreturn: not implemented\n");
5468 return -TARGET_ENOSYS
;
5471 long do_rt_sigreturn(CPUArchState
*env
)
5473 fprintf(stderr
, "do_rt_sigreturn: not implemented\n");
5474 return -TARGET_ENOSYS
;
5479 void process_pending_signals(CPUArchState
*cpu_env
)
5483 sigset_t set
, old_set
;
5484 target_sigset_t target_old_set
;
5485 struct emulated_sigtable
*k
;
5486 struct target_sigaction
*sa
;
5488 TaskState
*ts
= cpu_env
->opaque
;
5490 if (!ts
->signal_pending
)
5493 /* FIXME: This is not threadsafe. */
5495 for(sig
= 1; sig
<= TARGET_NSIG
; sig
++) {
5500 /* if no signal is pending, just return */
5501 ts
->signal_pending
= 0;
5506 fprintf(stderr
, "qemu: process signal %d\n", sig
);
5508 /* dequeue signal */
5514 sig
= gdb_handlesig (cpu_env
, sig
);
5517 handler
= TARGET_SIG_IGN
;
5519 sa
= &sigact_table
[sig
- 1];
5520 handler
= sa
->_sa_handler
;
5523 if (handler
== TARGET_SIG_DFL
) {
5524 /* default handler : ignore some signal. The other are job control or fatal */
5525 if (sig
== TARGET_SIGTSTP
|| sig
== TARGET_SIGTTIN
|| sig
== TARGET_SIGTTOU
) {
5526 kill(getpid(),SIGSTOP
);
5527 } else if (sig
!= TARGET_SIGCHLD
&&
5528 sig
!= TARGET_SIGURG
&&
5529 sig
!= TARGET_SIGWINCH
&&
5530 sig
!= TARGET_SIGCONT
) {
5533 } else if (handler
== TARGET_SIG_IGN
) {
5535 } else if (handler
== TARGET_SIG_ERR
) {
5538 /* compute the blocked signals during the handler execution */
5539 target_to_host_sigset(&set
, &sa
->sa_mask
);
5540 /* SA_NODEFER indicates that the current signal should not be
5541 blocked during the handler */
5542 if (!(sa
->sa_flags
& TARGET_SA_NODEFER
))
5543 sigaddset(&set
, target_to_host_signal(sig
));
5545 /* block signals in the handler using Linux */
5546 sigprocmask(SIG_BLOCK
, &set
, &old_set
);
5547 /* save the previous blocked signal state to restore it at the
5548 end of the signal execution (see do_sigreturn) */
5549 host_to_target_sigset_internal(&target_old_set
, &old_set
);
5551 /* if the CPU is in VM86 mode, we restore the 32 bit values */
5552 #if defined(TARGET_I386) && !defined(TARGET_X86_64)
5554 CPUX86State
*env
= cpu_env
;
5555 if (env
->eflags
& VM_MASK
)
5556 save_v86_state(env
);
5559 /* prepare the stack frame of the virtual CPU */
5560 if (sa
->sa_flags
& TARGET_SA_SIGINFO
)
5561 setup_rt_frame(sig
, sa
, &q
->info
, &target_old_set
, cpu_env
);
5563 setup_frame(sig
, sa
, &target_old_set
, cpu_env
);
5564 if (sa
->sa_flags
& TARGET_SA_RESETHAND
)
5565 sa
->_sa_handler
= TARGET_SIG_DFL
;
5568 free_sigqueue(cpu_env
, q
);