From patchwork Thu Mar 19 09:26:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 1258061 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=vivier.eu Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48jhTS5PTZz9sRY for ; Thu, 19 Mar 2020 20:30:20 +1100 (AEDT) Received: from localhost ([::1]:35280 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jErVK-0003vz-HR for incoming@patchwork.ozlabs.org; Thu, 19 Mar 2020 05:30:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40949) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jErRy-0005Qu-D5 for qemu-devel@nongnu.org; Thu, 19 Mar 2020 05:26:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jErRx-0004F3-29 for qemu-devel@nongnu.org; Thu, 19 Mar 2020 05:26:50 -0400 Received: from mout.kundenserver.de ([212.227.126.135]:33917) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jErRw-0004E8-P7 for qemu-devel@nongnu.org; Thu, 19 Mar 2020 05:26:48 -0400 Received: from localhost.localdomain ([82.252.135.106]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.167]) with ESMTPSA (Nemesis) id 1Mc1hn-1jqfIn2n7f-00dTuI; Thu, 19 Mar 2020 10:26:38 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL v3 11/16] linux-user/syscall: Add support for clock_gettime64/clock_settime64 Date: Thu, 19 Mar 2020 10:26:22 +0100 Message-Id: <20200319092627.51487-12-laurent@vivier.eu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200319092627.51487-1-laurent@vivier.eu> References: <20200319092627.51487-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:L9uGFhJuOpdqZ11JjA5qmhOkxad9EpMTdmTYCQSsFM3t3oRux9s k+BgrnC5/eJteZAE9/PDuRyaqem/D1lL6qPWSFXmPDBAu5llwvv0sq4IzY4Dq7YSO3EA9o9 oT3PHJr3rHsb7Z0yGknnN3Mu6leuCRKLCUkTWqUHShJeFAxVY41nx0P0iGY0D4BrdMhddKJ HC0jVu6OrwIa+SziKXy2g== X-UI-Out-Filterresults: notjunk:1; V03:K0:hdwfzrX7RyI=:tEUyfOLVlQEw+D9J8JjgEQ ROJL9gJcpmjkuU1LkdJsQN80MJWfEWKfUMLksAwvUoWUPDBDToTDfMTOEAYYB0vhypynlBavk /FRVCQWsn7ILmSBl3MkyZ9uv6aCJwVIOXCxZRj5fNirNbETJmJytb6LMt+WOaVGYMyqT0lMjB cuLWKC9Fl0TlfKBRnLbT+ggOY5XJGDvqhaD0KOSkmQ7r9o/qRIWv+ZwuxKswlbSBmTXpF6BqS CqeUqJDax8M7kM7ieYop32weMJYxNuZ8QXF8yP67DQt1WHmGIDX5XC1gHKDQ2C1zOuc0FQC1Z JbWDxJ8b2rnOXSfvu5ttEh7H2hziA/sBMmela003kY38Mhvx15BeT9aBB0m2SWM12NYhTmDJ9 hC6cdYF0TelsdAlQev0L2UAV4jRHA35lhgflQToVE7QiKOeu49RsP13Bqql9GopjtOzPQQmzL xob2bAqQ3ew//DYdioNDFiaynQ26t/14RtPqpSxsy4ouVjy23ZqU1mrhhYhXHt1NSD9BlZwqw Lbw7WCxzJyNTBpBgQTIuzp4YzA5G7Cf9iisvpysgb+ZAA3kT1oNoDsPkad272LW5SpsjrmSkD 05cmHoYs9FkUOJ5Wb5zRAs3MLXSpiAfJbcULLJg+oFCtIWWIlLBE9hkkDSI+4A2K88K+UBAfW +uqlRu5EAizIal94cWkdjR/UFdpnm3a1OwIpjp+0QWN+Ea/XpFnDXSNpW4eBo6JN+vWl7LbB9 mkEa/T5gIeOundFokfmYEwBcy2Wx1BdVPLbn0dJiAtNoPtHmoUlOFljChYz74hRc/+XI1SIaF 2Au8ADBgXexxtlZuCHQRZjmYRdhShWOaBV8UXSV6sKhVdIrfr5UfTW+33d1U8zIXYrVrPwk 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: Riku Voipio , Alistair Francis , Laurent Vivier Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Alistair Francis Add support for the clock_gettime64/clock_settime64 syscalls. If your host is 64-bit or is 32-bit with the *_time64 syscall then the timespec will correctly be a 64-bit time_t. Otherwise the host will return a 32-bit time_t which will be rounded to 64-bits. This will be incorrect after y2038. Signed-off-by: Alistair Francis Reviewed-by: Laurent Vivier Message-Id: <4a7fd05532400d10aa0f684c9043e2ac7b34d91c.1584051142.git.alistair.francis@wdc.com> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index ea1c84dc5de5..661404687080 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -1229,6 +1229,22 @@ static inline abi_long target_to_host_timespec(struct timespec *host_ts, } #endif +#if defined(TARGET_NR_clock_settime64) +static inline abi_long target_to_host_timespec64(struct timespec *host_ts, + abi_ulong target_addr) +{ + struct target__kernel_timespec *target_ts; + + if (!lock_user_struct(VERIFY_READ, target_ts, target_addr, 1)) { + return -TARGET_EFAULT; + } + __get_user(host_ts->tv_sec, &target_ts->tv_sec); + __get_user(host_ts->tv_nsec, &target_ts->tv_nsec); + unlock_user_struct(target_ts, target_addr, 0); + return 0; +} +#endif + static inline abi_long host_to_target_timespec(abi_ulong target_addr, struct timespec *host_ts) { @@ -11493,6 +11509,18 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, return ret; } #endif +#ifdef TARGET_NR_clock_settime64 + case TARGET_NR_clock_settime64: + { + struct timespec ts; + + ret = target_to_host_timespec64(&ts, arg2); + if (!is_error(ret)) { + ret = get_errno(clock_settime(arg1, &ts)); + } + return ret; + } +#endif #ifdef TARGET_NR_clock_gettime case TARGET_NR_clock_gettime: { @@ -11504,6 +11532,17 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, return ret; } #endif +#ifdef TARGET_NR_clock_gettime64 + case TARGET_NR_clock_gettime64: + { + struct timespec ts; + ret = get_errno(clock_gettime(arg1, &ts)); + if (!is_error(ret)) { + ret = host_to_target_timespec64(arg2, &ts); + } + return ret; + } +#endif #ifdef TARGET_NR_clock_getres case TARGET_NR_clock_getres: {