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/>.
19 #include "qemu/osdep.h"
20 #include "qemu/bitops.h"
21 #include <sys/ucontext.h>
22 #include <sys/resource.h>
25 #include "qemu-common.h"
26 #include "target_signal.h"
29 static struct target_sigaltstack target_sigaltstack_used
= {
32 .ss_flags
= TARGET_SS_DISABLE
,
35 static struct target_sigaction sigact_table
[TARGET_NSIG
];
37 static void host_signal_handler(int host_signum
, siginfo_t
*info
,
40 static uint8_t host_to_target_signal_table
[_NSIG
] = {
41 [SIGHUP
] = TARGET_SIGHUP
,
42 [SIGINT
] = TARGET_SIGINT
,
43 [SIGQUIT
] = TARGET_SIGQUIT
,
44 [SIGILL
] = TARGET_SIGILL
,
45 [SIGTRAP
] = TARGET_SIGTRAP
,
46 [SIGABRT
] = TARGET_SIGABRT
,
47 /* [SIGIOT] = TARGET_SIGIOT,*/
48 [SIGBUS
] = TARGET_SIGBUS
,
49 [SIGFPE
] = TARGET_SIGFPE
,
50 [SIGKILL
] = TARGET_SIGKILL
,
51 [SIGUSR1
] = TARGET_SIGUSR1
,
52 [SIGSEGV
] = TARGET_SIGSEGV
,
53 [SIGUSR2
] = TARGET_SIGUSR2
,
54 [SIGPIPE
] = TARGET_SIGPIPE
,
55 [SIGALRM
] = TARGET_SIGALRM
,
56 [SIGTERM
] = TARGET_SIGTERM
,
58 [SIGSTKFLT
] = TARGET_SIGSTKFLT
,
60 [SIGCHLD
] = TARGET_SIGCHLD
,
61 [SIGCONT
] = TARGET_SIGCONT
,
62 [SIGSTOP
] = TARGET_SIGSTOP
,
63 [SIGTSTP
] = TARGET_SIGTSTP
,
64 [SIGTTIN
] = TARGET_SIGTTIN
,
65 [SIGTTOU
] = TARGET_SIGTTOU
,
66 [SIGURG
] = TARGET_SIGURG
,
67 [SIGXCPU
] = TARGET_SIGXCPU
,
68 [SIGXFSZ
] = TARGET_SIGXFSZ
,
69 [SIGVTALRM
] = TARGET_SIGVTALRM
,
70 [SIGPROF
] = TARGET_SIGPROF
,
71 [SIGWINCH
] = TARGET_SIGWINCH
,
72 [SIGIO
] = TARGET_SIGIO
,
73 [SIGPWR
] = TARGET_SIGPWR
,
74 [SIGSYS
] = TARGET_SIGSYS
,
75 /* next signals stay the same */
76 /* Nasty hack: Reverse SIGRTMIN and SIGRTMAX to avoid overlap with
77 host libpthread signals. This assumes no one actually uses SIGRTMAX :-/
78 To fix this properly we need to do manual signal delivery multiplexed
79 over a single host signal. */
80 [__SIGRTMIN
] = __SIGRTMAX
,
81 [__SIGRTMAX
] = __SIGRTMIN
,
83 static uint8_t target_to_host_signal_table
[_NSIG
];
85 static inline int on_sig_stack(unsigned long sp
)
87 return (sp
- target_sigaltstack_used
.ss_sp
88 < target_sigaltstack_used
.ss_size
);
91 static inline int sas_ss_flags(unsigned long sp
)
93 return (target_sigaltstack_used
.ss_size
== 0 ? SS_DISABLE
94 : on_sig_stack(sp
) ? SS_ONSTACK
: 0);
97 int host_to_target_signal(int sig
)
99 if (sig
< 0 || sig
>= _NSIG
)
101 return host_to_target_signal_table
[sig
];
104 int target_to_host_signal(int sig
)
106 if (sig
< 0 || sig
>= _NSIG
)
108 return target_to_host_signal_table
[sig
];
111 static inline void target_sigemptyset(target_sigset_t
*set
)
113 memset(set
, 0, sizeof(*set
));
116 static inline void target_sigaddset(target_sigset_t
*set
, int signum
)
119 abi_ulong mask
= (abi_ulong
)1 << (signum
% TARGET_NSIG_BPW
);
120 set
->sig
[signum
/ TARGET_NSIG_BPW
] |= mask
;
123 static inline int target_sigismember(const target_sigset_t
*set
, int signum
)
126 abi_ulong mask
= (abi_ulong
)1 << (signum
% TARGET_NSIG_BPW
);
127 return ((set
->sig
[signum
/ TARGET_NSIG_BPW
] & mask
) != 0);
130 static void host_to_target_sigset_internal(target_sigset_t
*d
,
134 target_sigemptyset(d
);
135 for (i
= 1; i
<= TARGET_NSIG
; i
++) {
136 if (sigismember(s
, i
)) {
137 target_sigaddset(d
, host_to_target_signal(i
));
142 void host_to_target_sigset(target_sigset_t
*d
, const sigset_t
*s
)
147 host_to_target_sigset_internal(&d1
, s
);
148 for(i
= 0;i
< TARGET_NSIG_WORDS
; i
++)
149 d
->sig
[i
] = tswapal(d1
.sig
[i
]);
152 static void target_to_host_sigset_internal(sigset_t
*d
,
153 const target_sigset_t
*s
)
157 for (i
= 1; i
<= TARGET_NSIG
; i
++) {
158 if (target_sigismember(s
, i
)) {
159 sigaddset(d
, target_to_host_signal(i
));
164 void target_to_host_sigset(sigset_t
*d
, const target_sigset_t
*s
)
169 for(i
= 0;i
< TARGET_NSIG_WORDS
; i
++)
170 s1
.sig
[i
] = tswapal(s
->sig
[i
]);
171 target_to_host_sigset_internal(d
, &s1
);
174 void host_to_target_old_sigset(abi_ulong
*old_sigset
,
175 const sigset_t
*sigset
)
178 host_to_target_sigset(&d
, sigset
);
179 *old_sigset
= d
.sig
[0];
182 void target_to_host_old_sigset(sigset_t
*sigset
,
183 const abi_ulong
*old_sigset
)
188 d
.sig
[0] = *old_sigset
;
189 for(i
= 1;i
< TARGET_NSIG_WORDS
; i
++)
191 target_to_host_sigset(sigset
, &d
);
194 int block_signals(void)
196 TaskState
*ts
= (TaskState
*)thread_cpu
->opaque
;
199 /* It's OK to block everything including SIGSEGV, because we won't
200 * run any further guest code before unblocking signals in
201 * process_pending_signals().
204 sigprocmask(SIG_SETMASK
, &set
, 0);
206 return atomic_xchg(&ts
->signal_pending
, 1);
209 /* Wrapper for sigprocmask function
210 * Emulates a sigprocmask in a safe way for the guest. Note that set and oldset
211 * are host signal set, not guest ones. Returns -TARGET_ERESTARTSYS if
212 * a signal was already pending and the syscall must be restarted, or
214 * If set is NULL, this is guaranteed not to fail.
216 int do_sigprocmask(int how
, const sigset_t
*set
, sigset_t
*oldset
)
218 TaskState
*ts
= (TaskState
*)thread_cpu
->opaque
;
221 *oldset
= ts
->signal_mask
;
227 if (block_signals()) {
228 return -TARGET_ERESTARTSYS
;
233 sigorset(&ts
->signal_mask
, &ts
->signal_mask
, set
);
236 for (i
= 1; i
<= NSIG
; ++i
) {
237 if (sigismember(set
, i
)) {
238 sigdelset(&ts
->signal_mask
, i
);
243 ts
->signal_mask
= *set
;
246 g_assert_not_reached();
249 /* Silently ignore attempts to change blocking status of KILL or STOP */
250 sigdelset(&ts
->signal_mask
, SIGKILL
);
251 sigdelset(&ts
->signal_mask
, SIGSTOP
);
256 #if !defined(TARGET_OPENRISC) && !defined(TARGET_UNICORE32) && \
257 !defined(TARGET_X86_64)
258 /* Just set the guest's signal mask to the specified value; the
259 * caller is assumed to have called block_signals() already.
261 static void set_sigmask(const sigset_t
*set
)
263 TaskState
*ts
= (TaskState
*)thread_cpu
->opaque
;
265 ts
->signal_mask
= *set
;
269 /* siginfo conversion */
271 static inline void host_to_target_siginfo_noswap(target_siginfo_t
*tinfo
,
272 const siginfo_t
*info
)
274 int sig
= host_to_target_signal(info
->si_signo
);
275 int si_code
= info
->si_code
;
277 tinfo
->si_signo
= sig
;
279 tinfo
->si_code
= info
->si_code
;
281 /* This is awkward, because we have to use a combination of
282 * the si_code and si_signo to figure out which of the union's
283 * members are valid. (Within the host kernel it is always possible
284 * to tell, but the kernel carefully avoids giving userspace the
285 * high 16 bits of si_code, so we don't have the information to
286 * do this the easy way...) We therefore make our best guess,
287 * bearing in mind that a guest can spoof most of the si_codes
288 * via rt_sigqueueinfo() if it likes.
290 * Once we have made our guess, we record it in the top 16 bits of
291 * the si_code, so that tswap_siginfo() later can use it.
292 * tswap_siginfo() will strip these top bits out before writing
293 * si_code to the guest (sign-extending the lower bits).
300 /* Sent via kill(), tkill() or tgkill(), or direct from the kernel.
301 * These are the only unspoofable si_code values.
303 tinfo
->_sifields
._kill
._pid
= info
->si_pid
;
304 tinfo
->_sifields
._kill
._uid
= info
->si_uid
;
305 si_type
= QEMU_SI_KILL
;
308 /* Everything else is spoofable. Make best guess based on signal */
311 tinfo
->_sifields
._sigchld
._pid
= info
->si_pid
;
312 tinfo
->_sifields
._sigchld
._uid
= info
->si_uid
;
313 tinfo
->_sifields
._sigchld
._status
314 = host_to_target_waitstatus(info
->si_status
);
315 tinfo
->_sifields
._sigchld
._utime
= info
->si_utime
;
316 tinfo
->_sifields
._sigchld
._stime
= info
->si_stime
;
317 si_type
= QEMU_SI_CHLD
;
320 tinfo
->_sifields
._sigpoll
._band
= info
->si_band
;
321 tinfo
->_sifields
._sigpoll
._fd
= info
->si_fd
;
322 si_type
= QEMU_SI_POLL
;
325 /* Assume a sigqueue()/mq_notify()/rt_sigqueueinfo() source. */
326 tinfo
->_sifields
._rt
._pid
= info
->si_pid
;
327 tinfo
->_sifields
._rt
._uid
= info
->si_uid
;
328 /* XXX: potential problem if 64 bit */
329 tinfo
->_sifields
._rt
._sigval
.sival_ptr
330 = (abi_ulong
)(unsigned long)info
->si_value
.sival_ptr
;
331 si_type
= QEMU_SI_RT
;
337 tinfo
->si_code
= deposit32(si_code
, 16, 16, si_type
);
340 static void tswap_siginfo(target_siginfo_t
*tinfo
,
341 const target_siginfo_t
*info
)
343 int si_type
= extract32(info
->si_code
, 16, 16);
344 int si_code
= sextract32(info
->si_code
, 0, 16);
346 __put_user(info
->si_signo
, &tinfo
->si_signo
);
347 __put_user(info
->si_errno
, &tinfo
->si_errno
);
348 __put_user(si_code
, &tinfo
->si_code
);
350 /* We can use our internal marker of which fields in the structure
351 * are valid, rather than duplicating the guesswork of
352 * host_to_target_siginfo_noswap() here.
356 __put_user(info
->_sifields
._kill
._pid
, &tinfo
->_sifields
._kill
._pid
);
357 __put_user(info
->_sifields
._kill
._uid
, &tinfo
->_sifields
._kill
._uid
);
360 __put_user(info
->_sifields
._timer
._timer1
,
361 &tinfo
->_sifields
._timer
._timer1
);
362 __put_user(info
->_sifields
._timer
._timer2
,
363 &tinfo
->_sifields
._timer
._timer2
);
366 __put_user(info
->_sifields
._sigpoll
._band
,
367 &tinfo
->_sifields
._sigpoll
._band
);
368 __put_user(info
->_sifields
._sigpoll
._fd
,
369 &tinfo
->_sifields
._sigpoll
._fd
);
372 __put_user(info
->_sifields
._sigfault
._addr
,
373 &tinfo
->_sifields
._sigfault
._addr
);
376 __put_user(info
->_sifields
._sigchld
._pid
,
377 &tinfo
->_sifields
._sigchld
._pid
);
378 __put_user(info
->_sifields
._sigchld
._uid
,
379 &tinfo
->_sifields
._sigchld
._uid
);
380 __put_user(info
->_sifields
._sigchld
._status
,
381 &tinfo
->_sifields
._sigchld
._status
);
382 __put_user(info
->_sifields
._sigchld
._utime
,
383 &tinfo
->_sifields
._sigchld
._utime
);
384 __put_user(info
->_sifields
._sigchld
._stime
,
385 &tinfo
->_sifields
._sigchld
._stime
);
388 __put_user(info
->_sifields
._rt
._pid
, &tinfo
->_sifields
._rt
._pid
);
389 __put_user(info
->_sifields
._rt
._uid
, &tinfo
->_sifields
._rt
._uid
);
390 __put_user(info
->_sifields
._rt
._sigval
.sival_ptr
,
391 &tinfo
->_sifields
._rt
._sigval
.sival_ptr
);
394 g_assert_not_reached();
398 void host_to_target_siginfo(target_siginfo_t
*tinfo
, const siginfo_t
*info
)
400 host_to_target_siginfo_noswap(tinfo
, info
);
401 tswap_siginfo(tinfo
, tinfo
);
404 /* XXX: we support only POSIX RT signals are used. */
405 /* XXX: find a solution for 64 bit (additional malloced data is needed) */
406 void target_to_host_siginfo(siginfo_t
*info
, const target_siginfo_t
*tinfo
)
408 /* This conversion is used only for the rt_sigqueueinfo syscall,
409 * and so we know that the _rt fields are the valid ones.
413 __get_user(info
->si_signo
, &tinfo
->si_signo
);
414 __get_user(info
->si_errno
, &tinfo
->si_errno
);
415 __get_user(info
->si_code
, &tinfo
->si_code
);
416 __get_user(info
->si_pid
, &tinfo
->_sifields
._rt
._pid
);
417 __get_user(info
->si_uid
, &tinfo
->_sifields
._rt
._uid
);
418 __get_user(sival_ptr
, &tinfo
->_sifields
._rt
._sigval
.sival_ptr
);
419 info
->si_value
.sival_ptr
= (void *)(long)sival_ptr
;
422 static int fatal_signal (int sig
)
427 case TARGET_SIGWINCH
:
428 /* Ignored by default. */
435 /* Job control signals. */
442 /* returns 1 if given signal should dump core if not handled */
443 static int core_dump_signal(int sig
)
459 void signal_init(void)
461 TaskState
*ts
= (TaskState
*)thread_cpu
->opaque
;
462 struct sigaction act
;
463 struct sigaction oact
;
467 /* generate signal conversion tables */
468 for(i
= 1; i
< _NSIG
; i
++) {
469 if (host_to_target_signal_table
[i
] == 0)
470 host_to_target_signal_table
[i
] = i
;
472 for(i
= 1; i
< _NSIG
; i
++) {
473 j
= host_to_target_signal_table
[i
];
474 target_to_host_signal_table
[j
] = i
;
477 /* Set the signal mask from the host mask. */
478 sigprocmask(0, 0, &ts
->signal_mask
);
480 /* set all host signal handlers. ALL signals are blocked during
481 the handlers to serialize them. */
482 memset(sigact_table
, 0, sizeof(sigact_table
));
484 sigfillset(&act
.sa_mask
);
485 act
.sa_flags
= SA_SIGINFO
;
486 act
.sa_sigaction
= host_signal_handler
;
487 for(i
= 1; i
<= TARGET_NSIG
; i
++) {
488 host_sig
= target_to_host_signal(i
);
489 sigaction(host_sig
, NULL
, &oact
);
490 if (oact
.sa_sigaction
== (void *)SIG_IGN
) {
491 sigact_table
[i
- 1]._sa_handler
= TARGET_SIG_IGN
;
492 } else if (oact
.sa_sigaction
== (void *)SIG_DFL
) {
493 sigact_table
[i
- 1]._sa_handler
= TARGET_SIG_DFL
;
495 /* If there's already a handler installed then something has
496 gone horribly wrong, so don't even try to handle that case. */
497 /* Install some handlers for our own use. We need at least
498 SIGSEGV and SIGBUS, to detect exceptions. We can not just
499 trap all signals because it affects syscall interrupt
500 behavior. But do trap all default-fatal signals. */
501 if (fatal_signal (i
))
502 sigaction(host_sig
, &act
, NULL
);
507 /* abort execution with signal */
508 static void QEMU_NORETURN
force_sig(int target_sig
)
510 CPUState
*cpu
= thread_cpu
;
511 CPUArchState
*env
= cpu
->env_ptr
;
512 TaskState
*ts
= (TaskState
*)cpu
->opaque
;
513 int host_sig
, core_dumped
= 0;
514 struct sigaction act
;
516 host_sig
= target_to_host_signal(target_sig
);
517 trace_user_force_sig(env
, target_sig
, host_sig
);
518 gdb_signalled(env
, target_sig
);
520 /* dump core if supported by target binary format */
521 if (core_dump_signal(target_sig
) && (ts
->bprm
->core_dump
!= NULL
)) {
524 ((*ts
->bprm
->core_dump
)(target_sig
, env
) == 0);
527 /* we already dumped the core of target process, we don't want
528 * a coredump of qemu itself */
529 struct rlimit nodump
;
530 getrlimit(RLIMIT_CORE
, &nodump
);
532 setrlimit(RLIMIT_CORE
, &nodump
);
533 (void) fprintf(stderr
, "qemu: uncaught target signal %d (%s) - %s\n",
534 target_sig
, strsignal(host_sig
), "core dumped" );
537 /* The proper exit code for dying from an uncaught signal is
538 * -<signal>. The kernel doesn't allow exit() or _exit() to pass
539 * a negative value. To get the proper exit code we need to
540 * actually die from an uncaught signal. Here the default signal
541 * handler is installed, we send ourself a signal and we wait for
543 sigfillset(&act
.sa_mask
);
544 act
.sa_handler
= SIG_DFL
;
546 sigaction(host_sig
, &act
, NULL
);
548 /* For some reason raise(host_sig) doesn't send the signal when
549 * statically linked on x86-64. */
550 kill(getpid(), host_sig
);
552 /* Make sure the signal isn't masked (just reuse the mask inside
554 sigdelset(&act
.sa_mask
, host_sig
);
555 sigsuspend(&act
.sa_mask
);
561 /* queue a signal so that it will be send to the virtual CPU as soon
563 int queue_signal(CPUArchState
*env
, int sig
, target_siginfo_t
*info
)
565 CPUState
*cpu
= ENV_GET_CPU(env
);
566 TaskState
*ts
= cpu
->opaque
;
568 trace_user_queue_signal(env
, sig
);
570 /* Currently all callers define siginfo structures which
571 * use the _sifields._sigfault union member, so we can
572 * set the type here. If that changes we should push this
573 * out so the si_type is passed in by callers.
575 info
->si_code
= deposit32(info
->si_code
, 16, 16, QEMU_SI_FAULT
);
577 ts
->sync_signal
.info
= *info
;
578 ts
->sync_signal
.pending
= sig
;
579 /* signal that a new signal is pending */
580 atomic_set(&ts
->signal_pending
, 1);
581 return 1; /* indicates that the signal was queued */
584 #ifndef HAVE_SAFE_SYSCALL
585 static inline void rewind_if_in_safe_syscall(void *puc
)
587 /* Default version: never rewind */
591 static void host_signal_handler(int host_signum
, siginfo_t
*info
,
594 CPUArchState
*env
= thread_cpu
->env_ptr
;
595 CPUState
*cpu
= ENV_GET_CPU(env
);
596 TaskState
*ts
= cpu
->opaque
;
599 target_siginfo_t tinfo
;
600 ucontext_t
*uc
= puc
;
601 struct emulated_sigtable
*k
;
603 /* the CPU emulator uses some host signals to detect exceptions,
604 we forward to it some signals */
605 if ((host_signum
== SIGSEGV
|| host_signum
== SIGBUS
)
606 && info
->si_code
> 0) {
607 if (cpu_signal_handler(host_signum
, info
, puc
))
611 /* get target signal number */
612 sig
= host_to_target_signal(host_signum
);
613 if (sig
< 1 || sig
> TARGET_NSIG
)
615 trace_user_host_signal(env
, host_signum
, sig
);
617 rewind_if_in_safe_syscall(puc
);
619 host_to_target_siginfo_noswap(&tinfo
, info
);
620 k
= &ts
->sigtab
[sig
- 1];
623 ts
->signal_pending
= 1;
625 /* Block host signals until target signal handler entered. We
626 * can't block SIGSEGV or SIGBUS while we're executing guest
627 * code in case the guest code provokes one in the window between
628 * now and it getting out to the main loop. Signals will be
629 * unblocked again in process_pending_signals().
631 sigfillset(&uc
->uc_sigmask
);
632 sigdelset(&uc
->uc_sigmask
, SIGSEGV
);
633 sigdelset(&uc
->uc_sigmask
, SIGBUS
);
635 /* interrupt the virtual CPU as soon as possible */
636 cpu_exit(thread_cpu
);
639 /* do_sigaltstack() returns target values and errnos. */
640 /* compare linux/kernel/signal.c:do_sigaltstack() */
641 abi_long
do_sigaltstack(abi_ulong uss_addr
, abi_ulong uoss_addr
, abi_ulong sp
)
644 struct target_sigaltstack oss
;
646 /* XXX: test errors */
649 __put_user(target_sigaltstack_used
.ss_sp
, &oss
.ss_sp
);
650 __put_user(target_sigaltstack_used
.ss_size
, &oss
.ss_size
);
651 __put_user(sas_ss_flags(sp
), &oss
.ss_flags
);
656 struct target_sigaltstack
*uss
;
657 struct target_sigaltstack ss
;
658 size_t minstacksize
= TARGET_MINSIGSTKSZ
;
660 #if defined(TARGET_PPC64)
661 /* ELF V2 for PPC64 has a 4K minimum stack size for signal handlers */
662 struct image_info
*image
= ((TaskState
*)thread_cpu
->opaque
)->info
;
663 if (get_ppc64_abi(image
) > 1) {
668 ret
= -TARGET_EFAULT
;
669 if (!lock_user_struct(VERIFY_READ
, uss
, uss_addr
, 1)) {
672 __get_user(ss
.ss_sp
, &uss
->ss_sp
);
673 __get_user(ss
.ss_size
, &uss
->ss_size
);
674 __get_user(ss
.ss_flags
, &uss
->ss_flags
);
675 unlock_user_struct(uss
, uss_addr
, 0);
678 if (on_sig_stack(sp
))
681 ret
= -TARGET_EINVAL
;
682 if (ss
.ss_flags
!= TARGET_SS_DISABLE
683 && ss
.ss_flags
!= TARGET_SS_ONSTACK
687 if (ss
.ss_flags
== TARGET_SS_DISABLE
) {
691 ret
= -TARGET_ENOMEM
;
692 if (ss
.ss_size
< minstacksize
) {
697 target_sigaltstack_used
.ss_sp
= ss
.ss_sp
;
698 target_sigaltstack_used
.ss_size
= ss
.ss_size
;
702 ret
= -TARGET_EFAULT
;
703 if (copy_to_user(uoss_addr
, &oss
, sizeof(oss
)))
712 /* do_sigaction() return target values and host errnos */
713 int do_sigaction(int sig
, const struct target_sigaction
*act
,
714 struct target_sigaction
*oact
)
716 struct target_sigaction
*k
;
717 struct sigaction act1
;
721 if (sig
< 1 || sig
> TARGET_NSIG
|| sig
== TARGET_SIGKILL
|| sig
== TARGET_SIGSTOP
) {
722 return -TARGET_EINVAL
;
725 if (block_signals()) {
726 return -TARGET_ERESTARTSYS
;
729 k
= &sigact_table
[sig
- 1];
731 __put_user(k
->_sa_handler
, &oact
->_sa_handler
);
732 __put_user(k
->sa_flags
, &oact
->sa_flags
);
733 #if !defined(TARGET_MIPS)
734 __put_user(k
->sa_restorer
, &oact
->sa_restorer
);
737 oact
->sa_mask
= k
->sa_mask
;
740 /* FIXME: This is not threadsafe. */
741 __get_user(k
->_sa_handler
, &act
->_sa_handler
);
742 __get_user(k
->sa_flags
, &act
->sa_flags
);
743 #if !defined(TARGET_MIPS)
744 __get_user(k
->sa_restorer
, &act
->sa_restorer
);
746 /* To be swapped in target_to_host_sigset. */
747 k
->sa_mask
= act
->sa_mask
;
749 /* we update the host linux signal state */
750 host_sig
= target_to_host_signal(sig
);
751 if (host_sig
!= SIGSEGV
&& host_sig
!= SIGBUS
) {
752 sigfillset(&act1
.sa_mask
);
753 act1
.sa_flags
= SA_SIGINFO
;
754 if (k
->sa_flags
& TARGET_SA_RESTART
)
755 act1
.sa_flags
|= SA_RESTART
;
756 /* NOTE: it is important to update the host kernel signal
757 ignore state to avoid getting unexpected interrupted
759 if (k
->_sa_handler
== TARGET_SIG_IGN
) {
760 act1
.sa_sigaction
= (void *)SIG_IGN
;
761 } else if (k
->_sa_handler
== TARGET_SIG_DFL
) {
762 if (fatal_signal (sig
))
763 act1
.sa_sigaction
= host_signal_handler
;
765 act1
.sa_sigaction
= (void *)SIG_DFL
;
767 act1
.sa_sigaction
= host_signal_handler
;
769 ret
= sigaction(host_sig
, &act1
, NULL
);
775 #if defined(TARGET_I386) && TARGET_ABI_BITS == 32
777 /* from the Linux kernel */
779 struct target_fpreg
{
780 uint16_t significand
[4];
784 struct target_fpxreg
{
785 uint16_t significand
[4];
790 struct target_xmmreg
{
791 abi_ulong element
[4];
794 struct target_fpstate
{
795 /* Regular FPU environment */
803 struct target_fpreg _st
[8];
805 uint16_t magic
; /* 0xffff = regular FPU data only */
807 /* FXSR FPU environment */
808 abi_ulong _fxsr_env
[6]; /* FXSR FPU env is ignored */
811 struct target_fpxreg _fxsr_st
[8]; /* FXSR FPU reg data is ignored */
812 struct target_xmmreg _xmm
[8];
813 abi_ulong padding
[56];
816 #define X86_FXSR_MAGIC 0x0000
818 struct target_sigcontext
{
836 abi_ulong esp_at_signal
;
838 abi_ulong fpstate
; /* pointer */
843 struct target_ucontext
{
846 target_stack_t tuc_stack
;
847 struct target_sigcontext tuc_mcontext
;
848 target_sigset_t tuc_sigmask
; /* mask last for extensibility */
855 struct target_sigcontext sc
;
856 struct target_fpstate fpstate
;
857 abi_ulong extramask
[TARGET_NSIG_WORDS
-1];
867 struct target_siginfo info
;
868 struct target_ucontext uc
;
869 struct target_fpstate fpstate
;
874 * Set up a signal frame.
877 /* XXX: save x87 state */
878 static void setup_sigcontext(struct target_sigcontext
*sc
,
879 struct target_fpstate
*fpstate
, CPUX86State
*env
, abi_ulong mask
,
880 abi_ulong fpstate_addr
)
882 CPUState
*cs
= CPU(x86_env_get_cpu(env
));
885 /* already locked in setup_frame() */
886 __put_user(env
->segs
[R_GS
].selector
, (unsigned int *)&sc
->gs
);
887 __put_user(env
->segs
[R_FS
].selector
, (unsigned int *)&sc
->fs
);
888 __put_user(env
->segs
[R_ES
].selector
, (unsigned int *)&sc
->es
);
889 __put_user(env
->segs
[R_DS
].selector
, (unsigned int *)&sc
->ds
);
890 __put_user(env
->regs
[R_EDI
], &sc
->edi
);
891 __put_user(env
->regs
[R_ESI
], &sc
->esi
);
892 __put_user(env
->regs
[R_EBP
], &sc
->ebp
);
893 __put_user(env
->regs
[R_ESP
], &sc
->esp
);
894 __put_user(env
->regs
[R_EBX
], &sc
->ebx
);
895 __put_user(env
->regs
[R_EDX
], &sc
->edx
);
896 __put_user(env
->regs
[R_ECX
], &sc
->ecx
);
897 __put_user(env
->regs
[R_EAX
], &sc
->eax
);
898 __put_user(cs
->exception_index
, &sc
->trapno
);
899 __put_user(env
->error_code
, &sc
->err
);
900 __put_user(env
->eip
, &sc
->eip
);
901 __put_user(env
->segs
[R_CS
].selector
, (unsigned int *)&sc
->cs
);
902 __put_user(env
->eflags
, &sc
->eflags
);
903 __put_user(env
->regs
[R_ESP
], &sc
->esp_at_signal
);
904 __put_user(env
->segs
[R_SS
].selector
, (unsigned int *)&sc
->ss
);
906 cpu_x86_fsave(env
, fpstate_addr
, 1);
907 fpstate
->status
= fpstate
->sw
;
909 __put_user(magic
, &fpstate
->magic
);
910 __put_user(fpstate_addr
, &sc
->fpstate
);
912 /* non-iBCS2 extensions.. */
913 __put_user(mask
, &sc
->oldmask
);
914 __put_user(env
->cr
[2], &sc
->cr2
);
918 * Determine which stack to use..
921 static inline abi_ulong
922 get_sigframe(struct target_sigaction
*ka
, CPUX86State
*env
, size_t frame_size
)
926 /* Default to using normal stack */
927 esp
= env
->regs
[R_ESP
];
928 /* This is the X/Open sanctioned signal stack switching. */
929 if (ka
->sa_flags
& TARGET_SA_ONSTACK
) {
930 if (sas_ss_flags(esp
) == 0) {
931 esp
= target_sigaltstack_used
.ss_sp
+ target_sigaltstack_used
.ss_size
;
935 /* This is the legacy signal stack switching. */
936 if ((env
->segs
[R_SS
].selector
& 0xffff) != __USER_DS
&&
937 !(ka
->sa_flags
& TARGET_SA_RESTORER
) &&
939 esp
= (unsigned long) ka
->sa_restorer
;
942 return (esp
- frame_size
) & -8ul;
945 /* compare linux/arch/i386/kernel/signal.c:setup_frame() */
946 static void setup_frame(int sig
, struct target_sigaction
*ka
,
947 target_sigset_t
*set
, CPUX86State
*env
)
949 abi_ulong frame_addr
;
950 struct sigframe
*frame
;
953 frame_addr
= get_sigframe(ka
, env
, sizeof(*frame
));
954 trace_user_setup_frame(env
, frame_addr
);
956 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0))
959 __put_user(sig
, &frame
->sig
);
961 setup_sigcontext(&frame
->sc
, &frame
->fpstate
, env
, set
->sig
[0],
962 frame_addr
+ offsetof(struct sigframe
, fpstate
));
964 for(i
= 1; i
< TARGET_NSIG_WORDS
; i
++) {
965 __put_user(set
->sig
[i
], &frame
->extramask
[i
- 1]);
968 /* Set up to return from userspace. If provided, use a stub
969 already in userspace. */
970 if (ka
->sa_flags
& TARGET_SA_RESTORER
) {
971 __put_user(ka
->sa_restorer
, &frame
->pretcode
);
974 abi_ulong retcode_addr
;
975 retcode_addr
= frame_addr
+ offsetof(struct sigframe
, retcode
);
976 __put_user(retcode_addr
, &frame
->pretcode
);
977 /* This is popl %eax ; movl $,%eax ; int $0x80 */
979 __put_user(val16
, (uint16_t *)(frame
->retcode
+0));
980 __put_user(TARGET_NR_sigreturn
, (int *)(frame
->retcode
+2));
982 __put_user(val16
, (uint16_t *)(frame
->retcode
+6));
986 /* Set up registers for signal handler */
987 env
->regs
[R_ESP
] = frame_addr
;
988 env
->eip
= ka
->_sa_handler
;
990 cpu_x86_load_seg(env
, R_DS
, __USER_DS
);
991 cpu_x86_load_seg(env
, R_ES
, __USER_DS
);
992 cpu_x86_load_seg(env
, R_SS
, __USER_DS
);
993 cpu_x86_load_seg(env
, R_CS
, __USER_CS
);
994 env
->eflags
&= ~TF_MASK
;
996 unlock_user_struct(frame
, frame_addr
, 1);
1001 if (sig
== TARGET_SIGSEGV
) {
1002 ka
->_sa_handler
= TARGET_SIG_DFL
;
1004 force_sig(TARGET_SIGSEGV
/* , current */);
1007 /* compare linux/arch/i386/kernel/signal.c:setup_rt_frame() */
1008 static void setup_rt_frame(int sig
, struct target_sigaction
*ka
,
1009 target_siginfo_t
*info
,
1010 target_sigset_t
*set
, CPUX86State
*env
)
1012 abi_ulong frame_addr
, addr
;
1013 struct rt_sigframe
*frame
;
1016 frame_addr
= get_sigframe(ka
, env
, sizeof(*frame
));
1017 trace_user_setup_rt_frame(env
, frame_addr
);
1019 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0))
1022 __put_user(sig
, &frame
->sig
);
1023 addr
= frame_addr
+ offsetof(struct rt_sigframe
, info
);
1024 __put_user(addr
, &frame
->pinfo
);
1025 addr
= frame_addr
+ offsetof(struct rt_sigframe
, uc
);
1026 __put_user(addr
, &frame
->puc
);
1027 tswap_siginfo(&frame
->info
, info
);
1029 /* Create the ucontext. */
1030 __put_user(0, &frame
->uc
.tuc_flags
);
1031 __put_user(0, &frame
->uc
.tuc_link
);
1032 __put_user(target_sigaltstack_used
.ss_sp
, &frame
->uc
.tuc_stack
.ss_sp
);
1033 __put_user(sas_ss_flags(get_sp_from_cpustate(env
)),
1034 &frame
->uc
.tuc_stack
.ss_flags
);
1035 __put_user(target_sigaltstack_used
.ss_size
,
1036 &frame
->uc
.tuc_stack
.ss_size
);
1037 setup_sigcontext(&frame
->uc
.tuc_mcontext
, &frame
->fpstate
, env
,
1038 set
->sig
[0], frame_addr
+ offsetof(struct rt_sigframe
, fpstate
));
1040 for(i
= 0; i
< TARGET_NSIG_WORDS
; i
++) {
1041 __put_user(set
->sig
[i
], &frame
->uc
.tuc_sigmask
.sig
[i
]);
1044 /* Set up to return from userspace. If provided, use a stub
1045 already in userspace. */
1046 if (ka
->sa_flags
& TARGET_SA_RESTORER
) {
1047 __put_user(ka
->sa_restorer
, &frame
->pretcode
);
1050 addr
= frame_addr
+ offsetof(struct rt_sigframe
, retcode
);
1051 __put_user(addr
, &frame
->pretcode
);
1052 /* This is movl $,%eax ; int $0x80 */
1053 __put_user(0xb8, (char *)(frame
->retcode
+0));
1054 __put_user(TARGET_NR_rt_sigreturn
, (int *)(frame
->retcode
+1));
1056 __put_user(val16
, (uint16_t *)(frame
->retcode
+5));
1059 /* Set up registers for signal handler */
1060 env
->regs
[R_ESP
] = frame_addr
;
1061 env
->eip
= ka
->_sa_handler
;
1063 cpu_x86_load_seg(env
, R_DS
, __USER_DS
);
1064 cpu_x86_load_seg(env
, R_ES
, __USER_DS
);
1065 cpu_x86_load_seg(env
, R_SS
, __USER_DS
);
1066 cpu_x86_load_seg(env
, R_CS
, __USER_CS
);
1067 env
->eflags
&= ~TF_MASK
;
1069 unlock_user_struct(frame
, frame_addr
, 1);
1074 if (sig
== TARGET_SIGSEGV
) {
1075 ka
->_sa_handler
= TARGET_SIG_DFL
;
1077 force_sig(TARGET_SIGSEGV
/* , current */);
1081 restore_sigcontext(CPUX86State
*env
, struct target_sigcontext
*sc
)
1083 unsigned int err
= 0;
1084 abi_ulong fpstate_addr
;
1085 unsigned int tmpflags
;
1087 cpu_x86_load_seg(env
, R_GS
, tswap16(sc
->gs
));
1088 cpu_x86_load_seg(env
, R_FS
, tswap16(sc
->fs
));
1089 cpu_x86_load_seg(env
, R_ES
, tswap16(sc
->es
));
1090 cpu_x86_load_seg(env
, R_DS
, tswap16(sc
->ds
));
1092 env
->regs
[R_EDI
] = tswapl(sc
->edi
);
1093 env
->regs
[R_ESI
] = tswapl(sc
->esi
);
1094 env
->regs
[R_EBP
] = tswapl(sc
->ebp
);
1095 env
->regs
[R_ESP
] = tswapl(sc
->esp
);
1096 env
->regs
[R_EBX
] = tswapl(sc
->ebx
);
1097 env
->regs
[R_EDX
] = tswapl(sc
->edx
);
1098 env
->regs
[R_ECX
] = tswapl(sc
->ecx
);
1099 env
->regs
[R_EAX
] = tswapl(sc
->eax
);
1100 env
->eip
= tswapl(sc
->eip
);
1102 cpu_x86_load_seg(env
, R_CS
, lduw_p(&sc
->cs
) | 3);
1103 cpu_x86_load_seg(env
, R_SS
, lduw_p(&sc
->ss
) | 3);
1105 tmpflags
= tswapl(sc
->eflags
);
1106 env
->eflags
= (env
->eflags
& ~0x40DD5) | (tmpflags
& 0x40DD5);
1107 // regs->orig_eax = -1; /* disable syscall checks */
1109 fpstate_addr
= tswapl(sc
->fpstate
);
1110 if (fpstate_addr
!= 0) {
1111 if (!access_ok(VERIFY_READ
, fpstate_addr
,
1112 sizeof(struct target_fpstate
)))
1114 cpu_x86_frstor(env
, fpstate_addr
, 1);
1122 long do_sigreturn(CPUX86State
*env
)
1124 struct sigframe
*frame
;
1125 abi_ulong frame_addr
= env
->regs
[R_ESP
] - 8;
1126 target_sigset_t target_set
;
1130 trace_user_do_sigreturn(env
, frame_addr
);
1131 if (!lock_user_struct(VERIFY_READ
, frame
, frame_addr
, 1))
1133 /* set blocked signals */
1134 __get_user(target_set
.sig
[0], &frame
->sc
.oldmask
);
1135 for(i
= 1; i
< TARGET_NSIG_WORDS
; i
++) {
1136 __get_user(target_set
.sig
[i
], &frame
->extramask
[i
- 1]);
1139 target_to_host_sigset_internal(&set
, &target_set
);
1142 /* restore registers */
1143 if (restore_sigcontext(env
, &frame
->sc
))
1145 unlock_user_struct(frame
, frame_addr
, 0);
1146 return -TARGET_QEMU_ESIGRETURN
;
1149 unlock_user_struct(frame
, frame_addr
, 0);
1150 force_sig(TARGET_SIGSEGV
);
1154 long do_rt_sigreturn(CPUX86State
*env
)
1156 abi_ulong frame_addr
;
1157 struct rt_sigframe
*frame
;
1160 frame_addr
= env
->regs
[R_ESP
] - 4;
1161 trace_user_do_rt_sigreturn(env
, frame_addr
);
1162 if (!lock_user_struct(VERIFY_READ
, frame
, frame_addr
, 1))
1164 target_to_host_sigset(&set
, &frame
->uc
.tuc_sigmask
);
1167 if (restore_sigcontext(env
, &frame
->uc
.tuc_mcontext
)) {
1171 if (do_sigaltstack(frame_addr
+ offsetof(struct rt_sigframe
, uc
.tuc_stack
), 0,
1172 get_sp_from_cpustate(env
)) == -EFAULT
) {
1176 unlock_user_struct(frame
, frame_addr
, 0);
1177 return -TARGET_QEMU_ESIGRETURN
;
1180 unlock_user_struct(frame
, frame_addr
, 0);
1181 force_sig(TARGET_SIGSEGV
);
1185 #elif defined(TARGET_AARCH64)
1187 struct target_sigcontext
{
1188 uint64_t fault_address
;
1189 /* AArch64 registers */
1194 /* 4K reserved for FP/SIMD state and future expansion */
1195 char __reserved
[4096] __attribute__((__aligned__(16)));
1198 struct target_ucontext
{
1199 abi_ulong tuc_flags
;
1201 target_stack_t tuc_stack
;
1202 target_sigset_t tuc_sigmask
;
1203 /* glibc uses a 1024-bit sigset_t */
1204 char __unused
[1024 / 8 - sizeof(target_sigset_t
)];
1205 /* last for future expansion */
1206 struct target_sigcontext tuc_mcontext
;
1210 * Header to be used at the beginning of structures extending the user
1211 * context. Such structures must be placed after the rt_sigframe on the stack
1212 * and be 16-byte aligned. The last structure must be a dummy one with the
1213 * magic and size set to 0.
1215 struct target_aarch64_ctx
{
1220 #define TARGET_FPSIMD_MAGIC 0x46508001
1222 struct target_fpsimd_context
{
1223 struct target_aarch64_ctx head
;
1226 uint64_t vregs
[32 * 2]; /* really uint128_t vregs[32] */
1230 * Auxiliary context saved in the sigcontext.__reserved array. Not exported to
1231 * user space as it will change with the addition of new context. User space
1232 * should check the magic/size information.
1234 struct target_aux_context
{
1235 struct target_fpsimd_context fpsimd
;
1236 /* additional context to be added before "end" */
1237 struct target_aarch64_ctx end
;
1240 struct target_rt_sigframe
{
1241 struct target_siginfo info
;
1242 struct target_ucontext uc
;
1248 static int target_setup_sigframe(struct target_rt_sigframe
*sf
,
1249 CPUARMState
*env
, target_sigset_t
*set
)
1252 struct target_aux_context
*aux
=
1253 (struct target_aux_context
*)sf
->uc
.tuc_mcontext
.__reserved
;
1255 /* set up the stack frame for unwinding */
1256 __put_user(env
->xregs
[29], &sf
->fp
);
1257 __put_user(env
->xregs
[30], &sf
->lr
);
1259 for (i
= 0; i
< 31; i
++) {
1260 __put_user(env
->xregs
[i
], &sf
->uc
.tuc_mcontext
.regs
[i
]);
1262 __put_user(env
->xregs
[31], &sf
->uc
.tuc_mcontext
.sp
);
1263 __put_user(env
->pc
, &sf
->uc
.tuc_mcontext
.pc
);
1264 __put_user(pstate_read(env
), &sf
->uc
.tuc_mcontext
.pstate
);
1266 __put_user(env
->exception
.vaddress
, &sf
->uc
.tuc_mcontext
.fault_address
);
1268 for (i
= 0; i
< TARGET_NSIG_WORDS
; i
++) {
1269 __put_user(set
->sig
[i
], &sf
->uc
.tuc_sigmask
.sig
[i
]);
1272 for (i
= 0; i
< 32; i
++) {
1273 #ifdef TARGET_WORDS_BIGENDIAN
1274 __put_user(env
->vfp
.regs
[i
* 2], &aux
->fpsimd
.vregs
[i
* 2 + 1]);
1275 __put_user(env
->vfp
.regs
[i
* 2 + 1], &aux
->fpsimd
.vregs
[i
* 2]);
1277 __put_user(env
->vfp
.regs
[i
* 2], &aux
->fpsimd
.vregs
[i
* 2]);
1278 __put_user(env
->vfp
.regs
[i
* 2 + 1], &aux
->fpsimd
.vregs
[i
* 2 + 1]);
1281 __put_user(vfp_get_fpsr(env
), &aux
->fpsimd
.fpsr
);
1282 __put_user(vfp_get_fpcr(env
), &aux
->fpsimd
.fpcr
);
1283 __put_user(TARGET_FPSIMD_MAGIC
, &aux
->fpsimd
.head
.magic
);
1284 __put_user(sizeof(struct target_fpsimd_context
),
1285 &aux
->fpsimd
.head
.size
);
1287 /* set the "end" magic */
1288 __put_user(0, &aux
->end
.magic
);
1289 __put_user(0, &aux
->end
.size
);
1294 static int target_restore_sigframe(CPUARMState
*env
,
1295 struct target_rt_sigframe
*sf
)
1299 struct target_aux_context
*aux
=
1300 (struct target_aux_context
*)sf
->uc
.tuc_mcontext
.__reserved
;
1301 uint32_t magic
, size
, fpsr
, fpcr
;
1304 target_to_host_sigset(&set
, &sf
->uc
.tuc_sigmask
);
1307 for (i
= 0; i
< 31; i
++) {
1308 __get_user(env
->xregs
[i
], &sf
->uc
.tuc_mcontext
.regs
[i
]);
1311 __get_user(env
->xregs
[31], &sf
->uc
.tuc_mcontext
.sp
);
1312 __get_user(env
->pc
, &sf
->uc
.tuc_mcontext
.pc
);
1313 __get_user(pstate
, &sf
->uc
.tuc_mcontext
.pstate
);
1314 pstate_write(env
, pstate
);
1316 __get_user(magic
, &aux
->fpsimd
.head
.magic
);
1317 __get_user(size
, &aux
->fpsimd
.head
.size
);
1319 if (magic
!= TARGET_FPSIMD_MAGIC
1320 || size
!= sizeof(struct target_fpsimd_context
)) {
1324 for (i
= 0; i
< 32; i
++) {
1325 #ifdef TARGET_WORDS_BIGENDIAN
1326 __get_user(env
->vfp
.regs
[i
* 2], &aux
->fpsimd
.vregs
[i
* 2 + 1]);
1327 __get_user(env
->vfp
.regs
[i
* 2 + 1], &aux
->fpsimd
.vregs
[i
* 2]);
1329 __get_user(env
->vfp
.regs
[i
* 2], &aux
->fpsimd
.vregs
[i
* 2]);
1330 __get_user(env
->vfp
.regs
[i
* 2 + 1], &aux
->fpsimd
.vregs
[i
* 2 + 1]);
1333 __get_user(fpsr
, &aux
->fpsimd
.fpsr
);
1334 vfp_set_fpsr(env
, fpsr
);
1335 __get_user(fpcr
, &aux
->fpsimd
.fpcr
);
1336 vfp_set_fpcr(env
, fpcr
);
1341 static abi_ulong
get_sigframe(struct target_sigaction
*ka
, CPUARMState
*env
)
1345 sp
= env
->xregs
[31];
1348 * This is the X/Open sanctioned signal stack switching.
1350 if ((ka
->sa_flags
& TARGET_SA_ONSTACK
) && !sas_ss_flags(sp
)) {
1351 sp
= target_sigaltstack_used
.ss_sp
+ target_sigaltstack_used
.ss_size
;
1354 sp
= (sp
- sizeof(struct target_rt_sigframe
)) & ~15;
1359 static void target_setup_frame(int usig
, struct target_sigaction
*ka
,
1360 target_siginfo_t
*info
, target_sigset_t
*set
,
1363 struct target_rt_sigframe
*frame
;
1364 abi_ulong frame_addr
, return_addr
;
1366 frame_addr
= get_sigframe(ka
, env
);
1367 trace_user_setup_frame(env
, frame_addr
);
1368 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0)) {
1372 __put_user(0, &frame
->uc
.tuc_flags
);
1373 __put_user(0, &frame
->uc
.tuc_link
);
1375 __put_user(target_sigaltstack_used
.ss_sp
,
1376 &frame
->uc
.tuc_stack
.ss_sp
);
1377 __put_user(sas_ss_flags(env
->xregs
[31]),
1378 &frame
->uc
.tuc_stack
.ss_flags
);
1379 __put_user(target_sigaltstack_used
.ss_size
,
1380 &frame
->uc
.tuc_stack
.ss_size
);
1381 target_setup_sigframe(frame
, env
, set
);
1382 if (ka
->sa_flags
& TARGET_SA_RESTORER
) {
1383 return_addr
= ka
->sa_restorer
;
1385 /* mov x8,#__NR_rt_sigreturn; svc #0 */
1386 __put_user(0xd2801168, &frame
->tramp
[0]);
1387 __put_user(0xd4000001, &frame
->tramp
[1]);
1388 return_addr
= frame_addr
+ offsetof(struct target_rt_sigframe
, tramp
);
1390 env
->xregs
[0] = usig
;
1391 env
->xregs
[31] = frame_addr
;
1392 env
->xregs
[29] = env
->xregs
[31] + offsetof(struct target_rt_sigframe
, fp
);
1393 env
->pc
= ka
->_sa_handler
;
1394 env
->xregs
[30] = return_addr
;
1396 tswap_siginfo(&frame
->info
, info
);
1397 env
->xregs
[1] = frame_addr
+ offsetof(struct target_rt_sigframe
, info
);
1398 env
->xregs
[2] = frame_addr
+ offsetof(struct target_rt_sigframe
, uc
);
1401 unlock_user_struct(frame
, frame_addr
, 1);
1405 unlock_user_struct(frame
, frame_addr
, 1);
1406 force_sig(TARGET_SIGSEGV
);
1409 static void setup_rt_frame(int sig
, struct target_sigaction
*ka
,
1410 target_siginfo_t
*info
, target_sigset_t
*set
,
1413 target_setup_frame(sig
, ka
, info
, set
, env
);
1416 static void setup_frame(int sig
, struct target_sigaction
*ka
,
1417 target_sigset_t
*set
, CPUARMState
*env
)
1419 target_setup_frame(sig
, ka
, 0, set
, env
);
1422 long do_rt_sigreturn(CPUARMState
*env
)
1424 struct target_rt_sigframe
*frame
= NULL
;
1425 abi_ulong frame_addr
= env
->xregs
[31];
1427 trace_user_do_rt_sigreturn(env
, frame_addr
);
1428 if (frame_addr
& 15) {
1432 if (!lock_user_struct(VERIFY_READ
, frame
, frame_addr
, 1)) {
1436 if (target_restore_sigframe(env
, frame
)) {
1440 if (do_sigaltstack(frame_addr
+
1441 offsetof(struct target_rt_sigframe
, uc
.tuc_stack
),
1442 0, get_sp_from_cpustate(env
)) == -EFAULT
) {
1446 unlock_user_struct(frame
, frame_addr
, 0);
1447 return -TARGET_QEMU_ESIGRETURN
;
1450 unlock_user_struct(frame
, frame_addr
, 0);
1451 force_sig(TARGET_SIGSEGV
);
1455 long do_sigreturn(CPUARMState
*env
)
1457 return do_rt_sigreturn(env
);
1460 #elif defined(TARGET_ARM)
1462 struct target_sigcontext
{
1464 abi_ulong error_code
;
1483 abi_ulong fault_address
;
1486 struct target_ucontext_v1
{
1487 abi_ulong tuc_flags
;
1489 target_stack_t tuc_stack
;
1490 struct target_sigcontext tuc_mcontext
;
1491 target_sigset_t tuc_sigmask
; /* mask last for extensibility */
1494 struct target_ucontext_v2
{
1495 abi_ulong tuc_flags
;
1497 target_stack_t tuc_stack
;
1498 struct target_sigcontext tuc_mcontext
;
1499 target_sigset_t tuc_sigmask
; /* mask last for extensibility */
1500 char __unused
[128 - sizeof(target_sigset_t
)];
1501 abi_ulong tuc_regspace
[128] __attribute__((__aligned__(8)));
1504 struct target_user_vfp
{
1505 uint64_t fpregs
[32];
1509 struct target_user_vfp_exc
{
1515 struct target_vfp_sigframe
{
1518 struct target_user_vfp ufp
;
1519 struct target_user_vfp_exc ufp_exc
;
1520 } __attribute__((__aligned__(8)));
1522 struct target_iwmmxt_sigframe
{
1526 /* Note that not all the coprocessor control registers are stored here */
1533 } __attribute__((__aligned__(8)));
1535 #define TARGET_VFP_MAGIC 0x56465001
1536 #define TARGET_IWMMXT_MAGIC 0x12ef842a
1540 struct target_sigcontext sc
;
1541 abi_ulong extramask
[TARGET_NSIG_WORDS
-1];
1547 struct target_ucontext_v2 uc
;
1551 struct rt_sigframe_v1
1555 struct target_siginfo info
;
1556 struct target_ucontext_v1 uc
;
1560 struct rt_sigframe_v2
1562 struct target_siginfo info
;
1563 struct target_ucontext_v2 uc
;
1567 #define TARGET_CONFIG_CPU_32 1
1570 * For ARM syscalls, we encode the syscall number into the instruction.
1572 #define SWI_SYS_SIGRETURN (0xef000000|(TARGET_NR_sigreturn + ARM_SYSCALL_BASE))
1573 #define SWI_SYS_RT_SIGRETURN (0xef000000|(TARGET_NR_rt_sigreturn + ARM_SYSCALL_BASE))
1576 * For Thumb syscalls, we pass the syscall number via r7. We therefore
1577 * need two 16-bit instructions.
1579 #define SWI_THUMB_SIGRETURN (0xdf00 << 16 | 0x2700 | (TARGET_NR_sigreturn))
1580 #define SWI_THUMB_RT_SIGRETURN (0xdf00 << 16 | 0x2700 | (TARGET_NR_rt_sigreturn))
1582 static const abi_ulong retcodes
[4] = {
1583 SWI_SYS_SIGRETURN
, SWI_THUMB_SIGRETURN
,
1584 SWI_SYS_RT_SIGRETURN
, SWI_THUMB_RT_SIGRETURN
1588 static inline int valid_user_regs(CPUARMState
*regs
)
1594 setup_sigcontext(struct target_sigcontext
*sc
, /*struct _fpstate *fpstate,*/
1595 CPUARMState
*env
, abi_ulong mask
)
1597 __put_user(env
->regs
[0], &sc
->arm_r0
);
1598 __put_user(env
->regs
[1], &sc
->arm_r1
);
1599 __put_user(env
->regs
[2], &sc
->arm_r2
);
1600 __put_user(env
->regs
[3], &sc
->arm_r3
);
1601 __put_user(env
->regs
[4], &sc
->arm_r4
);
1602 __put_user(env
->regs
[5], &sc
->arm_r5
);
1603 __put_user(env
->regs
[6], &sc
->arm_r6
);
1604 __put_user(env
->regs
[7], &sc
->arm_r7
);
1605 __put_user(env
->regs
[8], &sc
->arm_r8
);
1606 __put_user(env
->regs
[9], &sc
->arm_r9
);
1607 __put_user(env
->regs
[10], &sc
->arm_r10
);
1608 __put_user(env
->regs
[11], &sc
->arm_fp
);
1609 __put_user(env
->regs
[12], &sc
->arm_ip
);
1610 __put_user(env
->regs
[13], &sc
->arm_sp
);
1611 __put_user(env
->regs
[14], &sc
->arm_lr
);
1612 __put_user(env
->regs
[15], &sc
->arm_pc
);
1613 #ifdef TARGET_CONFIG_CPU_32
1614 __put_user(cpsr_read(env
), &sc
->arm_cpsr
);
1617 __put_user(/* current->thread.trap_no */ 0, &sc
->trap_no
);
1618 __put_user(/* current->thread.error_code */ 0, &sc
->error_code
);
1619 __put_user(/* current->thread.address */ 0, &sc
->fault_address
);
1620 __put_user(mask
, &sc
->oldmask
);
1623 static inline abi_ulong
1624 get_sigframe(struct target_sigaction
*ka
, CPUARMState
*regs
, int framesize
)
1626 unsigned long sp
= regs
->regs
[13];
1629 * This is the X/Open sanctioned signal stack switching.
1631 if ((ka
->sa_flags
& TARGET_SA_ONSTACK
) && !sas_ss_flags(sp
)) {
1632 sp
= target_sigaltstack_used
.ss_sp
+ target_sigaltstack_used
.ss_size
;
1635 * ATPCS B01 mandates 8-byte alignment
1637 return (sp
- framesize
) & ~7;
1641 setup_return(CPUARMState
*env
, struct target_sigaction
*ka
,
1642 abi_ulong
*rc
, abi_ulong frame_addr
, int usig
, abi_ulong rc_addr
)
1644 abi_ulong handler
= ka
->_sa_handler
;
1646 int thumb
= handler
& 1;
1647 uint32_t cpsr
= cpsr_read(env
);
1656 if (ka
->sa_flags
& TARGET_SA_RESTORER
) {
1657 retcode
= ka
->sa_restorer
;
1659 unsigned int idx
= thumb
;
1661 if (ka
->sa_flags
& TARGET_SA_SIGINFO
) {
1665 __put_user(retcodes
[idx
], rc
);
1667 retcode
= rc_addr
+ thumb
;
1670 env
->regs
[0] = usig
;
1671 env
->regs
[13] = frame_addr
;
1672 env
->regs
[14] = retcode
;
1673 env
->regs
[15] = handler
& (thumb
? ~1 : ~3);
1674 cpsr_write(env
, cpsr
, CPSR_IT
| CPSR_T
, CPSRWriteByInstr
);
1677 static abi_ulong
*setup_sigframe_v2_vfp(abi_ulong
*regspace
, CPUARMState
*env
)
1680 struct target_vfp_sigframe
*vfpframe
;
1681 vfpframe
= (struct target_vfp_sigframe
*)regspace
;
1682 __put_user(TARGET_VFP_MAGIC
, &vfpframe
->magic
);
1683 __put_user(sizeof(*vfpframe
), &vfpframe
->size
);
1684 for (i
= 0; i
< 32; i
++) {
1685 __put_user(float64_val(env
->vfp
.regs
[i
]), &vfpframe
->ufp
.fpregs
[i
]);
1687 __put_user(vfp_get_fpscr(env
), &vfpframe
->ufp
.fpscr
);
1688 __put_user(env
->vfp
.xregs
[ARM_VFP_FPEXC
], &vfpframe
->ufp_exc
.fpexc
);
1689 __put_user(env
->vfp
.xregs
[ARM_VFP_FPINST
], &vfpframe
->ufp_exc
.fpinst
);
1690 __put_user(env
->vfp
.xregs
[ARM_VFP_FPINST2
], &vfpframe
->ufp_exc
.fpinst2
);
1691 return (abi_ulong
*)(vfpframe
+1);
1694 static abi_ulong
*setup_sigframe_v2_iwmmxt(abi_ulong
*regspace
,
1698 struct target_iwmmxt_sigframe
*iwmmxtframe
;
1699 iwmmxtframe
= (struct target_iwmmxt_sigframe
*)regspace
;
1700 __put_user(TARGET_IWMMXT_MAGIC
, &iwmmxtframe
->magic
);
1701 __put_user(sizeof(*iwmmxtframe
), &iwmmxtframe
->size
);
1702 for (i
= 0; i
< 16; i
++) {
1703 __put_user(env
->iwmmxt
.regs
[i
], &iwmmxtframe
->regs
[i
]);
1705 __put_user(env
->vfp
.xregs
[ARM_IWMMXT_wCSSF
], &iwmmxtframe
->wcssf
);
1706 __put_user(env
->vfp
.xregs
[ARM_IWMMXT_wCASF
], &iwmmxtframe
->wcssf
);
1707 __put_user(env
->vfp
.xregs
[ARM_IWMMXT_wCGR0
], &iwmmxtframe
->wcgr0
);
1708 __put_user(env
->vfp
.xregs
[ARM_IWMMXT_wCGR1
], &iwmmxtframe
->wcgr1
);
1709 __put_user(env
->vfp
.xregs
[ARM_IWMMXT_wCGR2
], &iwmmxtframe
->wcgr2
);
1710 __put_user(env
->vfp
.xregs
[ARM_IWMMXT_wCGR3
], &iwmmxtframe
->wcgr3
);
1711 return (abi_ulong
*)(iwmmxtframe
+1);
1714 static void setup_sigframe_v2(struct target_ucontext_v2
*uc
,
1715 target_sigset_t
*set
, CPUARMState
*env
)
1717 struct target_sigaltstack stack
;
1719 abi_ulong
*regspace
;
1721 /* Clear all the bits of the ucontext we don't use. */
1722 memset(uc
, 0, offsetof(struct target_ucontext_v2
, tuc_mcontext
));
1724 memset(&stack
, 0, sizeof(stack
));
1725 __put_user(target_sigaltstack_used
.ss_sp
, &stack
.ss_sp
);
1726 __put_user(target_sigaltstack_used
.ss_size
, &stack
.ss_size
);
1727 __put_user(sas_ss_flags(get_sp_from_cpustate(env
)), &stack
.ss_flags
);
1728 memcpy(&uc
->tuc_stack
, &stack
, sizeof(stack
));
1730 setup_sigcontext(&uc
->tuc_mcontext
, env
, set
->sig
[0]);
1731 /* Save coprocessor signal frame. */
1732 regspace
= uc
->tuc_regspace
;
1733 if (arm_feature(env
, ARM_FEATURE_VFP
)) {
1734 regspace
= setup_sigframe_v2_vfp(regspace
, env
);
1736 if (arm_feature(env
, ARM_FEATURE_IWMMXT
)) {
1737 regspace
= setup_sigframe_v2_iwmmxt(regspace
, env
);
1740 /* Write terminating magic word */
1741 __put_user(0, regspace
);
1743 for(i
= 0; i
< TARGET_NSIG_WORDS
; i
++) {
1744 __put_user(set
->sig
[i
], &uc
->tuc_sigmask
.sig
[i
]);
1748 /* compare linux/arch/arm/kernel/signal.c:setup_frame() */
1749 static void setup_frame_v1(int usig
, struct target_sigaction
*ka
,
1750 target_sigset_t
*set
, CPUARMState
*regs
)
1752 struct sigframe_v1
*frame
;
1753 abi_ulong frame_addr
= get_sigframe(ka
, regs
, sizeof(*frame
));
1756 trace_user_setup_frame(regs
, frame_addr
);
1757 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0)) {
1761 setup_sigcontext(&frame
->sc
, regs
, set
->sig
[0]);
1763 for(i
= 1; i
< TARGET_NSIG_WORDS
; i
++) {
1764 __put_user(set
->sig
[i
], &frame
->extramask
[i
- 1]);
1767 setup_return(regs
, ka
, &frame
->retcode
, frame_addr
, usig
,
1768 frame_addr
+ offsetof(struct sigframe_v1
, retcode
));
1770 unlock_user_struct(frame
, frame_addr
, 1);
1773 static void setup_frame_v2(int usig
, struct target_sigaction
*ka
,
1774 target_sigset_t
*set
, CPUARMState
*regs
)
1776 struct sigframe_v2
*frame
;
1777 abi_ulong frame_addr
= get_sigframe(ka
, regs
, sizeof(*frame
));
1779 trace_user_setup_frame(regs
, frame_addr
);
1780 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0)) {
1784 setup_sigframe_v2(&frame
->uc
, set
, regs
);
1786 setup_return(regs
, ka
, &frame
->retcode
, frame_addr
, usig
,
1787 frame_addr
+ offsetof(struct sigframe_v2
, retcode
));
1789 unlock_user_struct(frame
, frame_addr
, 1);
1792 static void setup_frame(int usig
, struct target_sigaction
*ka
,
1793 target_sigset_t
*set
, CPUARMState
*regs
)
1795 if (get_osversion() >= 0x020612) {
1796 setup_frame_v2(usig
, ka
, set
, regs
);
1798 setup_frame_v1(usig
, ka
, set
, regs
);
1802 /* compare linux/arch/arm/kernel/signal.c:setup_rt_frame() */
1803 static void setup_rt_frame_v1(int usig
, struct target_sigaction
*ka
,
1804 target_siginfo_t
*info
,
1805 target_sigset_t
*set
, CPUARMState
*env
)
1807 struct rt_sigframe_v1
*frame
;
1808 abi_ulong frame_addr
= get_sigframe(ka
, env
, sizeof(*frame
));
1809 struct target_sigaltstack stack
;
1811 abi_ulong info_addr
, uc_addr
;
1813 trace_user_setup_rt_frame(env
, frame_addr
);
1814 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0)) {
1818 info_addr
= frame_addr
+ offsetof(struct rt_sigframe_v1
, info
);
1819 __put_user(info_addr
, &frame
->pinfo
);
1820 uc_addr
= frame_addr
+ offsetof(struct rt_sigframe_v1
, uc
);
1821 __put_user(uc_addr
, &frame
->puc
);
1822 tswap_siginfo(&frame
->info
, info
);
1824 /* Clear all the bits of the ucontext we don't use. */
1825 memset(&frame
->uc
, 0, offsetof(struct target_ucontext_v1
, tuc_mcontext
));
1827 memset(&stack
, 0, sizeof(stack
));
1828 __put_user(target_sigaltstack_used
.ss_sp
, &stack
.ss_sp
);
1829 __put_user(target_sigaltstack_used
.ss_size
, &stack
.ss_size
);
1830 __put_user(sas_ss_flags(get_sp_from_cpustate(env
)), &stack
.ss_flags
);
1831 memcpy(&frame
->uc
.tuc_stack
, &stack
, sizeof(stack
));
1833 setup_sigcontext(&frame
->uc
.tuc_mcontext
, env
, set
->sig
[0]);
1834 for(i
= 0; i
< TARGET_NSIG_WORDS
; i
++) {
1835 __put_user(set
->sig
[i
], &frame
->uc
.tuc_sigmask
.sig
[i
]);
1838 setup_return(env
, ka
, &frame
->retcode
, frame_addr
, usig
,
1839 frame_addr
+ offsetof(struct rt_sigframe_v1
, retcode
));
1841 env
->regs
[1] = info_addr
;
1842 env
->regs
[2] = uc_addr
;
1844 unlock_user_struct(frame
, frame_addr
, 1);
1847 static void setup_rt_frame_v2(int usig
, struct target_sigaction
*ka
,
1848 target_siginfo_t
*info
,
1849 target_sigset_t
*set
, CPUARMState
*env
)
1851 struct rt_sigframe_v2
*frame
;
1852 abi_ulong frame_addr
= get_sigframe(ka
, env
, sizeof(*frame
));
1853 abi_ulong info_addr
, uc_addr
;
1855 trace_user_setup_rt_frame(env
, frame_addr
);
1856 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0)) {
1860 info_addr
= frame_addr
+ offsetof(struct rt_sigframe_v2
, info
);
1861 uc_addr
= frame_addr
+ offsetof(struct rt_sigframe_v2
, uc
);
1862 tswap_siginfo(&frame
->info
, info
);
1864 setup_sigframe_v2(&frame
->uc
, set
, env
);
1866 setup_return(env
, ka
, &frame
->retcode
, frame_addr
, usig
,
1867 frame_addr
+ offsetof(struct rt_sigframe_v2
, retcode
));
1869 env
->regs
[1] = info_addr
;
1870 env
->regs
[2] = uc_addr
;
1872 unlock_user_struct(frame
, frame_addr
, 1);
1875 static void setup_rt_frame(int usig
, struct target_sigaction
*ka
,
1876 target_siginfo_t
*info
,
1877 target_sigset_t
*set
, CPUARMState
*env
)
1879 if (get_osversion() >= 0x020612) {
1880 setup_rt_frame_v2(usig
, ka
, info
, set
, env
);
1882 setup_rt_frame_v1(usig
, ka
, info
, set
, env
);
1887 restore_sigcontext(CPUARMState
*env
, struct target_sigcontext
*sc
)
1892 __get_user(env
->regs
[0], &sc
->arm_r0
);
1893 __get_user(env
->regs
[1], &sc
->arm_r1
);
1894 __get_user(env
->regs
[2], &sc
->arm_r2
);
1895 __get_user(env
->regs
[3], &sc
->arm_r3
);
1896 __get_user(env
->regs
[4], &sc
->arm_r4
);
1897 __get_user(env
->regs
[5], &sc
->arm_r5
);
1898 __get_user(env
->regs
[6], &sc
->arm_r6
);
1899 __get_user(env
->regs
[7], &sc
->arm_r7
);
1900 __get_user(env
->regs
[8], &sc
->arm_r8
);
1901 __get_user(env
->regs
[9], &sc
->arm_r9
);
1902 __get_user(env
->regs
[10], &sc
->arm_r10
);
1903 __get_user(env
->regs
[11], &sc
->arm_fp
);
1904 __get_user(env
->regs
[12], &sc
->arm_ip
);
1905 __get_user(env
->regs
[13], &sc
->arm_sp
);
1906 __get_user(env
->regs
[14], &sc
->arm_lr
);
1907 __get_user(env
->regs
[15], &sc
->arm_pc
);
1908 #ifdef TARGET_CONFIG_CPU_32
1909 __get_user(cpsr
, &sc
->arm_cpsr
);
1910 cpsr_write(env
, cpsr
, CPSR_USER
| CPSR_EXEC
, CPSRWriteByInstr
);
1913 err
|= !valid_user_regs(env
);
1918 static long do_sigreturn_v1(CPUARMState
*env
)
1920 abi_ulong frame_addr
;
1921 struct sigframe_v1
*frame
= NULL
;
1922 target_sigset_t set
;
1927 * Since we stacked the signal on a 64-bit boundary,
1928 * then 'sp' should be word aligned here. If it's
1929 * not, then the user is trying to mess with us.
1931 frame_addr
= env
->regs
[13];
1932 trace_user_do_sigreturn(env
, frame_addr
);
1933 if (frame_addr
& 7) {
1937 if (!lock_user_struct(VERIFY_READ
, frame
, frame_addr
, 1)) {
1941 __get_user(set
.sig
[0], &frame
->sc
.oldmask
);
1942 for(i
= 1; i
< TARGET_NSIG_WORDS
; i
++) {
1943 __get_user(set
.sig
[i
], &frame
->extramask
[i
- 1]);
1946 target_to_host_sigset_internal(&host_set
, &set
);
1947 set_sigmask(&host_set
);
1949 if (restore_sigcontext(env
, &frame
->sc
)) {
1954 /* Send SIGTRAP if we're single-stepping */
1955 if (ptrace_cancel_bpt(current
))
1956 send_sig(SIGTRAP
, current
, 1);
1958 unlock_user_struct(frame
, frame_addr
, 0);
1959 return -TARGET_QEMU_ESIGRETURN
;
1962 force_sig(TARGET_SIGSEGV
/* , current */);
1966 static abi_ulong
*restore_sigframe_v2_vfp(CPUARMState
*env
, abi_ulong
*regspace
)
1969 abi_ulong magic
, sz
;
1970 uint32_t fpscr
, fpexc
;
1971 struct target_vfp_sigframe
*vfpframe
;
1972 vfpframe
= (struct target_vfp_sigframe
*)regspace
;
1974 __get_user(magic
, &vfpframe
->magic
);
1975 __get_user(sz
, &vfpframe
->size
);
1976 if (magic
!= TARGET_VFP_MAGIC
|| sz
!= sizeof(*vfpframe
)) {
1979 for (i
= 0; i
< 32; i
++) {
1980 __get_user(float64_val(env
->vfp
.regs
[i
]), &vfpframe
->ufp
.fpregs
[i
]);
1982 __get_user(fpscr
, &vfpframe
->ufp
.fpscr
);
1983 vfp_set_fpscr(env
, fpscr
);
1984 __get_user(fpexc
, &vfpframe
->ufp_exc
.fpexc
);
1985 /* Sanitise FPEXC: ensure VFP is enabled, FPINST2 is invalid
1986 * and the exception flag is cleared
1989 fpexc
&= ~((1 << 31) | (1 << 28));
1990 env
->vfp
.xregs
[ARM_VFP_FPEXC
] = fpexc
;
1991 __get_user(env
->vfp
.xregs
[ARM_VFP_FPINST
], &vfpframe
->ufp_exc
.fpinst
);
1992 __get_user(env
->vfp
.xregs
[ARM_VFP_FPINST2
], &vfpframe
->ufp_exc
.fpinst2
);
1993 return (abi_ulong
*)(vfpframe
+ 1);
1996 static abi_ulong
*restore_sigframe_v2_iwmmxt(CPUARMState
*env
,
1997 abi_ulong
*regspace
)
2000 abi_ulong magic
, sz
;
2001 struct target_iwmmxt_sigframe
*iwmmxtframe
;
2002 iwmmxtframe
= (struct target_iwmmxt_sigframe
*)regspace
;
2004 __get_user(magic
, &iwmmxtframe
->magic
);
2005 __get_user(sz
, &iwmmxtframe
->size
);
2006 if (magic
!= TARGET_IWMMXT_MAGIC
|| sz
!= sizeof(*iwmmxtframe
)) {
2009 for (i
= 0; i
< 16; i
++) {
2010 __get_user(env
->iwmmxt
.regs
[i
], &iwmmxtframe
->regs
[i
]);
2012 __get_user(env
->vfp
.xregs
[ARM_IWMMXT_wCSSF
], &iwmmxtframe
->wcssf
);
2013 __get_user(env
->vfp
.xregs
[ARM_IWMMXT_wCASF
], &iwmmxtframe
->wcssf
);
2014 __get_user(env
->vfp
.xregs
[ARM_IWMMXT_wCGR0
], &iwmmxtframe
->wcgr0
);
2015 __get_user(env
->vfp
.xregs
[ARM_IWMMXT_wCGR1
], &iwmmxtframe
->wcgr1
);
2016 __get_user(env
->vfp
.xregs
[ARM_IWMMXT_wCGR2
], &iwmmxtframe
->wcgr2
);
2017 __get_user(env
->vfp
.xregs
[ARM_IWMMXT_wCGR3
], &iwmmxtframe
->wcgr3
);
2018 return (abi_ulong
*)(iwmmxtframe
+ 1);
2021 static int do_sigframe_return_v2(CPUARMState
*env
, target_ulong frame_addr
,
2022 struct target_ucontext_v2
*uc
)
2025 abi_ulong
*regspace
;
2027 target_to_host_sigset(&host_set
, &uc
->tuc_sigmask
);
2028 set_sigmask(&host_set
);
2030 if (restore_sigcontext(env
, &uc
->tuc_mcontext
))
2033 /* Restore coprocessor signal frame */
2034 regspace
= uc
->tuc_regspace
;
2035 if (arm_feature(env
, ARM_FEATURE_VFP
)) {
2036 regspace
= restore_sigframe_v2_vfp(env
, regspace
);
2041 if (arm_feature(env
, ARM_FEATURE_IWMMXT
)) {
2042 regspace
= restore_sigframe_v2_iwmmxt(env
, regspace
);
2048 if (do_sigaltstack(frame_addr
+ offsetof(struct target_ucontext_v2
, tuc_stack
), 0, get_sp_from_cpustate(env
)) == -EFAULT
)
2052 /* Send SIGTRAP if we're single-stepping */
2053 if (ptrace_cancel_bpt(current
))
2054 send_sig(SIGTRAP
, current
, 1);
2060 static long do_sigreturn_v2(CPUARMState
*env
)
2062 abi_ulong frame_addr
;
2063 struct sigframe_v2
*frame
= NULL
;
2066 * Since we stacked the signal on a 64-bit boundary,
2067 * then 'sp' should be word aligned here. If it's
2068 * not, then the user is trying to mess with us.
2070 frame_addr
= env
->regs
[13];
2071 trace_user_do_sigreturn(env
, frame_addr
);
2072 if (frame_addr
& 7) {
2076 if (!lock_user_struct(VERIFY_READ
, frame
, frame_addr
, 1)) {
2080 if (do_sigframe_return_v2(env
, frame_addr
, &frame
->uc
)) {
2084 unlock_user_struct(frame
, frame_addr
, 0);
2085 return -TARGET_QEMU_ESIGRETURN
;
2088 unlock_user_struct(frame
, frame_addr
, 0);
2089 force_sig(TARGET_SIGSEGV
/* , current */);
2093 long do_sigreturn(CPUARMState
*env
)
2095 if (get_osversion() >= 0x020612) {
2096 return do_sigreturn_v2(env
);
2098 return do_sigreturn_v1(env
);
2102 static long do_rt_sigreturn_v1(CPUARMState
*env
)
2104 abi_ulong frame_addr
;
2105 struct rt_sigframe_v1
*frame
= NULL
;
2109 * Since we stacked the signal on a 64-bit boundary,
2110 * then 'sp' should be word aligned here. If it's
2111 * not, then the user is trying to mess with us.
2113 frame_addr
= env
->regs
[13];
2114 trace_user_do_rt_sigreturn(env
, frame_addr
);
2115 if (frame_addr
& 7) {
2119 if (!lock_user_struct(VERIFY_READ
, frame
, frame_addr
, 1)) {
2123 target_to_host_sigset(&host_set
, &frame
->uc
.tuc_sigmask
);
2124 set_sigmask(&host_set
);
2126 if (restore_sigcontext(env
, &frame
->uc
.tuc_mcontext
)) {
2130 if (do_sigaltstack(frame_addr
+ offsetof(struct rt_sigframe_v1
, uc
.tuc_stack
), 0, get_sp_from_cpustate(env
)) == -EFAULT
)
2134 /* Send SIGTRAP if we're single-stepping */
2135 if (ptrace_cancel_bpt(current
))
2136 send_sig(SIGTRAP
, current
, 1);
2138 unlock_user_struct(frame
, frame_addr
, 0);
2139 return -TARGET_QEMU_ESIGRETURN
;
2142 unlock_user_struct(frame
, frame_addr
, 0);
2143 force_sig(TARGET_SIGSEGV
/* , current */);
2147 static long do_rt_sigreturn_v2(CPUARMState
*env
)
2149 abi_ulong frame_addr
;
2150 struct rt_sigframe_v2
*frame
= NULL
;
2153 * Since we stacked the signal on a 64-bit boundary,
2154 * then 'sp' should be word aligned here. If it's
2155 * not, then the user is trying to mess with us.
2157 frame_addr
= env
->regs
[13];
2158 trace_user_do_rt_sigreturn(env
, frame_addr
);
2159 if (frame_addr
& 7) {
2163 if (!lock_user_struct(VERIFY_READ
, frame
, frame_addr
, 1)) {
2167 if (do_sigframe_return_v2(env
, frame_addr
, &frame
->uc
)) {
2171 unlock_user_struct(frame
, frame_addr
, 0);
2172 return -TARGET_QEMU_ESIGRETURN
;
2175 unlock_user_struct(frame
, frame_addr
, 0);
2176 force_sig(TARGET_SIGSEGV
/* , current */);
2180 long do_rt_sigreturn(CPUARMState
*env
)
2182 if (get_osversion() >= 0x020612) {
2183 return do_rt_sigreturn_v2(env
);
2185 return do_rt_sigreturn_v1(env
);
2189 #elif defined(TARGET_SPARC)
2191 #define __SUNOS_MAXWIN 31
2193 /* This is what SunOS does, so shall I. */
2194 struct target_sigcontext
{
2195 abi_ulong sigc_onstack
; /* state to restore */
2197 abi_ulong sigc_mask
; /* sigmask to restore */
2198 abi_ulong sigc_sp
; /* stack pointer */
2199 abi_ulong sigc_pc
; /* program counter */
2200 abi_ulong sigc_npc
; /* next program counter */
2201 abi_ulong sigc_psr
; /* for condition codes etc */
2202 abi_ulong sigc_g1
; /* User uses these two registers */
2203 abi_ulong sigc_o0
; /* within the trampoline code. */
2205 /* Now comes information regarding the users window set
2206 * at the time of the signal.
2208 abi_ulong sigc_oswins
; /* outstanding windows */
2210 /* stack ptrs for each regwin buf */
2211 char *sigc_spbuf
[__SUNOS_MAXWIN
];
2213 /* Windows to restore after signal */
2215 abi_ulong locals
[8];
2217 } sigc_wbuf
[__SUNOS_MAXWIN
];
2219 /* A Sparc stack frame */
2220 struct sparc_stackf
{
2221 abi_ulong locals
[8];
2223 /* It's simpler to treat fp and callers_pc as elements of ins[]
2224 * since we never need to access them ourselves.
2228 abi_ulong xxargs
[1];
2237 abi_ulong u_regs
[16]; /* globals and ins */
2243 abi_ulong si_float_regs
[32];
2244 unsigned long si_fsr
;
2245 unsigned long si_fpqdepth
;
2247 unsigned long *insn_addr
;
2250 } qemu_siginfo_fpu_t
;
2253 struct target_signal_frame
{
2254 struct sparc_stackf ss
;
2257 abi_ulong insns
[2] __attribute__ ((aligned (8)));
2258 abi_ulong extramask
[TARGET_NSIG_WORDS
- 1];
2259 abi_ulong extra_size
; /* Should be 0 */
2260 qemu_siginfo_fpu_t fpu_state
;
2262 struct target_rt_signal_frame
{
2263 struct sparc_stackf ss
;
2268 unsigned int insns
[2];
2270 unsigned int extra_size
; /* Should be 0 */
2271 qemu_siginfo_fpu_t fpu_state
;
2285 #define UREG_FP UREG_I6
2286 #define UREG_SP UREG_O6
2288 static inline abi_ulong
get_sigframe(struct target_sigaction
*sa
,
2290 unsigned long framesize
)
2294 sp
= env
->regwptr
[UREG_FP
];
2296 /* This is the X/Open sanctioned signal stack switching. */
2297 if (sa
->sa_flags
& TARGET_SA_ONSTACK
) {
2298 if (!on_sig_stack(sp
)
2299 && !((target_sigaltstack_used
.ss_sp
+ target_sigaltstack_used
.ss_size
) & 7)) {
2300 sp
= target_sigaltstack_used
.ss_sp
+ target_sigaltstack_used
.ss_size
;
2303 return sp
- framesize
;
2307 setup___siginfo(__siginfo_t
*si
, CPUSPARCState
*env
, abi_ulong mask
)
2311 __put_user(env
->psr
, &si
->si_regs
.psr
);
2312 __put_user(env
->pc
, &si
->si_regs
.pc
);
2313 __put_user(env
->npc
, &si
->si_regs
.npc
);
2314 __put_user(env
->y
, &si
->si_regs
.y
);
2315 for (i
=0; i
< 8; i
++) {
2316 __put_user(env
->gregs
[i
], &si
->si_regs
.u_regs
[i
]);
2318 for (i
=0; i
< 8; i
++) {
2319 __put_user(env
->regwptr
[UREG_I0
+ i
], &si
->si_regs
.u_regs
[i
+8]);
2321 __put_user(mask
, &si
->si_mask
);
2327 setup_sigcontext(struct target_sigcontext
*sc
, /*struct _fpstate *fpstate,*/
2328 CPUSPARCState
*env
, unsigned long mask
)
2332 __put_user(mask
, &sc
->sigc_mask
);
2333 __put_user(env
->regwptr
[UREG_SP
], &sc
->sigc_sp
);
2334 __put_user(env
->pc
, &sc
->sigc_pc
);
2335 __put_user(env
->npc
, &sc
->sigc_npc
);
2336 __put_user(env
->psr
, &sc
->sigc_psr
);
2337 __put_user(env
->gregs
[1], &sc
->sigc_g1
);
2338 __put_user(env
->regwptr
[UREG_O0
], &sc
->sigc_o0
);
2343 #define NF_ALIGNEDSZ (((sizeof(struct target_signal_frame) + 7) & (~7)))
2345 static void setup_frame(int sig
, struct target_sigaction
*ka
,
2346 target_sigset_t
*set
, CPUSPARCState
*env
)
2349 struct target_signal_frame
*sf
;
2350 int sigframe_size
, err
, i
;
2352 /* 1. Make sure everything is clean */
2353 //synchronize_user_stack();
2355 sigframe_size
= NF_ALIGNEDSZ
;
2356 sf_addr
= get_sigframe(ka
, env
, sigframe_size
);
2357 trace_user_setup_frame(env
, sf_addr
);
2359 sf
= lock_user(VERIFY_WRITE
, sf_addr
,
2360 sizeof(struct target_signal_frame
), 0);
2365 if (invalid_frame_pointer(sf
, sigframe_size
))
2366 goto sigill_and_return
;
2368 /* 2. Save the current process state */
2369 err
= setup___siginfo(&sf
->info
, env
, set
->sig
[0]);
2370 __put_user(0, &sf
->extra_size
);
2372 //save_fpu_state(regs, &sf->fpu_state);
2373 //__put_user(&sf->fpu_state, &sf->fpu_save);
2375 __put_user(set
->sig
[0], &sf
->info
.si_mask
);
2376 for (i
= 0; i
< TARGET_NSIG_WORDS
- 1; i
++) {
2377 __put_user(set
->sig
[i
+ 1], &sf
->extramask
[i
]);
2380 for (i
= 0; i
< 8; i
++) {
2381 __put_user(env
->regwptr
[i
+ UREG_L0
], &sf
->ss
.locals
[i
]);
2383 for (i
= 0; i
< 8; i
++) {
2384 __put_user(env
->regwptr
[i
+ UREG_I0
], &sf
->ss
.ins
[i
]);
2389 /* 3. signal handler back-trampoline and parameters */
2390 env
->regwptr
[UREG_FP
] = sf_addr
;
2391 env
->regwptr
[UREG_I0
] = sig
;
2392 env
->regwptr
[UREG_I1
] = sf_addr
+
2393 offsetof(struct target_signal_frame
, info
);
2394 env
->regwptr
[UREG_I2
] = sf_addr
+
2395 offsetof(struct target_signal_frame
, info
);
2397 /* 4. signal handler */
2398 env
->pc
= ka
->_sa_handler
;
2399 env
->npc
= (env
->pc
+ 4);
2400 /* 5. return to kernel instructions */
2401 if (ka
->sa_restorer
) {
2402 env
->regwptr
[UREG_I7
] = ka
->sa_restorer
;
2406 env
->regwptr
[UREG_I7
] = sf_addr
+
2407 offsetof(struct target_signal_frame
, insns
) - 2 * 4;
2409 /* mov __NR_sigreturn, %g1 */
2411 __put_user(val32
, &sf
->insns
[0]);
2415 __put_user(val32
, &sf
->insns
[1]);
2419 /* Flush instruction space. */
2420 // flush_sig_insns(current->mm, (unsigned long) &(sf->insns[0]));
2423 unlock_user(sf
, sf_addr
, sizeof(struct target_signal_frame
));
2427 force_sig(TARGET_SIGILL
);
2430 unlock_user(sf
, sf_addr
, sizeof(struct target_signal_frame
));
2431 force_sig(TARGET_SIGSEGV
);
2434 static void setup_rt_frame(int sig
, struct target_sigaction
*ka
,
2435 target_siginfo_t
*info
,
2436 target_sigset_t
*set
, CPUSPARCState
*env
)
2438 fprintf(stderr
, "setup_rt_frame: not implemented\n");
2441 long do_sigreturn(CPUSPARCState
*env
)
2444 struct target_signal_frame
*sf
;
2445 uint32_t up_psr
, pc
, npc
;
2446 target_sigset_t set
;
2450 sf_addr
= env
->regwptr
[UREG_FP
];
2451 trace_user_do_sigreturn(env
, sf_addr
);
2452 if (!lock_user_struct(VERIFY_READ
, sf
, sf_addr
, 1)) {
2456 /* 1. Make sure we are not getting garbage from the user */
2461 __get_user(pc
, &sf
->info
.si_regs
.pc
);
2462 __get_user(npc
, &sf
->info
.si_regs
.npc
);
2464 if ((pc
| npc
) & 3) {
2468 /* 2. Restore the state */
2469 __get_user(up_psr
, &sf
->info
.si_regs
.psr
);
2471 /* User can only change condition codes and FPU enabling in %psr. */
2472 env
->psr
= (up_psr
& (PSR_ICC
/* | PSR_EF */))
2473 | (env
->psr
& ~(PSR_ICC
/* | PSR_EF */));
2477 __get_user(env
->y
, &sf
->info
.si_regs
.y
);
2478 for (i
=0; i
< 8; i
++) {
2479 __get_user(env
->gregs
[i
], &sf
->info
.si_regs
.u_regs
[i
]);
2481 for (i
=0; i
< 8; i
++) {
2482 __get_user(env
->regwptr
[i
+ UREG_I0
], &sf
->info
.si_regs
.u_regs
[i
+8]);
2485 /* FIXME: implement FPU save/restore:
2486 * __get_user(fpu_save, &sf->fpu_save);
2488 * err |= restore_fpu_state(env, fpu_save);
2491 /* This is pretty much atomic, no amount locking would prevent
2492 * the races which exist anyways.
2494 __get_user(set
.sig
[0], &sf
->info
.si_mask
);
2495 for(i
= 1; i
< TARGET_NSIG_WORDS
; i
++) {
2496 __get_user(set
.sig
[i
], &sf
->extramask
[i
- 1]);
2499 target_to_host_sigset_internal(&host_set
, &set
);
2500 set_sigmask(&host_set
);
2505 unlock_user_struct(sf
, sf_addr
, 0);
2506 return -TARGET_QEMU_ESIGRETURN
;
2509 unlock_user_struct(sf
, sf_addr
, 0);
2510 force_sig(TARGET_SIGSEGV
);
2513 long do_rt_sigreturn(CPUSPARCState
*env
)
2515 trace_user_do_rt_sigreturn(env
, 0);
2516 fprintf(stderr
, "do_rt_sigreturn: not implemented\n");
2517 return -TARGET_ENOSYS
;
2520 #if defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
2542 typedef abi_ulong target_mc_greg_t
;
2543 typedef target_mc_greg_t target_mc_gregset_t
[MC_NGREG
];
2545 struct target_mc_fq
{
2546 abi_ulong
*mcfq_addr
;
2550 struct target_mc_fpu
{
2554 //uint128_t qregs[16];
2556 abi_ulong mcfpu_fsr
;
2557 abi_ulong mcfpu_fprs
;
2558 abi_ulong mcfpu_gsr
;
2559 struct target_mc_fq
*mcfpu_fq
;
2560 unsigned char mcfpu_qcnt
;
2561 unsigned char mcfpu_qentsz
;
2562 unsigned char mcfpu_enab
;
2564 typedef struct target_mc_fpu target_mc_fpu_t
;
2567 target_mc_gregset_t mc_gregs
;
2568 target_mc_greg_t mc_fp
;
2569 target_mc_greg_t mc_i7
;
2570 target_mc_fpu_t mc_fpregs
;
2571 } target_mcontext_t
;
2573 struct target_ucontext
{
2574 struct target_ucontext
*tuc_link
;
2575 abi_ulong tuc_flags
;
2576 target_sigset_t tuc_sigmask
;
2577 target_mcontext_t tuc_mcontext
;
2580 /* A V9 register window */
2581 struct target_reg_window
{
2582 abi_ulong locals
[8];
2586 #define TARGET_STACK_BIAS 2047
2588 /* {set, get}context() needed for 64-bit SparcLinux userland. */
2589 void sparc64_set_context(CPUSPARCState
*env
)
2592 struct target_ucontext
*ucp
;
2593 target_mc_gregset_t
*grp
;
2594 abi_ulong pc
, npc
, tstate
;
2595 abi_ulong fp
, i7
, w_addr
;
2598 ucp_addr
= env
->regwptr
[UREG_I0
];
2599 if (!lock_user_struct(VERIFY_READ
, ucp
, ucp_addr
, 1)) {
2602 grp
= &ucp
->tuc_mcontext
.mc_gregs
;
2603 __get_user(pc
, &((*grp
)[MC_PC
]));
2604 __get_user(npc
, &((*grp
)[MC_NPC
]));
2605 if ((pc
| npc
) & 3) {
2608 if (env
->regwptr
[UREG_I1
]) {
2609 target_sigset_t target_set
;
2612 if (TARGET_NSIG_WORDS
== 1) {
2613 __get_user(target_set
.sig
[0], &ucp
->tuc_sigmask
.sig
[0]);
2615 abi_ulong
*src
, *dst
;
2616 src
= ucp
->tuc_sigmask
.sig
;
2617 dst
= target_set
.sig
;
2618 for (i
= 0; i
< TARGET_NSIG_WORDS
; i
++, dst
++, src
++) {
2619 __get_user(*dst
, src
);
2622 target_to_host_sigset_internal(&set
, &target_set
);
2627 __get_user(env
->y
, &((*grp
)[MC_Y
]));
2628 __get_user(tstate
, &((*grp
)[MC_TSTATE
]));
2629 env
->asi
= (tstate
>> 24) & 0xff;
2630 cpu_put_ccr(env
, tstate
>> 32);
2631 cpu_put_cwp64(env
, tstate
& 0x1f);
2632 __get_user(env
->gregs
[1], (&(*grp
)[MC_G1
]));
2633 __get_user(env
->gregs
[2], (&(*grp
)[MC_G2
]));
2634 __get_user(env
->gregs
[3], (&(*grp
)[MC_G3
]));
2635 __get_user(env
->gregs
[4], (&(*grp
)[MC_G4
]));
2636 __get_user(env
->gregs
[5], (&(*grp
)[MC_G5
]));
2637 __get_user(env
->gregs
[6], (&(*grp
)[MC_G6
]));
2638 __get_user(env
->gregs
[7], (&(*grp
)[MC_G7
]));
2639 __get_user(env
->regwptr
[UREG_I0
], (&(*grp
)[MC_O0
]));
2640 __get_user(env
->regwptr
[UREG_I1
], (&(*grp
)[MC_O1
]));
2641 __get_user(env
->regwptr
[UREG_I2
], (&(*grp
)[MC_O2
]));
2642 __get_user(env
->regwptr
[UREG_I3
], (&(*grp
)[MC_O3
]));
2643 __get_user(env
->regwptr
[UREG_I4
], (&(*grp
)[MC_O4
]));
2644 __get_user(env
->regwptr
[UREG_I5
], (&(*grp
)[MC_O5
]));
2645 __get_user(env
->regwptr
[UREG_I6
], (&(*grp
)[MC_O6
]));
2646 __get_user(env
->regwptr
[UREG_I7
], (&(*grp
)[MC_O7
]));
2648 __get_user(fp
, &(ucp
->tuc_mcontext
.mc_fp
));
2649 __get_user(i7
, &(ucp
->tuc_mcontext
.mc_i7
));
2651 w_addr
= TARGET_STACK_BIAS
+env
->regwptr
[UREG_I6
];
2652 if (put_user(fp
, w_addr
+ offsetof(struct target_reg_window
, ins
[6]),
2656 if (put_user(i7
, w_addr
+ offsetof(struct target_reg_window
, ins
[7]),
2660 /* FIXME this does not match how the kernel handles the FPU in
2661 * its sparc64_set_context implementation. In particular the FPU
2662 * is only restored if fenab is non-zero in:
2663 * __get_user(fenab, &(ucp->tuc_mcontext.mc_fpregs.mcfpu_enab));
2665 __get_user(env
->fprs
, &(ucp
->tuc_mcontext
.mc_fpregs
.mcfpu_fprs
));
2667 uint32_t *src
= ucp
->tuc_mcontext
.mc_fpregs
.mcfpu_fregs
.sregs
;
2668 for (i
= 0; i
< 64; i
++, src
++) {
2670 __get_user(env
->fpr
[i
/2].l
.lower
, src
);
2672 __get_user(env
->fpr
[i
/2].l
.upper
, src
);
2676 __get_user(env
->fsr
,
2677 &(ucp
->tuc_mcontext
.mc_fpregs
.mcfpu_fsr
));
2678 __get_user(env
->gsr
,
2679 &(ucp
->tuc_mcontext
.mc_fpregs
.mcfpu_gsr
));
2680 unlock_user_struct(ucp
, ucp_addr
, 0);
2683 unlock_user_struct(ucp
, ucp_addr
, 0);
2684 force_sig(TARGET_SIGSEGV
);
2687 void sparc64_get_context(CPUSPARCState
*env
)
2690 struct target_ucontext
*ucp
;
2691 target_mc_gregset_t
*grp
;
2692 target_mcontext_t
*mcp
;
2693 abi_ulong fp
, i7
, w_addr
;
2696 target_sigset_t target_set
;
2699 ucp_addr
= env
->regwptr
[UREG_I0
];
2700 if (!lock_user_struct(VERIFY_WRITE
, ucp
, ucp_addr
, 0)) {
2704 mcp
= &ucp
->tuc_mcontext
;
2705 grp
= &mcp
->mc_gregs
;
2707 /* Skip over the trap instruction, first. */
2711 /* If we're only reading the signal mask then do_sigprocmask()
2712 * is guaranteed not to fail, which is important because we don't
2713 * have any way to signal a failure or restart this operation since
2714 * this is not a normal syscall.
2716 err
= do_sigprocmask(0, NULL
, &set
);
2718 host_to_target_sigset_internal(&target_set
, &set
);
2719 if (TARGET_NSIG_WORDS
== 1) {
2720 __put_user(target_set
.sig
[0],
2721 (abi_ulong
*)&ucp
->tuc_sigmask
);
2723 abi_ulong
*src
, *dst
;
2724 src
= target_set
.sig
;
2725 dst
= ucp
->tuc_sigmask
.sig
;
2726 for (i
= 0; i
< TARGET_NSIG_WORDS
; i
++, dst
++, src
++) {
2727 __put_user(*src
, dst
);
2733 /* XXX: tstate must be saved properly */
2734 // __put_user(env->tstate, &((*grp)[MC_TSTATE]));
2735 __put_user(env
->pc
, &((*grp
)[MC_PC
]));
2736 __put_user(env
->npc
, &((*grp
)[MC_NPC
]));
2737 __put_user(env
->y
, &((*grp
)[MC_Y
]));
2738 __put_user(env
->gregs
[1], &((*grp
)[MC_G1
]));
2739 __put_user(env
->gregs
[2], &((*grp
)[MC_G2
]));
2740 __put_user(env
->gregs
[3], &((*grp
)[MC_G3
]));
2741 __put_user(env
->gregs
[4], &((*grp
)[MC_G4
]));
2742 __put_user(env
->gregs
[5], &((*grp
)[MC_G5
]));
2743 __put_user(env
->gregs
[6], &((*grp
)[MC_G6
]));
2744 __put_user(env
->gregs
[7], &((*grp
)[MC_G7
]));
2745 __put_user(env
->regwptr
[UREG_I0
], &((*grp
)[MC_O0
]));
2746 __put_user(env
->regwptr
[UREG_I1
], &((*grp
)[MC_O1
]));
2747 __put_user(env
->regwptr
[UREG_I2
], &((*grp
)[MC_O2
]));
2748 __put_user(env
->regwptr
[UREG_I3
], &((*grp
)[MC_O3
]));
2749 __put_user(env
->regwptr
[UREG_I4
], &((*grp
)[MC_O4
]));
2750 __put_user(env
->regwptr
[UREG_I5
], &((*grp
)[MC_O5
]));
2751 __put_user(env
->regwptr
[UREG_I6
], &((*grp
)[MC_O6
]));
2752 __put_user(env
->regwptr
[UREG_I7
], &((*grp
)[MC_O7
]));
2754 w_addr
= TARGET_STACK_BIAS
+env
->regwptr
[UREG_I6
];
2756 if (get_user(fp
, w_addr
+ offsetof(struct target_reg_window
, ins
[6]),
2760 if (get_user(i7
, w_addr
+ offsetof(struct target_reg_window
, ins
[7]),
2764 __put_user(fp
, &(mcp
->mc_fp
));
2765 __put_user(i7
, &(mcp
->mc_i7
));
2768 uint32_t *dst
= ucp
->tuc_mcontext
.mc_fpregs
.mcfpu_fregs
.sregs
;
2769 for (i
= 0; i
< 64; i
++, dst
++) {
2771 __put_user(env
->fpr
[i
/2].l
.lower
, dst
);
2773 __put_user(env
->fpr
[i
/2].l
.upper
, dst
);
2777 __put_user(env
->fsr
, &(mcp
->mc_fpregs
.mcfpu_fsr
));
2778 __put_user(env
->gsr
, &(mcp
->mc_fpregs
.mcfpu_gsr
));
2779 __put_user(env
->fprs
, &(mcp
->mc_fpregs
.mcfpu_fprs
));
2783 unlock_user_struct(ucp
, ucp_addr
, 1);
2786 unlock_user_struct(ucp
, ucp_addr
, 1);
2787 force_sig(TARGET_SIGSEGV
);
2790 #elif defined(TARGET_MIPS) || defined(TARGET_MIPS64)
2792 # if defined(TARGET_ABI_MIPSO32)
2793 struct target_sigcontext
{
2794 uint32_t sc_regmask
; /* Unused */
2797 uint64_t sc_regs
[32];
2798 uint64_t sc_fpregs
[32];
2799 uint32_t sc_ownedfp
; /* Unused */
2800 uint32_t sc_fpc_csr
;
2801 uint32_t sc_fpc_eir
; /* Unused */
2802 uint32_t sc_used_math
;
2803 uint32_t sc_dsp
; /* dsp status, was sc_ssflags */
2807 target_ulong sc_hi1
; /* Was sc_cause */
2808 target_ulong sc_lo1
; /* Was sc_badvaddr */
2809 target_ulong sc_hi2
; /* Was sc_sigset[4] */
2810 target_ulong sc_lo2
;
2811 target_ulong sc_hi3
;
2812 target_ulong sc_lo3
;
2814 # else /* N32 || N64 */
2815 struct target_sigcontext
{
2816 uint64_t sc_regs
[32];
2817 uint64_t sc_fpregs
[32];
2827 uint32_t sc_fpc_csr
;
2828 uint32_t sc_used_math
;
2830 uint32_t sc_reserved
;
2835 uint32_t sf_ass
[4]; /* argument save space for o32 */
2836 uint32_t sf_code
[2]; /* signal trampoline */
2837 struct target_sigcontext sf_sc
;
2838 target_sigset_t sf_mask
;
2841 struct target_ucontext
{
2842 target_ulong tuc_flags
;
2843 target_ulong tuc_link
;
2844 target_stack_t tuc_stack
;
2846 struct target_sigcontext tuc_mcontext
;
2847 target_sigset_t tuc_sigmask
;
2850 struct target_rt_sigframe
{
2851 uint32_t rs_ass
[4]; /* argument save space for o32 */
2852 uint32_t rs_code
[2]; /* signal trampoline */
2853 struct target_siginfo rs_info
;
2854 struct target_ucontext rs_uc
;
2857 /* Install trampoline to jump back from signal handler */
2858 static inline int install_sigtramp(unsigned int *tramp
, unsigned int syscall
)
2863 * Set up the return code ...
2865 * li v0, __NR__foo_sigreturn
2869 __put_user(0x24020000 + syscall
, tramp
+ 0);
2870 __put_user(0x0000000c , tramp
+ 1);
2874 static inline void setup_sigcontext(CPUMIPSState
*regs
,
2875 struct target_sigcontext
*sc
)
2879 __put_user(exception_resume_pc(regs
), &sc
->sc_pc
);
2880 regs
->hflags
&= ~MIPS_HFLAG_BMASK
;
2882 __put_user(0, &sc
->sc_regs
[0]);
2883 for (i
= 1; i
< 32; ++i
) {
2884 __put_user(regs
->active_tc
.gpr
[i
], &sc
->sc_regs
[i
]);
2887 __put_user(regs
->active_tc
.HI
[0], &sc
->sc_mdhi
);
2888 __put_user(regs
->active_tc
.LO
[0], &sc
->sc_mdlo
);
2890 /* Rather than checking for dsp existence, always copy. The storage
2891 would just be garbage otherwise. */
2892 __put_user(regs
->active_tc
.HI
[1], &sc
->sc_hi1
);
2893 __put_user(regs
->active_tc
.HI
[2], &sc
->sc_hi2
);
2894 __put_user(regs
->active_tc
.HI
[3], &sc
->sc_hi3
);
2895 __put_user(regs
->active_tc
.LO
[1], &sc
->sc_lo1
);
2896 __put_user(regs
->active_tc
.LO
[2], &sc
->sc_lo2
);
2897 __put_user(regs
->active_tc
.LO
[3], &sc
->sc_lo3
);
2899 uint32_t dsp
= cpu_rddsp(0x3ff, regs
);
2900 __put_user(dsp
, &sc
->sc_dsp
);
2903 __put_user(1, &sc
->sc_used_math
);
2905 for (i
= 0; i
< 32; ++i
) {
2906 __put_user(regs
->active_fpu
.fpr
[i
].d
, &sc
->sc_fpregs
[i
]);
2911 restore_sigcontext(CPUMIPSState
*regs
, struct target_sigcontext
*sc
)
2915 __get_user(regs
->CP0_EPC
, &sc
->sc_pc
);
2917 __get_user(regs
->active_tc
.HI
[0], &sc
->sc_mdhi
);
2918 __get_user(regs
->active_tc
.LO
[0], &sc
->sc_mdlo
);
2920 for (i
= 1; i
< 32; ++i
) {
2921 __get_user(regs
->active_tc
.gpr
[i
], &sc
->sc_regs
[i
]);
2924 __get_user(regs
->active_tc
.HI
[1], &sc
->sc_hi1
);
2925 __get_user(regs
->active_tc
.HI
[2], &sc
->sc_hi2
);
2926 __get_user(regs
->active_tc
.HI
[3], &sc
->sc_hi3
);
2927 __get_user(regs
->active_tc
.LO
[1], &sc
->sc_lo1
);
2928 __get_user(regs
->active_tc
.LO
[2], &sc
->sc_lo2
);
2929 __get_user(regs
->active_tc
.LO
[3], &sc
->sc_lo3
);
2932 __get_user(dsp
, &sc
->sc_dsp
);
2933 cpu_wrdsp(dsp
, 0x3ff, regs
);
2936 for (i
= 0; i
< 32; ++i
) {
2937 __get_user(regs
->active_fpu
.fpr
[i
].d
, &sc
->sc_fpregs
[i
]);
2942 * Determine which stack to use..
2944 static inline abi_ulong
2945 get_sigframe(struct target_sigaction
*ka
, CPUMIPSState
*regs
, size_t frame_size
)
2949 /* Default to using normal stack */
2950 sp
= regs
->active_tc
.gpr
[29];
2953 * FPU emulator may have its own trampoline active just
2954 * above the user stack, 16-bytes before the next lowest
2955 * 16 byte boundary. Try to avoid trashing it.
2959 /* This is the X/Open sanctioned signal stack switching. */
2960 if ((ka
->sa_flags
& TARGET_SA_ONSTACK
) && (sas_ss_flags (sp
) == 0)) {
2961 sp
= target_sigaltstack_used
.ss_sp
+ target_sigaltstack_used
.ss_size
;
2964 return (sp
- frame_size
) & ~7;
2967 static void mips_set_hflags_isa_mode_from_pc(CPUMIPSState
*env
)
2969 if (env
->insn_flags
& (ASE_MIPS16
| ASE_MICROMIPS
)) {
2970 env
->hflags
&= ~MIPS_HFLAG_M16
;
2971 env
->hflags
|= (env
->active_tc
.PC
& 1) << MIPS_HFLAG_M16_SHIFT
;
2972 env
->active_tc
.PC
&= ~(target_ulong
) 1;
2976 # if defined(TARGET_ABI_MIPSO32)
2977 /* compare linux/arch/mips/kernel/signal.c:setup_frame() */
2978 static void setup_frame(int sig
, struct target_sigaction
* ka
,
2979 target_sigset_t
*set
, CPUMIPSState
*regs
)
2981 struct sigframe
*frame
;
2982 abi_ulong frame_addr
;
2985 frame_addr
= get_sigframe(ka
, regs
, sizeof(*frame
));
2986 trace_user_setup_frame(regs
, frame_addr
);
2987 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0)) {
2991 install_sigtramp(frame
->sf_code
, TARGET_NR_sigreturn
);
2993 setup_sigcontext(regs
, &frame
->sf_sc
);
2995 for(i
= 0; i
< TARGET_NSIG_WORDS
; i
++) {
2996 __put_user(set
->sig
[i
], &frame
->sf_mask
.sig
[i
]);
3000 * Arguments to signal handler:
3002 * a0 = signal number
3003 * a1 = 0 (should be cause)
3004 * a2 = pointer to struct sigcontext
3006 * $25 and PC point to the signal handler, $29 points to the
3009 regs
->active_tc
.gpr
[ 4] = sig
;
3010 regs
->active_tc
.gpr
[ 5] = 0;
3011 regs
->active_tc
.gpr
[ 6] = frame_addr
+ offsetof(struct sigframe
, sf_sc
);
3012 regs
->active_tc
.gpr
[29] = frame_addr
;
3013 regs
->active_tc
.gpr
[31] = frame_addr
+ offsetof(struct sigframe
, sf_code
);
3014 /* The original kernel code sets CP0_EPC to the handler
3015 * since it returns to userland using eret
3016 * we cannot do this here, and we must set PC directly */
3017 regs
->active_tc
.PC
= regs
->active_tc
.gpr
[25] = ka
->_sa_handler
;
3018 mips_set_hflags_isa_mode_from_pc(regs
);
3019 unlock_user_struct(frame
, frame_addr
, 1);
3023 force_sig(TARGET_SIGSEGV
/*, current*/);
3026 long do_sigreturn(CPUMIPSState
*regs
)
3028 struct sigframe
*frame
;
3029 abi_ulong frame_addr
;
3031 target_sigset_t target_set
;
3034 frame_addr
= regs
->active_tc
.gpr
[29];
3035 trace_user_do_sigreturn(regs
, frame_addr
);
3036 if (!lock_user_struct(VERIFY_READ
, frame
, frame_addr
, 1))
3039 for(i
= 0; i
< TARGET_NSIG_WORDS
; i
++) {
3040 __get_user(target_set
.sig
[i
], &frame
->sf_mask
.sig
[i
]);
3043 target_to_host_sigset_internal(&blocked
, &target_set
);
3044 set_sigmask(&blocked
);
3046 restore_sigcontext(regs
, &frame
->sf_sc
);
3050 * Don't let your children do this ...
3052 __asm__
__volatile__(
3060 regs
->active_tc
.PC
= regs
->CP0_EPC
;
3061 mips_set_hflags_isa_mode_from_pc(regs
);
3062 /* I am not sure this is right, but it seems to work
3063 * maybe a problem with nested signals ? */
3065 return -TARGET_QEMU_ESIGRETURN
;
3068 force_sig(TARGET_SIGSEGV
/*, current*/);
3073 static void setup_rt_frame(int sig
, struct target_sigaction
*ka
,
3074 target_siginfo_t
*info
,
3075 target_sigset_t
*set
, CPUMIPSState
*env
)
3077 struct target_rt_sigframe
*frame
;
3078 abi_ulong frame_addr
;
3081 frame_addr
= get_sigframe(ka
, env
, sizeof(*frame
));
3082 trace_user_setup_rt_frame(env
, frame_addr
);
3083 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0)) {
3087 install_sigtramp(frame
->rs_code
, TARGET_NR_rt_sigreturn
);
3089 tswap_siginfo(&frame
->rs_info
, info
);
3091 __put_user(0, &frame
->rs_uc
.tuc_flags
);
3092 __put_user(0, &frame
->rs_uc
.tuc_link
);
3093 __put_user(target_sigaltstack_used
.ss_sp
, &frame
->rs_uc
.tuc_stack
.ss_sp
);
3094 __put_user(target_sigaltstack_used
.ss_size
, &frame
->rs_uc
.tuc_stack
.ss_size
);
3095 __put_user(sas_ss_flags(get_sp_from_cpustate(env
)),
3096 &frame
->rs_uc
.tuc_stack
.ss_flags
);
3098 setup_sigcontext(env
, &frame
->rs_uc
.tuc_mcontext
);
3100 for(i
= 0; i
< TARGET_NSIG_WORDS
; i
++) {
3101 __put_user(set
->sig
[i
], &frame
->rs_uc
.tuc_sigmask
.sig
[i
]);
3105 * Arguments to signal handler:
3107 * a0 = signal number
3108 * a1 = pointer to siginfo_t
3109 * a2 = pointer to struct ucontext
3111 * $25 and PC point to the signal handler, $29 points to the
3114 env
->active_tc
.gpr
[ 4] = sig
;
3115 env
->active_tc
.gpr
[ 5] = frame_addr
3116 + offsetof(struct target_rt_sigframe
, rs_info
);
3117 env
->active_tc
.gpr
[ 6] = frame_addr
3118 + offsetof(struct target_rt_sigframe
, rs_uc
);
3119 env
->active_tc
.gpr
[29] = frame_addr
;
3120 env
->active_tc
.gpr
[31] = frame_addr
3121 + offsetof(struct target_rt_sigframe
, rs_code
);
3122 /* The original kernel code sets CP0_EPC to the handler
3123 * since it returns to userland using eret
3124 * we cannot do this here, and we must set PC directly */
3125 env
->active_tc
.PC
= env
->active_tc
.gpr
[25] = ka
->_sa_handler
;
3126 mips_set_hflags_isa_mode_from_pc(env
);
3127 unlock_user_struct(frame
, frame_addr
, 1);
3131 unlock_user_struct(frame
, frame_addr
, 1);
3132 force_sig(TARGET_SIGSEGV
/*, current*/);
3135 long do_rt_sigreturn(CPUMIPSState
*env
)
3137 struct target_rt_sigframe
*frame
;
3138 abi_ulong frame_addr
;
3141 frame_addr
= env
->active_tc
.gpr
[29];
3142 trace_user_do_rt_sigreturn(env
, frame_addr
);
3143 if (!lock_user_struct(VERIFY_READ
, frame
, frame_addr
, 1)) {
3147 target_to_host_sigset(&blocked
, &frame
->rs_uc
.tuc_sigmask
);
3148 set_sigmask(&blocked
);
3150 restore_sigcontext(env
, &frame
->rs_uc
.tuc_mcontext
);
3152 if (do_sigaltstack(frame_addr
+
3153 offsetof(struct target_rt_sigframe
, rs_uc
.tuc_stack
),
3154 0, get_sp_from_cpustate(env
)) == -EFAULT
)
3157 env
->active_tc
.PC
= env
->CP0_EPC
;
3158 mips_set_hflags_isa_mode_from_pc(env
);
3159 /* I am not sure this is right, but it seems to work
3160 * maybe a problem with nested signals ? */
3162 return -TARGET_QEMU_ESIGRETURN
;
3165 force_sig(TARGET_SIGSEGV
/*, current*/);
3169 #elif defined(TARGET_SH4)
3172 * code and data structures from linux kernel:
3173 * include/asm-sh/sigcontext.h
3174 * arch/sh/kernel/signal.c
3177 struct target_sigcontext
{
3178 target_ulong oldmask
;
3181 target_ulong sc_gregs
[16];
3185 target_ulong sc_gbr
;
3186 target_ulong sc_mach
;
3187 target_ulong sc_macl
;
3190 target_ulong sc_fpregs
[16];
3191 target_ulong sc_xfpregs
[16];
3192 unsigned int sc_fpscr
;
3193 unsigned int sc_fpul
;
3194 unsigned int sc_ownedfp
;
3197 struct target_sigframe
3199 struct target_sigcontext sc
;
3200 target_ulong extramask
[TARGET_NSIG_WORDS
-1];
3201 uint16_t retcode
[3];
3205 struct target_ucontext
{
3206 target_ulong tuc_flags
;
3207 struct target_ucontext
*tuc_link
;
3208 target_stack_t tuc_stack
;
3209 struct target_sigcontext tuc_mcontext
;
3210 target_sigset_t tuc_sigmask
; /* mask last for extensibility */
3213 struct target_rt_sigframe
3215 struct target_siginfo info
;
3216 struct target_ucontext uc
;
3217 uint16_t retcode
[3];
3221 #define MOVW(n) (0x9300|((n)-2)) /* Move mem word at PC+n to R3 */
3222 #define TRAP_NOARG 0xc310 /* Syscall w/no args (NR in R3) SH3/4 */
3224 static abi_ulong
get_sigframe(struct target_sigaction
*ka
,
3225 unsigned long sp
, size_t frame_size
)
3227 if ((ka
->sa_flags
& TARGET_SA_ONSTACK
) && (sas_ss_flags(sp
) == 0)) {
3228 sp
= target_sigaltstack_used
.ss_sp
+ target_sigaltstack_used
.ss_size
;
3231 return (sp
- frame_size
) & -8ul;
3234 static void setup_sigcontext(struct target_sigcontext
*sc
,
3235 CPUSH4State
*regs
, unsigned long mask
)
3239 #define COPY(x) __put_user(regs->x, &sc->sc_##x)
3240 COPY(gregs
[0]); COPY(gregs
[1]);
3241 COPY(gregs
[2]); COPY(gregs
[3]);
3242 COPY(gregs
[4]); COPY(gregs
[5]);
3243 COPY(gregs
[6]); COPY(gregs
[7]);
3244 COPY(gregs
[8]); COPY(gregs
[9]);
3245 COPY(gregs
[10]); COPY(gregs
[11]);
3246 COPY(gregs
[12]); COPY(gregs
[13]);
3247 COPY(gregs
[14]); COPY(gregs
[15]);
3248 COPY(gbr
); COPY(mach
);
3249 COPY(macl
); COPY(pr
);
3253 for (i
=0; i
<16; i
++) {
3254 __put_user(regs
->fregs
[i
], &sc
->sc_fpregs
[i
]);
3256 __put_user(regs
->fpscr
, &sc
->sc_fpscr
);
3257 __put_user(regs
->fpul
, &sc
->sc_fpul
);
3259 /* non-iBCS2 extensions.. */
3260 __put_user(mask
, &sc
->oldmask
);
3263 static void restore_sigcontext(CPUSH4State
*regs
, struct target_sigcontext
*sc
)
3267 #define COPY(x) __get_user(regs->x, &sc->sc_##x)
3268 COPY(gregs
[0]); COPY(gregs
[1]);
3269 COPY(gregs
[2]); COPY(gregs
[3]);
3270 COPY(gregs
[4]); COPY(gregs
[5]);
3271 COPY(gregs
[6]); COPY(gregs
[7]);
3272 COPY(gregs
[8]); COPY(gregs
[9]);
3273 COPY(gregs
[10]); COPY(gregs
[11]);
3274 COPY(gregs
[12]); COPY(gregs
[13]);
3275 COPY(gregs
[14]); COPY(gregs
[15]);
3276 COPY(gbr
); COPY(mach
);
3277 COPY(macl
); COPY(pr
);
3281 for (i
=0; i
<16; i
++) {
3282 __get_user(regs
->fregs
[i
], &sc
->sc_fpregs
[i
]);
3284 __get_user(regs
->fpscr
, &sc
->sc_fpscr
);
3285 __get_user(regs
->fpul
, &sc
->sc_fpul
);
3287 regs
->tra
= -1; /* disable syscall checks */
3290 static void setup_frame(int sig
, struct target_sigaction
*ka
,
3291 target_sigset_t
*set
, CPUSH4State
*regs
)
3293 struct target_sigframe
*frame
;
3294 abi_ulong frame_addr
;
3297 frame_addr
= get_sigframe(ka
, regs
->gregs
[15], sizeof(*frame
));
3298 trace_user_setup_frame(regs
, frame_addr
);
3299 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0)) {
3303 setup_sigcontext(&frame
->sc
, regs
, set
->sig
[0]);
3305 for (i
= 0; i
< TARGET_NSIG_WORDS
- 1; i
++) {
3306 __put_user(set
->sig
[i
+ 1], &frame
->extramask
[i
]);
3309 /* Set up to return from userspace. If provided, use a stub
3310 already in userspace. */
3311 if (ka
->sa_flags
& TARGET_SA_RESTORER
) {
3312 regs
->pr
= (unsigned long) ka
->sa_restorer
;
3314 /* Generate return code (system call to sigreturn) */
3315 abi_ulong retcode_addr
= frame_addr
+
3316 offsetof(struct target_sigframe
, retcode
);
3317 __put_user(MOVW(2), &frame
->retcode
[0]);
3318 __put_user(TRAP_NOARG
, &frame
->retcode
[1]);
3319 __put_user((TARGET_NR_sigreturn
), &frame
->retcode
[2]);
3320 regs
->pr
= (unsigned long) retcode_addr
;
3323 /* Set up registers for signal handler */
3324 regs
->gregs
[15] = frame_addr
;
3325 regs
->gregs
[4] = sig
; /* Arg for signal handler */
3327 regs
->gregs
[6] = frame_addr
+= offsetof(typeof(*frame
), sc
);
3328 regs
->pc
= (unsigned long) ka
->_sa_handler
;
3330 unlock_user_struct(frame
, frame_addr
, 1);
3334 unlock_user_struct(frame
, frame_addr
, 1);
3335 force_sig(TARGET_SIGSEGV
);
3338 static void setup_rt_frame(int sig
, struct target_sigaction
*ka
,
3339 target_siginfo_t
*info
,
3340 target_sigset_t
*set
, CPUSH4State
*regs
)
3342 struct target_rt_sigframe
*frame
;
3343 abi_ulong frame_addr
;
3346 frame_addr
= get_sigframe(ka
, regs
->gregs
[15], sizeof(*frame
));
3347 trace_user_setup_rt_frame(regs
, frame_addr
);
3348 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0)) {
3352 tswap_siginfo(&frame
->info
, info
);
3354 /* Create the ucontext. */
3355 __put_user(0, &frame
->uc
.tuc_flags
);
3356 __put_user(0, (unsigned long *)&frame
->uc
.tuc_link
);
3357 __put_user((unsigned long)target_sigaltstack_used
.ss_sp
,
3358 &frame
->uc
.tuc_stack
.ss_sp
);
3359 __put_user(sas_ss_flags(regs
->gregs
[15]),
3360 &frame
->uc
.tuc_stack
.ss_flags
);
3361 __put_user(target_sigaltstack_used
.ss_size
,
3362 &frame
->uc
.tuc_stack
.ss_size
);
3363 setup_sigcontext(&frame
->uc
.tuc_mcontext
,
3365 for(i
= 0; i
< TARGET_NSIG_WORDS
; i
++) {
3366 __put_user(set
->sig
[i
], &frame
->uc
.tuc_sigmask
.sig
[i
]);
3369 /* Set up to return from userspace. If provided, use a stub
3370 already in userspace. */
3371 if (ka
->sa_flags
& TARGET_SA_RESTORER
) {
3372 regs
->pr
= (unsigned long) ka
->sa_restorer
;
3374 /* Generate return code (system call to sigreturn) */
3375 abi_ulong retcode_addr
= frame_addr
+
3376 offsetof(struct target_rt_sigframe
, retcode
);
3377 __put_user(MOVW(2), &frame
->retcode
[0]);
3378 __put_user(TRAP_NOARG
, &frame
->retcode
[1]);
3379 __put_user((TARGET_NR_rt_sigreturn
), &frame
->retcode
[2]);
3380 regs
->pr
= (unsigned long) retcode_addr
;
3383 /* Set up registers for signal handler */
3384 regs
->gregs
[15] = frame_addr
;
3385 regs
->gregs
[4] = sig
; /* Arg for signal handler */
3386 regs
->gregs
[5] = frame_addr
+ offsetof(typeof(*frame
), info
);
3387 regs
->gregs
[6] = frame_addr
+ offsetof(typeof(*frame
), uc
);
3388 regs
->pc
= (unsigned long) ka
->_sa_handler
;
3390 unlock_user_struct(frame
, frame_addr
, 1);
3394 unlock_user_struct(frame
, frame_addr
, 1);
3395 force_sig(TARGET_SIGSEGV
);
3398 long do_sigreturn(CPUSH4State
*regs
)
3400 struct target_sigframe
*frame
;
3401 abi_ulong frame_addr
;
3403 target_sigset_t target_set
;
3407 frame_addr
= regs
->gregs
[15];
3408 trace_user_do_sigreturn(regs
, frame_addr
);
3409 if (!lock_user_struct(VERIFY_READ
, frame
, frame_addr
, 1)) {
3413 __get_user(target_set
.sig
[0], &frame
->sc
.oldmask
);
3414 for(i
= 1; i
< TARGET_NSIG_WORDS
; i
++) {
3415 __get_user(target_set
.sig
[i
], &frame
->extramask
[i
- 1]);
3421 target_to_host_sigset_internal(&blocked
, &target_set
);
3422 set_sigmask(&blocked
);
3424 restore_sigcontext(regs
, &frame
->sc
);
3426 unlock_user_struct(frame
, frame_addr
, 0);
3427 return -TARGET_QEMU_ESIGRETURN
;
3430 unlock_user_struct(frame
, frame_addr
, 0);
3431 force_sig(TARGET_SIGSEGV
);
3435 long do_rt_sigreturn(CPUSH4State
*regs
)
3437 struct target_rt_sigframe
*frame
;
3438 abi_ulong frame_addr
;
3441 frame_addr
= regs
->gregs
[15];
3442 trace_user_do_rt_sigreturn(regs
, frame_addr
);
3443 if (!lock_user_struct(VERIFY_READ
, frame
, frame_addr
, 1)) {
3447 target_to_host_sigset(&blocked
, &frame
->uc
.tuc_sigmask
);
3448 set_sigmask(&blocked
);
3450 restore_sigcontext(regs
, &frame
->uc
.tuc_mcontext
);
3452 if (do_sigaltstack(frame_addr
+
3453 offsetof(struct target_rt_sigframe
, uc
.tuc_stack
),
3454 0, get_sp_from_cpustate(regs
)) == -EFAULT
) {
3458 unlock_user_struct(frame
, frame_addr
, 0);
3459 return -TARGET_QEMU_ESIGRETURN
;
3462 unlock_user_struct(frame
, frame_addr
, 0);
3463 force_sig(TARGET_SIGSEGV
);
3466 #elif defined(TARGET_MICROBLAZE)
3468 struct target_sigcontext
{
3469 struct target_pt_regs regs
; /* needs to be first */
3473 struct target_stack_t
{
3476 unsigned int ss_size
;
3479 struct target_ucontext
{
3480 abi_ulong tuc_flags
;
3482 struct target_stack_t tuc_stack
;
3483 struct target_sigcontext tuc_mcontext
;
3484 uint32_t tuc_extramask
[TARGET_NSIG_WORDS
- 1];
3487 /* Signal frames. */
3488 struct target_signal_frame
{
3489 struct target_ucontext uc
;
3490 uint32_t extramask
[TARGET_NSIG_WORDS
- 1];
3494 struct rt_signal_frame
{
3500 static void setup_sigcontext(struct target_sigcontext
*sc
, CPUMBState
*env
)
3502 __put_user(env
->regs
[0], &sc
->regs
.r0
);
3503 __put_user(env
->regs
[1], &sc
->regs
.r1
);
3504 __put_user(env
->regs
[2], &sc
->regs
.r2
);
3505 __put_user(env
->regs
[3], &sc
->regs
.r3
);
3506 __put_user(env
->regs
[4], &sc
->regs
.r4
);
3507 __put_user(env
->regs
[5], &sc
->regs
.r5
);
3508 __put_user(env
->regs
[6], &sc
->regs
.r6
);
3509 __put_user(env
->regs
[7], &sc
->regs
.r7
);
3510 __put_user(env
->regs
[8], &sc
->regs
.r8
);
3511 __put_user(env
->regs
[9], &sc
->regs
.r9
);
3512 __put_user(env
->regs
[10], &sc
->regs
.r10
);
3513 __put_user(env
->regs
[11], &sc
->regs
.r11
);
3514 __put_user(env
->regs
[12], &sc
->regs
.r12
);
3515 __put_user(env
->regs
[13], &sc
->regs
.r13
);
3516 __put_user(env
->regs
[14], &sc
->regs
.r14
);
3517 __put_user(env
->regs
[15], &sc
->regs
.r15
);
3518 __put_user(env
->regs
[16], &sc
->regs
.r16
);
3519 __put_user(env
->regs
[17], &sc
->regs
.r17
);
3520 __put_user(env
->regs
[18], &sc
->regs
.r18
);
3521 __put_user(env
->regs
[19], &sc
->regs
.r19
);
3522 __put_user(env
->regs
[20], &sc
->regs
.r20
);
3523 __put_user(env
->regs
[21], &sc
->regs
.r21
);
3524 __put_user(env
->regs
[22], &sc
->regs
.r22
);
3525 __put_user(env
->regs
[23], &sc
->regs
.r23
);
3526 __put_user(env
->regs
[24], &sc
->regs
.r24
);
3527 __put_user(env
->regs
[25], &sc
->regs
.r25
);
3528 __put_user(env
->regs
[26], &sc
->regs
.r26
);
3529 __put_user(env
->regs
[27], &sc
->regs
.r27
);
3530 __put_user(env
->regs
[28], &sc
->regs
.r28
);
3531 __put_user(env
->regs
[29], &sc
->regs
.r29
);
3532 __put_user(env
->regs
[30], &sc
->regs
.r30
);
3533 __put_user(env
->regs
[31], &sc
->regs
.r31
);
3534 __put_user(env
->sregs
[SR_PC
], &sc
->regs
.pc
);
3537 static void restore_sigcontext(struct target_sigcontext
*sc
, CPUMBState
*env
)
3539 __get_user(env
->regs
[0], &sc
->regs
.r0
);
3540 __get_user(env
->regs
[1], &sc
->regs
.r1
);
3541 __get_user(env
->regs
[2], &sc
->regs
.r2
);
3542 __get_user(env
->regs
[3], &sc
->regs
.r3
);
3543 __get_user(env
->regs
[4], &sc
->regs
.r4
);
3544 __get_user(env
->regs
[5], &sc
->regs
.r5
);
3545 __get_user(env
->regs
[6], &sc
->regs
.r6
);
3546 __get_user(env
->regs
[7], &sc
->regs
.r7
);
3547 __get_user(env
->regs
[8], &sc
->regs
.r8
);
3548 __get_user(env
->regs
[9], &sc
->regs
.r9
);
3549 __get_user(env
->regs
[10], &sc
->regs
.r10
);
3550 __get_user(env
->regs
[11], &sc
->regs
.r11
);
3551 __get_user(env
->regs
[12], &sc
->regs
.r12
);
3552 __get_user(env
->regs
[13], &sc
->regs
.r13
);
3553 __get_user(env
->regs
[14], &sc
->regs
.r14
);
3554 __get_user(env
->regs
[15], &sc
->regs
.r15
);
3555 __get_user(env
->regs
[16], &sc
->regs
.r16
);
3556 __get_user(env
->regs
[17], &sc
->regs
.r17
);
3557 __get_user(env
->regs
[18], &sc
->regs
.r18
);
3558 __get_user(env
->regs
[19], &sc
->regs
.r19
);
3559 __get_user(env
->regs
[20], &sc
->regs
.r20
);
3560 __get_user(env
->regs
[21], &sc
->regs
.r21
);
3561 __get_user(env
->regs
[22], &sc
->regs
.r22
);
3562 __get_user(env
->regs
[23], &sc
->regs
.r23
);
3563 __get_user(env
->regs
[24], &sc
->regs
.r24
);
3564 __get_user(env
->regs
[25], &sc
->regs
.r25
);
3565 __get_user(env
->regs
[26], &sc
->regs
.r26
);
3566 __get_user(env
->regs
[27], &sc
->regs
.r27
);
3567 __get_user(env
->regs
[28], &sc
->regs
.r28
);
3568 __get_user(env
->regs
[29], &sc
->regs
.r29
);
3569 __get_user(env
->regs
[30], &sc
->regs
.r30
);
3570 __get_user(env
->regs
[31], &sc
->regs
.r31
);
3571 __get_user(env
->sregs
[SR_PC
], &sc
->regs
.pc
);
3574 static abi_ulong
get_sigframe(struct target_sigaction
*ka
,
3575 CPUMBState
*env
, int frame_size
)
3577 abi_ulong sp
= env
->regs
[1];
3579 if ((ka
->sa_flags
& TARGET_SA_ONSTACK
) != 0 && !on_sig_stack(sp
)) {
3580 sp
= target_sigaltstack_used
.ss_sp
+ target_sigaltstack_used
.ss_size
;
3583 return ((sp
- frame_size
) & -8UL);
3586 static void setup_frame(int sig
, struct target_sigaction
*ka
,
3587 target_sigset_t
*set
, CPUMBState
*env
)
3589 struct target_signal_frame
*frame
;
3590 abi_ulong frame_addr
;
3593 frame_addr
= get_sigframe(ka
, env
, sizeof *frame
);
3594 trace_user_setup_frame(env
, frame_addr
);
3595 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0))
3598 /* Save the mask. */
3599 __put_user(set
->sig
[0], &frame
->uc
.tuc_mcontext
.oldmask
);
3601 for(i
= 1; i
< TARGET_NSIG_WORDS
; i
++) {
3602 __put_user(set
->sig
[i
], &frame
->extramask
[i
- 1]);
3605 setup_sigcontext(&frame
->uc
.tuc_mcontext
, env
);
3607 /* Set up to return from userspace. If provided, use a stub
3608 already in userspace. */
3609 /* minus 8 is offset to cater for "rtsd r15,8" offset */
3610 if (ka
->sa_flags
& TARGET_SA_RESTORER
) {
3611 env
->regs
[15] = ((unsigned long)ka
->sa_restorer
)-8;
3614 /* Note, these encodings are _big endian_! */
3615 /* addi r12, r0, __NR_sigreturn */
3616 t
= 0x31800000UL
| TARGET_NR_sigreturn
;
3617 __put_user(t
, frame
->tramp
+ 0);
3620 __put_user(t
, frame
->tramp
+ 1);
3622 /* Return from sighandler will jump to the tramp.
3623 Negative 8 offset because return is rtsd r15, 8 */
3624 env
->regs
[15] = frame_addr
+ offsetof(struct target_signal_frame
, tramp
)
3628 /* Set up registers for signal handler */
3629 env
->regs
[1] = frame_addr
;
3630 /* Signal handler args: */
3631 env
->regs
[5] = sig
; /* Arg 0: signum */
3633 /* arg 1: sigcontext */
3634 env
->regs
[7] = frame_addr
+= offsetof(typeof(*frame
), uc
);
3636 /* Offset of 4 to handle microblaze rtid r14, 0 */
3637 env
->sregs
[SR_PC
] = (unsigned long)ka
->_sa_handler
;
3639 unlock_user_struct(frame
, frame_addr
, 1);
3642 force_sig(TARGET_SIGSEGV
);
3645 static void setup_rt_frame(int sig
, struct target_sigaction
*ka
,
3646 target_siginfo_t
*info
,
3647 target_sigset_t
*set
, CPUMBState
*env
)
3649 fprintf(stderr
, "Microblaze setup_rt_frame: not implemented\n");
3652 long do_sigreturn(CPUMBState
*env
)
3654 struct target_signal_frame
*frame
;
3655 abi_ulong frame_addr
;
3656 target_sigset_t target_set
;
3660 frame_addr
= env
->regs
[R_SP
];
3661 trace_user_do_sigreturn(env
, frame_addr
);
3662 /* Make sure the guest isn't playing games. */
3663 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 1))
3666 /* Restore blocked signals */
3667 __get_user(target_set
.sig
[0], &frame
->uc
.tuc_mcontext
.oldmask
);
3668 for(i
= 1; i
< TARGET_NSIG_WORDS
; i
++) {
3669 __get_user(target_set
.sig
[i
], &frame
->extramask
[i
- 1]);
3671 target_to_host_sigset_internal(&set
, &target_set
);
3674 restore_sigcontext(&frame
->uc
.tuc_mcontext
, env
);
3675 /* We got here through a sigreturn syscall, our path back is via an
3676 rtb insn so setup r14 for that. */
3677 env
->regs
[14] = env
->sregs
[SR_PC
];
3679 unlock_user_struct(frame
, frame_addr
, 0);
3680 return -TARGET_QEMU_ESIGRETURN
;
3682 force_sig(TARGET_SIGSEGV
);
3685 long do_rt_sigreturn(CPUMBState
*env
)
3687 trace_user_do_rt_sigreturn(env
, 0);
3688 fprintf(stderr
, "Microblaze do_rt_sigreturn: not implemented\n");
3689 return -TARGET_ENOSYS
;
3692 #elif defined(TARGET_CRIS)
3694 struct target_sigcontext
{
3695 struct target_pt_regs regs
; /* needs to be first */
3697 uint32_t usp
; /* usp before stacking this gunk on it */
3700 /* Signal frames. */
3701 struct target_signal_frame
{
3702 struct target_sigcontext sc
;
3703 uint32_t extramask
[TARGET_NSIG_WORDS
- 1];
3704 uint16_t retcode
[4]; /* Trampoline code. */
3707 struct rt_signal_frame
{
3712 uint16_t retcode
[4]; /* Trampoline code. */
3715 static void setup_sigcontext(struct target_sigcontext
*sc
, CPUCRISState
*env
)
3717 __put_user(env
->regs
[0], &sc
->regs
.r0
);
3718 __put_user(env
->regs
[1], &sc
->regs
.r1
);
3719 __put_user(env
->regs
[2], &sc
->regs
.r2
);
3720 __put_user(env
->regs
[3], &sc
->regs
.r3
);
3721 __put_user(env
->regs
[4], &sc
->regs
.r4
);
3722 __put_user(env
->regs
[5], &sc
->regs
.r5
);
3723 __put_user(env
->regs
[6], &sc
->regs
.r6
);
3724 __put_user(env
->regs
[7], &sc
->regs
.r7
);
3725 __put_user(env
->regs
[8], &sc
->regs
.r8
);
3726 __put_user(env
->regs
[9], &sc
->regs
.r9
);
3727 __put_user(env
->regs
[10], &sc
->regs
.r10
);
3728 __put_user(env
->regs
[11], &sc
->regs
.r11
);
3729 __put_user(env
->regs
[12], &sc
->regs
.r12
);
3730 __put_user(env
->regs
[13], &sc
->regs
.r13
);
3731 __put_user(env
->regs
[14], &sc
->usp
);
3732 __put_user(env
->regs
[15], &sc
->regs
.acr
);
3733 __put_user(env
->pregs
[PR_MOF
], &sc
->regs
.mof
);
3734 __put_user(env
->pregs
[PR_SRP
], &sc
->regs
.srp
);
3735 __put_user(env
->pc
, &sc
->regs
.erp
);
3738 static void restore_sigcontext(struct target_sigcontext
*sc
, CPUCRISState
*env
)
3740 __get_user(env
->regs
[0], &sc
->regs
.r0
);
3741 __get_user(env
->regs
[1], &sc
->regs
.r1
);
3742 __get_user(env
->regs
[2], &sc
->regs
.r2
);
3743 __get_user(env
->regs
[3], &sc
->regs
.r3
);
3744 __get_user(env
->regs
[4], &sc
->regs
.r4
);
3745 __get_user(env
->regs
[5], &sc
->regs
.r5
);
3746 __get_user(env
->regs
[6], &sc
->regs
.r6
);
3747 __get_user(env
->regs
[7], &sc
->regs
.r7
);
3748 __get_user(env
->regs
[8], &sc
->regs
.r8
);
3749 __get_user(env
->regs
[9], &sc
->regs
.r9
);
3750 __get_user(env
->regs
[10], &sc
->regs
.r10
);
3751 __get_user(env
->regs
[11], &sc
->regs
.r11
);
3752 __get_user(env
->regs
[12], &sc
->regs
.r12
);
3753 __get_user(env
->regs
[13], &sc
->regs
.r13
);
3754 __get_user(env
->regs
[14], &sc
->usp
);
3755 __get_user(env
->regs
[15], &sc
->regs
.acr
);
3756 __get_user(env
->pregs
[PR_MOF
], &sc
->regs
.mof
);
3757 __get_user(env
->pregs
[PR_SRP
], &sc
->regs
.srp
);
3758 __get_user(env
->pc
, &sc
->regs
.erp
);
3761 static abi_ulong
get_sigframe(CPUCRISState
*env
, int framesize
)
3764 /* Align the stack downwards to 4. */
3765 sp
= (env
->regs
[R_SP
] & ~3);
3766 return sp
- framesize
;
3769 static void setup_frame(int sig
, struct target_sigaction
*ka
,
3770 target_sigset_t
*set
, CPUCRISState
*env
)
3772 struct target_signal_frame
*frame
;
3773 abi_ulong frame_addr
;
3776 frame_addr
= get_sigframe(env
, sizeof *frame
);
3777 trace_user_setup_frame(env
, frame_addr
);
3778 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0))
3782 * The CRIS signal return trampoline. A real linux/CRIS kernel doesn't
3783 * use this trampoline anymore but it sets it up for GDB.
3784 * In QEMU, using the trampoline simplifies things a bit so we use it.
3786 * This is movu.w __NR_sigreturn, r9; break 13;
3788 __put_user(0x9c5f, frame
->retcode
+0);
3789 __put_user(TARGET_NR_sigreturn
,
3790 frame
->retcode
+ 1);
3791 __put_user(0xe93d, frame
->retcode
+ 2);
3793 /* Save the mask. */
3794 __put_user(set
->sig
[0], &frame
->sc
.oldmask
);
3796 for(i
= 1; i
< TARGET_NSIG_WORDS
; i
++) {
3797 __put_user(set
->sig
[i
], &frame
->extramask
[i
- 1]);
3800 setup_sigcontext(&frame
->sc
, env
);
3802 /* Move the stack and setup the arguments for the handler. */
3803 env
->regs
[R_SP
] = frame_addr
;
3804 env
->regs
[10] = sig
;
3805 env
->pc
= (unsigned long) ka
->_sa_handler
;
3806 /* Link SRP so the guest returns through the trampoline. */
3807 env
->pregs
[PR_SRP
] = frame_addr
+ offsetof(typeof(*frame
), retcode
);
3809 unlock_user_struct(frame
, frame_addr
, 1);
3812 force_sig(TARGET_SIGSEGV
);
3815 static void setup_rt_frame(int sig
, struct target_sigaction
*ka
,
3816 target_siginfo_t
*info
,
3817 target_sigset_t
*set
, CPUCRISState
*env
)
3819 fprintf(stderr
, "CRIS setup_rt_frame: not implemented\n");
3822 long do_sigreturn(CPUCRISState
*env
)
3824 struct target_signal_frame
*frame
;
3825 abi_ulong frame_addr
;
3826 target_sigset_t target_set
;
3830 frame_addr
= env
->regs
[R_SP
];
3831 trace_user_do_sigreturn(env
, frame_addr
);
3832 /* Make sure the guest isn't playing games. */
3833 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 1)) {
3837 /* Restore blocked signals */
3838 __get_user(target_set
.sig
[0], &frame
->sc
.oldmask
);
3839 for(i
= 1; i
< TARGET_NSIG_WORDS
; i
++) {
3840 __get_user(target_set
.sig
[i
], &frame
->extramask
[i
- 1]);
3842 target_to_host_sigset_internal(&set
, &target_set
);
3845 restore_sigcontext(&frame
->sc
, env
);
3846 unlock_user_struct(frame
, frame_addr
, 0);
3847 return -TARGET_QEMU_ESIGRETURN
;
3849 force_sig(TARGET_SIGSEGV
);
3852 long do_rt_sigreturn(CPUCRISState
*env
)
3854 trace_user_do_rt_sigreturn(env
, 0);
3855 fprintf(stderr
, "CRIS do_rt_sigreturn: not implemented\n");
3856 return -TARGET_ENOSYS
;
3859 #elif defined(TARGET_OPENRISC)
3861 struct target_sigcontext
{
3862 struct target_pt_regs regs
;
3867 struct target_ucontext
{
3868 abi_ulong tuc_flags
;
3870 target_stack_t tuc_stack
;
3871 struct target_sigcontext tuc_mcontext
;
3872 target_sigset_t tuc_sigmask
; /* mask last for extensibility */
3875 struct target_rt_sigframe
{
3878 struct target_siginfo info
;
3879 struct target_sigcontext sc
;
3880 struct target_ucontext uc
;
3881 unsigned char retcode
[16]; /* trampoline code */
3884 /* This is the asm-generic/ucontext.h version */
3886 static int restore_sigcontext(CPUOpenRISCState
*regs
,
3887 struct target_sigcontext
*sc
)
3889 unsigned int err
= 0;
3890 unsigned long old_usp
;
3892 /* Alwys make any pending restarted system call return -EINTR */
3893 current_thread_info()->restart_block
.fn
= do_no_restart_syscall
;
3895 /* restore the regs from &sc->regs (same as sc, since regs is first)
3896 * (sc is already checked for VERIFY_READ since the sigframe was
3897 * checked in sys_sigreturn previously)
3900 if (copy_from_user(regs
, &sc
, sizeof(struct target_pt_regs
))) {
3904 /* make sure the U-flag is set so user-mode cannot fool us */
3908 /* restore the old USP as it was before we stacked the sc etc.
3909 * (we cannot just pop the sigcontext since we aligned the sp and
3910 * stuff after pushing it)
3913 __get_user(old_usp
, &sc
->usp
);
3914 phx_signal("old_usp 0x%lx", old_usp
);
3916 __PHX__ REALLY
/* ??? */
3918 regs
->gpr
[1] = old_usp
;
3920 /* TODO: the other ports use regs->orig_XX to disable syscall checks
3921 * after this completes, but we don't use that mechanism. maybe we can
3932 /* Set up a signal frame. */
3934 static void setup_sigcontext(struct target_sigcontext
*sc
,
3935 CPUOpenRISCState
*regs
,
3938 unsigned long usp
= regs
->gpr
[1];
3940 /* copy the regs. they are first in sc so we can use sc directly */
3942 /*copy_to_user(&sc, regs, sizeof(struct target_pt_regs));*/
3944 /* Set the frametype to CRIS_FRAME_NORMAL for the execution of
3945 the signal handler. The frametype will be restored to its previous
3946 value in restore_sigcontext. */
3947 /*regs->frametype = CRIS_FRAME_NORMAL;*/
3949 /* then some other stuff */
3950 __put_user(mask
, &sc
->oldmask
);
3951 __put_user(usp
, &sc
->usp
);
3954 static inline unsigned long align_sigframe(unsigned long sp
)
3959 static inline abi_ulong
get_sigframe(struct target_sigaction
*ka
,
3960 CPUOpenRISCState
*regs
,
3963 unsigned long sp
= regs
->gpr
[1];
3964 int onsigstack
= on_sig_stack(sp
);
3967 /* This is the X/Open sanctioned signal stack switching. */
3968 if ((ka
->sa_flags
& TARGET_SA_ONSTACK
) != 0 && !onsigstack
) {
3969 sp
= target_sigaltstack_used
.ss_sp
+ target_sigaltstack_used
.ss_size
;
3972 sp
= align_sigframe(sp
- frame_size
);
3975 * If we are on the alternate signal stack and would overflow it, don't.
3976 * Return an always-bogus address instead so we will die with SIGSEGV.
3979 if (onsigstack
&& !likely(on_sig_stack(sp
))) {
3986 static void setup_rt_frame(int sig
, struct target_sigaction
*ka
,
3987 target_siginfo_t
*info
,
3988 target_sigset_t
*set
, CPUOpenRISCState
*env
)
3991 abi_ulong frame_addr
;
3992 unsigned long return_ip
;
3993 struct target_rt_sigframe
*frame
;
3994 abi_ulong info_addr
, uc_addr
;
3996 frame_addr
= get_sigframe(ka
, env
, sizeof(*frame
));
3997 trace_user_setup_rt_frame(env
, frame_addr
);
3998 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0)) {
4002 info_addr
= frame_addr
+ offsetof(struct target_rt_sigframe
, info
);
4003 __put_user(info_addr
, &frame
->pinfo
);
4004 uc_addr
= frame_addr
+ offsetof(struct target_rt_sigframe
, uc
);
4005 __put_user(uc_addr
, &frame
->puc
);
4007 if (ka
->sa_flags
& SA_SIGINFO
) {
4008 tswap_siginfo(&frame
->info
, info
);
4011 /*err |= __clear_user(&frame->uc, offsetof(struct ucontext, uc_mcontext));*/
4012 __put_user(0, &frame
->uc
.tuc_flags
);
4013 __put_user(0, &frame
->uc
.tuc_link
);
4014 __put_user(target_sigaltstack_used
.ss_sp
,
4015 &frame
->uc
.tuc_stack
.ss_sp
);
4016 __put_user(sas_ss_flags(env
->gpr
[1]), &frame
->uc
.tuc_stack
.ss_flags
);
4017 __put_user(target_sigaltstack_used
.ss_size
,
4018 &frame
->uc
.tuc_stack
.ss_size
);
4019 setup_sigcontext(&frame
->sc
, env
, set
->sig
[0]);
4021 /*err |= copy_to_user(frame->uc.tuc_sigmask, set, sizeof(*set));*/
4023 /* trampoline - the desired return ip is the retcode itself */
4024 return_ip
= (unsigned long)&frame
->retcode
;
4025 /* This is l.ori r11,r0,__NR_sigreturn, l.sys 1 */
4026 __put_user(0xa960, (short *)(frame
->retcode
+ 0));
4027 __put_user(TARGET_NR_rt_sigreturn
, (short *)(frame
->retcode
+ 2));
4028 __put_user(0x20000001, (unsigned long *)(frame
->retcode
+ 4));
4029 __put_user(0x15000000, (unsigned long *)(frame
->retcode
+ 8));
4035 /* TODO what is the current->exec_domain stuff and invmap ? */
4037 /* Set up registers for signal handler */
4038 env
->pc
= (unsigned long)ka
->_sa_handler
; /* what we enter NOW */
4039 env
->gpr
[9] = (unsigned long)return_ip
; /* what we enter LATER */
4040 env
->gpr
[3] = (unsigned long)sig
; /* arg 1: signo */
4041 env
->gpr
[4] = (unsigned long)&frame
->info
; /* arg 2: (siginfo_t*) */
4042 env
->gpr
[5] = (unsigned long)&frame
->uc
; /* arg 3: ucontext */
4044 /* actually move the usp to reflect the stacked frame */
4045 env
->gpr
[1] = (unsigned long)frame
;
4050 unlock_user_struct(frame
, frame_addr
, 1);
4051 if (sig
== TARGET_SIGSEGV
) {
4052 ka
->_sa_handler
= TARGET_SIG_DFL
;
4054 force_sig(TARGET_SIGSEGV
);
4057 long do_sigreturn(CPUOpenRISCState
*env
)
4059 trace_user_do_sigreturn(env
, 0);
4060 fprintf(stderr
, "do_sigreturn: not implemented\n");
4061 return -TARGET_ENOSYS
;
4064 long do_rt_sigreturn(CPUOpenRISCState
*env
)
4066 trace_user_do_rt_sigreturn(env
, 0);
4067 fprintf(stderr
, "do_rt_sigreturn: not implemented\n");
4068 return -TARGET_ENOSYS
;
4070 /* TARGET_OPENRISC */
4072 #elif defined(TARGET_S390X)
4074 #define __NUM_GPRS 16
4075 #define __NUM_FPRS 16
4076 #define __NUM_ACRS 16
4078 #define S390_SYSCALL_SIZE 2
4079 #define __SIGNAL_FRAMESIZE 160 /* FIXME: 31-bit mode -> 96 */
4081 #define _SIGCONTEXT_NSIG 64
4082 #define _SIGCONTEXT_NSIG_BPW 64 /* FIXME: 31-bit mode -> 32 */
4083 #define _SIGCONTEXT_NSIG_WORDS (_SIGCONTEXT_NSIG / _SIGCONTEXT_NSIG_BPW)
4084 #define _SIGMASK_COPY_SIZE (sizeof(unsigned long)*_SIGCONTEXT_NSIG_WORDS)
4085 #define PSW_ADDR_AMODE 0x0000000000000000UL /* 0x80000000UL for 31-bit */
4086 #define S390_SYSCALL_OPCODE ((uint16_t)0x0a00)
4090 target_ulong gprs
[__NUM_GPRS
];
4091 unsigned int acrs
[__NUM_ACRS
];
4092 } target_s390_regs_common
;
4096 double fprs
[__NUM_FPRS
];
4097 } target_s390_fp_regs
;
4100 target_s390_regs_common regs
;
4101 target_s390_fp_regs fpregs
;
4104 struct target_sigcontext
{
4105 target_ulong oldmask
[_SIGCONTEXT_NSIG_WORDS
];
4106 target_sigregs
*sregs
;
4110 uint8_t callee_used_stack
[__SIGNAL_FRAMESIZE
];
4111 struct target_sigcontext sc
;
4112 target_sigregs sregs
;
4114 uint8_t retcode
[S390_SYSCALL_SIZE
];
4117 struct target_ucontext
{
4118 target_ulong tuc_flags
;
4119 struct target_ucontext
*tuc_link
;
4120 target_stack_t tuc_stack
;
4121 target_sigregs tuc_mcontext
;
4122 target_sigset_t tuc_sigmask
; /* mask last for extensibility */
4126 uint8_t callee_used_stack
[__SIGNAL_FRAMESIZE
];
4127 uint8_t retcode
[S390_SYSCALL_SIZE
];
4128 struct target_siginfo info
;
4129 struct target_ucontext uc
;
4132 static inline abi_ulong
4133 get_sigframe(struct target_sigaction
*ka
, CPUS390XState
*env
, size_t frame_size
)
4137 /* Default to using normal stack */
4140 /* This is the X/Open sanctioned signal stack switching. */
4141 if (ka
->sa_flags
& TARGET_SA_ONSTACK
) {
4142 if (!sas_ss_flags(sp
)) {
4143 sp
= target_sigaltstack_used
.ss_sp
+
4144 target_sigaltstack_used
.ss_size
;
4148 /* This is the legacy signal stack switching. */
4149 else if (/* FIXME !user_mode(regs) */ 0 &&
4150 !(ka
->sa_flags
& TARGET_SA_RESTORER
) &&
4152 sp
= (abi_ulong
) ka
->sa_restorer
;
4155 return (sp
- frame_size
) & -8ul;
4158 static void save_sigregs(CPUS390XState
*env
, target_sigregs
*sregs
)
4161 //save_access_regs(current->thread.acrs); FIXME
4163 /* Copy a 'clean' PSW mask to the user to avoid leaking
4164 information about whether PER is currently on. */
4165 __put_user(env
->psw
.mask
, &sregs
->regs
.psw
.mask
);
4166 __put_user(env
->psw
.addr
, &sregs
->regs
.psw
.addr
);
4167 for (i
= 0; i
< 16; i
++) {
4168 __put_user(env
->regs
[i
], &sregs
->regs
.gprs
[i
]);
4170 for (i
= 0; i
< 16; i
++) {
4171 __put_user(env
->aregs
[i
], &sregs
->regs
.acrs
[i
]);
4174 * We have to store the fp registers to current->thread.fp_regs
4175 * to merge them with the emulated registers.
4177 //save_fp_regs(¤t->thread.fp_regs); FIXME
4178 for (i
= 0; i
< 16; i
++) {
4179 __put_user(get_freg(env
, i
)->ll
, &sregs
->fpregs
.fprs
[i
]);
4183 static void setup_frame(int sig
, struct target_sigaction
*ka
,
4184 target_sigset_t
*set
, CPUS390XState
*env
)
4187 abi_ulong frame_addr
;
4189 frame_addr
= get_sigframe(ka
, env
, sizeof(*frame
));
4190 trace_user_setup_frame(env
, frame_addr
);
4191 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0)) {
4195 __put_user(set
->sig
[0], &frame
->sc
.oldmask
[0]);
4197 save_sigregs(env
, &frame
->sregs
);
4199 __put_user((abi_ulong
)(unsigned long)&frame
->sregs
,
4200 (abi_ulong
*)&frame
->sc
.sregs
);
4202 /* Set up to return from userspace. If provided, use a stub
4203 already in userspace. */
4204 if (ka
->sa_flags
& TARGET_SA_RESTORER
) {
4205 env
->regs
[14] = (unsigned long)
4206 ka
->sa_restorer
| PSW_ADDR_AMODE
;
4208 env
->regs
[14] = (frame_addr
+ offsetof(sigframe
, retcode
))
4210 __put_user(S390_SYSCALL_OPCODE
| TARGET_NR_sigreturn
,
4211 (uint16_t *)(frame
->retcode
));
4214 /* Set up backchain. */
4215 __put_user(env
->regs
[15], (abi_ulong
*) frame
);
4217 /* Set up registers for signal handler */
4218 env
->regs
[15] = frame_addr
;
4219 env
->psw
.addr
= (target_ulong
) ka
->_sa_handler
| PSW_ADDR_AMODE
;
4221 env
->regs
[2] = sig
; //map_signal(sig);
4222 env
->regs
[3] = frame_addr
+= offsetof(typeof(*frame
), sc
);
4224 /* We forgot to include these in the sigcontext.
4225 To avoid breaking binary compatibility, they are passed as args. */
4226 env
->regs
[4] = 0; // FIXME: no clue... current->thread.trap_no;
4227 env
->regs
[5] = 0; // FIXME: no clue... current->thread.prot_addr;
4229 /* Place signal number on stack to allow backtrace from handler. */
4230 __put_user(env
->regs
[2], (int *) &frame
->signo
);
4231 unlock_user_struct(frame
, frame_addr
, 1);
4235 force_sig(TARGET_SIGSEGV
);
4238 static void setup_rt_frame(int sig
, struct target_sigaction
*ka
,
4239 target_siginfo_t
*info
,
4240 target_sigset_t
*set
, CPUS390XState
*env
)
4244 abi_ulong frame_addr
;
4246 frame_addr
= get_sigframe(ka
, env
, sizeof *frame
);
4247 trace_user_setup_rt_frame(env
, frame_addr
);
4248 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0)) {
4252 tswap_siginfo(&frame
->info
, info
);
4254 /* Create the ucontext. */
4255 __put_user(0, &frame
->uc
.tuc_flags
);
4256 __put_user((abi_ulong
)0, (abi_ulong
*)&frame
->uc
.tuc_link
);
4257 __put_user(target_sigaltstack_used
.ss_sp
, &frame
->uc
.tuc_stack
.ss_sp
);
4258 __put_user(sas_ss_flags(get_sp_from_cpustate(env
)),
4259 &frame
->uc
.tuc_stack
.ss_flags
);
4260 __put_user(target_sigaltstack_used
.ss_size
, &frame
->uc
.tuc_stack
.ss_size
);
4261 save_sigregs(env
, &frame
->uc
.tuc_mcontext
);
4262 for (i
= 0; i
< TARGET_NSIG_WORDS
; i
++) {
4263 __put_user((abi_ulong
)set
->sig
[i
],
4264 (abi_ulong
*)&frame
->uc
.tuc_sigmask
.sig
[i
]);
4267 /* Set up to return from userspace. If provided, use a stub
4268 already in userspace. */
4269 if (ka
->sa_flags
& TARGET_SA_RESTORER
) {
4270 env
->regs
[14] = (unsigned long) ka
->sa_restorer
| PSW_ADDR_AMODE
;
4272 env
->regs
[14] = (unsigned long) frame
->retcode
| PSW_ADDR_AMODE
;
4273 __put_user(S390_SYSCALL_OPCODE
| TARGET_NR_rt_sigreturn
,
4274 (uint16_t *)(frame
->retcode
));
4277 /* Set up backchain. */
4278 __put_user(env
->regs
[15], (abi_ulong
*) frame
);
4280 /* Set up registers for signal handler */
4281 env
->regs
[15] = frame_addr
;
4282 env
->psw
.addr
= (target_ulong
) ka
->_sa_handler
| PSW_ADDR_AMODE
;
4284 env
->regs
[2] = sig
; //map_signal(sig);
4285 env
->regs
[3] = frame_addr
+ offsetof(typeof(*frame
), info
);
4286 env
->regs
[4] = frame_addr
+ offsetof(typeof(*frame
), uc
);
4290 force_sig(TARGET_SIGSEGV
);
4294 restore_sigregs(CPUS390XState
*env
, target_sigregs
*sc
)
4299 for (i
= 0; i
< 16; i
++) {
4300 __get_user(env
->regs
[i
], &sc
->regs
.gprs
[i
]);
4303 __get_user(env
->psw
.mask
, &sc
->regs
.psw
.mask
);
4304 trace_user_s390x_restore_sigregs(env
, (unsigned long long)sc
->regs
.psw
.addr
,
4305 (unsigned long long)env
->psw
.addr
);
4306 __get_user(env
->psw
.addr
, &sc
->regs
.psw
.addr
);
4307 /* FIXME: 31-bit -> | PSW_ADDR_AMODE */
4309 for (i
= 0; i
< 16; i
++) {
4310 __get_user(env
->aregs
[i
], &sc
->regs
.acrs
[i
]);
4312 for (i
= 0; i
< 16; i
++) {
4313 __get_user(get_freg(env
, i
)->ll
, &sc
->fpregs
.fprs
[i
]);
4319 long do_sigreturn(CPUS390XState
*env
)
4322 abi_ulong frame_addr
= env
->regs
[15];
4323 target_sigset_t target_set
;
4326 trace_user_do_sigreturn(env
, frame_addr
);
4327 if (!lock_user_struct(VERIFY_READ
, frame
, frame_addr
, 1)) {
4330 __get_user(target_set
.sig
[0], &frame
->sc
.oldmask
[0]);
4332 target_to_host_sigset_internal(&set
, &target_set
);
4333 set_sigmask(&set
); /* ~_BLOCKABLE? */
4335 if (restore_sigregs(env
, &frame
->sregs
)) {
4339 unlock_user_struct(frame
, frame_addr
, 0);
4340 return -TARGET_QEMU_ESIGRETURN
;
4343 force_sig(TARGET_SIGSEGV
);
4347 long do_rt_sigreturn(CPUS390XState
*env
)
4350 abi_ulong frame_addr
= env
->regs
[15];
4353 trace_user_do_rt_sigreturn(env
, frame_addr
);
4354 if (!lock_user_struct(VERIFY_READ
, frame
, frame_addr
, 1)) {
4357 target_to_host_sigset(&set
, &frame
->uc
.tuc_sigmask
);
4359 set_sigmask(&set
); /* ~_BLOCKABLE? */
4361 if (restore_sigregs(env
, &frame
->uc
.tuc_mcontext
)) {
4365 if (do_sigaltstack(frame_addr
+ offsetof(rt_sigframe
, uc
.tuc_stack
), 0,
4366 get_sp_from_cpustate(env
)) == -EFAULT
) {
4369 unlock_user_struct(frame
, frame_addr
, 0);
4370 return -TARGET_QEMU_ESIGRETURN
;
4373 unlock_user_struct(frame
, frame_addr
, 0);
4374 force_sig(TARGET_SIGSEGV
);
4378 #elif defined(TARGET_PPC)
4380 /* Size of dummy stack frame allocated when calling signal handler.
4381 See arch/powerpc/include/asm/ptrace.h. */
4382 #if defined(TARGET_PPC64)
4383 #define SIGNAL_FRAMESIZE 128
4385 #define SIGNAL_FRAMESIZE 64
4388 /* See arch/powerpc/include/asm/ucontext.h. Only used for 32-bit PPC;
4389 on 64-bit PPC, sigcontext and mcontext are one and the same. */
4390 struct target_mcontext
{
4391 target_ulong mc_gregs
[48];
4392 /* Includes fpscr. */
4393 uint64_t mc_fregs
[33];
4394 target_ulong mc_pad
[2];
4395 /* We need to handle Altivec and SPE at the same time, which no
4396 kernel needs to do. Fortunately, the kernel defines this bit to
4397 be Altivec-register-large all the time, rather than trying to
4398 twiddle it based on the specific platform. */
4400 /* SPE vector registers. One extra for SPEFSCR. */
4402 /* Altivec vector registers. The packing of VSCR and VRSAVE
4403 varies depending on whether we're PPC64 or not: PPC64 splits
4404 them apart; PPC32 stuffs them together. */
4405 #if defined(TARGET_PPC64)
4406 #define QEMU_NVRREG 34
4408 #define QEMU_NVRREG 33
4410 ppc_avr_t altivec
[QEMU_NVRREG
];
4412 } mc_vregs
__attribute__((__aligned__(16)));
4415 /* See arch/powerpc/include/asm/sigcontext.h. */
4416 struct target_sigcontext
{
4417 target_ulong _unused
[4];
4419 #if defined(TARGET_PPC64)
4422 target_ulong handler
;
4423 target_ulong oldmask
;
4424 target_ulong regs
; /* struct pt_regs __user * */
4425 #if defined(TARGET_PPC64)
4426 struct target_mcontext mcontext
;
4430 /* Indices for target_mcontext.mc_gregs, below.
4431 See arch/powerpc/include/asm/ptrace.h for details. */
4467 TARGET_PT_ORIG_R3
= 34,
4472 /* Yes, there are two registers with #39. One is 64-bit only. */
4474 TARGET_PT_SOFTE
= 39,
4475 TARGET_PT_TRAP
= 40,
4477 TARGET_PT_DSISR
= 42,
4478 TARGET_PT_RESULT
= 43,
4479 TARGET_PT_REGS_COUNT
= 44
4483 struct target_ucontext
{
4484 target_ulong tuc_flags
;
4485 target_ulong tuc_link
; /* struct ucontext __user * */
4486 struct target_sigaltstack tuc_stack
;
4487 #if !defined(TARGET_PPC64)
4489 target_ulong tuc_regs
; /* struct mcontext __user *
4490 points to uc_mcontext field */
4492 target_sigset_t tuc_sigmask
;
4493 #if defined(TARGET_PPC64)
4494 target_sigset_t unused
[15]; /* Allow for uc_sigmask growth */
4495 struct target_sigcontext tuc_sigcontext
;
4497 int32_t tuc_maskext
[30];
4498 int32_t tuc_pad2
[3];
4499 struct target_mcontext tuc_mcontext
;
4503 /* See arch/powerpc/kernel/signal_32.c. */
4504 struct target_sigframe
{
4505 struct target_sigcontext sctx
;
4506 struct target_mcontext mctx
;
4510 #if defined(TARGET_PPC64)
4512 #define TARGET_TRAMP_SIZE 6
4514 struct target_rt_sigframe
{
4515 /* sys_rt_sigreturn requires the ucontext be the first field */
4516 struct target_ucontext uc
;
4517 target_ulong _unused
[2];
4518 uint32_t trampoline
[TARGET_TRAMP_SIZE
];
4519 target_ulong pinfo
; /* struct siginfo __user * */
4520 target_ulong puc
; /* void __user * */
4521 struct target_siginfo info
;
4522 /* 64 bit ABI allows for 288 bytes below sp before decrementing it. */
4524 } __attribute__((aligned(16)));
4528 struct target_rt_sigframe
{
4529 struct target_siginfo info
;
4530 struct target_ucontext uc
;
4536 #if defined(TARGET_PPC64)
4538 struct target_func_ptr
{
4545 /* We use the mc_pad field for the signal return trampoline. */
4546 #define tramp mc_pad
4548 /* See arch/powerpc/kernel/signal.c. */
4549 static target_ulong
get_sigframe(struct target_sigaction
*ka
,
4555 oldsp
= env
->gpr
[1];
4557 if ((ka
->sa_flags
& TARGET_SA_ONSTACK
) &&
4558 (sas_ss_flags(oldsp
) == 0)) {
4559 oldsp
= (target_sigaltstack_used
.ss_sp
4560 + target_sigaltstack_used
.ss_size
);
4563 return (oldsp
- frame_size
) & ~0xFUL
;
4566 static void save_user_regs(CPUPPCState
*env
, struct target_mcontext
*frame
)
4568 target_ulong msr
= env
->msr
;
4570 target_ulong ccr
= 0;
4572 /* In general, the kernel attempts to be intelligent about what it
4573 needs to save for Altivec/FP/SPE registers. We don't care that
4574 much, so we just go ahead and save everything. */
4576 /* Save general registers. */
4577 for (i
= 0; i
< ARRAY_SIZE(env
->gpr
); i
++) {
4578 __put_user(env
->gpr
[i
], &frame
->mc_gregs
[i
]);
4580 __put_user(env
->nip
, &frame
->mc_gregs
[TARGET_PT_NIP
]);
4581 __put_user(env
->ctr
, &frame
->mc_gregs
[TARGET_PT_CTR
]);
4582 __put_user(env
->lr
, &frame
->mc_gregs
[TARGET_PT_LNK
]);
4583 __put_user(env
->xer
, &frame
->mc_gregs
[TARGET_PT_XER
]);
4585 for (i
= 0; i
< ARRAY_SIZE(env
->crf
); i
++) {
4586 ccr
|= env
->crf
[i
] << (32 - ((i
+ 1) * 4));
4588 __put_user(ccr
, &frame
->mc_gregs
[TARGET_PT_CCR
]);
4590 /* Save Altivec registers if necessary. */
4591 if (env
->insns_flags
& PPC_ALTIVEC
) {
4592 for (i
= 0; i
< ARRAY_SIZE(env
->avr
); i
++) {
4593 ppc_avr_t
*avr
= &env
->avr
[i
];
4594 ppc_avr_t
*vreg
= &frame
->mc_vregs
.altivec
[i
];
4596 __put_user(avr
->u64
[0], &vreg
->u64
[0]);
4597 __put_user(avr
->u64
[1], &vreg
->u64
[1]);
4599 /* Set MSR_VR in the saved MSR value to indicate that
4600 frame->mc_vregs contains valid data. */
4602 __put_user((uint32_t)env
->spr
[SPR_VRSAVE
],
4603 &frame
->mc_vregs
.altivec
[32].u32
[3]);
4606 /* Save floating point registers. */
4607 if (env
->insns_flags
& PPC_FLOAT
) {
4608 for (i
= 0; i
< ARRAY_SIZE(env
->fpr
); i
++) {
4609 __put_user(env
->fpr
[i
], &frame
->mc_fregs
[i
]);
4611 __put_user((uint64_t) env
->fpscr
, &frame
->mc_fregs
[32]);
4614 /* Save SPE registers. The kernel only saves the high half. */
4615 if (env
->insns_flags
& PPC_SPE
) {
4616 #if defined(TARGET_PPC64)
4617 for (i
= 0; i
< ARRAY_SIZE(env
->gpr
); i
++) {
4618 __put_user(env
->gpr
[i
] >> 32, &frame
->mc_vregs
.spe
[i
]);
4621 for (i
= 0; i
< ARRAY_SIZE(env
->gprh
); i
++) {
4622 __put_user(env
->gprh
[i
], &frame
->mc_vregs
.spe
[i
]);
4625 /* Set MSR_SPE in the saved MSR value to indicate that
4626 frame->mc_vregs contains valid data. */
4628 __put_user(env
->spe_fscr
, &frame
->mc_vregs
.spe
[32]);
4632 __put_user(msr
, &frame
->mc_gregs
[TARGET_PT_MSR
]);
4635 static void encode_trampoline(int sigret
, uint32_t *tramp
)
4637 /* Set up the sigreturn trampoline: li r0,sigret; sc. */
4639 __put_user(0x38000000 | sigret
, &tramp
[0]);
4640 __put_user(0x44000002, &tramp
[1]);
4644 static void restore_user_regs(CPUPPCState
*env
,
4645 struct target_mcontext
*frame
, int sig
)
4647 target_ulong save_r2
= 0;
4654 save_r2
= env
->gpr
[2];
4657 /* Restore general registers. */
4658 for (i
= 0; i
< ARRAY_SIZE(env
->gpr
); i
++) {
4659 __get_user(env
->gpr
[i
], &frame
->mc_gregs
[i
]);
4661 __get_user(env
->nip
, &frame
->mc_gregs
[TARGET_PT_NIP
]);
4662 __get_user(env
->ctr
, &frame
->mc_gregs
[TARGET_PT_CTR
]);
4663 __get_user(env
->lr
, &frame
->mc_gregs
[TARGET_PT_LNK
]);
4664 __get_user(env
->xer
, &frame
->mc_gregs
[TARGET_PT_XER
]);
4665 __get_user(ccr
, &frame
->mc_gregs
[TARGET_PT_CCR
]);
4667 for (i
= 0; i
< ARRAY_SIZE(env
->crf
); i
++) {
4668 env
->crf
[i
] = (ccr
>> (32 - ((i
+ 1) * 4))) & 0xf;
4672 env
->gpr
[2] = save_r2
;
4675 __get_user(msr
, &frame
->mc_gregs
[TARGET_PT_MSR
]);
4677 /* If doing signal return, restore the previous little-endian mode. */
4679 env
->msr
= (env
->msr
& ~(1ull << MSR_LE
)) | (msr
& (1ull << MSR_LE
));
4681 /* Restore Altivec registers if necessary. */
4682 if (env
->insns_flags
& PPC_ALTIVEC
) {
4683 for (i
= 0; i
< ARRAY_SIZE(env
->avr
); i
++) {
4684 ppc_avr_t
*avr
= &env
->avr
[i
];
4685 ppc_avr_t
*vreg
= &frame
->mc_vregs
.altivec
[i
];
4687 __get_user(avr
->u64
[0], &vreg
->u64
[0]);
4688 __get_user(avr
->u64
[1], &vreg
->u64
[1]);
4690 /* Set MSR_VEC in the saved MSR value to indicate that
4691 frame->mc_vregs contains valid data. */
4692 __get_user(env
->spr
[SPR_VRSAVE
],
4693 (target_ulong
*)(&frame
->mc_vregs
.altivec
[32].u32
[3]));
4696 /* Restore floating point registers. */
4697 if (env
->insns_flags
& PPC_FLOAT
) {
4699 for (i
= 0; i
< ARRAY_SIZE(env
->fpr
); i
++) {
4700 __get_user(env
->fpr
[i
], &frame
->mc_fregs
[i
]);
4702 __get_user(fpscr
, &frame
->mc_fregs
[32]);
4703 env
->fpscr
= (uint32_t) fpscr
;
4706 /* Save SPE registers. The kernel only saves the high half. */
4707 if (env
->insns_flags
& PPC_SPE
) {
4708 #if defined(TARGET_PPC64)
4709 for (i
= 0; i
< ARRAY_SIZE(env
->gpr
); i
++) {
4712 __get_user(hi
, &frame
->mc_vregs
.spe
[i
]);
4713 env
->gpr
[i
] = ((uint64_t)hi
<< 32) | ((uint32_t) env
->gpr
[i
]);
4716 for (i
= 0; i
< ARRAY_SIZE(env
->gprh
); i
++) {
4717 __get_user(env
->gprh
[i
], &frame
->mc_vregs
.spe
[i
]);
4720 __get_user(env
->spe_fscr
, &frame
->mc_vregs
.spe
[32]);
4724 static void setup_frame(int sig
, struct target_sigaction
*ka
,
4725 target_sigset_t
*set
, CPUPPCState
*env
)
4727 struct target_sigframe
*frame
;
4728 struct target_sigcontext
*sc
;
4729 target_ulong frame_addr
, newsp
;
4731 #if defined(TARGET_PPC64)
4732 struct image_info
*image
= ((TaskState
*)thread_cpu
->opaque
)->info
;
4735 frame_addr
= get_sigframe(ka
, env
, sizeof(*frame
));
4736 trace_user_setup_frame(env
, frame_addr
);
4737 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 1))
4741 __put_user(ka
->_sa_handler
, &sc
->handler
);
4742 __put_user(set
->sig
[0], &sc
->oldmask
);
4743 #if TARGET_ABI_BITS == 64
4744 __put_user(set
->sig
[0] >> 32, &sc
->_unused
[3]);
4746 __put_user(set
->sig
[1], &sc
->_unused
[3]);
4748 __put_user(h2g(&frame
->mctx
), &sc
->regs
);
4749 __put_user(sig
, &sc
->signal
);
4751 /* Save user regs. */
4752 save_user_regs(env
, &frame
->mctx
);
4754 /* Construct the trampoline code on the stack. */
4755 encode_trampoline(TARGET_NR_sigreturn
, (uint32_t *)&frame
->mctx
.tramp
);
4757 /* The kernel checks for the presence of a VDSO here. We don't
4758 emulate a vdso, so use a sigreturn system call. */
4759 env
->lr
= (target_ulong
) h2g(frame
->mctx
.tramp
);
4761 /* Turn off all fp exceptions. */
4764 /* Create a stack frame for the caller of the handler. */
4765 newsp
= frame_addr
- SIGNAL_FRAMESIZE
;
4766 err
|= put_user(env
->gpr
[1], newsp
, target_ulong
);
4771 /* Set up registers for signal handler. */
4772 env
->gpr
[1] = newsp
;
4774 env
->gpr
[4] = frame_addr
+ offsetof(struct target_sigframe
, sctx
);
4776 #if defined(TARGET_PPC64)
4777 if (get_ppc64_abi(image
) < 2) {
4778 /* ELFv1 PPC64 function pointers are pointers to OPD entries. */
4779 struct target_func_ptr
*handler
=
4780 (struct target_func_ptr
*)g2h(ka
->_sa_handler
);
4781 env
->nip
= tswapl(handler
->entry
);
4782 env
->gpr
[2] = tswapl(handler
->toc
);
4784 /* ELFv2 PPC64 function pointers are entry points, but R12
4785 * must also be set */
4786 env
->nip
= tswapl((target_ulong
) ka
->_sa_handler
);
4787 env
->gpr
[12] = env
->nip
;
4790 env
->nip
= (target_ulong
) ka
->_sa_handler
;
4793 /* Signal handlers are entered in big-endian mode. */
4794 env
->msr
&= ~(1ull << MSR_LE
);
4796 unlock_user_struct(frame
, frame_addr
, 1);
4800 unlock_user_struct(frame
, frame_addr
, 1);
4801 force_sig(TARGET_SIGSEGV
);
4804 static void setup_rt_frame(int sig
, struct target_sigaction
*ka
,
4805 target_siginfo_t
*info
,
4806 target_sigset_t
*set
, CPUPPCState
*env
)
4808 struct target_rt_sigframe
*rt_sf
;
4809 uint32_t *trampptr
= 0;
4810 struct target_mcontext
*mctx
= 0;
4811 target_ulong rt_sf_addr
, newsp
= 0;
4813 #if defined(TARGET_PPC64)
4814 struct image_info
*image
= ((TaskState
*)thread_cpu
->opaque
)->info
;
4817 rt_sf_addr
= get_sigframe(ka
, env
, sizeof(*rt_sf
));
4818 if (!lock_user_struct(VERIFY_WRITE
, rt_sf
, rt_sf_addr
, 1))
4821 tswap_siginfo(&rt_sf
->info
, info
);
4823 __put_user(0, &rt_sf
->uc
.tuc_flags
);
4824 __put_user(0, &rt_sf
->uc
.tuc_link
);
4825 __put_user((target_ulong
)target_sigaltstack_used
.ss_sp
,
4826 &rt_sf
->uc
.tuc_stack
.ss_sp
);
4827 __put_user(sas_ss_flags(env
->gpr
[1]),
4828 &rt_sf
->uc
.tuc_stack
.ss_flags
);
4829 __put_user(target_sigaltstack_used
.ss_size
,
4830 &rt_sf
->uc
.tuc_stack
.ss_size
);
4831 #if !defined(TARGET_PPC64)
4832 __put_user(h2g (&rt_sf
->uc
.tuc_mcontext
),
4833 &rt_sf
->uc
.tuc_regs
);
4835 for(i
= 0; i
< TARGET_NSIG_WORDS
; i
++) {
4836 __put_user(set
->sig
[i
], &rt_sf
->uc
.tuc_sigmask
.sig
[i
]);
4839 #if defined(TARGET_PPC64)
4840 mctx
= &rt_sf
->uc
.tuc_sigcontext
.mcontext
;
4841 trampptr
= &rt_sf
->trampoline
[0];
4843 mctx
= &rt_sf
->uc
.tuc_mcontext
;
4844 trampptr
= (uint32_t *)&rt_sf
->uc
.tuc_mcontext
.tramp
;
4847 save_user_regs(env
, mctx
);
4848 encode_trampoline(TARGET_NR_rt_sigreturn
, trampptr
);
4850 /* The kernel checks for the presence of a VDSO here. We don't
4851 emulate a vdso, so use a sigreturn system call. */
4852 env
->lr
= (target_ulong
) h2g(trampptr
);
4854 /* Turn off all fp exceptions. */
4857 /* Create a stack frame for the caller of the handler. */
4858 newsp
= rt_sf_addr
- (SIGNAL_FRAMESIZE
+ 16);
4859 err
|= put_user(env
->gpr
[1], newsp
, target_ulong
);
4864 /* Set up registers for signal handler. */
4865 env
->gpr
[1] = newsp
;
4866 env
->gpr
[3] = (target_ulong
) sig
;
4867 env
->gpr
[4] = (target_ulong
) h2g(&rt_sf
->info
);
4868 env
->gpr
[5] = (target_ulong
) h2g(&rt_sf
->uc
);
4869 env
->gpr
[6] = (target_ulong
) h2g(rt_sf
);
4871 #if defined(TARGET_PPC64)
4872 if (get_ppc64_abi(image
) < 2) {
4873 /* ELFv1 PPC64 function pointers are pointers to OPD entries. */
4874 struct target_func_ptr
*handler
=
4875 (struct target_func_ptr
*)g2h(ka
->_sa_handler
);
4876 env
->nip
= tswapl(handler
->entry
);
4877 env
->gpr
[2] = tswapl(handler
->toc
);
4879 /* ELFv2 PPC64 function pointers are entry points, but R12
4880 * must also be set */
4881 env
->nip
= tswapl((target_ulong
) ka
->_sa_handler
);
4882 env
->gpr
[12] = env
->nip
;
4885 env
->nip
= (target_ulong
) ka
->_sa_handler
;
4888 /* Signal handlers are entered in big-endian mode. */
4889 env
->msr
&= ~(1ull << MSR_LE
);
4891 unlock_user_struct(rt_sf
, rt_sf_addr
, 1);
4895 unlock_user_struct(rt_sf
, rt_sf_addr
, 1);
4896 force_sig(TARGET_SIGSEGV
);
4900 long do_sigreturn(CPUPPCState
*env
)
4902 struct target_sigcontext
*sc
= NULL
;
4903 struct target_mcontext
*sr
= NULL
;
4904 target_ulong sr_addr
= 0, sc_addr
;
4906 target_sigset_t set
;
4908 sc_addr
= env
->gpr
[1] + SIGNAL_FRAMESIZE
;
4909 if (!lock_user_struct(VERIFY_READ
, sc
, sc_addr
, 1))
4912 #if defined(TARGET_PPC64)
4913 set
.sig
[0] = sc
->oldmask
+ ((uint64_t)(sc
->_unused
[3]) << 32);
4915 __get_user(set
.sig
[0], &sc
->oldmask
);
4916 __get_user(set
.sig
[1], &sc
->_unused
[3]);
4918 target_to_host_sigset_internal(&blocked
, &set
);
4919 set_sigmask(&blocked
);
4921 __get_user(sr_addr
, &sc
->regs
);
4922 if (!lock_user_struct(VERIFY_READ
, sr
, sr_addr
, 1))
4924 restore_user_regs(env
, sr
, 1);
4926 unlock_user_struct(sr
, sr_addr
, 1);
4927 unlock_user_struct(sc
, sc_addr
, 1);
4928 return -TARGET_QEMU_ESIGRETURN
;
4931 unlock_user_struct(sr
, sr_addr
, 1);
4932 unlock_user_struct(sc
, sc_addr
, 1);
4933 force_sig(TARGET_SIGSEGV
);
4937 /* See arch/powerpc/kernel/signal_32.c. */
4938 static int do_setcontext(struct target_ucontext
*ucp
, CPUPPCState
*env
, int sig
)
4940 struct target_mcontext
*mcp
;
4941 target_ulong mcp_addr
;
4943 target_sigset_t set
;
4945 if (copy_from_user(&set
, h2g(ucp
) + offsetof(struct target_ucontext
, tuc_sigmask
),
4949 #if defined(TARGET_PPC64)
4950 mcp_addr
= h2g(ucp
) +
4951 offsetof(struct target_ucontext
, tuc_sigcontext
.mcontext
);
4953 __get_user(mcp_addr
, &ucp
->tuc_regs
);
4956 if (!lock_user_struct(VERIFY_READ
, mcp
, mcp_addr
, 1))
4959 target_to_host_sigset_internal(&blocked
, &set
);
4960 set_sigmask(&blocked
);
4961 restore_user_regs(env
, mcp
, sig
);
4963 unlock_user_struct(mcp
, mcp_addr
, 1);
4967 long do_rt_sigreturn(CPUPPCState
*env
)
4969 struct target_rt_sigframe
*rt_sf
= NULL
;
4970 target_ulong rt_sf_addr
;
4972 rt_sf_addr
= env
->gpr
[1] + SIGNAL_FRAMESIZE
+ 16;
4973 if (!lock_user_struct(VERIFY_READ
, rt_sf
, rt_sf_addr
, 1))
4976 if (do_setcontext(&rt_sf
->uc
, env
, 1))
4979 do_sigaltstack(rt_sf_addr
4980 + offsetof(struct target_rt_sigframe
, uc
.tuc_stack
),
4983 unlock_user_struct(rt_sf
, rt_sf_addr
, 1);
4984 return -TARGET_QEMU_ESIGRETURN
;
4987 unlock_user_struct(rt_sf
, rt_sf_addr
, 1);
4988 force_sig(TARGET_SIGSEGV
);
4992 #elif defined(TARGET_M68K)
4994 struct target_sigcontext
{
5001 unsigned short sc_sr
;
5005 struct target_sigframe
5012 abi_ulong extramask
[TARGET_NSIG_WORDS
-1];
5013 struct target_sigcontext sc
;
5016 typedef int target_greg_t
;
5017 #define TARGET_NGREG 18
5018 typedef target_greg_t target_gregset_t
[TARGET_NGREG
];
5020 typedef struct target_fpregset
{
5023 } target_fpregset_t
;
5025 struct target_mcontext
{
5027 target_gregset_t gregs
;
5028 target_fpregset_t fpregs
;
5031 #define TARGET_MCONTEXT_VERSION 2
5033 struct target_ucontext
{
5034 abi_ulong tuc_flags
;
5036 target_stack_t tuc_stack
;
5037 struct target_mcontext tuc_mcontext
;
5038 abi_long tuc_filler
[80];
5039 target_sigset_t tuc_sigmask
;
5042 struct target_rt_sigframe
5049 struct target_siginfo info
;
5050 struct target_ucontext uc
;
5053 static void setup_sigcontext(struct target_sigcontext
*sc
, CPUM68KState
*env
,
5056 __put_user(mask
, &sc
->sc_mask
);
5057 __put_user(env
->aregs
[7], &sc
->sc_usp
);
5058 __put_user(env
->dregs
[0], &sc
->sc_d0
);
5059 __put_user(env
->dregs
[1], &sc
->sc_d1
);
5060 __put_user(env
->aregs
[0], &sc
->sc_a0
);
5061 __put_user(env
->aregs
[1], &sc
->sc_a1
);
5062 __put_user(env
->sr
, &sc
->sc_sr
);
5063 __put_user(env
->pc
, &sc
->sc_pc
);
5067 restore_sigcontext(CPUM68KState
*env
, struct target_sigcontext
*sc
)
5071 __get_user(env
->aregs
[7], &sc
->sc_usp
);
5072 __get_user(env
->dregs
[0], &sc
->sc_d0
);
5073 __get_user(env
->dregs
[1], &sc
->sc_d1
);
5074 __get_user(env
->aregs
[0], &sc
->sc_a0
);
5075 __get_user(env
->aregs
[1], &sc
->sc_a1
);
5076 __get_user(env
->pc
, &sc
->sc_pc
);
5077 __get_user(temp
, &sc
->sc_sr
);
5078 env
->sr
= (env
->sr
& 0xff00) | (temp
& 0xff);
5082 * Determine which stack to use..
5084 static inline abi_ulong
5085 get_sigframe(struct target_sigaction
*ka
, CPUM68KState
*regs
,
5090 sp
= regs
->aregs
[7];
5092 /* This is the X/Open sanctioned signal stack switching. */
5093 if ((ka
->sa_flags
& TARGET_SA_ONSTACK
) && (sas_ss_flags (sp
) == 0)) {
5094 sp
= target_sigaltstack_used
.ss_sp
+ target_sigaltstack_used
.ss_size
;
5097 return ((sp
- frame_size
) & -8UL);
5100 static void setup_frame(int sig
, struct target_sigaction
*ka
,
5101 target_sigset_t
*set
, CPUM68KState
*env
)
5103 struct target_sigframe
*frame
;
5104 abi_ulong frame_addr
;
5105 abi_ulong retcode_addr
;
5109 frame_addr
= get_sigframe(ka
, env
, sizeof *frame
);
5110 trace_user_setup_frame(env
, frame_addr
);
5111 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0)) {
5115 __put_user(sig
, &frame
->sig
);
5117 sc_addr
= frame_addr
+ offsetof(struct target_sigframe
, sc
);
5118 __put_user(sc_addr
, &frame
->psc
);
5120 setup_sigcontext(&frame
->sc
, env
, set
->sig
[0]);
5122 for(i
= 1; i
< TARGET_NSIG_WORDS
; i
++) {
5123 __put_user(set
->sig
[i
], &frame
->extramask
[i
- 1]);
5126 /* Set up to return from userspace. */
5128 retcode_addr
= frame_addr
+ offsetof(struct target_sigframe
, retcode
);
5129 __put_user(retcode_addr
, &frame
->pretcode
);
5131 /* moveq #,d0; trap #0 */
5133 __put_user(0x70004e40 + (TARGET_NR_sigreturn
<< 16),
5134 (uint32_t *)(frame
->retcode
));
5136 /* Set up to return from userspace */
5138 env
->aregs
[7] = frame_addr
;
5139 env
->pc
= ka
->_sa_handler
;
5141 unlock_user_struct(frame
, frame_addr
, 1);
5145 force_sig(TARGET_SIGSEGV
);
5148 static inline int target_rt_setup_ucontext(struct target_ucontext
*uc
,
5151 target_greg_t
*gregs
= uc
->tuc_mcontext
.gregs
;
5153 __put_user(TARGET_MCONTEXT_VERSION
, &uc
->tuc_mcontext
.version
);
5154 __put_user(env
->dregs
[0], &gregs
[0]);
5155 __put_user(env
->dregs
[1], &gregs
[1]);
5156 __put_user(env
->dregs
[2], &gregs
[2]);
5157 __put_user(env
->dregs
[3], &gregs
[3]);
5158 __put_user(env
->dregs
[4], &gregs
[4]);
5159 __put_user(env
->dregs
[5], &gregs
[5]);
5160 __put_user(env
->dregs
[6], &gregs
[6]);
5161 __put_user(env
->dregs
[7], &gregs
[7]);
5162 __put_user(env
->aregs
[0], &gregs
[8]);
5163 __put_user(env
->aregs
[1], &gregs
[9]);
5164 __put_user(env
->aregs
[2], &gregs
[10]);
5165 __put_user(env
->aregs
[3], &gregs
[11]);
5166 __put_user(env
->aregs
[4], &gregs
[12]);
5167 __put_user(env
->aregs
[5], &gregs
[13]);
5168 __put_user(env
->aregs
[6], &gregs
[14]);
5169 __put_user(env
->aregs
[7], &gregs
[15]);
5170 __put_user(env
->pc
, &gregs
[16]);
5171 __put_user(env
->sr
, &gregs
[17]);
5176 static inline int target_rt_restore_ucontext(CPUM68KState
*env
,
5177 struct target_ucontext
*uc
)
5180 target_greg_t
*gregs
= uc
->tuc_mcontext
.gregs
;
5182 __get_user(temp
, &uc
->tuc_mcontext
.version
);
5183 if (temp
!= TARGET_MCONTEXT_VERSION
)
5186 /* restore passed registers */
5187 __get_user(env
->dregs
[0], &gregs
[0]);
5188 __get_user(env
->dregs
[1], &gregs
[1]);
5189 __get_user(env
->dregs
[2], &gregs
[2]);
5190 __get_user(env
->dregs
[3], &gregs
[3]);
5191 __get_user(env
->dregs
[4], &gregs
[4]);
5192 __get_user(env
->dregs
[5], &gregs
[5]);
5193 __get_user(env
->dregs
[6], &gregs
[6]);
5194 __get_user(env
->dregs
[7], &gregs
[7]);
5195 __get_user(env
->aregs
[0], &gregs
[8]);
5196 __get_user(env
->aregs
[1], &gregs
[9]);
5197 __get_user(env
->aregs
[2], &gregs
[10]);
5198 __get_user(env
->aregs
[3], &gregs
[11]);
5199 __get_user(env
->aregs
[4], &gregs
[12]);
5200 __get_user(env
->aregs
[5], &gregs
[13]);
5201 __get_user(env
->aregs
[6], &gregs
[14]);
5202 __get_user(env
->aregs
[7], &gregs
[15]);
5203 __get_user(env
->pc
, &gregs
[16]);
5204 __get_user(temp
, &gregs
[17]);
5205 env
->sr
= (env
->sr
& 0xff00) | (temp
& 0xff);
5213 static void setup_rt_frame(int sig
, struct target_sigaction
*ka
,
5214 target_siginfo_t
*info
,
5215 target_sigset_t
*set
, CPUM68KState
*env
)
5217 struct target_rt_sigframe
*frame
;
5218 abi_ulong frame_addr
;
5219 abi_ulong retcode_addr
;
5220 abi_ulong info_addr
;
5225 frame_addr
= get_sigframe(ka
, env
, sizeof *frame
);
5226 trace_user_setup_rt_frame(env
, frame_addr
);
5227 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0)) {
5231 __put_user(sig
, &frame
->sig
);
5233 info_addr
= frame_addr
+ offsetof(struct target_rt_sigframe
, info
);
5234 __put_user(info_addr
, &frame
->pinfo
);
5236 uc_addr
= frame_addr
+ offsetof(struct target_rt_sigframe
, uc
);
5237 __put_user(uc_addr
, &frame
->puc
);
5239 tswap_siginfo(&frame
->info
, info
);
5241 /* Create the ucontext */
5243 __put_user(0, &frame
->uc
.tuc_flags
);
5244 __put_user(0, &frame
->uc
.tuc_link
);
5245 __put_user(target_sigaltstack_used
.ss_sp
,
5246 &frame
->uc
.tuc_stack
.ss_sp
);
5247 __put_user(sas_ss_flags(env
->aregs
[7]),
5248 &frame
->uc
.tuc_stack
.ss_flags
);
5249 __put_user(target_sigaltstack_used
.ss_size
,
5250 &frame
->uc
.tuc_stack
.ss_size
);
5251 err
|= target_rt_setup_ucontext(&frame
->uc
, env
);
5256 for(i
= 0; i
< TARGET_NSIG_WORDS
; i
++) {
5257 __put_user(set
->sig
[i
], &frame
->uc
.tuc_sigmask
.sig
[i
]);
5260 /* Set up to return from userspace. */
5262 retcode_addr
= frame_addr
+ offsetof(struct target_sigframe
, retcode
);
5263 __put_user(retcode_addr
, &frame
->pretcode
);
5265 /* moveq #,d0; notb d0; trap #0 */
5267 __put_user(0x70004600 + ((TARGET_NR_rt_sigreturn
^ 0xff) << 16),
5268 (uint32_t *)(frame
->retcode
+ 0));
5269 __put_user(0x4e40, (uint16_t *)(frame
->retcode
+ 4));
5274 /* Set up to return from userspace */
5276 env
->aregs
[7] = frame_addr
;
5277 env
->pc
= ka
->_sa_handler
;
5279 unlock_user_struct(frame
, frame_addr
, 1);
5283 unlock_user_struct(frame
, frame_addr
, 1);
5284 force_sig(TARGET_SIGSEGV
);
5287 long do_sigreturn(CPUM68KState
*env
)
5289 struct target_sigframe
*frame
;
5290 abi_ulong frame_addr
= env
->aregs
[7] - 4;
5291 target_sigset_t target_set
;
5295 trace_user_do_sigreturn(env
, frame_addr
);
5296 if (!lock_user_struct(VERIFY_READ
, frame
, frame_addr
, 1))
5299 /* set blocked signals */
5301 __get_user(target_set
.sig
[0], &frame
->sc
.sc_mask
);
5303 for(i
= 1; i
< TARGET_NSIG_WORDS
; i
++) {
5304 __get_user(target_set
.sig
[i
], &frame
->extramask
[i
- 1]);
5307 target_to_host_sigset_internal(&set
, &target_set
);
5310 /* restore registers */
5312 restore_sigcontext(env
, &frame
->sc
);
5314 unlock_user_struct(frame
, frame_addr
, 0);
5315 return -TARGET_QEMU_ESIGRETURN
;
5318 force_sig(TARGET_SIGSEGV
);
5322 long do_rt_sigreturn(CPUM68KState
*env
)
5324 struct target_rt_sigframe
*frame
;
5325 abi_ulong frame_addr
= env
->aregs
[7] - 4;
5326 target_sigset_t target_set
;
5329 trace_user_do_rt_sigreturn(env
, frame_addr
);
5330 if (!lock_user_struct(VERIFY_READ
, frame
, frame_addr
, 1))
5333 target_to_host_sigset_internal(&set
, &target_set
);
5336 /* restore registers */
5338 if (target_rt_restore_ucontext(env
, &frame
->uc
))
5341 if (do_sigaltstack(frame_addr
+
5342 offsetof(struct target_rt_sigframe
, uc
.tuc_stack
),
5343 0, get_sp_from_cpustate(env
)) == -EFAULT
)
5346 unlock_user_struct(frame
, frame_addr
, 0);
5347 return -TARGET_QEMU_ESIGRETURN
;
5350 unlock_user_struct(frame
, frame_addr
, 0);
5351 force_sig(TARGET_SIGSEGV
);
5355 #elif defined(TARGET_ALPHA)
5357 struct target_sigcontext
{
5358 abi_long sc_onstack
;
5362 abi_long sc_regs
[32];
5363 abi_long sc_ownedfp
;
5364 abi_long sc_fpregs
[32];
5366 abi_ulong sc_fp_control
;
5367 abi_ulong sc_reserved1
;
5368 abi_ulong sc_reserved2
;
5371 abi_ulong sc_traparg_a0
;
5372 abi_ulong sc_traparg_a1
;
5373 abi_ulong sc_traparg_a2
;
5374 abi_ulong sc_fp_trap_pc
;
5375 abi_ulong sc_fp_trigger_sum
;
5376 abi_ulong sc_fp_trigger_inst
;
5379 struct target_ucontext
{
5380 abi_ulong tuc_flags
;
5382 abi_ulong tuc_osf_sigmask
;
5383 target_stack_t tuc_stack
;
5384 struct target_sigcontext tuc_mcontext
;
5385 target_sigset_t tuc_sigmask
;
5388 struct target_sigframe
{
5389 struct target_sigcontext sc
;
5390 unsigned int retcode
[3];
5393 struct target_rt_sigframe
{
5394 target_siginfo_t info
;
5395 struct target_ucontext uc
;
5396 unsigned int retcode
[3];
5399 #define INSN_MOV_R30_R16 0x47fe0410
5400 #define INSN_LDI_R0 0x201f0000
5401 #define INSN_CALLSYS 0x00000083
5403 static void setup_sigcontext(struct target_sigcontext
*sc
, CPUAlphaState
*env
,
5404 abi_ulong frame_addr
, target_sigset_t
*set
)
5408 __put_user(on_sig_stack(frame_addr
), &sc
->sc_onstack
);
5409 __put_user(set
->sig
[0], &sc
->sc_mask
);
5410 __put_user(env
->pc
, &sc
->sc_pc
);
5411 __put_user(8, &sc
->sc_ps
);
5413 for (i
= 0; i
< 31; ++i
) {
5414 __put_user(env
->ir
[i
], &sc
->sc_regs
[i
]);
5416 __put_user(0, &sc
->sc_regs
[31]);
5418 for (i
= 0; i
< 31; ++i
) {
5419 __put_user(env
->fir
[i
], &sc
->sc_fpregs
[i
]);
5421 __put_user(0, &sc
->sc_fpregs
[31]);
5422 __put_user(cpu_alpha_load_fpcr(env
), &sc
->sc_fpcr
);
5424 __put_user(0, &sc
->sc_traparg_a0
); /* FIXME */
5425 __put_user(0, &sc
->sc_traparg_a1
); /* FIXME */
5426 __put_user(0, &sc
->sc_traparg_a2
); /* FIXME */
5429 static void restore_sigcontext(CPUAlphaState
*env
,
5430 struct target_sigcontext
*sc
)
5435 __get_user(env
->pc
, &sc
->sc_pc
);
5437 for (i
= 0; i
< 31; ++i
) {
5438 __get_user(env
->ir
[i
], &sc
->sc_regs
[i
]);
5440 for (i
= 0; i
< 31; ++i
) {
5441 __get_user(env
->fir
[i
], &sc
->sc_fpregs
[i
]);
5444 __get_user(fpcr
, &sc
->sc_fpcr
);
5445 cpu_alpha_store_fpcr(env
, fpcr
);
5448 static inline abi_ulong
get_sigframe(struct target_sigaction
*sa
,
5450 unsigned long framesize
)
5452 abi_ulong sp
= env
->ir
[IR_SP
];
5454 /* This is the X/Open sanctioned signal stack switching. */
5455 if ((sa
->sa_flags
& TARGET_SA_ONSTACK
) != 0 && !sas_ss_flags(sp
)) {
5456 sp
= target_sigaltstack_used
.ss_sp
+ target_sigaltstack_used
.ss_size
;
5458 return (sp
- framesize
) & -32;
5461 static void setup_frame(int sig
, struct target_sigaction
*ka
,
5462 target_sigset_t
*set
, CPUAlphaState
*env
)
5464 abi_ulong frame_addr
, r26
;
5465 struct target_sigframe
*frame
;
5468 frame_addr
= get_sigframe(ka
, env
, sizeof(*frame
));
5469 trace_user_setup_frame(env
, frame_addr
);
5470 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0)) {
5474 setup_sigcontext(&frame
->sc
, env
, frame_addr
, set
);
5476 if (ka
->sa_restorer
) {
5477 r26
= ka
->sa_restorer
;
5479 __put_user(INSN_MOV_R30_R16
, &frame
->retcode
[0]);
5480 __put_user(INSN_LDI_R0
+ TARGET_NR_sigreturn
,
5481 &frame
->retcode
[1]);
5482 __put_user(INSN_CALLSYS
, &frame
->retcode
[2]);
5487 unlock_user_struct(frame
, frame_addr
, 1);
5491 if (sig
== TARGET_SIGSEGV
) {
5492 ka
->_sa_handler
= TARGET_SIG_DFL
;
5494 force_sig(TARGET_SIGSEGV
);
5497 env
->ir
[IR_RA
] = r26
;
5498 env
->ir
[IR_PV
] = env
->pc
= ka
->_sa_handler
;
5499 env
->ir
[IR_A0
] = sig
;
5501 env
->ir
[IR_A2
] = frame_addr
+ offsetof(struct target_sigframe
, sc
);
5502 env
->ir
[IR_SP
] = frame_addr
;
5505 static void setup_rt_frame(int sig
, struct target_sigaction
*ka
,
5506 target_siginfo_t
*info
,
5507 target_sigset_t
*set
, CPUAlphaState
*env
)
5509 abi_ulong frame_addr
, r26
;
5510 struct target_rt_sigframe
*frame
;
5513 frame_addr
= get_sigframe(ka
, env
, sizeof(*frame
));
5514 trace_user_setup_rt_frame(env
, frame_addr
);
5515 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0)) {
5519 tswap_siginfo(&frame
->info
, info
);
5521 __put_user(0, &frame
->uc
.tuc_flags
);
5522 __put_user(0, &frame
->uc
.tuc_link
);
5523 __put_user(set
->sig
[0], &frame
->uc
.tuc_osf_sigmask
);
5524 __put_user(target_sigaltstack_used
.ss_sp
,
5525 &frame
->uc
.tuc_stack
.ss_sp
);
5526 __put_user(sas_ss_flags(env
->ir
[IR_SP
]),
5527 &frame
->uc
.tuc_stack
.ss_flags
);
5528 __put_user(target_sigaltstack_used
.ss_size
,
5529 &frame
->uc
.tuc_stack
.ss_size
);
5530 setup_sigcontext(&frame
->uc
.tuc_mcontext
, env
, frame_addr
, set
);
5531 for (i
= 0; i
< TARGET_NSIG_WORDS
; ++i
) {
5532 __put_user(set
->sig
[i
], &frame
->uc
.tuc_sigmask
.sig
[i
]);
5535 if (ka
->sa_restorer
) {
5536 r26
= ka
->sa_restorer
;
5538 __put_user(INSN_MOV_R30_R16
, &frame
->retcode
[0]);
5539 __put_user(INSN_LDI_R0
+ TARGET_NR_rt_sigreturn
,
5540 &frame
->retcode
[1]);
5541 __put_user(INSN_CALLSYS
, &frame
->retcode
[2]);
5548 if (sig
== TARGET_SIGSEGV
) {
5549 ka
->_sa_handler
= TARGET_SIG_DFL
;
5551 force_sig(TARGET_SIGSEGV
);
5554 env
->ir
[IR_RA
] = r26
;
5555 env
->ir
[IR_PV
] = env
->pc
= ka
->_sa_handler
;
5556 env
->ir
[IR_A0
] = sig
;
5557 env
->ir
[IR_A1
] = frame_addr
+ offsetof(struct target_rt_sigframe
, info
);
5558 env
->ir
[IR_A2
] = frame_addr
+ offsetof(struct target_rt_sigframe
, uc
);
5559 env
->ir
[IR_SP
] = frame_addr
;
5562 long do_sigreturn(CPUAlphaState
*env
)
5564 struct target_sigcontext
*sc
;
5565 abi_ulong sc_addr
= env
->ir
[IR_A0
];
5566 target_sigset_t target_set
;
5569 if (!lock_user_struct(VERIFY_READ
, sc
, sc_addr
, 1)) {
5573 target_sigemptyset(&target_set
);
5574 __get_user(target_set
.sig
[0], &sc
->sc_mask
);
5576 target_to_host_sigset_internal(&set
, &target_set
);
5579 restore_sigcontext(env
, sc
);
5580 unlock_user_struct(sc
, sc_addr
, 0);
5581 return -TARGET_QEMU_ESIGRETURN
;
5584 force_sig(TARGET_SIGSEGV
);
5587 long do_rt_sigreturn(CPUAlphaState
*env
)
5589 abi_ulong frame_addr
= env
->ir
[IR_A0
];
5590 struct target_rt_sigframe
*frame
;
5593 trace_user_do_rt_sigreturn(env
, frame_addr
);
5594 if (!lock_user_struct(VERIFY_READ
, frame
, frame_addr
, 1)) {
5597 target_to_host_sigset(&set
, &frame
->uc
.tuc_sigmask
);
5600 restore_sigcontext(env
, &frame
->uc
.tuc_mcontext
);
5601 if (do_sigaltstack(frame_addr
+ offsetof(struct target_rt_sigframe
,
5603 0, env
->ir
[IR_SP
]) == -EFAULT
) {
5607 unlock_user_struct(frame
, frame_addr
, 0);
5608 return -TARGET_QEMU_ESIGRETURN
;
5612 unlock_user_struct(frame
, frame_addr
, 0);
5613 force_sig(TARGET_SIGSEGV
);
5616 #elif defined(TARGET_TILEGX)
5618 struct target_sigcontext
{
5620 /* General-purpose registers. */
5621 abi_ulong gregs
[56];
5623 abi_ulong __gregs
[53];
5624 abi_ulong tp
; /* Aliases gregs[TREG_TP]. */
5625 abi_ulong sp
; /* Aliases gregs[TREG_SP]. */
5626 abi_ulong lr
; /* Aliases gregs[TREG_LR]. */
5629 abi_ulong pc
; /* Program counter. */
5630 abi_ulong ics
; /* In Interrupt Critical Section? */
5631 abi_ulong faultnum
; /* Fault number. */
5635 struct target_ucontext
{
5636 abi_ulong tuc_flags
;
5638 target_stack_t tuc_stack
;
5639 struct target_sigcontext tuc_mcontext
;
5640 target_sigset_t tuc_sigmask
; /* mask last for extensibility */
5643 struct target_rt_sigframe
{
5644 unsigned char save_area
[16]; /* caller save area */
5645 struct target_siginfo info
;
5646 struct target_ucontext uc
;
5647 abi_ulong retcode
[2];
5650 #define INSN_MOVELI_R10_139 0x00045fe551483000ULL /* { moveli r10, 139 } */
5651 #define INSN_SWINT1 0x286b180051485000ULL /* { swint1 } */
5654 static void setup_sigcontext(struct target_sigcontext
*sc
,
5655 CPUArchState
*env
, int signo
)
5659 for (i
= 0; i
< TILEGX_R_COUNT
; ++i
) {
5660 __put_user(env
->regs
[i
], &sc
->gregs
[i
]);
5663 __put_user(env
->pc
, &sc
->pc
);
5664 __put_user(0, &sc
->ics
);
5665 __put_user(signo
, &sc
->faultnum
);
5668 static void restore_sigcontext(CPUTLGState
*env
, struct target_sigcontext
*sc
)
5672 for (i
= 0; i
< TILEGX_R_COUNT
; ++i
) {
5673 __get_user(env
->regs
[i
], &sc
->gregs
[i
]);
5676 __get_user(env
->pc
, &sc
->pc
);
5679 static abi_ulong
get_sigframe(struct target_sigaction
*ka
, CPUArchState
*env
,
5682 unsigned long sp
= env
->regs
[TILEGX_R_SP
];
5684 if (on_sig_stack(sp
) && !likely(on_sig_stack(sp
- frame_size
))) {
5688 if ((ka
->sa_flags
& SA_ONSTACK
) && !sas_ss_flags(sp
)) {
5689 sp
= target_sigaltstack_used
.ss_sp
+ target_sigaltstack_used
.ss_size
;
5697 static void setup_rt_frame(int sig
, struct target_sigaction
*ka
,
5698 target_siginfo_t
*info
,
5699 target_sigset_t
*set
, CPUArchState
*env
)
5701 abi_ulong frame_addr
;
5702 struct target_rt_sigframe
*frame
;
5703 unsigned long restorer
;
5705 frame_addr
= get_sigframe(ka
, env
, sizeof(*frame
));
5706 trace_user_setup_rt_frame(env
, frame_addr
);
5707 if (!lock_user_struct(VERIFY_WRITE
, frame
, frame_addr
, 0)) {
5711 /* Always write at least the signal number for the stack backtracer. */
5712 if (ka
->sa_flags
& TARGET_SA_SIGINFO
) {
5713 /* At sigreturn time, restore the callee-save registers too. */
5714 tswap_siginfo(&frame
->info
, info
);
5715 /* regs->flags |= PT_FLAGS_RESTORE_REGS; FIXME: we can skip it? */
5717 __put_user(info
->si_signo
, &frame
->info
.si_signo
);
5720 /* Create the ucontext. */
5721 __put_user(0, &frame
->uc
.tuc_flags
);
5722 __put_user(0, &frame
->uc
.tuc_link
);
5723 __put_user(target_sigaltstack_used
.ss_sp
, &frame
->uc
.tuc_stack
.ss_sp
);
5724 __put_user(sas_ss_flags(env
->regs
[TILEGX_R_SP
]),
5725 &frame
->uc
.tuc_stack
.ss_flags
);
5726 __put_user(target_sigaltstack_used
.ss_size
, &frame
->uc
.tuc_stack
.ss_size
);
5727 setup_sigcontext(&frame
->uc
.tuc_mcontext
, env
, info
->si_signo
);
5729 if (ka
->sa_flags
& TARGET_SA_RESTORER
) {
5730 restorer
= (unsigned long) ka
->sa_restorer
;
5732 __put_user(INSN_MOVELI_R10_139
, &frame
->retcode
[0]);
5733 __put_user(INSN_SWINT1
, &frame
->retcode
[1]);
5734 restorer
= frame_addr
+ offsetof(struct target_rt_sigframe
, retcode
);
5736 env
->pc
= (unsigned long) ka
->_sa_handler
;
5737 env
->regs
[TILEGX_R_SP
] = (unsigned long) frame
;
5738 env
->regs
[TILEGX_R_LR
] = restorer
;
5739 env
->regs
[0] = (unsigned long) sig
;
5740 env
->regs
[1] = (unsigned long) &frame
->info
;
5741 env
->regs
[2] = (unsigned long) &frame
->uc
;
5742 /* regs->flags |= PT_FLAGS_CALLER_SAVES; FIXME: we can skip it? */
5744 unlock_user_struct(frame
, frame_addr
, 1);
5748 if (sig
== TARGET_SIGSEGV
) {
5749 ka
->_sa_handler
= TARGET_SIG_DFL
;
5751 force_sig(TARGET_SIGSEGV
/* , current */);
5754 long do_rt_sigreturn(CPUTLGState
*env
)
5756 abi_ulong frame_addr
= env
->regs
[TILEGX_R_SP
];
5757 struct target_rt_sigframe
*frame
;
5760 trace_user_do_rt_sigreturn(env
, frame_addr
);
5761 if (!lock_user_struct(VERIFY_READ
, frame
, frame_addr
, 1)) {
5764 target_to_host_sigset(&set
, &frame
->uc
.tuc_sigmask
);
5767 restore_sigcontext(env
, &frame
->uc
.tuc_mcontext
);
5768 if (do_sigaltstack(frame_addr
+ offsetof(struct target_rt_sigframe
,
5770 0, env
->regs
[TILEGX_R_SP
]) == -EFAULT
) {
5774 unlock_user_struct(frame
, frame_addr
, 0);
5775 return -TARGET_QEMU_ESIGRETURN
;
5779 unlock_user_struct(frame
, frame_addr
, 0);
5780 force_sig(TARGET_SIGSEGV
);
5785 static void setup_frame(int sig
, struct target_sigaction
*ka
,
5786 target_sigset_t
*set
, CPUArchState
*env
)
5788 fprintf(stderr
, "setup_frame: not implemented\n");
5791 static void setup_rt_frame(int sig
, struct target_sigaction
*ka
,
5792 target_siginfo_t
*info
,
5793 target_sigset_t
*set
, CPUArchState
*env
)
5795 fprintf(stderr
, "setup_rt_frame: not implemented\n");
5798 long do_sigreturn(CPUArchState
*env
)
5800 fprintf(stderr
, "do_sigreturn: not implemented\n");
5801 return -TARGET_ENOSYS
;
5804 long do_rt_sigreturn(CPUArchState
*env
)
5806 fprintf(stderr
, "do_rt_sigreturn: not implemented\n");
5807 return -TARGET_ENOSYS
;
5812 static void handle_pending_signal(CPUArchState
*cpu_env
, int sig
)
5814 CPUState
*cpu
= ENV_GET_CPU(cpu_env
);
5817 target_sigset_t target_old_set
;
5818 struct target_sigaction
*sa
;
5819 TaskState
*ts
= cpu
->opaque
;
5820 struct emulated_sigtable
*k
= &ts
->sigtab
[sig
- 1];
5822 trace_user_handle_signal(cpu_env
, sig
);
5823 /* dequeue signal */
5826 sig
= gdb_handlesig(cpu
, sig
);
5829 handler
= TARGET_SIG_IGN
;
5831 sa
= &sigact_table
[sig
- 1];
5832 handler
= sa
->_sa_handler
;
5835 if (handler
== TARGET_SIG_DFL
) {
5836 /* default handler : ignore some signal. The other are job control or fatal */
5837 if (sig
== TARGET_SIGTSTP
|| sig
== TARGET_SIGTTIN
|| sig
== TARGET_SIGTTOU
) {
5838 kill(getpid(),SIGSTOP
);
5839 } else if (sig
!= TARGET_SIGCHLD
&&
5840 sig
!= TARGET_SIGURG
&&
5841 sig
!= TARGET_SIGWINCH
&&
5842 sig
!= TARGET_SIGCONT
) {
5845 } else if (handler
== TARGET_SIG_IGN
) {
5847 } else if (handler
== TARGET_SIG_ERR
) {
5850 /* compute the blocked signals during the handler execution */
5851 sigset_t
*blocked_set
;
5853 target_to_host_sigset(&set
, &sa
->sa_mask
);
5854 /* SA_NODEFER indicates that the current signal should not be
5855 blocked during the handler */
5856 if (!(sa
->sa_flags
& TARGET_SA_NODEFER
))
5857 sigaddset(&set
, target_to_host_signal(sig
));
5859 /* save the previous blocked signal state to restore it at the
5860 end of the signal execution (see do_sigreturn) */
5861 host_to_target_sigset_internal(&target_old_set
, &ts
->signal_mask
);
5863 /* block signals in the handler */
5864 blocked_set
= ts
->in_sigsuspend
?
5865 &ts
->sigsuspend_mask
: &ts
->signal_mask
;
5866 sigorset(&ts
->signal_mask
, blocked_set
, &set
);
5867 ts
->in_sigsuspend
= 0;
5869 /* if the CPU is in VM86 mode, we restore the 32 bit values */
5870 #if defined(TARGET_I386) && !defined(TARGET_X86_64)
5872 CPUX86State
*env
= cpu_env
;
5873 if (env
->eflags
& VM_MASK
)
5874 save_v86_state(env
);
5877 /* prepare the stack frame of the virtual CPU */
5878 #if defined(TARGET_ABI_MIPSN32) || defined(TARGET_ABI_MIPSN64) \
5879 || defined(TARGET_OPENRISC) || defined(TARGET_TILEGX)
5880 /* These targets do not have traditional signals. */
5881 setup_rt_frame(sig
, sa
, &k
->info
, &target_old_set
, cpu_env
);
5883 if (sa
->sa_flags
& TARGET_SA_SIGINFO
)
5884 setup_rt_frame(sig
, sa
, &k
->info
, &target_old_set
, cpu_env
);
5886 setup_frame(sig
, sa
, &target_old_set
, cpu_env
);
5888 if (sa
->sa_flags
& TARGET_SA_RESETHAND
) {
5889 sa
->_sa_handler
= TARGET_SIG_DFL
;
5894 void process_pending_signals(CPUArchState
*cpu_env
)
5896 CPUState
*cpu
= ENV_GET_CPU(cpu_env
);
5898 TaskState
*ts
= cpu
->opaque
;
5900 sigset_t
*blocked_set
;
5902 while (atomic_read(&ts
->signal_pending
)) {
5903 /* FIXME: This is not threadsafe. */
5905 sigprocmask(SIG_SETMASK
, &set
, 0);
5907 sig
= ts
->sync_signal
.pending
;
5909 /* Synchronous signals are forced,
5910 * see force_sig_info() and callers in Linux
5911 * Note that not all of our queue_signal() calls in QEMU correspond
5912 * to force_sig_info() calls in Linux (some are send_sig_info()).
5913 * However it seems like a kernel bug to me to allow the process
5914 * to block a synchronous signal since it could then just end up
5915 * looping round and round indefinitely.
5917 if (sigismember(&ts
->signal_mask
, target_to_host_signal_table
[sig
])
5918 || sigact_table
[sig
- 1]._sa_handler
== TARGET_SIG_IGN
) {
5919 sigdelset(&ts
->signal_mask
, target_to_host_signal_table
[sig
]);
5920 sigact_table
[sig
- 1]._sa_handler
= TARGET_SIG_DFL
;
5923 handle_pending_signal(cpu_env
, sig
);
5926 for (sig
= 1; sig
<= TARGET_NSIG
; sig
++) {
5927 blocked_set
= ts
->in_sigsuspend
?
5928 &ts
->sigsuspend_mask
: &ts
->signal_mask
;
5930 if (ts
->sigtab
[sig
- 1].pending
&&
5931 (!sigismember(blocked_set
,
5932 target_to_host_signal_table
[sig
]))) {
5933 handle_pending_signal(cpu_env
, sig
);
5934 /* Restart scan from the beginning */
5939 /* if no signal is pending, unblock signals and recheck (the act
5940 * of unblocking might cause us to take another host signal which
5941 * will set signal_pending again).
5943 atomic_set(&ts
->signal_pending
, 0);
5944 ts
->in_sigsuspend
= 0;
5945 set
= ts
->signal_mask
;
5946 sigdelset(&set
, SIGSEGV
);
5947 sigdelset(&set
, SIGBUS
);
5948 sigprocmask(SIG_SETMASK
, &set
, 0);
5950 ts
->in_sigsuspend
= 0;