From patchwork Fri Jan 7 21:32:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 530500 Delivered-To: patch@linaro.org Received: by 2002:ad5:544f:0:0:0:0:0 with SMTP id a15csp720580imp; Fri, 7 Jan 2022 13:42:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJzRkWnz3fblJik9pQ93ZlUlvLIUnKCRkVzL1FlXCveQb446wTpoN+8DuEQtW+PwlFDBhEaU X-Received: by 2002:a25:7444:: with SMTP id p65mr65805840ybc.254.1641591729825; Fri, 07 Jan 2022 13:42:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641591729; cv=none; d=google.com; s=arc-20160816; b=NrSWfbC9GRxjKWV6mt8lhstIaprkn7ppaliKBUJJsVh4eykRoOI8gLLxo/MGL/84w1 X4OLin6avl6HrbodUZmtuWbZURSS21Hbx/EKGVtvxsEw+xCk2nOeh1D8YV69rupsZda9 jg0SFNWt687cZ6eSqCKGce06yXdvwJvmWyDLmXpYnScMuONNKS1VbraMpxqoq1rKv3n/ 0PT7lEiQj7Oxt320u1BFBppGGGoIG6NudCJ+MV5PTZScFfyabut1+hkoYVnKbi122mJP VpO2afkaRBBtpc3rMjbL/oz7ipAodTccfgQ7Upyzpj9lrjfkarFExrb6XHuPdGQxCeuy DP1w== 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 :dkim-signature; bh=TpHn0Fhs0LB5c3hIVLLK+G+3+OaCxi58Bs9uIsk1ZnQ=; b=McNMH1xCG/K+h275qc0PMVumKIGjV0YTqO2HV08SQHCwlWl1LL5jyMAqbxQfL0WyQP /TkVGhk+4tUq3iRW2no2RKzNvIKpOnHa5Od4EItYs5Do7R24xwCsJ7ofyhBtuebP+kel mRHLKBQTum4FVXAEM+Ik5AlJ86SOpoc26VhlFr5OMV249IeWIclipxSzuXdtmLAgUz2M 2LfnmE/pRtdJ1yiM4XvGA7Q91P0YnYAhH8erYi1OhdX7VevTmhd4LPoGBev5geoO1ANF hRlmW5yupq+W6EbtT6mnV7QgzyVTDDnY/ePcqCWuCFnzaJ4KFuW2tNhMhNOlWm3aD6rw D12Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="uwZ/wfBh"; 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"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id e11si4551550ybf.480.2022.01.07.13.42.09 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Jan 2022 13:42:09 -0800 (PST) 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; dkim=fail header.i=@linaro.org header.s=google header.b="uwZ/wfBh"; 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"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:55272 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n5wzx-0000Su-9l for patch@linaro.org; Fri, 07 Jan 2022 16:42:09 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42524) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n5wr1-00059o-B8 for qemu-devel@nongnu.org; Fri, 07 Jan 2022 16:32:55 -0500 Received: from [2607:f8b0:4864:20::42e] (port=41499 helo=mail-pf1-x42e.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n5wqx-0007os-PC for qemu-devel@nongnu.org; Fri, 07 Jan 2022 16:32:53 -0500 Received: by mail-pf1-x42e.google.com with SMTP id m1so6162452pfk.8 for ; Fri, 07 Jan 2022 13:32:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TpHn0Fhs0LB5c3hIVLLK+G+3+OaCxi58Bs9uIsk1ZnQ=; b=uwZ/wfBhzUcC30H2TxBlD1vOXu/AZ0daelKzYm9CeH7G3pnMbemTBaA2/jLp8gtDbG vwmhK8x9B79/55ahED2+DfAZpoYZxZ6iRbNQRLwaKv+euWjz2PHS2pQ2XzuKaFy0Dhc8 5aw3+YwSGvXwIhQpFf9dH97b92+c+kl9751c7Ydqecm+ShaqlWwQP1BNf8uJ1I1HK//e puxnC9v9czMhIplBt41J3qCp/d4AhScF0vF29fYLsjE1OG5eqaPj+cVGekwpIKXKalgG Ce9/iXSU1dz0MeYLM+/yIiEIBhOqEbqPqZT52pcizP2pk8jr7a/Gpl1J9Kg5pNBq9u7J zKzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TpHn0Fhs0LB5c3hIVLLK+G+3+OaCxi58Bs9uIsk1ZnQ=; b=5IDkodbf55VKdG1M1B3C9ym70SN04k1zkXaX2t/+8ifGIjcnRFZey8qV3YXFUC+EuR Ajd/FFaTJvLIih/V5CDDOc4J3/0wPkf+nEMubUZ7ftcCCYwYEROIDhUfyywBxs8Oj0eH OLQGgLFSYnFms2zt8HawkgGQOD1cDK6gUNFCehRbWVmJ3uSeFEHKhXwhj3yYbuMAuBGF 5JDtd09rhx3HnqXHjstPdeMu5tMQe2ubsXGdhooCZXyEIDnfvf1lzVqiIUpzpRd5OOVk Q4BZ1pBAmwtKOP1fSO/cweuQDfAhwNWRp4qTXsvmIugL8Rsty7YoCyrjn4daElHWqN4s qwhQ== X-Gm-Message-State: AOAM533phWn151196bgnWEt0T1q+d4YGt92dvZwhKksg0AYR6ugOFj7N rdGbwLO+DS41k9Gf9ixiFxXcJVFEh7wj+w== X-Received: by 2002:a63:8c09:: with SMTP id m9mr26845782pgd.138.1641591170524; Fri, 07 Jan 2022 13:32:50 -0800 (PST) Received: from localhost.localdomain (174-21-75-75.tukw.qwest.net. [174.21.75.75]) by smtp.gmail.com with ESMTPSA id y11sm6633030pfi.80.2022.01.07.13.32.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jan 2022 13:32:50 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v5 10/24] linux-user/i386: Use force_sig, force_sig_fault Date: Fri, 7 Jan 2022 13:32:29 -0800 Message-Id: <20220107213243.212806-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220107213243.212806-1-richard.henderson@linaro.org> References: <20220107213243.212806-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::42e (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::42e; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42e.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Replace the local gen_signal with the generic functions that match how the kernel raises signals. Fill in the missing PC for SIGTRAP. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- linux-user/i386/cpu_loop.c | 47 +++++++++++++++----------------------- 1 file changed, 18 insertions(+), 29 deletions(-) diff --git a/linux-user/i386/cpu_loop.c b/linux-user/i386/cpu_loop.c index ac0f4e3211..29dfd7cd0c 100644 --- a/linux-user/i386/cpu_loop.c +++ b/linux-user/i386/cpu_loop.c @@ -84,17 +84,6 @@ 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); -} - #ifdef TARGET_X86_64 static bool write_ok_or_segv(CPUX86State *env, abi_ptr addr, size_t len) { @@ -107,7 +96,7 @@ static bool write_ok_or_segv(CPUX86State *env, abi_ptr addr, size_t len) } env->error_code = PG_ERROR_W_MASK | PG_ERROR_U_MASK; - gen_signal(env, TARGET_SIGSEGV, TARGET_SEGV_MAPERR, addr); + force_sig_fault(TARGET_SIGSEGV, TARGET_SEGV_MAPERR, addr); return false; } @@ -193,8 +182,7 @@ static void emulate_vsyscall(CPUX86State *env) return; sigsegv: - /* Like force_sig(SIGSEGV). */ - gen_signal(env, TARGET_SIGSEGV, TARGET_SI_KERNEL, 0); + force_sig(TARGET_SIGSEGV); } #endif @@ -266,53 +254,54 @@ void cpu_loop(CPUX86State *env) #endif case EXCP0B_NOSEG: case EXCP0C_STACK: - gen_signal(env, TARGET_SIGBUS, TARGET_SI_KERNEL, 0); + force_sig(TARGET_SIGBUS); break; case EXCP0D_GPF: /* XXX: potential problem if ABI32 */ if (maybe_handle_vm86_trap(env, trapnr)) { break; } - gen_signal(env, TARGET_SIGSEGV, TARGET_SI_KERNEL, 0); + force_sig(TARGET_SIGSEGV); break; case EXCP0E_PAGE: - gen_signal(env, TARGET_SIGSEGV, - (env->error_code & 1 ? - TARGET_SEGV_ACCERR : TARGET_SEGV_MAPERR), - env->cr[2]); + force_sig_fault(TARGET_SIGSEGV, + (env->error_code & PG_ERROR_P_MASK ? + TARGET_SEGV_ACCERR : TARGET_SEGV_MAPERR), + env->cr[2]); break; case EXCP00_DIVZ: if (maybe_handle_vm86_trap(env, trapnr)) { break; } - gen_signal(env, TARGET_SIGFPE, TARGET_FPE_INTDIV, env->eip); + force_sig_fault(TARGET_SIGFPE, TARGET_FPE_INTDIV, env->eip); break; case EXCP01_DB: + if (maybe_handle_vm86_trap(env, trapnr)) { + break; + } + force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->eip); + break; case EXCP03_INT3: if (maybe_handle_vm86_trap(env, trapnr)) { break; } - if (trapnr == EXCP01_DB) { - gen_signal(env, TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->eip); - } else { - gen_signal(env, TARGET_SIGTRAP, TARGET_SI_KERNEL, 0); - } + force_sig(TARGET_SIGTRAP); break; case EXCP04_INTO: case EXCP05_BOUND: if (maybe_handle_vm86_trap(env, trapnr)) { break; } - gen_signal(env, TARGET_SIGSEGV, TARGET_SI_KERNEL, 0); + force_sig(TARGET_SIGSEGV); break; case EXCP06_ILLOP: - gen_signal(env, TARGET_SIGILL, TARGET_ILL_ILLOPN, env->eip); + force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPN, env->eip); break; case EXCP_INTERRUPT: /* just indicate that signals should be handled asap */ break; case EXCP_DEBUG: - gen_signal(env, TARGET_SIGTRAP, TARGET_TRAP_BRKPT, 0); + force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->eip); break; case EXCP_ATOMIC: cpu_exec_step_atomic(cs);