From nobody Tue Oct 14 02:06:25 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1581564202230594.803237836133; Wed, 12 Feb 2020 19:23:22 -0800 (PST) Received: from localhost ([::1]:46817 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2560-0003gH-Rz for importer@patchew.org; Wed, 12 Feb 2020 22:23:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:60132) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j255B-0002BP-95 for qemu-devel@nongnu.org; Wed, 12 Feb 2020 22:22:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j255A-0008W3-7e for qemu-devel@nongnu.org; Wed, 12 Feb 2020 22:22:29 -0500 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]:38429) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j255A-0008Uj-2M for qemu-devel@nongnu.org; Wed, 12 Feb 2020 22:22:28 -0500 Received: by mail-pl1-x642.google.com with SMTP id t6so1750871plj.5 for ; 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.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Feb 2020 19:22:26 -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=b0SUyaJJjQZuc34rLJlUYZCom+bkortVckKDUk4LlxA=; b=tEI+Wq+MT+AsYiUz4cgA7Dp9LDe139xyevHXaao51NWk4Qy+oHi8p3FQTzxyP6TQoL vn3yo3aKQhiqaWVSgTQBnM/i1ZWcF5GRjHnqZqpIKSop9zahZmSW2lPkOX/K6XirkBqm /hEGcr3q0MjJCWTwiswI8i2EZOSz4V9Sot3kp/G5Jn0xXD8rkcDjqidnN4iRidn+LqYn CL0QQQPBoVyX1fX+aG0+o5NWXugfdCywTMVZr0ky8Jl71dNhDP1GxrSAI0cSSXXvXP/L qubE268Myx0bhtFagMfU4vyfzI6m5q6blBQnJK5Yu3TiEkvqqwctKFggO0iwgVl/PAua rVRA== 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=b0SUyaJJjQZuc34rLJlUYZCom+bkortVckKDUk4LlxA=; b=f5KhhQ7ouOqjRD1qePlmcoiYc/ZdLcd+1DwgoY5WItmNHCaxBy5ueaYsmZo3BH4OnW 56gkZJjrqUiyy7vCNNUYs7Q5aZFeqZulBaJ5P5pxgkFcENsojOtjicf6+LncNSIp4B1W FCaDoxvLRNfe8YPQS2kobvmFrsjsx5G5IkOMybGvAIqoODk3XPzHXExpOInOJmpj6Hia cWsS1k88XpbEBDyxqamrlTzCsbi4MmGiODywfJSa4P8IQj5Ss+pKgsdV/hnf9f3jgJB+ XHoRVkEiMUnicuTWELG/jqtmZ/eECjvQdoc6f6JTTEVxvlDUjDxScTTxAezJ6aKnaSEH y8Lg== X-Gm-Message-State: APjAAAWxg+NATTcSOE4LDEJ8C9eWP6aU9bs58/MF6DYAHHNjTbX5OsbD uAwwl+zaIO8376E9kyRSmcnLX/VDHDs= X-Google-Smtp-Source: APXvYqwfbIZVmRRrcKRrI/Zf0x2uc2Ci6u8Lf9830+GAo06JS18B/AG1p2+VTYZEwfxWryFoWSgQvg== X-Received: by 2002:a17:90a:bf83:: with SMTP id d3mr2634922pjs.77.1581564146790; Wed, 12 Feb 2020 19:22:26 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 1/5] target/i386: Renumber EXCP_SYSCALL Date: Wed, 12 Feb 2020 19:22:19 -0800 Message-Id: <20200213032223.14643-2-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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::642 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=20Benn=C3=A9e?= , laurent@vivier.eu, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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=C3=A9e Reviewed-by: Philippe Mathieu-Daud=C3=A9 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 576f309bbf..08b4422f36 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -999,9 +999,8 @@ typedef uint64_t FeatureWordArray[FEATURE_WORDS]; #define EXCP11_ALGN 17 #define EXCP12_MCHK 18 =20 -#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 */ =20 /* i386-specific interrupt pending bits. */ #define CPU_INTERRUPT_POLL CPU_INTERRUPT_TGT_EXT_1 --=20 2.20.1 From nobody Tue Oct 14 02:06:25 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1581564210855371.730170865647; Wed, 12 Feb 2020 19:23:30 -0800 (PST) Received: from localhost ([::1]:46824 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2569-0003ut-IN for importer@patchew.org; Wed, 12 Feb 2020 22:23:29 -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) 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) 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-Google-Smtp-Source: APXvYqwkxsQgvc7yg6I/O5sR/X0zBZGvTBAQRGCjDSrVYOl77FHeccjroXaStw3fR+3IZMG//koEWw== X-Received: by 2002:a17:90a:f317:: with SMTP id ca23mr2611033pjb.20.1581564148049; Wed, 12 Feb 2020 19:22:28 -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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=20Benn=C3=A9e?= , laurent@vivier.eu, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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=C3=A9e Reviewed-by: Philippe Mathieu-Daud=C3=A9 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 =20 +static void gen_signal(CPUX86State *env, int sig, int code, abi_ptr addr) +{ + target_siginfo_t info =3D { + .si_signo =3D sig, + .si_code =3D code, + ._sifields._sigfault._addr =3D addr + }; + + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); +} + void cpu_loop(CPUX86State *env) { CPUState *cs =3D env_cpu(env); int trapnr; abi_ulong pc; abi_ulong ret; - target_siginfo_t info; =20 for(;;) { cpu_exec_start(cs); @@ -134,70 +144,45 @@ void cpu_loop(CPUX86State *env) #endif case EXCP0B_NOSEG: case EXCP0C_STACK: - info.si_signo =3D TARGET_SIGBUS; - info.si_errno =3D 0; - info.si_code =3D TARGET_SI_KERNEL; - info._sifields._sigfault._addr =3D 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 =3D TARGET_SIGSEGV; - info.si_errno =3D 0; - info.si_code =3D TARGET_SI_KERNEL; - info._sifields._sigfault._addr =3D 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 =3D TARGET_SIGSEGV; - info.si_errno =3D 0; - if (!(env->error_code & 1)) - info.si_code =3D TARGET_SEGV_MAPERR; - else - info.si_code =3D TARGET_SEGV_ACCERR; - info._sifields._sigfault._addr =3D 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 =3D TARGET_SIGFPE; - info.si_errno =3D 0; - info.si_code =3D TARGET_FPE_INTDIV; - info._sifields._sigfault._addr =3D 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 =3D TARGET_SIGTRAP; - info.si_errno =3D 0; - if (trapnr =3D=3D EXCP01_DB) { - info.si_code =3D TARGET_TRAP_BRKPT; - info._sifields._sigfault._addr =3D env->eip; - } else { - info.si_code =3D TARGET_SI_KERNEL; - info._sifields._sigfault._addr =3D 0; - } - queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + if (trapnr =3D=3D EXCP01_DB) { + gen_signal(env, TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->ei= p); + } 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 =3D TARGET_SIGSEGV; - info.si_errno =3D 0; - info.si_code =3D TARGET_SI_KERNEL; - info._sifields._sigfault._addr =3D 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 =3D TARGET_SIGILL; - info.si_errno =3D 0; - info.si_code =3D TARGET_ILL_ILLOPN; - info._sifields._sigfault._addr =3D 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 =3D TARGET_SIGTRAP; - info.si_errno =3D 0; - info.si_code =3D 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); --=20 2.20.1 From nobody Tue Oct 14 02:06:25 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1581564274028313.80713194610166; Wed, 12 Feb 2020 19:24:34 -0800 (PST) Received: from localhost ([::1]:46852 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j257A-0005ys-RD for importer@patchew.org; Wed, 12 Feb 2020 22:24:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:60164) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j255E-0002E1-CT for qemu-devel@nongnu.org; Wed, 12 Feb 2020 22:22:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j255D-0000IU-0p for qemu-devel@nongnu.org; Wed, 12 Feb 2020 22:22:32 -0500 Received: from mail-pj1-x1041.google.com ([2607:f8b0:4864:20::1041]:38566) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j255C-0000E3-QX for qemu-devel@nongnu.org; Wed, 12 Feb 2020 22:22:30 -0500 Received: by mail-pj1-x1041.google.com with SMTP id j17so1772988pjz.3 for ; Wed, 12 Feb 2020 19:22:30 -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.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Feb 2020 19:22:28 -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=hRsQ7XlJN4rMifYbK1S2B4u9AT4d8Fx9ZqVq28vUwr8=; b=l0j9dxdzytU2BofWbBFLt+92/1oDuW3FSzq/JoTfrGb93GIpGcaR/InhGpzg8KKbmy jsBvuMcn6le2JfX4L1Z0pqMtzkvuhyv5Quzh0/m35/8bpF5YbTUhqfEoIPiUGuaSHGGN 6hhHSU51ctjE4HqvZp6zBpJYnr+wc8HeJK8mKPaptz/ctnnCXPGvRNNHP5Ce5oI4JYQC dKFdaNPfJP2sMuXd3o8uZQH3iJlYFYVESclVCnTeGwor8/zqT+1FLnTzFezv6+3HE1vZ 3r4ITl93TNuTxck+jRbrrnytqGB5uIZIfb3mu25DjbekgM8oR2ZYcsyXWtwZmi/DGa0G 36DA== 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=hRsQ7XlJN4rMifYbK1S2B4u9AT4d8Fx9ZqVq28vUwr8=; b=bcMOX00oHEr/HuAAiPxpOmitOU6s5Vp86IB7cLigjzK388jZhiMVU3oiXSaDwZiNgU nvsRxGpqsU8CyWwDLyTQo5sxNRrPihMRut5VRiWySZOoJqQ5VV9Y1R5u7CDUy0U+tUwI Z0iO97DCygIysTAj3WU1scdipCwrIYslj4ednYfQ8rATYMOKBeBpfzVt4ReLZZ1wgSk7 mA/NviKdjeUZtHAhVD7z2mOW6oQSuiEnZSYoSnrudWHEwxteKU1FTLXEiTUAg0A6eikr LJOzB8H0dmON6O87BJTmFEH82j3ih9e6PN+1bW4X12UaoZ7d+qWtaPv0SiegTG0e8+A6 TizA== X-Gm-Message-State: APjAAAVVYNdFF3Tme0xAvN+CCXQjSRqNjFBJOGEdLUZCLKxLGwpSigct x6MWSG5H4qghRumHLeAThz3LwbXw93E= X-Google-Smtp-Source: APXvYqwvdaS/KDpDdl1vmq4Rni302aXJ1WGoT4oKpV2DlvdlJlbmvT+hn3usDSptN8b7qPYZn8Gwqw== X-Received: by 2002:a17:90a:7187:: with SMTP id i7mr2553289pjk.6.1581564149193; Wed, 12 Feb 2020 19:22:29 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 3/5] linux-user/i386: Emulate x86_64 vsyscalls Date: Wed, 12 Feb 2020 19:22:21 -0800 Message-Id: <20200213032223.14643-4-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 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::1041 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 , laurent@vivier.eu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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 --- v3: Adjust the gotos. Define TARGET_VSYSCALL_PAGE. --- target/i386/cpu.h | 7 +++ linux-user/i386/cpu_loop.c | 108 +++++++++++++++++++++++++++++++++++++ target/i386/translate.c | 14 ++++- 3 files changed, 128 insertions(+), 1 deletion(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 08b4422f36..39be555db3 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1001,6 +1001,7 @@ typedef uint64_t FeatureWordArray[FEATURE_WORDS]; =20 #define EXCP_VMEXIT 0x100 /* only for system emulation */ #define EXCP_SYSCALL 0x101 /* only for user emulation */ +#define EXCP_VSYSCALL 0x102 /* only for user emulation */ =20 /* i386-specific interrupt pending bits. */ #define CPU_INTERRUPT_POLL CPU_INTERRUPT_TGT_EXT_1 @@ -2215,4 +2216,10 @@ static inline bool hyperv_feat_enabled(X86CPU *cpu, = int feat) return !!(cpu->hyperv_features & BIT(feat)); } =20 +#if defined(TARGET_X86_64) && \ + defined(CONFIG_USER_ONLY) && \ + defined(CONFIG_LINUX) +# define TARGET_VSYSCALL_PAGE (UINT64_C(-10) << 20) +#endif + #endif /* I386_CPU_H */ diff --git a/linux-user/i386/cpu_loop.c b/linux-user/i386/cpu_loop.c index e217cca5ee..70cde417e6 100644 --- a/linux-user/i386/cpu_loop.c +++ b/linux-user/i386/cpu_loop.c @@ -92,6 +92,109 @@ static void gen_signal(CPUX86State *env, int sig, int c= ode, abi_ptr addr) queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); } =20 +#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 =3D=3D 0 || access_ok(VERIFY_WRITE, addr, len)) { + return true; + } + + env->error_code =3D 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 to get here; now verify the offset. + */ + switch (env->eip & ~TARGET_PAGE_MASK) { + case 0x000: + syscall =3D TARGET_NR_gettimeofday; + break; + case 0x400: + syscall =3D TARGET_NR_time; + break; + case 0x800: + syscall =3D TARGET_NR_getcpu; + break; + default: + goto sigsegv; + } + + /* + * 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. + */ + ret =3D 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 !=3D -TARGET_ERESTARTSYS); + g_assert(ret !=3D -TARGET_QEMU_ESIGRETURN); + if (ret =3D=3D -TARGET_EFAULT) { + goto sigsegv; + } + env->regs[R_EAX] =3D ret; + + /* Emulate a ret instruction to leave the vsyscall page. */ + env->eip =3D caller; + env->regs[R_ESP] +=3D 8; + return; + + sigsegv: + /* Like force_sig(SIGSEGV). */ + gen_signal(env, TARGET_SIGSEGV, TARGET_SI_KERNEL, 0); +} +#endif + void cpu_loop(CPUX86State *env) { CPUState *cs =3D env_cpu(env); @@ -141,6 +244,11 @@ void cpu_loop(CPUX86State *env) env->regs[R_EAX] =3D 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 d9af8f4078..5e5dbb41b0 100644 --- a/target/i386/translate.c +++ b/target/i386/translate.c @@ -8555,7 +8555,19 @@ static bool i386_tr_breakpoint_check(DisasContextBas= e *dcbase, CPUState *cpu, static void i386_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) { DisasContext *dc =3D container_of(dcbase, DisasContext, base); - target_ulong pc_next =3D disas_insn(dc, cpu); + target_ulong pc_next; + +#ifdef TARGET_VSYSCALL_PAGE + /* + * Detect entry into the vsyscall page and invoke the syscall. + */ + if ((dc->base.pc_next & TARGET_PAGE_MASK) =3D=3D TARGET_VSYSCALL_PAGE)= { + gen_exception(dc, EXCP_VSYSCALL, dc->base.pc_next); + return; + } +#endif + + pc_next =3D disas_insn(dc, cpu); =20 if (dc->tf || (dc->base.tb->flags & HF_INHIBIT_IRQ_MASK)) { /* if single step mode, we generate only one instruction and --=20 2.20.1 From nobody Tue Oct 14 02:06:25 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1581564212426211.66271596927777; Wed, 12 Feb 2020 19:23:32 -0800 (PST) Received: from localhost ([::1]:46828 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j256B-00042E-6Z for importer@patchew.org; Wed, 12 Feb 2020 22:23:31 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:60179) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j255G-0002Hb-3e for qemu-devel@nongnu.org; Wed, 12 Feb 2020 22:22:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j255F-0000NF-2o for qemu-devel@nongnu.org; Wed, 12 Feb 2020 22:22:34 -0500 Received: from mail-pj1-x1044.google.com ([2607:f8b0:4864:20::1044]:52547) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j255E-0000Lv-Ti for qemu-devel@nongnu.org; Wed, 12 Feb 2020 22:22:33 -0500 Received: by mail-pj1-x1044.google.com with SMTP id ep11so1746732pjb.2 for ; Wed, 12 Feb 2020 19:22:32 -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.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); 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=FNe39eIz0v47jOI5MYP3eadgdWO6rgbl92hzBmHUc0w=; b=HIXbCS1ZU372+NaJEEEzzWn7BlZr4pjvORj7nWp9LM5MR7V83wNETb0Pcgamv9jjPM MSCSrrwrVfKyjCrW9VbMTD6ZyvA9ltnyrPka96gWtNueWaFKyXL1LO6HzRZ1LxlsHwJH E4R9Dx/cdFt90v13RlD8xWLD+dUZk/Yku707pLxH9CFq3wSpyMKeXt7lvT0GR4/cvo37 aaByeQR7+gU7LctR6vhj89U4o+I0JElRL2jhtmhu8FmUNxZ9Iw95SJtqNwK9Ddn+FvKN IJMW05OECoHeWggQkSZrEjXuknGc8k9+psGW8QKHPQC1BjEZY92dYPBd/k7xZdaBIjqI HJIw== 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=FNe39eIz0v47jOI5MYP3eadgdWO6rgbl92hzBmHUc0w=; b=jJYh5IKeLU7vK9Fye2wJUzjZiNxY0vZMD0vwMx1kCBKjSuNffL6EE/CnN1jtR3zavh Ce8R7mOOn4LxHdqNFQY1/s3iChuQKs6FX5Y3S7yiD58S4xhc2nYqx5FpLH+/WN4Wc3fp 4mq1/57F6LgQVl/h1OqoouNrS2BPkUdfg8yzyW3KUmNTZI7OD+MUGLeEFYbTIN5aDn4/ j19sb0UfB3f5Zsgldk0SeEz43wfBOfs/ZCDO18wemDoZWXV2RzoUgeMzKJZMrXzXAlyu C+siWHRRxrECPWpU1LRx8CX+qi+Y64co9lMSq2F7d8y7GXpcpSJGe0q4Xc0Yfg3PS1ew M9AA== X-Gm-Message-State: APjAAAWxbI/LiWb6ao5lCPNUBt7xuYB6BwQR908IWW1Q0T6Brb9EsEOV YIyMocWafGyaID1TJ8bWGFVBvZ0JDu0= X-Google-Smtp-Source: APXvYqyak25r4LPVhe+F5zIlK4XmRTb7Jzafj/0qKW1dXi84aA/MhMrPUXVVG5JSr+dtW3/Z4cdcOQ== X-Received: by 2002:a17:902:ab95:: with SMTP id f21mr10487855plr.188.1581564150563; Wed, 12 Feb 2020 19:22:30 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 4/5] linux-user: Add x86_64 vsyscall page to /proc/self/maps Date: Wed, 12 Feb 2020 19:22:22 -0800 Message-Id: <20200213032223.14643-5-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 Content-Transfer-Encoding: quoted-printable 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: laurent@vivier.eu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Content-Type: text/plain; charset="utf-8" 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 --- v3: Use TARGET_VSYSCALL_PAGE. --- linux-user/syscall.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index d60142f069..b684727b83 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7012,6 +7012,16 @@ static int open_self_maps(void *cpu_env, int fd) } } =20 +#ifdef TARGET_VSYSCALL_PAGE + /* + * We only support execution from the vsyscall page. + * This is as if CONFIG_LEGACY_VSYSCALL_XONLY=3Dy from v5.3. + */ + dprintf(fd, TARGET_FMT_lx "-" TARGET_FMT_lx=20 + " --xp 00000000 00:00 0 [vsyscall]\n", + TARGET_VSYSCALL_PAGE, TARGET_VSYSCALL_PAGE + TARGET_PAGE_SIZE); +#endif + free(line); fclose(fp); =20 --=20 2.20.1 From nobody Tue Oct 14 02:06:25 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1581564326572162.41103812007316; Wed, 12 Feb 2020 19:25:26 -0800 (PST) Received: from localhost ([::1]:46864 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2580-0006xK-Hb for importer@patchew.org; Wed, 12 Feb 2020 22:25:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:60193) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j255H-0002KQ-4W for qemu-devel@nongnu.org; Wed, 12 Feb 2020 22:22:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j255G-0000TH-5u for qemu-devel@nongnu.org; Wed, 12 Feb 2020 22:22:35 -0500 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]:45221) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j255G-0000Pw-0d for qemu-devel@nongnu.org; Wed, 12 Feb 2020 22:22:34 -0500 Received: by mail-pl1-x643.google.com with SMTP id b22so1740614pls.12 for ; Wed, 12 Feb 2020 19:22:33 -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.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Feb 2020 19:22:32 -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=loZSDj7GbxB0gzb7RHJRf8hxO888UT+p/O47I0Z8QQ8=; b=ebFsybtErAWS33ZnmSR9QtMslkJ+yhZ1QYl+bDmPK8/RDQ4UPTffxGbi6DXGB54ZS+ R+vbhhSCdcQSMfT5dERWaIzUJfa1Oihc8oCYDvLx9h3LxCciGYsiS8vmGnEb4KnF0ntj HiwkAnilA9x4gtnDiiYimLfCblFIpDri62aW9NXAC0ToiwdzQoLfRiGx2NHCWnZV4EVP LIipGOgtOSqbyaPJ3iGg8XVWVKiq7P+XmWs9IqcI6XsQ570HiI4jEAF8opERscEnoCVt 1z0BQUhxgwAfpb737KDnQjd4wfRx6cxQUibhVRtiy+9qAYUHe9PFLi0y8lZgV3znDg+f tPWA== 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=loZSDj7GbxB0gzb7RHJRf8hxO888UT+p/O47I0Z8QQ8=; b=o7rh8FzJ/tctknX9aaO8B+fzLuEXf2C3ozQqlLAq0XA/sI8QemLBnd2NyDZ9a4wRYL YxXzgBw8yeaOy5deOlg8S1Kut2do2kIAfYD/o7D33jH6fAVtQT99HWZubajDe1o0GONr LBYSXvpLXCDNdIHFYyZrU9NUtdDaChKQK0q8bmEamujLpHd0fvzFQkRR1ZF1ADMU31f7 2fxDExWES6VraNw5tCfjMD5QUFxiDj/pKPcDCY7dymGA1l3Pu+3zxDqeW25YKj0CTVXC /h2KVLmSqPDM3NWQk5Hl6XgT8nIIa4HieX1abapBFrJ1qrh1vVivQo42/JrhkVdK1P31 4hAw== X-Gm-Message-State: APjAAAXxQ4eJJA8ZR4R4rh1RNCEWJfXdHMMgnZXXDyMxL3i0VkoOZr5l FF2pLWtl7K0HMLYTz3V8Bsx6c3hTtGA= X-Google-Smtp-Source: APXvYqwNvfsmkw+VtaU2TON506YdcYh+9hUlHOtRy3wqRYCVU5ax3+zzKVox8eLZ0IbJDGRUELqkyg== X-Received: by 2002:a17:90a:e509:: with SMTP id t9mr2534894pjy.110.1581564152733; Wed, 12 Feb 2020 19:22:32 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 5/5] linux-user: Flush out implementation of gettimeofday Date: Wed, 12 Feb 2020 19:22:23 -0800 Message-Id: <20200213032223.14643-6-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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::643 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=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , laurent@vivier.eu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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. Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Richard Henderson --- 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 b684727b83..a006e53088 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -1224,6 +1224,23 @@ static inline abi_long host_to_target_timespec64(abi= _ulong target_addr, return 0; } =20 +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) { @@ -8575,10 +8592,16 @@ static abi_long do_syscall1(void *cpu_env, int num,= abi_long arg1, case TARGET_NR_gettimeofday: { struct timeval tv; - ret =3D get_errno(gettimeofday(&tv, NULL)); + struct timezone tz; + + ret =3D 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; --=20 2.20.1