From nobody Sat May 4 18:05:19 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=1585044354; cv=none; d=zohomail.com; s=zohoarc; b=PVCdd4UySduUa5VYAN7ut5FUFSs4olQBxCcOC+vB38kHsuT7Dhdmyq4Q5PSzZA6Q9rbM5S1kCdrhiMAlJ1HCP0uwdRPm0R8yxVQ+pw+SNg9UCsz0uoWqvKiUMjvCPa3zAZTCsJpKyeEFSC1x+O8CLf15NxVC5Wh3w4xCu6CDmf8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585044354; 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=JVYsMC+V8V3uNAy11j5X+4TjDG8spvnUvoF9XMzTxTmgfyLPcdl9AUpOk6tn2F6hVSZan8fYU6CCyjzGu3+fTmkVwPV+lIRf7wnnrvQpTh+dR9fRJJIsmqGzBHsE34Ad5cyLs6qI/dzDyDmTdJMhSMKVSOojb2XeqdBmXzHyOM0= 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 1585044353879607.8866696412596; Tue, 24 Mar 2020 03:05:53 -0700 (PDT) Received: from localhost ([::1]:45298 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGgRU-0007mA-I6 for importer@patchew.org; Tue, 24 Mar 2020 06:05:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49409) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGgP5-0005z2-Rv for qemu-devel@nongnu.org; Tue, 24 Mar 2020 06:03:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jGgP4-0000bD-KB for qemu-devel@nongnu.org; Tue, 24 Mar 2020 06:03:23 -0400 Received: from mout.kundenserver.de ([217.72.192.74]:40601) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jGgP4-0000aL-BI for qemu-devel@nongnu.org; Tue, 24 Mar 2020 06:03:22 -0400 Received: from localhost.localdomain ([82.252.135.106]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.183]) with ESMTPSA (Nemesis) id 1M1HmG-1jF1RY1Bn8-002sq4; Tue, 24 Mar 2020 11:03:14 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 1/5] target/i386: Renumber EXCP_SYSCALL Date: Tue, 24 Mar 2020 11:03:07 +0100 Message-Id: <20200324100311.588288-2-laurent@vivier.eu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200324100311.588288-1-laurent@vivier.eu> References: <20200324100311.588288-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:nlPmbkZakYTpWoj3tyrKFhmTUvqrTfMerPIcRSr7ey2WCePc4e8 KGTpavyaH7zxfA+XbImm3ABuGI1vqO/3MHE76cJAOUAHmISZj6p/13p4dH39Outsp8gqU8Z I+oGI977R3pYXJSzXqmlFu2t9yqdsDiDn7J45pkIFbr0uQdbE65g2L6SLJhJkE9/gSPBAv+ VLpCmNH4YtZLmgqv0SxAg== X-UI-Out-Filterresults: notjunk:1;V03:K0:bjKTgcuTq6I=:FEWGO5wMM+b72Bi12/wE39 EvjIt3TxZPVrku3pA6lQoXdMxKKI3uS4vf5GBJdKn7zOEOWD7bp7Goo2BxqqI5BfYpFwlkFOU BQvIHsRF5UWOXlpeHTpfMutqYlpSpnN9AfA3dfwrNU+SLU7YqB+1XfWqTAymHnz/bVuy131x9 aELZWMzv1+LF0bMjHhklsmZtSOqXuwQg88sn9fKYvCwpSi9mx4alBkbHijXwXHdOTNkukXV0r Ym/QK/l5VIiUOM8De1FKTqkco3Fmp+35D+e6c8EreTjWUE3s35+Q+iDjACTwAANHewALaRfeg EuOLdxdoH1Cq/sbRpuGJQyPOW7KnfsnlkTHLzlfg9HdbDA9PUlEIo6E3afMWUHHUiuTjEGNix 4tsSkjA562V2ZsMmoz61tCOL54knMZXhppVxbx+FvKEXE9l9nNKdE+Na7tUm+s6emzs3LMmfG rgIoiYMb3y+4an3IE5FR63huBn7d3huNgFXm0KzHCX+D1c4kWxkuT+qB5qyjCmstKRMPCoGOO 7u9qawARgZSd1Su7sItplJd9OSfMFHOQy6zPoZYrp7z1ADIRftcopCO8fWP2yNqNSUzZeHqUk kxIhi26pn7ZKTRKXg9cVYEYo/YZ3ofvBsMV1stoyS2ueMmAfU48+Bc3MXFwwL3dAmgIw+q1Q3 N8VF2CqHgWQbHYL8C/J+2aftAHqR5BYXmU2t1KbkszHwpy/u0cUF0z6pvoJ4soUCiUDCm0sD3 XBXmh0pGCm+vkWokXjB2z5J5aAweG5qrOkT6amKilfPn6m7yuSk9hviF8jM9QYWSh5mFZhz4M 26A2y5dIR4BSXKSmItDLnIB8gL/cMhKRFfIQbrU4/qhvDp0VfcGKlj6lEa1NvTKoGgJ6bAT X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 217.72.192.74 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 Sat May 4 18:05:19 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=1585044431; cv=none; d=zohomail.com; s=zohoarc; b=PEvY/KvUc+xvW5VsxWnKAXhmx3xKT81D5/q8xQ8YVFxLYaBjUbIe+uJCAGJ5dPArC7PELcdr3LyeHFd3zcINuGFpXFxrNgGAWe5Z4ZHodWJYoEQnAL5aJggnco6qZj7HgUKCkng1a8XUbi6zuCg+yUMn28ZRRWddzeB39p4DkhQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585044431; 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=OhMEMqJfRqERqnVNiwDo9r2wbVYovIN7GlStxTsTEh1bSe0FqF1M0DLvSsHAzyw5qeHhg+fGWhsrfPFDPgEPREz8xfGDA5FLWX46CaHTLQIdSDJyQag+VCkBO7tNu9uwCV0Gs0RenfDJ2epH5ZgYoq6q9QCcKYWYLpNOOngyNFg= 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 1585044431637786.7202048566744; Tue, 24 Mar 2020 03:07:11 -0700 (PDT) Received: from localhost ([::1]:45340 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGgSk-0001NR-ER for importer@patchew.org; Tue, 24 Mar 2020 06:07:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49415) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGgP6-0005zd-1w for qemu-devel@nongnu.org; Tue, 24 Mar 2020 06:03:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jGgP4-0000b6-JV for qemu-devel@nongnu.org; Tue, 24 Mar 2020 06:03:23 -0400 Received: from mout.kundenserver.de ([217.72.192.74]:55719) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jGgP4-0000aN-9o for qemu-devel@nongnu.org; Tue, 24 Mar 2020 06:03:22 -0400 Received: from localhost.localdomain ([82.252.135.106]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.183]) with ESMTPSA (Nemesis) id 1McH1O-1jode3026G-00clcY; Tue, 24 Mar 2020 11:03:15 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 2/5] linux-user/i386: Split out gen_signal Date: Tue, 24 Mar 2020 11:03:08 +0100 Message-Id: <20200324100311.588288-3-laurent@vivier.eu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200324100311.588288-1-laurent@vivier.eu> References: <20200324100311.588288-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:KDGkdGysTorHu+lyENNEGinap9YULlqxASmrCjx6pd9q/7TcpIF FTxGr2d/WfJjJTBPF7F6/10F/nHvIIWGc+q/nyC8q8wx9NoMrirvlT8rnKfx0spkcUzu3x6 i5opCeNiPwPeGfDqaWDBR3B+LnAS4muapQEXlY3E3K+SAsXiLN0k1dfDR6/xbXenYx9TICF 9ElXn5qPOE7PCPhayexwg== X-UI-Out-Filterresults: notjunk:1;V03:K0:yCXWpCqa5ZQ=:rntgXdb7zkJk4tucKeS273 YW9cAcm0hnqfKhyRZvEKroKaE7uFRa1Umy9Mb1Yf937B9+ogVOcz6GrSraZtX5dqIPPgAsl9A LYheaInfYG0/QgW/NCkJi4yVquWG3A0ENfvxetl126+/hfnPMJ73opXAN7Y0H95uxFFWszoUZ 211saKcX3iBvTFeR5ovp3bAzCNipYLdXtru3/E1W9oSiLcZkb1NqgD/u69poFUjPDdmJ7J+JK RHP1ZcXxyHkOopc5JN1d9dIJAaDfPxto6bQ/ynFBHYW+MalbwBd7CP55RQZHLnkzxybJ7+lBD 1xjCPknHuOcNuCb5X1NQG8EvwPqSAb+3HPIjvEl2Q1h/GagZlYxPfjH2snwzznuMB9/ETUQ9O FEynVrPpKK5o4/l+pCbpzVDrv0fzRS31clTcZQ2YlWkRaL/d+yGpIaXjFjs/i9pNwJSQlXBW3 bFzHEyv58Va6UJ9LCFucdoBtX3xVqtvmZ/raGIi1KQnmiiDoTovWZrch6estlBwpAFU9ZstHs LiGbMqCTvHibmAAwj/+DrkY1l9kz8hADppgruIyMnnildKrCb9mRg/FtYLTNkduBY5TJjAkew 0vjANC4zBAQS93ZVxWH0KW9KkhM50eykndEH9UKJTmYFf16Llycwbc7dlt0du6AsnA6Awf693 ozCxYAqtLOoMBJNcaW742UUu2kmfcMJ7H8gKsCPfasEPhwOQw8pNlFC14vzqyIeDlbZFF4bPJ AVQYYmE7Iwwo7mnY3m0CWJqJC2528TOuQ1g6X4HRrceJyWAuf7km+m50vAHd1N9x+CXv5EKLd YLZ4IqxTu8cLGEch6/KQNbMA05S2LU7GSJPxBEnPfm4frf7eJAyFNW+88X+QBCRjoLhuBz5 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 217.72.192.74 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 Sat May 4 18:05:19 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=1585044457; cv=none; d=zohomail.com; s=zohoarc; b=coAfJ+JG2I/x4RyRQm3B9B61aTWWpXgyU3MZLxrAgteVatRIH9By5zTC8g0QbSFGeVRqEUUxWSiRwrmN45NfFSzzQ80t3SmaiS8g5Rl4UoU/bb1K+p9Es7Q6UqijO0HMXCLjAaUsSHLCEiILFdZHKSht3ITqEOMyXiIKUXyNWG0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585044457; 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=honkkd6JmDvnpIdP5KJNprAUx3AjXywA80bAwtUW1zLRuxh2xh0rml2CIWVvYLdBnnwbgh+RhoUdE2Bkiyn3Bj7VG2iCml1Kw2GkZT2JpADppx8qye/2gWiu16Su4BTkrzH6ON8DW1uGvSC+NSRAkHveDdQ7xfv66rL1l0QOAt0= 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 1585044457634376.84682750633397; Tue, 24 Mar 2020 03:07:37 -0700 (PDT) Received: from localhost ([::1]:45356 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGgTA-0002P3-F7 for importer@patchew.org; Tue, 24 Mar 2020 06:07:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49471) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGgPC-00069n-IA for qemu-devel@nongnu.org; Tue, 24 Mar 2020 06:03:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jGgPA-0000ep-NE for qemu-devel@nongnu.org; Tue, 24 Mar 2020 06:03:30 -0400 Received: from mout.kundenserver.de ([212.227.17.13]:60365) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jGgPA-0000eK-Do for qemu-devel@nongnu.org; Tue, 24 Mar 2020 06:03:28 -0400 Received: from localhost.localdomain ([82.252.135.106]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.183]) with ESMTPSA (Nemesis) id 1M2fDl-1jFqvM2Xdf-004FkX; Tue, 24 Mar 2020 11:03:15 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 3/5] linux-user/i386: Emulate x86_64 vsyscalls Date: Tue, 24 Mar 2020 11:03:09 +0100 Message-Id: <20200324100311.588288-4-laurent@vivier.eu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200324100311.588288-1-laurent@vivier.eu> References: <20200324100311.588288-1-laurent@vivier.eu> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:OXu2EBDMcXnv46HrJDbKY9A+52Hd7vrYXjTaMleT9EevKzQ9qQz S+hP+E4rNj/+ixO+fkI0HJYwx/fN/NCEaijyE+J1zIPF84DRLw438FvX0ynC4uD7QMIzA9d XfQq8PA1pyAfqJv+tlcy2U2YIkmHrB5EF4ZJl/Ou8fuX19cBwtPR1VcTQhskzTBSG87sIDQ FiqkDE47YA4xHeo2zwSlw== X-UI-Out-Filterresults: notjunk:1;V03:K0:Hufkybbf2n0=:P6v+ihT7h5V+5U0sD3zBG8 8ndo1lru968ESMimuGlAE/xUd3MfXyuGNUMJedDb+i3/BCjXaH00YDyomi4KQqn/owSuXgGmJ 1CkUwfjW8uy9zCEN6qQcy7D2TwgLsoix9+9jUEst8pHh1Sc4p92n8hDAMk7wev2EaecqIRcD1 tVxaEUPw4MvIb/jAHPsahT/QW+WVvuorl7qZ2vSTPC00g10lk5/QkMwaMnh3+jctRmlg09U0K 8fVG/1kWj6mJATi/s9ewJg3TkHT7sIsZ8mFMIG0+jCkNiSIwnrKFC95ubK+fhBcaGYvW1yuF0 2grKY9jM3INpUjI8X1NIqs7UP/HBppCl/zjCDsYpm/sYpcc1UtolDXc0RzK5ZuR6lfTIufX2E Dj0ilrSfwEmn6tUXbaPHrZjmgCgMLKMwR9iFJT4Ox0tqhUzVbDN517cgVUDW0x02XOL/+nG7w fBb2xzk5ulSYmkrW//Y7goDaL4GA7ITy2mAO9Y/9+k4D5Q4HBFiZFQ1c1Q0bwiatJnqFecSis oGwhuuggZRgIdrkpQTmSbkNPt4SomBgyNoj6bU/S2k30n1sa4LfXDmdvzStNC5EZKUdz2dvZo 0SnEdaiIsasFRix4RTMv+dQn08wzHE+aYBMHEq8bzDarwtRln6RDW7ccYMvyEf9d6Va4tgyQB CJvHZQTsJ1XtMwevGawQj8iRH7Ge9LKYQnX1bXSwvyj+HQyrjT42Y6ch+IPKoIOY62QA3c6VD 6xPUIoVzifItTeO7RDzRg00dSlCUrgiSRRv3FHyQSIx3EXTAjT1KcUEqKRQmVLKQL7T9VxQ0X FYXYtBo7Z8jvI2mz5QyzPhAvNQGrNLlOE/pWc6CIlAsR40RdptAxgPyCZThpcFhWrTs9e9C X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.17.13 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 Sat May 4 18:05:19 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=1585044634; cv=none; d=zohomail.com; s=zohoarc; b=CATu12slkVMaIW0TBb2jAaI/UVU0CLCRd8JT+AJcKosepxCoN5TN4fIL2DNuUgWmKMFxmKsnMMyBJ5PiMnBzmi119m/xLvJEw3vCMqypSa2/7lWWsegP0F0oAx0ryRzM7ikXWjuEWyg9+G9N71uCMKP/Q8CqqyI7GBikFp7IGeU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585044634; 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=ixK+A2itNZ4lwPhKsI14iONwkMwXKtt4iAgHw17JdcU=; b=X2q+tRtaVgkwsqym0hrfKci4Tq7p0iKUf87XcyviXGsRPoX77AhjSS4DjYb0xBWJZpTiYKJmahuFa+cLi/QsMYgpNUe3fOlULSlLd/WjKDY1zHJTe7vbvKAG525BAV0h9jWW7Q6Tkg4FrqU97j0yaff1cx4dKmpHdWcWepJi2Qs= 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 1585044634021705.79666119085; Tue, 24 Mar 2020 03:10:34 -0700 (PDT) Received: from localhost ([::1]:45414 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGgW0-0006hQ-SQ for importer@patchew.org; Tue, 24 Mar 2020 06:10:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49448) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGgP8-00062m-6J for qemu-devel@nongnu.org; Tue, 24 Mar 2020 06:03:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jGgP6-0000cl-VJ for qemu-devel@nongnu.org; Tue, 24 Mar 2020 06:03:26 -0400 Received: from mout.kundenserver.de ([212.227.17.24]:49247) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jGgP6-0000c6-MO for qemu-devel@nongnu.org; Tue, 24 Mar 2020 06:03:24 -0400 Received: from localhost.localdomain ([82.252.135.106]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MvbO4-1jZj7a1vao-00sdVw; Tue, 24 Mar 2020 11:03:16 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 4/5] linux-user: Add x86_64 vsyscall page to /proc/self/maps Date: Tue, 24 Mar 2020 11:03:10 +0100 Message-Id: <20200324100311.588288-5-laurent@vivier.eu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200324100311.588288-1-laurent@vivier.eu> References: <20200324100311.588288-1-laurent@vivier.eu> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:ojp0y9ce1pIflhkVnGrS0924Kx1UvotZXiVdnzyaYLXbC7DHsby UTlu88LeDlEWaTFQAi6LmWeryTRiCczMUzFrsJwRPFcAo2WNu4ElLf7S2Pc/xJ7qm5Q4uAn QUTlAzn0xtXioZmfQEw6zpz8gTzTWkVq2X1yDUkJBEIL5lBUeRVza0Ou7HY585tb1sAabAL Ofr9gV6gVTUYOX74ZVLpA== X-UI-Out-Filterresults: notjunk:1;V03:K0:wSua/9F1wzQ=:WNk5zu5Td8bhxYDdNTzI48 l8rAmHPd9s1fvIiM6mB/jpovAvbD+ah367nupiBYKrIK5Kr9ctSyn55Xzw4AM1B0VI1RzbIkK WE5dNuHc2MXrDkpfhnFVoHlD8q8zgU7y/RQLgy18nGfp8VDbyTegcmheAxNj1HkVk3864zzC+ fneEFTkjxfVVbkIubWOFBR/YWywGgh90yv0A357ikWO33OIdyyrqSfcG+m3NppDzGd4XUrLhf Hhxex2rMTiOjMSe27Mk85n+uBY/B4hEr6TFK9RgbnEOYppFETS3w7nibD48bQoz2og4vEByAs PBdEUQFVygztI/D2wLFXeepMBC14RN8lEbjcXapyWBWqM4jIUZ1/QUQQy1KFNex5ldxV7NU0+ ZkLlVjEZUJ+DpnM3xQMJ0lBpEJwVa3hkILMNkZG3C5d8qZ/D2wDOrsPYvv9ZLNtYtzvNDKGjJ NmLXEOwWT+RMxT//LYoDIqzbEYH7zbn5cjw+K2NUNa/M68SlApho4RwcnEdnfeKIjVRq1ffm/ 0cQoFzewMMFvyw2amasScdImuET3d45yVc9kSt1H99jeytqxCFir3nXUB5maxHrWmXLqixy8J yl46aW0vrV+2PerYnoZQ3AvPN56JWbFgpTpRzXq0TZFQX+rQ9TJ5a8hmCIYjD3XENhd06dHwt LjMlmltgI4envmSrbpED5PhWAIox1y5jQWxxyOe/dDjD1c9bSPNirk9tcAe29mPrlAbEJM3Ma xLYopaAd3ap/oOo3pol4Y37/3O4SX4yM5OnaG/EoTwWTU+kmN1uJJ3bft7sMG5akQKJ8K2Nya ion9N7Edgv4QfZsoJj5F1f2ar3F9xBPUCSB06wet6S2GVHzPdmjmWRyIbtor4L2GblpdMu4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.17.24 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> 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..5675eca962d7 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=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.25.1 From nobody Sat May 4 18:05:19 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=1585044709; cv=none; d=zohomail.com; s=zohoarc; b=LUBk8tgFX6B2G8vYj8lMLf+xJe1UZHTb/P8aK2hh6aZn6OUAXIMBESOW9w2WivfQ62YBN1oNkwes5XY05s0Ki70QZXpY++6eg5fO2QorCpdsM2F2IGb4mw/KP3tGAHa6U94kPQnLSADgvHh7l4adUBGXwgV//Wofa/ldIeC6hZg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585044709; 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=SgXfwN8X4ZTcMhyYWfjN1uvHUfIe1HSiFAkhFnRW288=; b=fgUP6J0eyJpZevWrdjkG16Jj0wxBOAAFch2DXejAT3TKzLdgNBOdxfqyF6WbESwe/VsJ1TTEHbgJAWxsHXFbdDuc6yNtJb5kisHIYw19YQP4D+wLPDsaNyAEbZfgo8OLWAFD7MFy1R19Zgakj0auboOZ3gThIYERlMq/w/znBfs= 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 1585044709064686.669153127686; Tue, 24 Mar 2020 03:11:49 -0700 (PDT) Received: from localhost ([::1]:45448 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGgXD-0000ra-SS for importer@patchew.org; Tue, 24 Mar 2020 06:11:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49474) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGgPC-0006AP-Uo for qemu-devel@nongnu.org; Tue, 24 Mar 2020 06:03:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jGgPB-0000fE-Qv for qemu-devel@nongnu.org; Tue, 24 Mar 2020 06:03:30 -0400 Received: from mout.kundenserver.de ([212.227.17.13]:45343) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jGgPB-0000ev-I1 for qemu-devel@nongnu.org; Tue, 24 Mar 2020 06:03:29 -0400 Received: from localhost.localdomain ([82.252.135.106]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MNbtF-1isfD40MKh-00P4OT; Tue, 24 Mar 2020 11:03:17 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 5/5] linux-user: Flush out implementation of gettimeofday Date: Tue, 24 Mar 2020 11:03:11 +0100 Message-Id: <20200324100311.588288-6-laurent@vivier.eu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200324100311.588288-1-laurent@vivier.eu> References: <20200324100311.588288-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:BDgKtJ3PdH38sT4Jmsw0Fn45Lmg9valKYxqr6lfeLDh3VR6EOxW QkdRhqFTqyMzdapPI1bsoGxPg/rh165/6KTEAAVh3U0C3UsBgIZQfiAwU9dChvEq956NInB BKUY1n/9Niflk/85K9MiU+mTPhm53uSZfgFAAMLSRe00P7OxiLNCyhskWGaU0DBTdTZBCuE 9Y5C3pzg1lyWAeXqe/p6g== X-UI-Out-Filterresults: notjunk:1;V03:K0:YA3TI2wChNg=:Zvy9njpM/w82aGvMT1aNE9 v+sEmeupzbMp7WAjjkSfUWzP9VSu7vaHKDrfy7GclHAb7co5WQhxMwd3PNSmQYWUgEQURT5c6 kBH3uZKXzNfaSeEygsvXCC2zqHWCzvGmkCF1SQaADaNEHqnAi6tcm1PI0E44S0OQKOAxHzy5D VBcPTAySslMqDnitHajcDdZgVcYHVkojPpWGhN/qI857fSmueWnb3nANxmokc+oTn4QROc3vI tKQLzRUJPqPZoNL++nWxpKchUXKzLHojoglhuLZVY9ekyxxL31raiAmfmJa77aCsefj2Kx7SH SaPDo4AmO/z1DI+MFOABzyXUberenh59lnLMpEp/YmXMFhE9u9BOw1lKU2QYs3GBkSFcdVN25 nR2333e5/rTnk41cHHkTkFd4gL0KpX62FSr77IVg4avzqGZPxv9/6IWftfWXB6XLF065Le5SA 0971qXlNDRAsSXtPxPJe1467R1Oy4UOwCk1pIjZ456Vvjp1jo2YDfTfgOeojEIAhExFN8Dszj ZSHhZu729beTG7Mc/XhOA+rNaLGywxKAXgCsH/jvx6FRNHO4pXSigAsSsprCGi1L/QXMyuQta NJJVPxwIaPbxZgSeq/aNQUBctSiZp/bVvCOe2lc1XW+giZ8ZrX+x+zWZLG+iu/l6dzH3PGWdk U9rEqawb+b1805Ml/KmAMet5pxY6VChaKebtOgf3LmTyjtfyPOm002MdKvoyxesgq+bAFutqc WeeEp7E4SYBAIfkFToMqyALMwtK2X5tJifhPgp0dFdummiEzYyAyPeERWDmrzwdy90nJDU2rh LT0tO1tbqlWAsPQT8C1/QnlvMtJiJq0t/4gTllO8yzZC9MEZq4QVR+3pWgDXAb1WceGJiMW X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.17.13 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 5675eca962d7..b7e8a98d4dc6 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