From patchwork Tue Mar 24 10:03:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 184766 Delivered-To: patch@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp5162257ile; Tue, 24 Mar 2020 03:07:34 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtVKgvkUEtFZmOADBqgAFrd7Ay8amRfL8GMzY1PoWfLYLfgRRYSjEuc+BP1LpJqLWhdeZwQ X-Received: by 2002:a05:6214:aa2:: with SMTP id ew2mr5231024qvb.123.1585044454469; Tue, 24 Mar 2020 03:07:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585044454; cv=none; d=google.com; s=arc-20160816; b=kjIBWTqKAGk4HejyqQfAgp2oKcNnrJT2PQvXd6GUk70QF3LeZy9uN/fLWgowZlkSxb HtHat5B2V3mTpj4QKKMhEXtp9IeyKMwza3M62IiY1/dtTG3Z9mBnBx3zH+qDqNZ6bkis TlFTJXVd6DHSdWwKULK+2NmNJMsHeCFjv++Xg4m4tF9waQgoOEceJmfAbbafs6RkdBKg zxTWApoouAWXuckdjeqRs5xjuBWaazu6h8GQA5O7PaoLOKOjMIUWT7mU8VLJa+B4rp6y uWgXwoOUAJdU5bSxKgWKuhY7ivZW88dEdY1yyahESZVjINjYpsYIXGTOZblzLVANty8k dfUw== 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=NvLy0DHRn9UzmfUsjoPbedsmpDx9Z8JInq3qZ/stWAuuX4kBQTtmJdjJb2nbDQssBZ rrKu4d1ovjLHX9962w31mmHK5Bm5xLt04IEI9vkN9FXbHnJes6n25lD3m0javpG6pwuB 04Q4RINoqjaWBT/EDn30YH70kfPymSda2jyWb3YN9eFwDpmX5jvAf0NCKE5WjkS5bYaR MvU4m4n1o+tA5fAA4uraapS9/x09uEAe00iDEMOowCMGKJk8+1GDECCL+wgCzZ23aaf6 PDAIB9hNBiTPS8lP4BqV8s4Ydx6PAlYaarQM13VM/pFJkeECkOPbaJkX94Wu51RL+b9P /zeQ== 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 s57si10066227qte.37.2020.03.24.03.07.34 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 24 Mar 2020 03:07:34 -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]:45358 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGgT7-0002if-Ul for patch@linaro.org; Tue, 24 Mar 2020 06:07:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49415) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGgP6-0005zd-1w for qemu-devel@nongnu.org; Tue, 24 Mar 2020 06:03:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jGgP4-0000b6-JV for qemu-devel@nongnu.org; Tue, 24 Mar 2020 06:03:23 -0400 Received: from mout.kundenserver.de ([217.72.192.74]:55719) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jGgP4-0000aN-9o for qemu-devel@nongnu.org; Tue, 24 Mar 2020 06:03:22 -0400 Received: from localhost.localdomain ([82.252.135.106]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.183]) with ESMTPSA (Nemesis) id 1McH1O-1jode3026G-00clcY; Tue, 24 Mar 2020 11:03:15 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 2/5] linux-user/i386: Split out gen_signal Date: Tue, 24 Mar 2020 11:03:08 +0100 Message-Id: <20200324100311.588288-3-laurent@vivier.eu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200324100311.588288-1-laurent@vivier.eu> References: <20200324100311.588288-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:KDGkdGysTorHu+lyENNEGinap9YULlqxASmrCjx6pd9q/7TcpIF FTxGr2d/WfJjJTBPF7F6/10F/nHvIIWGc+q/nyC8q8wx9NoMrirvlT8rnKfx0spkcUzu3x6 i5opCeNiPwPeGfDqaWDBR3B+LnAS4muapQEXlY3E3K+SAsXiLN0k1dfDR6/xbXenYx9TICF 9ElXn5qPOE7PCPhayexwg== X-UI-Out-Filterresults: notjunk:1; V03:K0:yCXWpCqa5ZQ=:rntgXdb7zkJk4tucKeS273 YW9cAcm0hnqfKhyRZvEKroKaE7uFRa1Umy9Mb1Yf937B9+ogVOcz6GrSraZtX5dqIPPgAsl9A LYheaInfYG0/QgW/NCkJi4yVquWG3A0ENfvxetl126+/hfnPMJ73opXAN7Y0H95uxFFWszoUZ 211saKcX3iBvTFeR5ovp3bAzCNipYLdXtru3/E1W9oSiLcZkb1NqgD/u69poFUjPDdmJ7J+JK RHP1ZcXxyHkOopc5JN1d9dIJAaDfPxto6bQ/ynFBHYW+MalbwBd7CP55RQZHLnkzxybJ7+lBD 1xjCPknHuOcNuCb5X1NQG8EvwPqSAb+3HPIjvEl2Q1h/GagZlYxPfjH2snwzznuMB9/ETUQ9O FEynVrPpKK5o4/l+pCbpzVDrv0fzRS31clTcZQ2YlWkRaL/d+yGpIaXjFjs/i9pNwJSQlXBW3 bFzHEyv58Va6UJ9LCFucdoBtX3xVqtvmZ/raGIi1KQnmiiDoTovWZrch6estlBwpAFU9ZstHs LiGbMqCTvHibmAAwj/+DrkY1l9kz8hADppgruIyMnnildKrCb9mRg/FtYLTNkduBY5TJjAkew 0vjANC4zBAQS93ZVxWH0KW9KkhM50eykndEH9UKJTmYFf16Llycwbc7dlt0du6AsnA6Awf693 ozCxYAqtLOoMBJNcaW742UUu2kmfcMJ7H8gKsCPfasEPhwOQw8pNlFC14vzqyIeDlbZFF4bPJ AVQYYmE7Iwwo7mnY3m0CWJqJC2528TOuQ1g6X4HRrceJyWAuf7km+m50vAHd1N9x+CXv5EKLd YLZ4IqxTu8cLGEch6/KQNbMA05S2LU7GSJPxBEnPfm4frf7eJAyFNW+88X+QBCRjoLhuBz5 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 217.72.192.74 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);