From patchwork Mon Jun 13 17:05:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 69905 Delivered-To: patch@linaro.org Received: by 10.140.106.246 with SMTP id e109csp1649308qgf; Mon, 13 Jun 2016 10:18:46 -0700 (PDT) X-Received: by 10.140.101.184 with SMTP id u53mr14809205qge.3.1465838326248; Mon, 13 Jun 2016 10:18:46 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id l36si15787798qte.35.2016.06.13.10.18.46 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 13 Jun 2016 10:18:46 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org Received: from localhost ([::1]:57969 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bCVVd-0004Tr-NU for patch@linaro.org; Mon, 13 Jun 2016 13:18:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39092) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bCVJ7-0001St-Tt for qemu-devel@nongnu.org; Mon, 13 Jun 2016 13:05:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bCVJ4-0001q2-Ti for qemu-devel@nongnu.org; Mon, 13 Jun 2016 13:05:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55570) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bCVJ4-0001py-LD for qemu-devel@nongnu.org; Mon, 13 Jun 2016 13:05:46 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 21E7281130; Mon, 13 Jun 2016 17:05:46 +0000 (UTC) Received: from localhost (ovpn-112-61.ams2.redhat.com [10.36.112.61]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u5DH5iCx012209; Mon, 13 Jun 2016 13:05:45 -0400 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Date: Mon, 13 Jun 2016 18:05:24 +0100 Message-Id: <1465837535-30067-5-git-send-email-stefanha@redhat.com> In-Reply-To: <1465837535-30067-1-git-send-email-stefanha@redhat.com> References: <1465837535-30067-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 13 Jun 2016 17:05:46 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 04/15] user-exec: Don't reextract sigmask from usercontext pointer X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , Fam Zheng , Jeff Cody , mreitz@redhat.com, jjherne@linux.vnet.ibm.com, Paolo Bonzini Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell Extracting the old signal mask from the usercontext pointer passed to a signal handler is a pain because it is OS and CPU dependent. Since we've already done it once and passed it to handle_cpu_signal(), there's no need to do it again in cpu_exit_tb_from_sighandler(). This then means we don't need to pass a usercontext pointer in to handle_cpu_signal() at all. Signed-off-by: Peter Maydell Reviewed-by: Sergey Fedorov Acked-by: Eduardo Habkost Acked-by: Riku Voipio Message-id: 1463494687-25947-5-git-send-email-peter.maydell@linaro.org --- user-exec.c | 48 ++++++++++++++++-------------------------------- 1 file changed, 16 insertions(+), 32 deletions(-) -- 2.5.5 diff --git a/user-exec.c b/user-exec.c index c5179a4..b9e7bec 100644 --- a/user-exec.c +++ b/user-exec.c @@ -55,25 +55,10 @@ static void exception_action(CPUState *cpu) /* exit the current TB from a signal handler. The host registers are restored in a state compatible with the CPU emulator */ -static void cpu_exit_tb_from_sighandler(CPUState *cpu, void *puc) +static void cpu_exit_tb_from_sighandler(CPUState *cpu, sigset_t *old_set) { -#ifdef __linux__ - struct ucontext *uc = puc; -#elif defined(__OpenBSD__) - struct sigcontext *uc = puc; -#endif - /* XXX: use siglongjmp ? */ -#ifdef __linux__ -#ifdef __ia64 - sigprocmask(SIG_SETMASK, (sigset_t *)&uc->uc_sigmask, NULL); -#else - sigprocmask(SIG_SETMASK, &uc->uc_sigmask, NULL); -#endif -#elif defined(__OpenBSD__) - sigprocmask(SIG_SETMASK, &uc->sc_mask, NULL); -#endif - + sigprocmask(SIG_SETMASK, old_set, NULL); cpu_loop_exit_noexc(cpu); } @@ -82,8 +67,7 @@ static void cpu_exit_tb_from_sighandler(CPUState *cpu, void *puc) write caused the exception and otherwise 0'. 'old_set' is the signal set which should be restored */ static inline int handle_cpu_signal(uintptr_t pc, unsigned long address, - int is_write, sigset_t *old_set, - void *puc) + int is_write, sigset_t *old_set) { CPUState *cpu; CPUClass *cc; @@ -111,7 +95,7 @@ static inline int handle_cpu_signal(uintptr_t pc, unsigned long address, * currently executing TB was modified and must be exited * immediately. */ - cpu_exit_tb_from_sighandler(current_cpu, puc); + cpu_exit_tb_from_sighandler(current_cpu, old_set); g_assert_not_reached(); default: g_assert_not_reached(); @@ -205,7 +189,7 @@ int cpu_signal_handler(int host_signum, void *pinfo, return handle_cpu_signal(pc, (unsigned long)info->si_addr, trapno == 0xe ? (ERROR_sig(uc) >> 1) & 1 : 0, - &MASK_sig(uc), puc); + &MASK_sig(uc)); } #elif defined(__x86_64__) @@ -251,7 +235,7 @@ int cpu_signal_handler(int host_signum, void *pinfo, return handle_cpu_signal(pc, (unsigned long)info->si_addr, TRAP_sig(uc) == 0xe ? (ERROR_sig(uc) >> 1) & 1 : 0, - &MASK_sig(uc), puc); + &MASK_sig(uc)); } #elif defined(_ARCH_PPC) @@ -367,7 +351,7 @@ int cpu_signal_handler(int host_signum, void *pinfo, } #endif return handle_cpu_signal(pc, (unsigned long)info->si_addr, - is_write, &uc->uc_sigmask, puc); + is_write, &uc->uc_sigmask); } #elif defined(__alpha__) @@ -398,7 +382,7 @@ int cpu_signal_handler(int host_signum, void *pinfo, } return handle_cpu_signal(pc, (unsigned long)info->si_addr, - is_write, &uc->uc_sigmask, puc); + is_write, &uc->uc_sigmask); } #elif defined(__sparc__) @@ -458,7 +442,7 @@ int cpu_signal_handler(int host_signum, void *pinfo, } } return handle_cpu_signal(pc, (unsigned long)info->si_addr, - is_write, sigmask, NULL); + is_write, sigmask); } #elif defined(__arm__) @@ -493,7 +477,7 @@ int cpu_signal_handler(int host_signum, void *pinfo, is_write = extract32(uc->uc_mcontext.error_code, 11, 1); return handle_cpu_signal(pc, (unsigned long)info->si_addr, is_write, - &uc->uc_sigmask, puc); + &uc->uc_sigmask); } #elif defined(__aarch64__) @@ -521,7 +505,7 @@ int cpu_signal_handler(int host_signum, void *pinfo, void *puc) || (insn & 0x3a400000) == 0x28000000); /* C3.3.7,14-16 */ return handle_cpu_signal(pc, (uintptr_t)info->si_addr, - is_write, &uc->uc_sigmask, puc); + is_write, &uc->uc_sigmask); } #elif defined(__mc68000) @@ -539,7 +523,7 @@ int cpu_signal_handler(int host_signum, void *pinfo, is_write = 0; return handle_cpu_signal(pc, (unsigned long)info->si_addr, is_write, - &uc->uc_sigmask, puc); + &uc->uc_sigmask); } #elif defined(__ia64) @@ -574,7 +558,7 @@ int cpu_signal_handler(int host_signum, void *pinfo, void *puc) } return handle_cpu_signal(ip, (unsigned long)info->si_addr, is_write, - (sigset_t *)&uc->uc_sigmask, puc); + (sigset_t *)&uc->uc_sigmask); } #elif defined(__s390__) @@ -627,7 +611,7 @@ int cpu_signal_handler(int host_signum, void *pinfo, break; } return handle_cpu_signal(pc, (unsigned long)info->si_addr, - is_write, &uc->uc_sigmask, puc); + is_write, &uc->uc_sigmask); } #elif defined(__mips__) @@ -643,7 +627,7 @@ int cpu_signal_handler(int host_signum, void *pinfo, /* XXX: compute is_write */ is_write = 0; return handle_cpu_signal(pc, (unsigned long)info->si_addr, - is_write, &uc->uc_sigmask, puc); + is_write, &uc->uc_sigmask); } #elif defined(__hppa__) @@ -685,7 +669,7 @@ int cpu_signal_handler(int host_signum, void *pinfo, } return handle_cpu_signal(pc, (unsigned long)info->si_addr, - is_write, &uc->uc_sigmask, puc); + is_write, &uc->uc_sigmask); } #else