From patchwork Mon Mar 16 16:15:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 184580 Delivered-To: patch@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp3102549ile; Mon, 16 Mar 2020 10:58:47 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuWxMd9x3mFJKCBV3ogRGmCxaO3jtgBTwGPzwTEzsBNHXTYBV+6rxqqz8zxlAjEgA8dCr3a X-Received: by 2002:ac8:6f6e:: with SMTP id u14mr1339202qtv.304.1584381527049; Mon, 16 Mar 2020 10:58:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584381527; cv=none; d=google.com; s=arc-20160816; b=FEu0OJqSz7OLKesJbMniXmb6qZPT0c0Kb+wGwI7w0u3/0mzLUjelKSFIUEbIAoWKJl 4AKpqE0J4nUu7OQdGOEADijxHaut2N3Fxo3REcsEAWTir6VVAUvYK4GLzNufTrdsHK1T 727HbDPMyt79pahcPEJj16YltlLAKv5eV1gGC5r6BqbI29GBnsIBwKneSfD8A0yvqqq0 46cK6qcUgaYEZOBFN4T8Ao29+SGWtwYoMBXwjhJwEun5VmkcN2GYw6Gc3Begx+u7jZEi FczFn/AemJCXhYFc/VYrkx9R6RdXsn+iYuX28vuVJozfA7GPTUorpCaA1mvJXFD+g9Eu Aj+Q== 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=Wjc2bWa1BgIXJOXmPfwioAw4KgPwMa6HOhu7IMy3hEQ=; b=qDcGe1Bo8JMmqAKoqeP6AnafQ3kkVHDiypnnHRRK6bwy2v2ysBeXJ1vKZdsxyzijTs eyX47e3LSdnHydCOK0T9kcoRl2V69s9aTUjbi2WdJqtswpuTOfRwYHCUC4tBEFZ4yOhh qpnWubVAWmlmrxOWnPW1Yf7sIPr86RLihbbbpTvnnmaREyu8sR4rI0xeJqGVus/RXn1a V+NY3iDOBtAbH31vEPHaMvXVfAyupp2b43XIF7CDx6VYOwKCgzopsXKlekG+gIPDf5JZ 4gD6sNdODVhy4fcBqNiFfsJwhqKqwgI9ky4mCgwxF2oFVDKqwhnWFNQKOG9zomCTE5Vf +WUQ== 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 r2si217414qte.140.2020.03.16.10.58.46 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Mar 2020 10:58:47 -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]:45104 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jDu0k-0008Tw-Ew for patch@linaro.org; Mon, 16 Mar 2020 13:58:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40120) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jDsPZ-0007si-BW for qemu-devel@nongnu.org; Mon, 16 Mar 2020 12:16:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jDsPX-0007Th-Vt for qemu-devel@nongnu.org; Mon, 16 Mar 2020 12:16:17 -0400 Received: from mout.kundenserver.de ([212.227.126.134]:43915) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jDsPX-0007Jc-Ll for qemu-devel@nongnu.org; Mon, 16 Mar 2020 12:16:15 -0400 Received: from localhost.localdomain ([82.252.135.106]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MpTpc-1jfE1Q2EZQ-00pryl; Mon, 16 Mar 2020 17:16:04 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 02/38] linux-user/i386: Split out gen_signal Date: Mon, 16 Mar 2020 17:15:14 +0100 Message-Id: <20200316161550.336150-3-laurent@vivier.eu> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200316161550.336150-1-laurent@vivier.eu> References: <20200316161550.336150-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:KrL6I/F7MNRegfxQaiB29bAN8Uwn/7ObA5TnQeZdB4gWJH9ikUW Ra1813wakb/rt0BRgSu9R8jfn1sFryE/E8krtgeCWu4xv0wCvN1rgbTTseygIPS8i3eGg+N Gi35z7nG/QTWBranhBE5ofLHdPM2Ja7kRBDVzRbAXgIDRlaqup/v5c7Txl0/hJ95FCX+HCf t25MCMT7BVRw8HcPshu5w== X-UI-Out-Filterresults: notjunk:1; V03:K0:i01+A/033oY=:EB1CbLBRvjfyCHmdn/VBhw LSmjpjvGWmDh5Zr/qHvhah5Ojqsr+qtvpUqdTky9jqOONjxDkTUAs3GUJogL3tCbonp0Qa1fR bW7+PoyR741cYkTcRpXPkO/9N8jGgOzaLBmfjPXxD5j1tuwe134HFRNNLeHHsv8/TLyWt4P3V zIWISABaT9/aXFigAIf78HfiUQWz3MNGHTnz50ZcyG09vJqXfqfDyRJg+EW/qTKCaivk/DPf9 9EmOQKUCp3rFTU/g8aK8xQb7Ju7ekFmcRww9VL3VMR0urhstx9XvuLwpbav1bO+kFtT4Raz6j iJ4TpXnThm/Q9yyL1A85Okmr8PoLyIl8oDPoy5q2fBuy08P9yoiZJpxwaH9OFR5sxvwMIXFZu 4nhF6v3ipeMHdFk0pLuSTvAdB/V8MMGMghzJqlyhB+8EfO+jTNZ11QdpgB2s5+1NIy5cy+391 9ZE88/NIH5tdbhmkeDD07pVBubD7Azspl9CG9nFPPZ8NpxHDWor3rgY3Fi1bKxp6jhxE8Jfnb RZx/kbu/k796z8NyB7glX1/dslcwtacC3N0X1k69lVSmgSKjIGeA6I9yUTEMhReb2RMq7VjCs RYCRJLeHMrQu/jQCC2xpGpZC1H8+GBnnpQ0MUEKAmXVeNP54r81xfCutjbvMPW5EzEL234zmi 142JjxLtLMO+x2PH2aAQMBPaauU/TN3q5lwgO4lQKu7dEdtkkVLg3g+NbfDyFZQONwmPMyY4G F8kRnmBbdulR4k6lwBSd4l641HcNe45+lvWgR1S3ogO5hqjDzpXCPybKMwuplCajgSl7AeXLT tMzUkMwYXEm7jq1C+sFeXjDPw/4piLaQ3mBIOZKGSmyh1Oj5/SamcGVCtQ24ru1tGmNQwmB X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.126.134 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.24.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);