From nobody Thu Apr 25 22:43:05 2024 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; 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 ARC-Seal: i=1; a=rsa-sha256; t=1585048804; cv=none; d=zohomail.com; s=zohoarc; b=dJ5ZybPXgaPUpXD0TAT+b4CO9DFMWI/XMjphQSbSsbk55Y9/pK7jjBy7JOUIxSwtbcowlSYFTSBG/NS7aBLphEGnGCyBcbLXDkK/BxxelXeZNtjS5upKUMpXrZ8Wi/Swfcxq97RIT+3AgbkbFhZ33IOTIK18PSn73EnqZje7xvk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585048804; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=zepXS5Ctu4clbwPElZa3Q+vMPu2qLGth3bMCdfXA4m0=; b=S94B8oqGbZwD9H7pjNaYnLIfQ7wMXixNfRJK6aqlOVhYI5C2QpmkxlcKTwx4LlieMXAIdxizKEcFDbgzfySdAOuofE91Eg6Ct1nGD1iDdDp//EQGMpvFhKVRAkridSfoIH3eXlL3Y/mIH5XlKoLyr2ztcRSoxTcJVZvRzDvwYBU= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 158504880460381.76405239077394; Tue, 24 Mar 2020 04:20:04 -0700 (PDT) Received: from localhost ([::1]:46908 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGhbH-0006DL-8i for importer@patchew.org; Tue, 24 Mar 2020 07:20:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33414) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGhYg-0002GF-KE for qemu-devel@nongnu.org; Tue, 24 Mar 2020 07:17:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jGhYd-0007Ls-Hp for qemu-devel@nongnu.org; Tue, 24 Mar 2020 07:17:22 -0400 Received: from mout.kundenserver.de ([212.227.126.130]:53075) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jGhYb-0007L7-RN for qemu-devel@nongnu.org; Tue, 24 Mar 2020 07:17:19 -0400 Received: from localhost.localdomain ([82.252.135.106]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.167]) with ESMTPSA (Nemesis) id 1Mz9lL-1jTzTW1qjb-00wDIK; Tue, 24 Mar 2020 12:17:05 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL v2 1/5] target/i386: Renumber EXCP_SYSCALL Date: Tue, 24 Mar 2020 12:16:56 +0100 Message-Id: <20200324111700.595531-2-laurent@vivier.eu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200324111700.595531-1-laurent@vivier.eu> References: <20200324111700.595531-1-laurent@vivier.eu> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:g2Fxb0GuhkTYvAajYGpmLlPs4e+ymKt2URFzBGmu2d6DmhoH3Ol daC9J+Tw1v2vob3eQU0EAe5MGgfbuuO//uwUcETQb28GQbLDapznh8dInZpBSMzBjtdV0t0 Rjp32akl6j4Te5M8FDRkVHX/KLS9mWfEIMXTenFeY+1EQfGT+59hF2omCIRqYvimmwKfjuW Nom86Jvsc9zgTdX6RY0xA== X-UI-Out-Filterresults: notjunk:1;V03:K0:+vbHFAJH61I=:MqwAeJqI+2YJRqL2X7N2Z7 4oc73e1VLASG3Lx9IrYIaY/N/KXFXtJ+pW6Q8fM7nWqrHmypi7H1R5VW5/GZ9imxr7ZPqsJ/b QWY9ePriHVFNIolM8GpI0n4EFt2yQxpfKowYKP8ncJXZWwOFDmt3z01QVnIqn4p9lcQC7sE5p offlu6PlisXXl2eytbhU/OyA5A26rP24OokMQvGBvnMKtMO1wmIrTrUWDob2LvvW2P07ayrPI 2AoBQTvEypWYMhQ+Ho1ydCRIOwmkkHEXB6+9l0A3WNVcVBMoV6nuJewByno8+3y6KerBVJ3Zs pyFh8kmoNQaeS1MkF4lgeXfZYR8YGxtuou5mxaXDg3wMT0sVf2TA5FqXoYI6k6hwKK28duN2G p/q+9yNk/maHdceX2ciI6q1T4E7jw1bg/QGwrITA+/sfarRjX/E1JGIC7Hy2Y3zEAwmYbr+ud g2dziIKhlBwG7vl3LLmVeoJFXWjVDoqv02r8xgheJgaZLctxcWg3P/0oID9iE+vCTA8ic0q7x PpbXIbUgjeH+KlhXjDNE62tpWagdT3A/4X3lJZm+I5Ky7I2AdUayc6ms/CX9oMrIxjyPV1Y7n W0ojlKgcl+hE2im1sV7HOlrDiNyUPT2kdUgMABLo/f0O0+WHT0RACvrQ9OgvKrrAp5CDIyqRn QkcA7AhFLeg394XIWkkXBezdSf92amGt6639mJBCc927Kj2zCIBE0A/0VyG6SYEjXqNuYeupZ Gs2478S2wqOhkq1HLOLsFrznym3/u4WR10MCeMBXixuIgE1Paug0v8cLSeBja+mXyjfYN8B1/ lvJteJV2QfNrH8ShrChUgXSdYfQwSa/X2Y+3Hl7lGvpGQqOMi9cVtCiLVyuXd+v3XSMP1Xp X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.126.130 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?= , Riku Voipio , Richard Henderson , Laurent Vivier , Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson 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 Message-Id: <20200213032223.14643-2-richard.henderson@linaro.org> Signed-off-by: Laurent Vivier --- 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 60d797d5941f..49ecc23104c9 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1001,9 +1001,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.25.1 From nobody Thu Apr 25 22:43:05 2024 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; 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 ARC-Seal: i=1; a=rsa-sha256; t=1585048811; cv=none; d=zohomail.com; s=zohoarc; b=Ab1St9F02GRHjI1moCjB7VIRzEfQoI/ZGqP7TQQtGA7AAGJhu0v27+GnGI/zrE1b2AHjRI8w7PHW6/R3bsUcm/Gj56NLVKnj4S0dS4ftSoOnVzS92CoYGUcxxhk7rOHLA0CsEVOn/ZZUUflzT7rdiphmxREfsO7t52URG7/pmHY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585048811; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=YEkw+BD3XM1DvhPhvynvQr2RL1QhFvPB4Cz5qQZtHws=; b=AQgenrewF5oqHzSUgUklwo0+GZuLEXw4Nkk2lx8xm1kRzHvJSYnfd9Y7KQYiK36BBUrAk8Hum7BvSd1VXQ0e/pjEe1BmNdxM+GRIBUbRdb+KEAQV9k44NM7KVz/YajjiZxGKfkcKNB/OTY6nUTsN+uys6GZ9lPOnCE5RuhXmlTs= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 15850488110100.0492736107556766; Tue, 24 Mar 2020 04:20:11 -0700 (PDT) Received: from localhost ([::1]:46910 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGhbN-0006Ri-OT for importer@patchew.org; Tue, 24 Mar 2020 07:20:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33416) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGhYg-0002GH-Kn for qemu-devel@nongnu.org; Tue, 24 Mar 2020 07:17:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jGhYd-0007M8-PM for qemu-devel@nongnu.org; Tue, 24 Mar 2020 07:17:22 -0400 Received: from mout.kundenserver.de ([212.227.126.187]:55871) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jGhYd-0007Lh-HV for qemu-devel@nongnu.org; Tue, 24 Mar 2020 07:17:19 -0400 Received: from localhost.localdomain ([82.252.135.106]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.167]) with ESMTPSA (Nemesis) id 1M2w4S-1jFaYw0i5c-003PmV; Tue, 24 Mar 2020 12:17:06 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL v2 2/5] linux-user/i386: Split out gen_signal Date: Tue, 24 Mar 2020 12:16:57 +0100 Message-Id: <20200324111700.595531-3-laurent@vivier.eu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200324111700.595531-1-laurent@vivier.eu> References: <20200324111700.595531-1-laurent@vivier.eu> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:VxCE7RwwZyD4HXt9FVuqM2pyJZNZ8hqs/H4L6BTFKFF5gVAh4RH 09o4ToLBxY96xrBdRtnBQ7KozaPqS4gXvZXYESjdBs+OCWNNOh7pRP9p9c+4ppMBZwHDafn JUVHU/Xz5u0jiJUxhqEWvEFMMFB9XtUM0Tas68TYGMuTSyEYh4idlKfLe/kEoDzWOFCGHwV uvrmcDhRXzdpcygdXU/WQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:iwzPQFpzSsc=:7Gl50LPpX2hTZ5nmL9nLeu X6qLqKfWRFPZ4jjn/i2I0jtq7FO6P6qEYVu3nN0ztSYlc2rMhwEpR4SbLVcFZRzi4Tg9UvEtb ynigiE99mpLX9cefN2cFfQfgybOSbRY83FVMuKgu4zk2jitKGXw1oYBL95ptvbmh2QVHXPJNy RMLRqliUsJV9thYR7yGrIvywueelmF+mdlzrzgmRFQYZ7obRwZ9KoQSIRJxmnxJytOxB8ij8N lGm2MeZcBtQu/mtDTaBEja66Y+uLaPqRKMp2oiVA3cDgF75fI0xPCvCueGYjoCj/nSwyjaYhl jDEnItF83kdwXT+r7SeIAGoyD8smmgXzG/c7v/AvWB7wJL3wkAsw8Dvq4nkFuiBzYxT3HhBWs MBNkhiHFzdq6Q/Ds5rhWMsiBZDWnLYMQuJog8WMZiibirwMVII3Z3ShXXdPGp4Wc/zLdGYxct 14AN5m+mwP//P4sTmEW3MBox4k/3+YQA3YXWNgqlkHqMWwFWfoOZj7sidqp5peARIwUZWH9B6 5xOkpPVal5rD/Iqrj92J9cDuVnykRaiVv71oSico5ADoxbaQxcIt4juNcI5xkOIav5/RPf2tR gG3TdMODv6690/FlUhYhO5K/XWBZRNtidj5iHE7iztloYpCsZEJzBvYT/O1xovbNhWQ3rhK/e zHB4oA0X/guAljoxjoUVy9OZOYvJS9vG4Gbxxb7rIiBRmSr9JJvoukQr0YDN3iGAnBXZ+FnJp bZBQAsqR8O5e77Fv3xI4GUwN1gsmpC+5q/F+KCMGWgcAC7OhSLWqtE/8Iijj8y2JvicaMiTg3 njTU+9HNgXf3wj64nngVImg2S3wJmK6fpWDSLTTRbGbdmMkXQ89zwY+vteN59TQeaFZQMCl X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.126.187 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?= , Riku Voipio , Richard Henderson , Laurent Vivier , Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson This is a bit tidier than open-coding the 5 lines necessary to initialize the target_siginfo_t. In addition, this zeros the remaining bytes of the target_siginfo_t, rather than passing in garbage. Reviewed-by: Paolo Bonzini Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Richard Henderson Message-Id: <20200213032223.14643-3-richard.henderson@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/i386/cpu_loop.c | 93 ++++++++++++++------------------------ 1 file changed, 33 insertions(+), 60 deletions(-) diff --git a/linux-user/i386/cpu_loop.c b/linux-user/i386/cpu_loop.c index 024b6f4d588c..e217cca5ee1e 100644 --- a/linux-user/i386/cpu_loop.c +++ b/linux-user/i386/cpu_loop.c @@ -81,13 +81,23 @@ static void set_idt(int n, unsigned int dpl) } #endif =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.25.1 From nobody Thu Apr 25 22:43:05 2024 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; 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 ARC-Seal: i=1; a=rsa-sha256; t=1585048893; cv=none; d=zohomail.com; s=zohoarc; b=E99zdFySb1gm3i7bn2pawfWZbGARh3L4XpQg1BbcI5gf7AATKYeMdaBhtfSdIozSE+OEdNADPRMkfzhOu5aJVcmjlIG1cpJ1pC0e06fJwgj4CDUXp6pkdr7siEZzNvOHbWyzAS+bJ0wW5LGOC3vMKoWBjMZOKbwjLzJw3e20L7s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585048893; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=HQcuny2i8MP7gcqKAR5NYN2iqfp4S26wayfcH9K+ABI=; b=iPAU41H327/UCb0je4tm5lM/0PcKK6KEBowTaYs5lvsBbzVgCpw4beTnAegwnB4JBhspYs5K2xhgKMa3r1JVX9q+NvwGbbX1JM9YInaLGeHt6Ache8ObMVB25dJvEplpNl8Yt5nMbZ5YpT9KmVEqMHkzkiM0AmhviCfN+iofizQ= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1585048893750874.2397439555155; Tue, 24 Mar 2020 04:21:33 -0700 (PDT) Received: from localhost ([::1]:46938 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGhci-0008HR-HA for importer@patchew.org; Tue, 24 Mar 2020 07:21:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33415) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGhYg-0002GG-K1 for qemu-devel@nongnu.org; Tue, 24 Mar 2020 07:17:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jGhYd-0007M2-Oj for qemu-devel@nongnu.org; Tue, 24 Mar 2020 07:17:22 -0400 Received: from mout.kundenserver.de ([212.227.126.187]:58085) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jGhYd-0007Lb-GZ for qemu-devel@nongnu.org; Tue, 24 Mar 2020 07:17:19 -0400 Received: from localhost.localdomain ([82.252.135.106]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MKKER-1iyCR33L8Z-00Lm0m; Tue, 24 Mar 2020 12:17:07 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL v2 3/5] linux-user/i386: Emulate x86_64 vsyscalls Date: Tue, 24 Mar 2020 12:16:58 +0100 Message-Id: <20200324111700.595531-4-laurent@vivier.eu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200324111700.595531-1-laurent@vivier.eu> References: <20200324111700.595531-1-laurent@vivier.eu> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:r9JZFDzHesbtdtjjLFO5e8F/goXYNKkaI25sGWvvho31XKg365x 1AS7MiJIEQrC+Y3yXUa+kBdVcdJy3ouC3IRNsm5hmi4t6p14diEGEvKGmSNm0z2rwxxIMzZ H6MLWiQMZ2v//B6EOzSIQWI+O+wgnES490hop+LwHdetUH1wDjiqIqBT0GKb1X3tzJTm1bW 6DLIY6Uo0eSHvZDexTYAg== X-UI-Out-Filterresults: notjunk:1;V03:K0:dnkYpM5ijW0=:eZphKNc94bqgjwwFsHSHsr iau5gIhsrLDWh/Rr7ona2aXKH1PNINk/QrpxPPn3nd4RwmuAmFO5lPfvJ4a9Ch0ZwtoBxpzTi UF1dJuMG3JP5osk5HBUuwoIuX7pu6f9UUYIbEnqzA5s2FygVWZKmH0dOr/bC3/dE5Za+J7BkI xvVxkF9wz6S0JkBGILFhTpoofJ/O751ZSof1oav+SSX/yNvDUt+dGxLR6J79tVUY5HKk45IW5 hGEtqqFReRdO5vfyI/aP26r93h8O1wS0xna5sIRVLh7KJXDPVGjoUdAfYvK+HpDOYrxRpfrJ/ c7NH4YHre46Px1lpQczh980ungR7R5lOtLFo5ojW//fRY5TTKkLI8yDmeUWcuaRG7sQzkqWzF UoIciW+BK/pufcqh9zAaQkIQ4DMThLJQKZAcq+8h/XIjOrhn4HRWI5TwqMhVJ+QcqWrPQM4Kv QPP3VB2Pb01cc8MsNGxZwELoN/ySt65j2oJxwZRhi7r01wQcYCHIiZCmfUlz41hzrFYVVuEnS PFjLWWGhagsEwVh1i1zV6UFTV8rNf6euMVuVYnfSzKnAVb53TMTvRGKMzyRAGSNL8rEc4b2WV 5B5o3j4donOU/ZWnhc4S2g1OesuCabRnm/CscVoAXHKZk6vB0aAAvCy+xAvc5WoD6AiZ5HQ+e rbNUZw0Jp9OcP5ng+ECs2E7+T8vr7lFgomwsVX8nU9hdPIPpSn6h/snLYvooVc22BUyevt/Df 9+olJwF1Qo/lP3LbdgI9heXfll0tfl8t2KDxVbe0IfBqzWgdSqqiyD2gTQnhtRUJZK45mlB7S VkUStpF5RABZbZBnPs1DLPiL2oNqrmT9828GZ2TDThU36E/PKdWTqK8qSEjZUi+ZZLM21FH X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.126.187 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 , Riku Voipio , Richard Henderson , Laurent Vivier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Richard Henderson 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 Message-Id: <20200213032223.14643-4-richard.henderson@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/i386/cpu_loop.c | 108 +++++++++++++++++++++++++++++++++++++ target/i386/cpu.h | 7 +++ target/i386/translate.c | 14 ++++- 3 files changed, 128 insertions(+), 1 deletion(-) diff --git a/linux-user/i386/cpu_loop.c b/linux-user/i386/cpu_loop.c index e217cca5ee1e..70cde417e605 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/cpu.h b/target/i386/cpu.h index 49ecc23104c9..9af1b0c12e8e 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1003,6 +1003,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 @@ -2218,4 +2219,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/target/i386/translate.c b/target/i386/translate.c index d9af8f4078b3..5e5dbb41b0ce 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.25.1 From nobody Thu Apr 25 22:43:05 2024 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; 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 ARC-Seal: i=1; a=rsa-sha256; t=1585048716; cv=none; d=zohomail.com; s=zohoarc; b=kZQ900syf1C+dN7aG7SWuElRa/WdMkkVX0KK5ZzxBljVXOrFIjInVjhQosGVDsBZk7ZQSarFJKvpA9dyKps3LpoJMf6jKNsKr/ESDYSF5Kw+pcmybKlyM9PDxhP8MKZTLEjxLs3+ttvNmKpzpbguUHAUadImfZlS+gMfaGjwNA8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585048716; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=mCV/6oi7njnCoIzMHyWV2UoCZd8lSLJWcIDwV87Mbcc=; b=PUHYoG+8Z0ixAk6spzgN7C7zjifRNvpDPFeShYqMfHYjiQc6sBurWnaoEb9y4bJLHVuA2ljWB+sQxVcmO0bDv/reLjAkaaVXmzEpNtNR7/nZG5Zdjr0pLdMYPRwgCpKybX/QmmyaN4qc4AERmGR73m0PAV4LKy9wdEBoK42+GRA= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1585048716135779.0310712920616; Tue, 24 Mar 2020 04:18:36 -0700 (PDT) Received: from localhost ([::1]:46886 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGhZq-0003P8-TO for importer@patchew.org; Tue, 24 Mar 2020 07:18:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33386) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGhYd-0002G8-Ky for qemu-devel@nongnu.org; Tue, 24 Mar 2020 07:17:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jGhYb-0007LP-QE for qemu-devel@nongnu.org; Tue, 24 Mar 2020 07:17:19 -0400 Received: from mout.kundenserver.de ([212.227.126.134]:41005) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jGhYb-0007Kc-BN for qemu-devel@nongnu.org; Tue, 24 Mar 2020 07:17:17 -0400 Received: from localhost.localdomain ([82.252.135.106]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.167]) with ESMTPSA (Nemesis) id 1Mw9Dg-1jZBsV1QUW-00s4Yd; Tue, 24 Mar 2020 12:17:07 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL v2 4/5] linux-user: Add x86_64 vsyscall page to /proc/self/maps Date: Tue, 24 Mar 2020 12:16:59 +0100 Message-Id: <20200324111700.595531-5-laurent@vivier.eu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200324111700.595531-1-laurent@vivier.eu> References: <20200324111700.595531-1-laurent@vivier.eu> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:U6JARm6Ix8awta0eIImuBEUlY9n4vZEjhbE9pGunEfXSgs883wI qZXU2uF5r3u5Pt+d5ru6xic8PbYdT3XI/ku97J+ptCqiSG7QWEMC72+ca8Bhe/mjoB713rA qKB3mwMMK9CR4IzOr9BYqfH7lLcaaeYJWlauvw6BHubsTAk4eaYWGFMmZcm2+59qr/eyNCT awX0PjBFM68ZQXLJ41e1A== X-UI-Out-Filterresults: notjunk:1;V03:K0:pcOySjJuoMU=:VT52kz82ERI8Ua8SYi6uY+ cdSO94GLycR+sJgwHxnXWmZ/xLXKaIhK4eJOt7PW3feFcFueGjC0iLq7QFQebqBm0W5flNUp8 cnf3r6Lp6MD5C2DlzqLNSc42qrRbkzEw54q0QwVLQE9DCO2bGIMzjCNnk0zgd3a/VXLYVjS6a bcHr1AoRr5HHfA5tfpYyOb93/UPz1mNVzoxLUxO06X3Pr7fxGMX7w6RnLegiSkUEYSv0+03w0 NihHTXkeYA8DoGCW0A9w3U74mCylNzg6YfNlcG9M1Tmnt7BStuq8Itk6iOhUHxx4WZ33nfQfE 6yoKxWHw7kQ6uniQQdwh/CbPMMHS9qoZdCtxTqRZ/g0BydkhblkHvyRcZTnrb3iCVo9kvDVon pYUIZZ7BWKEXOVncDbU5n65kFxD9pUofZOCqzidGUD6apWm6FL/EgXJ3q5nVWCK0IKtbkoniU tNrElbSddKN6VaD/M16XVdisKCggm9EnMzjadmCm5IlVDPtDqutSIXIb2ZtARtNKzwEHKUk08 J5er4F7vXRtUMEzpmpNPnirwE4s7pExbatb0xZab8nbNZNbkf/DhKZZ/Ti4fGYh5CGQOP9c8D f6+BXUXmoGdzCZ1RVgJIHOrCYVtlLuj3MDyZNy0dvsr6KhzUC3el1G5cj1Zd+CcJzkmnPFLvL 2OpuvFvJvagKdVOnd+6agn5Ac7xllD1w6ednghRZm7+SUUx0MzxoO01YieWZqYfYlFTQIMV2O k7CVw4Ilts1QgAEc1YFYN47jTnUcEfweQBKACSslsYsIm3lE+viSKW3acOEudJMQlSsB3rQH1 TC6YjwMbES+gjuq4cW30HdzUiPcilDUcl3cXymvtuNw3PRkj9meHuzD+sXIJzVSN+qwND5l X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.126.134 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: Riku Voipio , Richard Henderson , Laurent Vivier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Richard Henderson 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 Message-Id: <20200213032223.14643-5-richard.henderson@linaro.org> [lv: remove trailing space] Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 35f414666243..dbdd56e42077 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7144,6 +7144,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 + " --xp 00000000 00:00 0 [vsyscall]\n", + TARGET_VSYSCALL_PAGE, TARGET_VSYSCALL_PAGE + TARGET_PAGE_SIZE); +#endif + free(line); fclose(fp); =20 --=20 2.25.1 From nobody Thu Apr 25 22:43:05 2024 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; 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 ARC-Seal: i=1; a=rsa-sha256; t=1585048898; cv=none; d=zohomail.com; s=zohoarc; b=Ommqu2LjxIMaIAnfwc4jk9zYneUCgVKGXQc4v/4XjSEyoRzLUQU/llYGGpNIM0LUrAUL5c7EapHidMvwMM0SIm3o+x67lnxXTAmJYZT/lB+j9yLclOwsKp8Du6B+N7idOi4lDXlKENWlvXpydw30Cw0gbhiEff6w31xxllGNYNI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585048898; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=YkItsWsh646TTO0fzSehG+84gTKI50FwAt3l4hA2Gu0=; b=TD9pxq63kki2pnU7QU8WNZ+o7PZZLlPIiOaKHU0oXaFUDGA6qmrYdDxF1j+hRBIrNZ9nAsFZaHMID5RClF523mASCvER9PKZHryRMmPMQhZFdeV6+xlGAkMdIv+O3zLfp1nKzmELH2hxhyl4TROO7Jh2WwXL7pZfrGN9HC46OdY= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1585048898456454.6219122202149; Tue, 24 Mar 2020 04:21:38 -0700 (PDT) Received: from localhost ([::1]:46940 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGhcn-0008Pv-9Z for importer@patchew.org; Tue, 24 Mar 2020 07:21:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33526) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGhZJ-00035w-L4 for qemu-devel@nongnu.org; Tue, 24 Mar 2020 07:18:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jGhZI-0007bt-Eo for qemu-devel@nongnu.org; Tue, 24 Mar 2020 07:18:01 -0400 Received: from mout.kundenserver.de ([212.227.126.135]:44447) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jGhZI-0007bi-65 for qemu-devel@nongnu.org; Tue, 24 Mar 2020 07:18:00 -0400 Received: from localhost.localdomain ([82.252.135.106]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.167]) with ESMTPSA (Nemesis) id 1N49xZ-1jOzGE40vp-0100ec; Tue, 24 Mar 2020 12:17:08 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL v2 5/5] linux-user: Flush out implementation of gettimeofday Date: Tue, 24 Mar 2020 12:17:00 +0100 Message-Id: <20200324111700.595531-6-laurent@vivier.eu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200324111700.595531-1-laurent@vivier.eu> References: <20200324111700.595531-1-laurent@vivier.eu> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:nxNTZT40BDeQWB/pCBr2MQyPGlh4spQuOikUnuwKc+qNYYzVl9H tZdUzBP9eldOdp55TCExUBUEE+oRP6NZpOPG/LIsF/OaEbEpFQmA9buPBx5gHkJEGnmfVZ4 YG39jT6DsusHQbhflTUqsccaqCHkfag5/WPsJJaF34HiSNXLZxSEHm/Fsq2Kazdvm90F1VP i7di1p3fOh+Sw+EtAJ8OQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:Rhltnc+KlBU=:4IxLpHu/oKnm8CSNwBba6b 6DhFB7DqW4tSd89qrxpZyBV7Kgglh4bOYPw5RYjJEMdwqoxMtYzNXE+NAjvx2O5z1K0Pjviul YkeQcLqQzomLkin62DYzjYGIsP+ZjjqL7G2Rq3CUh42U608Tvu6P1qB2LLBYoeZ+N1zXre1W5 7H8uwyHVGscU60R60bqY+GPy3jECm4EaMfsGm2NXTLwR1xTr3ZoEvcZVmpIc21Lj9ff29L0Gk 1PS96VkICBekF3IWA47pjQV3XjtkqsOPycu41u87d/uynWTqL+MbWlkbTwYdwkaN1vZjRbUf8 NCz79J/j/7r1ZIiTKKZgwpYkX1soynkdxaUZoqn+2LkrGRrCL5yCDmwx9Xn25hVKnxeK8LJ2G knnygqmV1IpUjumjv23tmqsc0ZfAgNQ9dqyLh13l8cQimWaZZcx/U6R3J1fal0xQZl8LuDH1I eY6o1Q7PkI7I0Sst/AeGIlEUIC6RIxel1lBY/oxeJ4LhwOjx7EHPDSePz7w7ZWoXJy92RvN5G iRx1irjv/JMJ6SryBkl4mZlGhuIbCklGMGmgP1GTkOYuqhoq7fKCunmXu6V3w7dnxDRCBXydl jrpC5p77lAgwHLTFpXcbIaMSnvKFMKfwh6ZLBYwJp9GLL47fC6I0bTPOnK8mXhCEu93/qsTI9 +XgDQ5lc7KQ/Bi8hXW1POA/RoL/iKb4L8xwdzOPEeRSVuEM787107/dWm5o72Dy6FTGb9HTM+ kGadevAtZwU5PydCVrN1ZMRZJFhBXxW7PdyUPPLKvVOcNt1WONYwKQL30Yv55WWzeT+zwRgps 14/lE6s7qJR9ekw8/5um2BAe635gVyL9mwVlzusrB30l1tcQQmiHMGyGcu+OhEWiZgaJOTc X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.126.135 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?Alex=20Benn=C3=A9e?= , Riku Voipio , Richard Henderson , Laurent Vivier , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson 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 Message-Id: <20200213032223.14643-6-richard.henderson@linaro.org> [lv: add "#if defined(TARGET_NR_gettimeofday)"] Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index dbdd56e42077..49395dcea978 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -1273,6 +1273,25 @@ static inline abi_long host_to_target_timespec64(abi= _ulong target_addr, return 0; } =20 +#if defined(TARGET_NR_gettimeofday) +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; +} +#endif + #if defined(TARGET_NR_settimeofday) static inline abi_long copy_from_user_timezone(struct timezone *tz, abi_ulong target_tz_addr) @@ -8710,10 +8729,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.25.1