diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2010-11-24 15:20:06 +0000 |
---|---|---|
committer | Riku Voipio <riku.voipio@nokia.com> | 2010-12-03 15:09:39 +0200 |
commit | 5f9099d9cee0e9ed377aee705ca9f4db75e8948d (patch) | |
tree | 34f75c239d5dc6a7c4150fb6f0e737f209c13c2b /linux-user/signal.c | |
parent | 0d871bdbaac428601c84d29233a49f7cf6ecb6fc (diff) | |
download | qemu-5f9099d9cee0e9ed377aee705ca9f4db75e8948d.zip qemu-5f9099d9cee0e9ed377aee705ca9f4db75e8948d.tar.gz qemu-5f9099d9cee0e9ed377aee705ca9f4db75e8948d.tar.bz2 |
ARM: linux-user: Restore VFP state from ucontext on sigreturn
Restore the VFP registers from the ucontext on return from a signal
handler in linux-user mode. This means that signal handlers cannot
accidentally corrupt the interrupted code's VFP state, and allows
them to deliberately modify the state via the ucontext structure.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Riku Voipio <riku.voipio@nokia.com>
Diffstat (limited to 'linux-user/signal.c')
-rw-r--r-- | linux-user/signal.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/linux-user/signal.c b/linux-user/signal.c index af1e0eb..63d893b 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -1535,10 +1535,41 @@ badframe: return 0; } +static abi_ulong *restore_sigframe_v2_vfp(CPUState *env, abi_ulong *regspace) +{ + int i; + abi_ulong magic, sz; + uint32_t fpscr, fpexc; + struct target_vfp_sigframe *vfpframe; + vfpframe = (struct target_vfp_sigframe *)regspace; + + __get_user(magic, &vfpframe->magic); + __get_user(sz, &vfpframe->size); + if (magic != TARGET_VFP_MAGIC || sz != sizeof(*vfpframe)) { + return 0; + } + for (i = 0; i < 32; i++) { + __get_user(env->vfp.regs[i], &vfpframe->ufp.fpregs[i]); + } + __get_user(fpscr, &vfpframe->ufp.fpscr); + vfp_set_fpscr(env, fpscr); + __get_user(fpexc, &vfpframe->ufp_exc.fpexc); + /* Sanitise FPEXC: ensure VFP is enabled, FPINST2 is invalid + * and the exception flag is cleared + */ + fpexc |= (1 << 30); + fpexc &= ~((1 << 31) | (1 << 28)); + env->vfp.xregs[ARM_VFP_FPEXC] = fpexc; + __get_user(env->vfp.xregs[ARM_VFP_FPINST], &vfpframe->ufp_exc.fpinst); + __get_user(env->vfp.xregs[ARM_VFP_FPINST2], &vfpframe->ufp_exc.fpinst2); + return (abi_ulong*)(vfpframe + 1); +} + static int do_sigframe_return_v2(CPUState *env, target_ulong frame_addr, struct target_ucontext_v2 *uc) { sigset_t host_set; + abi_ulong *regspace; target_to_host_sigset(&host_set, &uc->tuc_sigmask); sigprocmask(SIG_SETMASK, &host_set, NULL); @@ -1546,6 +1577,15 @@ static int do_sigframe_return_v2(CPUState *env, target_ulong frame_addr, if (restore_sigcontext(env, &uc->tuc_mcontext)) return 1; + /* Restore coprocessor signal frame */ + regspace = uc->tuc_regspace; + if (arm_feature(env, ARM_FEATURE_VFP)) { + regspace = restore_sigframe_v2_vfp(env, regspace); + if (!regspace) { + return 1; + } + } + if (do_sigaltstack(frame_addr + offsetof(struct target_ucontext_v2, tuc_stack), 0, get_sp_from_cpustate(env)) == -EFAULT) return 1; |