From patchwork Wed Nov 24 15:20:06 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 72898 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 9B86EB6F10 for ; Thu, 25 Nov 2010 02:23:16 +1100 (EST) Received: from localhost ([127.0.0.1]:51643 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PLHBf-000880-IQ for incoming@patchwork.ozlabs.org; Wed, 24 Nov 2010 10:23:11 -0500 Received: from [140.186.70.92] (port=34684 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PLH8n-0006w0-Ei for qemu-devel@nongnu.org; Wed, 24 Nov 2010 10:20:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PLH8k-000471-TD for qemu-devel@nongnu.org; Wed, 24 Nov 2010 10:20:13 -0500 Received: from mnementh.archaic.org.uk ([81.2.115.146]:16641) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PLH8k-00045l-K9 for qemu-devel@nongnu.org; Wed, 24 Nov 2010 10:20:10 -0500 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.69) (envelope-from ) id 1PLH8i-0004s3-Eo for qemu-devel@nongnu.org; Wed, 24 Nov 2010 15:20:08 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Wed, 24 Nov 2010 15:20:06 +0000 Message-Id: <1290612008-18693-5-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1290612008-18693-1-git-send-email-peter.maydell@linaro.org> References: <1290612008-18693-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) Subject: [Qemu-devel] [PATCH 4/6] ARM: linux-user: Restore VFP state from ucontext on sigreturn X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 Reviewed-by: Nathan Froyd Reviewed-by: Nathan Froyd --- 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 71cc2cd..5e8cbeb 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;