From patchwork Thu Feb 13 03:22:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 183327 Delivered-To: patch@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp27882ile; Wed, 12 Feb 2020 19:22:44 -0800 (PST) X-Google-Smtp-Source: APXvYqxIJr2OzVxrGKkBTlM65mszoC3MWQc8IM0SRkShzBo12/T+Gq7GO2byTzs28DmHwqlZmGdL X-Received: by 2002:ac8:5055:: with SMTP id h21mr22002421qtm.30.1581564164060; Wed, 12 Feb 2020 19:22:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581564164; cv=none; d=google.com; s=arc-20160816; b=OeQs6tIgWd7l+UmpbtK2ouZBY5uaX8KHXRfOiKajqErzIrLjkODNuNqYZ+7bN3PgAi +zMGx647F8Tm0iW/ZkQYcXTvnGYWbDdQ5NdkqyKhu5pPd7S3zg3TeCLzHelu0I+STwda TaoEW4Le1zXo4TuGhF4YnuQlKwkRw5qAtw/wg4nvV9RFmaDWZUQ7Gy78Gm6dpHUb2/TQ 53LNRRmywXt3tICXbckZsyQzqr3Z/ULrkjnX4/rRnsNs26UobjecIDzxdB7N6g6Z4pWW meoRZHVsAJqgoEzMEJIqm1qBX93wrSIU4WbM+sLW71KF02jWSkPwfNkr2ZIN9oVA9etu kz9A== 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=3RA4GH2ajonQfyTX2FF7Fo2q74LDzhgpTLSFFMfVDM0=; b=vY9mkv7B1fvb9YXqdJQ3jMFbDhH6r12XWbY/15r59WMJzhzLwV7y6ht4sFNsc3+p8P 5V6WoCVdTzo584N7O7J3OOsnyjffpvN2//tuAI6e428oEqjrXPr5iCEKXfBbO3rQnPYb KWosPEI0TBxeFqQcDuoIBpj3I2AHEDgEoAPZMfC7Moj3DLduXyRsNuQAxDFL0qbd3NJK QopNPx3spORPWJLMliCo2cMb+4sORu7B6E3WHI5A11EMgfQs+CzZOQJFNtRp4s1CqDIN I4TCSG3kRWOtE1qdh6JHXEeNFfTzAWcegEeP9rvfO6HheYz5IK9yacgRduVntEcOJsKW L1mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=THdGCW3B; 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 w65si582876qkb.63.2020.02.12.19.22.43 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 12 Feb 2020 19:22:44 -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=THdGCW3B; 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]:46794 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j255P-0002HD-EZ for patch@linaro.org; Wed, 12 Feb 2020 22:22:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:60152) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j255D-0002Bh-6W for qemu-devel@nongnu.org; Wed, 12 Feb 2020 22:22:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j255B-0000BH-RB for qemu-devel@nongnu.org; Wed, 12 Feb 2020 22:22:31 -0500 Received: from mail-pj1-x1042.google.com ([2607:f8b0:4864:20::1042]:32824) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j255B-000076-Kr for qemu-devel@nongnu.org; Wed, 12 Feb 2020 22:22:29 -0500 Received: by mail-pj1-x1042.google.com with SMTP id m7so2277559pjs.0 for ; Wed, 12 Feb 2020 19:22:29 -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=3RA4GH2ajonQfyTX2FF7Fo2q74LDzhgpTLSFFMfVDM0=; b=THdGCW3BNt7EkumthnWSpnaggBv5wTqJePjQFtUbV0FtYNR6Elwo6RmDAszysaDX93 WZxt67oaz68yYxgCu/DmOwUR3qLrwQwuXBejZD7Fz7Jd0KgRtxo8rOLgJH3dSlvoyYQq 4kMCGRVoGb7U3CbOTjulcz3d/M/izPUoiprD+3lCjRfPdRf+c5JgKBmYFOabTGYpXpYQ rVIy0h07eIUin5tRf/RxBiQEMfvOx9jb0d+hVn1gRFnB6ASyeyPGgt+hQTZKJsaC0YF3 nvgh13RmH1LFDiqU54VZVgbW/d3+1+8pR+FlukC9/S26o+HJdwOddr3EewtR/vfWQlRk v0bA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3RA4GH2ajonQfyTX2FF7Fo2q74LDzhgpTLSFFMfVDM0=; b=LpIfLcNhtMhBXhb4yNvh25ACGWIs57eHXdwEkYhgTW95Jxhsonnv7nyQg/zUhxtavQ fgYpuiitKq0kAbow5m35O4hS4U8m75yRrtgqihpOFnBfnL7TvInvmAcwCGXcXHTtg+Yp b5VwMMLWNV7k5lyONtm25ioO9WX/UZ9GP8CKFDIquuEQDxuRuxEmiDHN80XBPTS1fFcS S3ewYEmGJ8LBI5j3ui6FBDtuIYK1/SH1NOt9oTepul9SdcCPIEzqv8zB7uMcUcAoIUYu ECYlZ/csl3VGeSr3DDYgsdETNioNKQIfohK/U+Qv0n+jKUbLYiSC4MvriCpgZMptjvCE wFqA== X-Gm-Message-State: APjAAAWIvY80pDpqcDlIwSZj0sEuhql7qC8rGMdT7jMwC/LtTfms3iOd IqLV9qXCDeJ6omyrpCWbk7vEpJRWrqM= X-Received: by 2002:a17:90a:f317:: with SMTP id ca23mr2611033pjb.20.1581564148049; Wed, 12 Feb 2020 19:22:28 -0800 (PST) Received: from localhost.localdomain (97-126-123-70.tukw.qwest.net. [97.126.123.70]) by smtp.gmail.com with ESMTPSA id l15sm536067pgi.31.2020.02.12.19.22.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Feb 2020 19:22:27 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 2/5] linux-user/i386: Split out gen_signal Date: Wed, 12 Feb 2020 19:22:20 -0800 Message-Id: <20200213032223.14643-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200213032223.14643-1-richard.henderson@linaro.org> References: <20200213032223.14643-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::1042 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: Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , laurent@vivier.eu, =?utf-8?q?Philippe_Mathi?= =?utf-8?b?ZXUtRGF1ZMOp?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 --- linux-user/i386/cpu_loop.c | 93 ++++++++++++++------------------------ 1 file changed, 33 insertions(+), 60 deletions(-) -- 2.20.1 diff --git a/linux-user/i386/cpu_loop.c b/linux-user/i386/cpu_loop.c index 024b6f4d58..e217cca5ee 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);