From patchwork Thu Jan 16 19:43:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1224397 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=ML24+9fN; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47zF7T2sZ1z9sTW for ; Fri, 17 Jan 2020 06:46:29 +1100 (AEDT) Received: from localhost ([::1]:47622 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1isB62-0008DP-QK for incoming@patchwork.ozlabs.org; Thu, 16 Jan 2020 14:46:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50176) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1isB3W-000512-JX for qemu-devel@nongnu.org; Thu, 16 Jan 2020 14:43:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1isB3V-0007NA-47 for qemu-devel@nongnu.org; Thu, 16 Jan 2020 14:43:50 -0500 Received: from mail-pj1-x1044.google.com ([2607:f8b0:4864:20::1044]:51534) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1isB3U-0007MZ-V2 for qemu-devel@nongnu.org; Thu, 16 Jan 2020 14:43:49 -0500 Received: by mail-pj1-x1044.google.com with SMTP id d15so2036567pjw.1 for ; Thu, 16 Jan 2020 11:43:48 -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=dVQPchFReqgJ20ne23FViP6RomyZ4oPHwhQNUV4fK+E=; b=ML24+9fN/mPfbJl4KFpjnO4mg2OiA/FfkJksOrTBE2dNmyi92coy9UOVwd3u9wcrZV wVjiPVCMTXtfYWhmfs2DNg5DqE8F9rZRayB0FrRFmdRMdxsaqVIiwt0jpAotjSOjoHlx vzKt3bC7L41RVkZF5UtR7rDy1zxE9IKySrsLwCZiXJD0mS4x4LyFWsHDXBrACXNUwpRu KCjAfPvht2+PQs8ZWtYkGObJF9w+w2Yjd56u3vLm4XyCtfqMo1SAGKAlLeqFIdeNc2Zh 6ZVRMuK9htpMJmeKl9qt+mJCaIoQD4Oj9D7lhS7yQ01/VUPXbx2G4VIbAW2BS3ThoFxY kezg== 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=dVQPchFReqgJ20ne23FViP6RomyZ4oPHwhQNUV4fK+E=; b=nyJdmPdNnXSp9jstQRcDgLs+Jhe18NP8WZpxSTOVe5GBHRstce3T2xPjYLmYPQp/Oi J0wANb1DJ8uq6qQup4PbjKFu9aPPPWWboZ9YTupp65t/KShwUnykRSETwxO6SmijLfID BemvL8F99RJ5c8iUtioEKVSUxgOZ56rCS1Yk4wZqWyajT1zWLQUFN3Kpz9/SONVP023r 95VvIfrys99eKjHD5XfBmuQITygbxqgJ59PqWAoM/Y6C0NnnEl+KxVrC2jSKkTX19MDw WB7D9TZyXML9ghwIHmMt+j8/KliEyKdUJCob2TUWmAZ1GqfTFNv2l7I4qPUlMTC8/Hre bV8g== X-Gm-Message-State: APjAAAXNQjsOyumhTb1FKeU+hIST6FHO9XU7ZyWNgjY768HH6bu0OdNT wkAecH4QRHUbaQOwfqU9J6qThrPkEVA= X-Google-Smtp-Source: APXvYqziYvnUGXcIGB5Hg5fLJjqx7KhOsgXGDzYJjQ3xf4dO9xZi+ufZfcQcg4FeYG3k6DWcEPp8JA== X-Received: by 2002:a17:90a:d205:: with SMTP id o5mr1015731pju.46.1579203827602; Thu, 16 Jan 2020 11:43:47 -0800 (PST) Received: from localhost.localdomain (rrcs-66-91-136-155.west.biz.rr.com. [66.91.136.155]) by smtp.gmail.com with ESMTPSA id g2sm26411831pgn.59.2020.01.16.11.43.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2020 11:43:46 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 1/5] target/i386: Renumber EXCP_SYSCALL Date: Thu, 16 Jan 2020 09:43:37 -1000 Message-Id: <20200116194341.402-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200116194341.402-1-richard.henderson@linaro.org> References: <20200116194341.402-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::1044 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 , alex.bennee@linaro.org, laurent@vivier.eu, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" We are not short of numbers for EXCP_*. There is no need to confuse things by having EXCP_VMEXIT and EXCP_SYSCALL overlap, even though the former is only used for system mode and the latter is only used for user mode. Reviewed-by: Paolo Bonzini Reviewed-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- target/i386/cpu.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 594326a794..164d038d1f 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -998,9 +998,8 @@ typedef uint64_t FeatureWordArray[FEATURE_WORDS]; #define EXCP11_ALGN 17 #define EXCP12_MCHK 18 -#define EXCP_SYSCALL 0x100 /* only happens in user only emulation - for syscall instruction */ -#define EXCP_VMEXIT 0x100 +#define EXCP_VMEXIT 0x100 /* only for system emulation */ +#define EXCP_SYSCALL 0x101 /* only for user emulation */ /* i386-specific interrupt pending bits. */ #define CPU_INTERRUPT_POLL CPU_INTERRUPT_TGT_EXT_1 From patchwork Thu Jan 16 19:43:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1224395 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=H/n/xI6p; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47zF5D3YnSz9sR0 for ; Fri, 17 Jan 2020 06:44:32 +1100 (AEDT) Received: from localhost ([::1]:47568 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1isB4A-0005AI-3U for incoming@patchwork.ozlabs.org; Thu, 16 Jan 2020 14:44:30 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50209) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1isB3Z-00052t-5Y for qemu-devel@nongnu.org; Thu, 16 Jan 2020 14:43:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1isB3X-0007PF-G4 for qemu-devel@nongnu.org; Thu, 16 Jan 2020 14:43:53 -0500 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]:38985) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1isB3W-0007O5-MI for qemu-devel@nongnu.org; Thu, 16 Jan 2020 14:43:51 -0500 Received: by mail-pl1-x644.google.com with SMTP id g6so8778919plp.6 for ; Thu, 16 Jan 2020 11:43:50 -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=H/n/xI6pUZfvcjRmTPN6f/aErwhprFpE/ICGDlbOcAGaPBoDdUTRPCuS1Os4I0epf0 NG3OD5KLKLWoF2WaCvYeCwh4FBgcPoyTsrdOyj3qyFPoclJg0qSvqkgQEm6UniTfsnwh nxB3txTzABpvVMTtukkHQxxorIlA8Oo+SvQIUPE8fe3fL0qljhCQo49XwBWbqhFyFAOw 4DLr35gkUcfZeHluO+u8mbyscn8iJg1Q2r5+d54caMpjkY8QTF1HuvFe1SFOPV43EXzz aMvTQb138v+P28a5LQW9LIkTQUZNch7iAbiT3r7ef5SfJSg3mVwhm9b6pYkUH1sSnyhS 5PtQ== 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=C7BttN9hVLU7hV5DUBY2u9JEAfig0SmvQFX6Hf3ajBd4e+bf+rEox3Qz7E8etg8htJ peTWwv+RoT4Exp5P3K97tK3rUJsRiAN5LCR2sZj/h5Ti8Ql2UfDVL8OfYrP+NIJWxUk2 20FrrAZNSon+ZgJVTC2jJDUdFh25R7a1notkknVp+9HycfZ2QrZBq16KSrpZz8MAKLYI JrcrkAg+nEYfOnNDQF5sWO+q6pJAzrHdkRQsk/oSmBu6OQaE6QJSEkI4BU+JVyLTQ+Jo z9gs+TFInHUmxu9Ww2d0RR1M9YISCkx2FgiQl/IXhBWvEP2263kNa9vBedmUDOVsTqjr wHPw== X-Gm-Message-State: APjAAAVzVQNXq5mtvC1WJ9jbB6vWEylApzwtlB7RRwBjn4zJuDzw+G1G ToQE57vGHrVTyziyuICr+5j/TuEIT0Y= X-Google-Smtp-Source: APXvYqxZ09Dy428YaH3J8oewtnxVeTTRTZg8vfi3bezLSX+BNxHac1F+DWS8Ehf+Wq3yIIZLUbk9Og== X-Received: by 2002:a17:902:44f:: with SMTP id 73mr33652143ple.81.1579203829383; Thu, 16 Jan 2020 11:43:49 -0800 (PST) Received: from localhost.localdomain (rrcs-66-91-136-155.west.biz.rr.com. [66.91.136.155]) by smtp.gmail.com with ESMTPSA id g2sm26411831pgn.59.2020.01.16.11.43.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2020 11:43:48 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 2/5] linux-user/i386: Split out gen_signal Date: Thu, 16 Jan 2020 09:43:38 -1000 Message-Id: <20200116194341.402-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200116194341.402-1-richard.henderson@linaro.org> References: <20200116194341.402-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::644 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 , alex.bennee@linaro.org, laurent@vivier.eu, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.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(-) 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); From patchwork Thu Jan 16 19:43:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1224418 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=XDruzHEP; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47zFBM1Q6hz9sTW for ; Fri, 17 Jan 2020 06:48:58 +1100 (AEDT) Received: from localhost ([::1]:47682 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1isB8S-0003Up-Em for incoming@patchwork.ozlabs.org; Thu, 16 Jan 2020 14:48:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50237) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1isB3a-00055D-P7 for qemu-devel@nongnu.org; Thu, 16 Jan 2020 14:43:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1isB3Z-0007Qo-A8 for qemu-devel@nongnu.org; Thu, 16 Jan 2020 14:43:54 -0500 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:39545) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1isB3Z-0007Px-4K for qemu-devel@nongnu.org; Thu, 16 Jan 2020 14:43:53 -0500 Received: by mail-pg1-x544.google.com with SMTP id b137so10420953pga.6 for ; Thu, 16 Jan 2020 11:43:52 -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=qBPdekzuUF9u9zLQuW/YaQ745tnM5NNl1KlJ3/Nz0A8=; b=XDruzHEP9bTEFFDvOKhWyaZaBZp5KHGlLgFzImlsI+1Yrrvg39ocHMEzGRKEJY7Chy WpD7TBUGnMpzfLkOBqgRDGT3peseFWq1zH1tFGZbyzZ+3Sapo4fql38QyyLNQrpSJYpT 4EMW3OF/Z6TOaFFf2jo5r/xQGaGCu8bXcfAj4lPSyxktE75LqIvScbv9PQCZfmgwSBZJ DV5VNp/9OjoclIxgVLo2JB+BgvygbBBJTJBzu7wfrS01xvjoCkc7OltYh5PVnUFkFEwd isu90XbjUsHxigXUsfkilMUEInCOTYbI2A+sE21dNPyUQwqLObJ1cingHCKB5YLe1DuS 0rBw== 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=qBPdekzuUF9u9zLQuW/YaQ745tnM5NNl1KlJ3/Nz0A8=; b=ZyYpwGJc/usLIH8WstMBK4psrpkdpAYuYZXLi0U2CfXlq9GCLamb9/Q6+i5sZgLVEo B++o256bUSi9CDBQHWOSurWWvA/D3CWTYwrZGJugAI+AvxpAunEOV1hvG24/PJKhM7xW 6xKDEPRLEn+Mc63QyZI2VmtAmxxzzHEYwh4JTi/+Ajlk5QrQ0HVqMu5YV8N1PU9y6LUn WashOh6K1eP8Pa5u+H/SLHHR0Xi9bwNRfFQuzbS4cwZHu59RI69vUhnBoOR2Cp8aTd7Q cFaHQlufDuRtIISG7c7jbCQCQOrDjVo7Yi+XuBx3EtsNpdBy2ckAdvxmUuFqLe7aNP7+ 8iTg== X-Gm-Message-State: APjAAAWq1Aay6z6Unrt3kelpm7YBGHHpp485XyAm+uhfkPMqYN0NZmYz X/XPMyFjEa1IBPgfvbUvB8cqtkEDq4I= X-Google-Smtp-Source: APXvYqyPBqIPdueyDCZgwwFPpeGd+tAucpF3F8Ja08MkN8MQX7+dAkEumI4P8B+E9b5x7RlciXMyFA== X-Received: by 2002:aa7:9816:: with SMTP id e22mr39608070pfl.229.1579203831646; Thu, 16 Jan 2020 11:43:51 -0800 (PST) Received: from localhost.localdomain (rrcs-66-91-136-155.west.biz.rr.com. [66.91.136.155]) by smtp.gmail.com with ESMTPSA id g2sm26411831pgn.59.2020.01.16.11.43.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2020 11:43:50 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 3/5] linux-user/i386: Emulate x86_64 vsyscalls Date: Thu, 16 Jan 2020 09:43:39 -1000 Message-Id: <20200116194341.402-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200116194341.402-1-richard.henderson@linaro.org> References: <20200116194341.402-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::544 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 , alex.bennee@linaro.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Notice the magic page during translate, much like we already do for the arm32 commpage. At runtime, raise an exception to return cpu_loop for emulation. Reviewed-by: Paolo Bonzini Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée --- target/i386/cpu.h | 1 + linux-user/i386/cpu_loop.c | 105 +++++++++++++++++++++++++++++++++++++ target/i386/translate.c | 16 +++++- 3 files changed, 121 insertions(+), 1 deletion(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 164d038d1f..3fb2d2a986 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1000,6 +1000,7 @@ typedef uint64_t FeatureWordArray[FEATURE_WORDS]; #define EXCP_VMEXIT 0x100 /* only for system emulation */ #define EXCP_SYSCALL 0x101 /* only for user emulation */ +#define EXCP_VSYSCALL 0x102 /* only for user emulation */ /* i386-specific interrupt pending bits. */ #define CPU_INTERRUPT_POLL CPU_INTERRUPT_TGT_EXT_1 diff --git a/linux-user/i386/cpu_loop.c b/linux-user/i386/cpu_loop.c index e217cca5ee..f9bf6cec27 100644 --- a/linux-user/i386/cpu_loop.c +++ b/linux-user/i386/cpu_loop.c @@ -92,6 +92,106 @@ static void gen_signal(CPUX86State *env, int sig, int code, abi_ptr 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) +{ + /* + * For all the vsyscalls, NULL means "don't write anything" not + * "write it at address 0". + */ + if (addr == 0 || access_ok(VERIFY_WRITE, addr, len)) { + return true; + } + + env->error_code = PG_ERROR_W_MASK | PG_ERROR_U_MASK; + gen_signal(env, TARGET_SIGSEGV, TARGET_SEGV_MAPERR, addr); + return false; +} + +/* + * Since v3.1, the kernel traps and emulates the vsyscall page. + * Entry points other than the official generate SIGSEGV. + */ +static void emulate_vsyscall(CPUX86State *env) +{ + int syscall; + abi_ulong ret; + uint64_t caller; + + /* + * Validate the entry point. We have already validated the page + * during translation, now verify the offset. + */ + switch (env->eip & ~TARGET_PAGE_MASK) { + case 0x000: + syscall = TARGET_NR_gettimeofday; + break; + case 0x400: + syscall = TARGET_NR_time; + break; + case 0x800: + syscall = TARGET_NR_getcpu; + break; + default: + sigsegv: + /* Like force_sig(SIGSEGV). */ + gen_signal(env, TARGET_SIGSEGV, TARGET_SI_KERNEL, 0); + return; + } + + /* + * Validate the return address. + * Note that the kernel treats this the same as an invalid entry point. + */ + if (get_user_u64(caller, env->regs[R_ESP])) { + goto sigsegv; + } + + /* + * Validate the the pointer arguments. + */ + switch (syscall) { + case TARGET_NR_gettimeofday: + if (!write_ok_or_segv(env, env->regs[R_EDI], + sizeof(struct target_timeval)) || + !write_ok_or_segv(env, env->regs[R_ESI], + sizeof(struct target_timezone))) { + return; + } + break; + case TARGET_NR_time: + if (!write_ok_or_segv(env, env->regs[R_EDI], sizeof(abi_long))) { + return; + } + break; + case TARGET_NR_getcpu: + if (!write_ok_or_segv(env, env->regs[R_EDI], sizeof(uint32_t)) || + !write_ok_or_segv(env, env->regs[R_ESI], sizeof(uint32_t))) { + return; + } + break; + default: + g_assert_not_reached(); + } + + /* + * Perform the syscall. None of the vsyscalls should need restarting, + * and all faults should have been caught above. + */ + ret = do_syscall(env, syscall, env->regs[R_EDI], env->regs[R_ESI], + env->regs[R_EDX], env->regs[10], env->regs[8], + env->regs[9], 0, 0); + g_assert(ret != -TARGET_ERESTARTSYS); + g_assert(ret != -TARGET_QEMU_ESIGRETURN); + g_assert(ret != -TARGET_EFAULT); + env->regs[R_EAX] = ret; + + /* Emulate a ret instruction to leave the vsyscall page. */ + env->eip = caller; + env->regs[R_ESP] += 8; +} +#endif + void cpu_loop(CPUX86State *env) { CPUState *cs = env_cpu(env); @@ -141,6 +241,11 @@ void cpu_loop(CPUX86State *env) env->regs[R_EAX] = ret; } break; +#endif +#ifdef TARGET_X86_64 + case EXCP_VSYSCALL: + emulate_vsyscall(env); + break; #endif case EXCP0B_NOSEG: case EXCP0C_STACK: diff --git a/target/i386/translate.c b/target/i386/translate.c index 7c99ef1385..391b4ef149 100644 --- a/target/i386/translate.c +++ b/target/i386/translate.c @@ -8555,7 +8555,21 @@ static bool i386_tr_breakpoint_check(DisasContextBase *dcbase, CPUState *cpu, static void i386_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) { DisasContext *dc = container_of(dcbase, DisasContext, base); - target_ulong pc_next = disas_insn(dc, cpu); + target_ulong pc_next; + +#if defined(TARGET_X86_64) && \ + defined(CONFIG_USER_ONLY) && \ + defined(CONFIG_LINUX) + /* + * Detect entry into the vsyscall page and invoke the syscall. + */ + if ((dc->base.pc_next & TARGET_PAGE_MASK) == 0xffffffffff600000ull) { + gen_exception(dc, EXCP_VSYSCALL, dc->base.pc_next); + return; + } +#endif + + pc_next = disas_insn(dc, cpu); if (dc->tf || (dc->base.tb->flags & HF_INHIBIT_IRQ_MASK)) { /* if single step mode, we generate only one instruction and From patchwork Thu Jan 16 19:43:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1224399 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=LFuUOFE0; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47zF7k5xPhz9sSs for ; Fri, 17 Jan 2020 06:46:42 +1100 (AEDT) Received: from localhost ([::1]:47630 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1isB6F-00005S-W8 for incoming@patchwork.ozlabs.org; Thu, 16 Jan 2020 14:46:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50262) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1isB3c-00055x-1w for qemu-devel@nongnu.org; Thu, 16 Jan 2020 14:43:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1isB3a-0007SU-RG for qemu-devel@nongnu.org; Thu, 16 Jan 2020 14:43:55 -0500 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]:46222) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1isB3a-0007RY-LC for qemu-devel@nongnu.org; Thu, 16 Jan 2020 14:43:54 -0500 Received: by mail-pg1-x543.google.com with SMTP id z124so10404163pgb.13 for ; Thu, 16 Jan 2020 11:43:54 -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=mlmrkeJpIzrykZtBoNNBzf4mMw31J+DYkBhjDwHekRc=; b=LFuUOFE0E970h9rzr6EFoFYOv2230PPKeJzHn3Ps17vThQ31K6HLEg5ZfQ4BL56/ql ZT04Sb+WEUdedU2ESw0aw0quwzLJr/EZ84SupQvlyQINgClfZizfb5PrU5fNay6pzmYZ lgxsfqE/G1V3MQmSJoUZjyy5eBhHf1AhTH4o2t+U+jAJzUqISOf1MQ4T29++dw+0CFW/ BEX5pSBsI8eF97oFxS31DkJEKV875CyMuCGFG5zaQTHStGeABteZfi8VC1GEa10xoiOD XEN6cuAqe5eqqmJ5B3wOZBzkDtvO5YvVxokoqhG8J5UWahuKRi1rTLhvA0m1A5fTdPKz mU5w== 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=mlmrkeJpIzrykZtBoNNBzf4mMw31J+DYkBhjDwHekRc=; b=KVAhu35d0G+/eV3Bo6Txbzh3pSqep8bUPVMDfnmfdZ5YLjtlEv8i5P3YiHE1I0BSlI v4DdFXoFSZ0BZFjUWhmpwkoBqRh9Yx5/c795XxIDZzPMKzWjMZoV+LONOmDB0XrF8A12 RzmISSkcTDTjpemiivNCfcxs171uBHsojh8xEHqI6jGYz+zbczYqAo3kROkEHnYoGdGG sv+m6ZjcW+s4xbB8z11evQlO9ZUojKB0iq9kM9cesGKbMA9Aw+oQ1sPIaEN70wUcfwRe FVSccq78E/fFatYTL7OCnNBBkek0KHq+udF6H8Ky99jONXhdR0Wiwoaoadoa0jYEWFmV Jnow== X-Gm-Message-State: APjAAAVcGO4vnMRr7z2rFGCmmu0HPKq+49FKnIunoyPQcyo0VH2hk/pn 2tt2dzY85+IgeUWNTekir/szMqAOYJE= X-Google-Smtp-Source: APXvYqzhrW9lxQeR8BHFha5JSUbw0KRD785JlC4MaJXnLIhGQcUBD3cbwCEKOjAn4wRwRILd9xcLIg== X-Received: by 2002:a62:1783:: with SMTP id 125mr39653076pfx.189.1579203833454; Thu, 16 Jan 2020 11:43:53 -0800 (PST) Received: from localhost.localdomain (rrcs-66-91-136-155.west.biz.rr.com. [66.91.136.155]) by smtp.gmail.com with ESMTPSA id g2sm26411831pgn.59.2020.01.16.11.43.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2020 11:43:52 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 4/5] linux-user: Add x86_64 vsyscall page to /proc/self/maps Date: Thu, 16 Jan 2020 09:43:40 -1000 Message-Id: <20200116194341.402-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200116194341.402-1-richard.henderson@linaro.org> References: <20200116194341.402-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::543 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: alex.bennee@linaro.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The page isn't (necessarily) present in the host /proc/self/maps, and even if it might be it isn't present in page_flags, and even if it was it might not have the same set of page permissions. The easiest thing to do, particularly when it comes to the "[vsyscall]" note at the end of line, is to special case it. Signed-off-by: Richard Henderson --- linux-user/syscall.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 171c0caef3..eb867a5296 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7005,6 +7005,15 @@ static int open_self_maps(void *cpu_env, int fd) } } +#ifdef TARGET_X86_64 + /* + * We only support execution from the vsyscall page. + * This is as if CONFIG_LEGACY_VSYSCALL_XONLY=y from v5.3. + */ + dprintf(fd, "ffffffffff600000-ffffffffff601000 --xp 00000000 00:00 0" + " [vsyscall]\n"); +#endif + free(line); fclose(fp); From patchwork Thu Jan 16 19:43:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1224396 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=v9eWnaT4; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47zF5t3v3mz9sR0 for ; Fri, 17 Jan 2020 06:45:06 +1100 (AEDT) Received: from localhost ([::1]:47576 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1isB4i-0006SB-1q for incoming@patchwork.ozlabs.org; Thu, 16 Jan 2020 14:45:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50299) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1isB3e-00058x-Th for qemu-devel@nongnu.org; Thu, 16 Jan 2020 14:44:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1isB3d-0007Ua-Rr for qemu-devel@nongnu.org; Thu, 16 Jan 2020 14:43:58 -0500 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]:38680) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1isB3c-0007Sw-2E for qemu-devel@nongnu.org; Thu, 16 Jan 2020 14:43:56 -0500 Received: by mail-pl1-x644.google.com with SMTP id f20so8775210plj.5 for ; Thu, 16 Jan 2020 11:43:56 -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=BF/LvenLVteHucTa2gOslze21R5NBa9gmgvuCLp0CGM=; b=v9eWnaT4uk14sUqPhUBJHZNkGk0PkX99tH3ogHXmtHQ3VhZrzOEeZmpD9XApE1vn9Y PsGUX6L+SIiqiBy5BMpOm3g2jt/YhDvVO52z9+QBrblWqLkmp+yXq/ymPPsGvtaYOecn 1G/P8lXkXCq1aL9M4xiv6bFrLDAzyJOKLkBl+lOkeXXV7Qq09wTxWJnJGCpzWd4F/g4/ b+Ck51pHLQ+OEw6gOqg2iNqWkIsY0MoPh8I7NiprSb1bzKLo3GkLKLyoAZTG98gtCKhR BRuI6j3Y9O++RvsvTkp3nxfHjgrQegrqXhckBRFiZlpmFXbK3Vn6X6SZiL0Y/BRT41sM 9YZQ== 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=BF/LvenLVteHucTa2gOslze21R5NBa9gmgvuCLp0CGM=; b=KZApnvN31k8YL9RlWevKQwaXn1mEnbXQ871nHms2bQ6FSPCH7R41Z7SFfPEKHH74u3 Quz5+7V+OWwrlmPm3G7ZD1m5GbqJ2AVkuwfeAOvVtaljFhgPra1tfqdXIdW/wEK0FL1W levXu3ecJhZ27pfV36Xf5Pd0/NH91BgsGpAoqDrjGkwseTycfbPea3zYZqCCAXEJ0Dj3 8tFKaA3i3XSybuWFWMGgE/o5Wo/cxcyTQQu8g8PSxChzEtN6fKUwzySpATBPhIPg06Ae sHaxLlzHyuxCb4i8FkcYGt3zIwWJxtApKh3FtZvqrsLw57oNlQJBA7Or67PJIwCZF6xA NTrQ== X-Gm-Message-State: APjAAAWbgZzEiyfqfGgSMTBLCnEdPICvxfeDOWbjx65QNozSqM8/wsa0 +Bk3T+rgsNCljUng0pTIL/38iBrKyVI= X-Google-Smtp-Source: APXvYqzk5IeP4GoyZA1rSIFEdBxOsGPw5rpOcm/lpjNEcTdFZO9Z/MPGvIc3RUKGoH3wMYVtXC8Pwg== X-Received: by 2002:a17:90a:17e5:: with SMTP id q92mr1033873pja.28.1579203834928; Thu, 16 Jan 2020 11:43:54 -0800 (PST) Received: from localhost.localdomain (rrcs-66-91-136-155.west.biz.rr.com. [66.91.136.155]) by smtp.gmail.com with ESMTPSA id g2sm26411831pgn.59.2020.01.16.11.43.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2020 11:43:54 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 5/5] linux-user: Flush out implementation of gettimeofday Date: Thu, 16 Jan 2020 09:43:41 -1000 Message-Id: <20200116194341.402-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200116194341.402-1-richard.henderson@linaro.org> References: <20200116194341.402-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::644 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: alex.bennee@linaro.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The first argument, timeval, is allowed to be NULL. The second argument, timezone, was missing. While its use is deprecated, it is still present in the syscall. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Alex Bennée --- linux-user/syscall.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index eb867a5296..628b4de9a1 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -1219,6 +1219,23 @@ static inline abi_long host_to_target_timespec64(abi_ulong target_addr, return 0; } +static inline abi_long copy_to_user_timezone(abi_ulong target_tz_addr, + struct timezone *tz) +{ + struct target_timezone *target_tz; + + if (!lock_user_struct(VERIFY_WRITE, target_tz, target_tz_addr, 1)) { + return -TARGET_EFAULT; + } + + __put_user(tz->tz_minuteswest, &target_tz->tz_minuteswest); + __put_user(tz->tz_dsttime, &target_tz->tz_dsttime); + + unlock_user_struct(target_tz, target_tz_addr, 1); + + return 0; +} + static inline abi_long copy_from_user_timezone(struct timezone *tz, abi_ulong target_tz_addr) { @@ -8567,10 +8584,16 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, case TARGET_NR_gettimeofday: { struct timeval tv; - ret = get_errno(gettimeofday(&tv, NULL)); + struct timezone tz; + + ret = get_errno(gettimeofday(&tv, &tz)); if (!is_error(ret)) { - if (copy_to_user_timeval(arg1, &tv)) + if (arg1 && copy_to_user_timeval(arg1, &tv)) { return -TARGET_EFAULT; + } + if (arg2 && copy_to_user_timezone(arg2, &tz)) { + return -TARGET_EFAULT; + } } } return ret;