From patchwork Thu Mar 26 07:23:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 184843 Delivered-To: patch@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp1534518ile; Thu, 26 Mar 2020 00:29:10 -0700 (PDT) X-Google-Smtp-Source: ADFU+vukVCrMQf5YCMNUVdzXNfoVM/V4ePLaXoWR8383ReLVBVv4Ac+6UMZ5s4PSa36Znktdell7 X-Received: by 2002:ac8:4e94:: with SMTP id 20mr6719566qtp.314.1585207750430; Thu, 26 Mar 2020 00:29:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585207750; cv=none; d=google.com; s=arc-20160816; b=c0aNN2sZC3VpxWvOVOiJSFsTcTeAiztl3zd5enD1SLGt85HZrG82rDaD7HJ4fePCdX Jmv9VGgrv5XA7/njs3sAr3/MhWZquXYhfzR8nj781tDQ6DdXxDh5P3SViJRXLzk5P4aS bziyTYzd0wO/4WNAMnBjGVvG4o49ZJdtTYnuWL2lnG7LjJpQ0SO24mgCEUxK9jBZXnnl jZRvBKeUq0cWl/PfJbKdxfChw60OmldX6lroIoSMkUn1mXPWGGyn2Cj9Uw5I7hUTdSfp KBpOsUmXVNdeToJVeAI+Z+GIhIrbtI4NRrZ15UEqk0gYC81i3GtwbUIRNOl3zQNGAN88 kaoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from; bh=YEkw+BD3XM1DvhPhvynvQr2RL1QhFvPB4Cz5qQZtHws=; b=iKf4i0j3I+U7DzwXjrywT86E//R5UD/sPtnZwwGwaHz+J8dnW95yNePuPho7xEPfqR z4keh+1a2q721AVlzOes7uzTGgbbxc84YO6mfSv2vlovt9awnXG1aD0XFriaAcg0gY4p U5iBqGa+PFHlQHJ4wUblgMG2CB48tfe1wAvn53j4oSGOI1kb7aXYCitPDfyA6Qwp3g2F wEPcnsex3IFtkXgv5ckHUjsET1gOUdd1LjJV3WnqJ+wnyCCUtJrVn/MeLg3F4XfKzVUN 4pxZPhvxTy5Jf1jEW72z1CiVqtqejKxSy730vVwvA1lh2qNnwE1+opOqNiO38fuYXXfW rgmQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id i50si755543qtc.349.2020.03.26.00.29.10 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 26 Mar 2020 00:29:10 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1]:47542 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHMwv-0003cQ-V4 for patch@linaro.org; Thu, 26 Mar 2020 03:29:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57173) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHMsA-0005RQ-K8 for qemu-devel@nongnu.org; Thu, 26 Mar 2020 03:24:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jHMs9-0007uN-6u for qemu-devel@nongnu.org; Thu, 26 Mar 2020 03:24:14 -0400 Received: from mout.kundenserver.de ([212.227.126.135]:42271) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jHMs8-0007uC-UA for qemu-devel@nongnu.org; Thu, 26 Mar 2020 03:24:13 -0400 Received: from localhost.localdomain ([82.252.135.106]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MwQCb-1jYDQh0sKL-00sLgZ; Thu, 26 Mar 2020 08:23:58 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 3/6] linux-user/i386: Split out gen_signal Date: Thu, 26 Mar 2020 08:23:49 +0100 Message-Id: <20200326072352.2056553-4-laurent@vivier.eu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200326072352.2056553-1-laurent@vivier.eu> References: <20200326072352.2056553-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:EX6P3vYaK2SZb/NgMTn3mSfuNyAZ1lq6tVRtSvJB0QTSO715RBW wkw5ixuk/4UOo7QMMkFdY85iDr1VDyzS2PwogmUN9ibsHnGkq4DCekmE0eJag/NKV8/KdoY YcxOJQ6yo4VuV8bFf7FuK0hB0dewGf1E3Wmcif6fFawd1vZtx/trsuM5L83bTK2HzCpPhFG 6fenm5f7L7Hdq6Gldps4Q== X-UI-Out-Filterresults: notjunk:1; V03:K0:UOZocdcNJgE=:M1EahAV9yHIRWoeEYRk2Sy RUoettWY3ytnqK0Ots3dsVXmSN1dMjEdp7xVGo2ShLN5Dw9wsm3krrpRPVVzMndwQoAGXwEqt 0VCqii6gjhhaW15JQaKJEfpzj+foe3NbgI+8TZU7X7ri+hvTJ/0X9VwY+nqKq5T7OcnWfFTcJ OISCvzXSOvQWo+ksBeBANkCNe4NwgsEgtM6rugFx+EU6xek8hJqNRf6v0BudyWBG/as60geKZ OPfxKOszNrSY1x0ogeXpoLIbZohZ7n1Y6FtCt60NPvo2ZYp7GwWQMxpSJo7P+wANDfnwgpGUA W0OvWyh1T5Wpk3n+qwZ0k1U4azBOWPkk7IE7WNIKAQDmuCkxgDPD4w7deOM12vh7tKzah3TuA eCNEBrh/TNaGvZroCbN/QeKrzgzakjBiIZohZ2yV6H6J7mrVVFWKD1UODoeNqCah4Kyr/yBTV QaDfEWa0VYtoyn5NaAXhCGnQCxhRuiRGI1SEVYSG/sHwU+HjRh2T/HqCYCOdGIAkBp5AkhSxA ZEj+1+gQmxO8ir2J3NF93HykguoJw0NUp1PyWy88knxOMFpplGergZniezRZ7KqH5yrHAeMo/ qn/Plxdt224sDu8YMT7xWNS2O156Aak4cEB+YvVsv42HOcnDwLKoQdoCfVOZBmeme2XXmnWLj tMs46RBwT46cw8SV8moBsEsewk8Qv//a1ORhoxtIRWVDlFAugigBajPIlC4IAsjpindMY0Ra0 y0pYDJ+j7PxKcAWRu9Ajdz1Mv/waq2kmKnnoZNJCaufK7/pOWWKRfjFs55AAN3xH03CHcxZWW T1x2JmP9g7EcXRBTfIkWOsWvdpwZmFxPmZsscjTfCv9xOjvTfUvL587SxEhYeSbxAZl2Qy0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.126.135 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Riku Voipio , Richard Henderson , Laurent Vivier , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson This is a bit tidier than open-coding the 5 lines necessary to initialize the target_siginfo_t. In addition, this zeros the remaining bytes of the target_siginfo_t, rather than passing in garbage. Reviewed-by: Paolo Bonzini Reviewed-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson Message-Id: <20200213032223.14643-3-richard.henderson@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/i386/cpu_loop.c | 93 ++++++++++++++------------------------ 1 file changed, 33 insertions(+), 60 deletions(-) -- 2.25.1 diff --git a/linux-user/i386/cpu_loop.c b/linux-user/i386/cpu_loop.c index 024b6f4d588c..e217cca5ee1e 100644 --- a/linux-user/i386/cpu_loop.c +++ b/linux-user/i386/cpu_loop.c @@ -81,13 +81,23 @@ static void set_idt(int n, unsigned int dpl) } #endif +static void gen_signal(CPUX86State *env, int sig, int code, abi_ptr addr) +{ + target_siginfo_t info = { + .si_signo = sig, + .si_code = code, + ._sifields._sigfault._addr = addr + }; + + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); +} + void cpu_loop(CPUX86State *env) { CPUState *cs = env_cpu(env); int trapnr; abi_ulong pc; abi_ulong ret; - target_siginfo_t info; for(;;) { cpu_exec_start(cs); @@ -134,70 +144,45 @@ void cpu_loop(CPUX86State *env) #endif case EXCP0B_NOSEG: case EXCP0C_STACK: - info.si_signo = TARGET_SIGBUS; - info.si_errno = 0; - info.si_code = TARGET_SI_KERNEL; - info._sifields._sigfault._addr = 0; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + gen_signal(env, TARGET_SIGBUS, TARGET_SI_KERNEL, 0); break; case EXCP0D_GPF: /* XXX: potential problem if ABI32 */ #ifndef TARGET_X86_64 if (env->eflags & VM_MASK) { handle_vm86_fault(env); - } else -#endif - { - info.si_signo = TARGET_SIGSEGV; - info.si_errno = 0; - info.si_code = TARGET_SI_KERNEL; - info._sifields._sigfault._addr = 0; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; } +#endif + gen_signal(env, TARGET_SIGSEGV, TARGET_SI_KERNEL, 0); break; case EXCP0E_PAGE: - info.si_signo = TARGET_SIGSEGV; - info.si_errno = 0; - if (!(env->error_code & 1)) - info.si_code = TARGET_SEGV_MAPERR; - else - info.si_code = TARGET_SEGV_ACCERR; - info._sifields._sigfault._addr = env->cr[2]; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + gen_signal(env, TARGET_SIGSEGV, + (env->error_code & 1 ? + TARGET_SEGV_ACCERR : TARGET_SEGV_MAPERR), + env->cr[2]); break; case EXCP00_DIVZ: #ifndef TARGET_X86_64 if (env->eflags & VM_MASK) { handle_vm86_trap(env, trapnr); - } else -#endif - { - /* division by zero */ - info.si_signo = TARGET_SIGFPE; - info.si_errno = 0; - info.si_code = TARGET_FPE_INTDIV; - info._sifields._sigfault._addr = env->eip; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; } +#endif + gen_signal(env, TARGET_SIGFPE, TARGET_FPE_INTDIV, env->eip); break; case EXCP01_DB: case EXCP03_INT3: #ifndef TARGET_X86_64 if (env->eflags & VM_MASK) { handle_vm86_trap(env, trapnr); - } else + break; + } #endif - { - info.si_signo = TARGET_SIGTRAP; - info.si_errno = 0; - if (trapnr == EXCP01_DB) { - info.si_code = TARGET_TRAP_BRKPT; - info._sifields._sigfault._addr = env->eip; - } else { - info.si_code = TARGET_SI_KERNEL; - info._sifields._sigfault._addr = 0; - } - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + if (trapnr == EXCP01_DB) { + gen_signal(env, TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->eip); + } else { + gen_signal(env, TARGET_SIGTRAP, TARGET_SI_KERNEL, 0); } break; case EXCP04_INTO: @@ -205,31 +190,19 @@ void cpu_loop(CPUX86State *env) #ifndef TARGET_X86_64 if (env->eflags & VM_MASK) { handle_vm86_trap(env, trapnr); - } else -#endif - { - info.si_signo = TARGET_SIGSEGV; - info.si_errno = 0; - info.si_code = TARGET_SI_KERNEL; - info._sifields._sigfault._addr = 0; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; } +#endif + gen_signal(env, TARGET_SIGSEGV, TARGET_SI_KERNEL, 0); break; case EXCP06_ILLOP: - info.si_signo = TARGET_SIGILL; - info.si_errno = 0; - info.si_code = TARGET_ILL_ILLOPN; - info._sifields._sigfault._addr = env->eip; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + gen_signal(env, TARGET_SIGILL, TARGET_ILL_ILLOPN, env->eip); break; case EXCP_INTERRUPT: /* just indicate that signals should be handled asap */ break; case EXCP_DEBUG: - info.si_signo = TARGET_SIGTRAP; - info.si_errno = 0; - info.si_code = TARGET_TRAP_BRKPT; - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + gen_signal(env, TARGET_SIGTRAP, TARGET_TRAP_BRKPT, 0); break; case EXCP_ATOMIC: cpu_exec_step_atomic(cs);