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: 9173659 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A13AC6048C for ; Mon, 13 Jun 2016 17:17:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8AAAB2040D for ; Mon, 13 Jun 2016 17:17:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7E20D265F9; Mon, 13 Jun 2016 17:17:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CE7EA2040D for ; Mon, 13 Jun 2016 17:17:04 +0000 (UTC) Received: from localhost ([::1]:57957 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bCVTz-0003aL-VR for patchwork-qemu-devel@patchwork.kernel.org; Mon, 13 Jun 2016 13:17:04 -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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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