{"id":811201,"url":"http://patchwork.ozlabs.org/api/patches/811201/?format=json","web_url":"http://patchwork.ozlabs.org/project/glibc/patch/20170907224219.12483-8-albert.aribaud@3adev.fr/","project":{"id":41,"url":"http://patchwork.ozlabs.org/api/projects/41/?format=json","name":"GNU C Library","link_name":"glibc","list_id":"libc-alpha.sourceware.org","list_email":"libc-alpha@sourceware.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20170907224219.12483-8-albert.aribaud@3adev.fr>","list_archive_url":null,"date":"2017-09-07T22:41:34","name":"[RFC,07/52] Y2038: add function __clock_gettime64","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"b6f1d1e170e78cbaae80c8a20deacad2fa64e05b","submitter":{"id":65557,"url":"http://patchwork.ozlabs.org/api/people/65557/?format=json","name":"Albert ARIBAUD (3ADEV)","email":"albert.aribaud@3adev.fr"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/glibc/patch/20170907224219.12483-8-albert.aribaud@3adev.fr/mbox/","series":[{"id":2074,"url":"http://patchwork.ozlabs.org/api/series/2074/?format=json","web_url":"http://patchwork.ozlabs.org/project/glibc/list/?series=2074","date":"2017-09-07T22:41:27","name":"Make GLIBC Y2038-proof","version":1,"mbox":"http://patchwork.ozlabs.org/series/2074/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/811201/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/811201/checks/","tags":{},"related":[],"headers":{"Return-Path":"<libc-alpha-return-84325-incoming=patchwork.ozlabs.org@sourceware.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list libc-alpha@sourceware.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=sourceware.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=libc-alpha-return-84325-incoming=patchwork.ozlabs.org@sourceware.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tsecure) header.d=sourceware.org header.i=@sourceware.org\n\theader.b=\"I2LAotUg\"; dkim-atps=neutral","sourceware.org; auth=none"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xpFqZ5nDmz9sCZ\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri,  8 Sep 2017 08:43:54 +1000 (AEST)","(qmail 63763 invoked by alias); 7 Sep 2017 22:42:59 -0000","(qmail 63641 invoked by uid 89); 7 Sep 2017 22:42:59 -0000"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id\n\t:list-unsubscribe:list-subscribe:list-archive:list-post\n\t:list-help:sender:from:to:cc:subject:date:message-id:in-reply-to\n\t:references; q=dns; s=default; b=L/xRdMpNFARitf7XH1PCw5Dr0r+DSMv\n\tWTvapJ3sT/z7hMZjih1yaAI5wfFvUbRCobajPnn1JL7NbrqHW4N74adhA5l6BbAJ\n\txo+wwu8hZYHSvK/L2lz6Bgw2KuBDiel50L4KK5h02DdMQdHfMJecHWGBVvSEPIsr\n\tc/uOXDbTGLKE=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id\n\t:list-unsubscribe:list-subscribe:list-archive:list-post\n\t:list-help:sender:from:to:cc:subject:date:message-id:in-reply-to\n\t:references; s=default; bh=oXY/zTTHn0Ycgo4bRRZgg3UmaAk=; b=I2LAo\n\ttUgU22rJQRMTmO5zlW4SW3aK3wykp2PxduZJZLdp4vL8OB/axX2VpQ6oYDc2VNgE\n\tEa2UxVNJXOQe1ujlTrF0WSSL283yDyHZlkIMKpi57/xAM8bPM0nm1kBkr9wk6Mbp\n\t5IAM9X5r7rUvcj6gHZpF3rMG/4s1yWV5XSe0/U=","Mailing-List":"contact libc-alpha-help@sourceware.org; run by ezmlm","Precedence":"bulk","List-Id":"<libc-alpha.sourceware.org>","List-Unsubscribe":"<mailto:libc-alpha-unsubscribe-incoming=patchwork.ozlabs.org@sourceware.org>","List-Subscribe":"<mailto:libc-alpha-subscribe@sourceware.org>","List-Archive":"<http://sourceware.org/ml/libc-alpha/>","List-Post":"<mailto:libc-alpha@sourceware.org>","List-Help":"<mailto:libc-alpha-help@sourceware.org>,\n\t<http://sourceware.org/ml/#faqs>","Sender":"libc-alpha-owner@sourceware.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-26.6 required=5.0 tests=BAYES_00, GIT_PATCH_0,\n\tGIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3,\n\tKAM_LAZY_DOMAIN_SECURITY,\n\tRCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy=","X-HELO":"smtp6-g21.free.fr","From":"\"Albert ARIBAUD (3ADEV)\" <albert.aribaud@3adev.fr>","To":"libc-alpha@sourceware.org","Cc":"\"Albert ARIBAUD (3ADEV)\" <albert.aribaud@3adev.fr>","Subject":"[RFC PATCH 07/52] Y2038: add function __clock_gettime64","Date":"Fri,  8 Sep 2017 00:41:34 +0200","Message-Id":"<20170907224219.12483-8-albert.aribaud@3adev.fr>","In-Reply-To":"<20170907224219.12483-7-albert.aribaud@3adev.fr>","References":"<20170907224219.12483-1-albert.aribaud@3adev.fr>\n\t<20170907224219.12483-2-albert.aribaud@3adev.fr>\n\t<20170907224219.12483-3-albert.aribaud@3adev.fr>\n\t<20170907224219.12483-4-albert.aribaud@3adev.fr>\n\t<20170907224219.12483-5-albert.aribaud@3adev.fr>\n\t<20170907224219.12483-6-albert.aribaud@3adev.fr>\n\t<20170907224219.12483-7-albert.aribaud@3adev.fr>"},"content":"Note: __clock_gettime64 is implemented in VDSO.\nSigned-off-by: Albert ARIBAUD (3ADEV) <albert.aribaud@3adev.fr>\n---\n include/time.h                           |  8 ++++++\n sysdeps/unix/clock_gettime.c             | 46 ++++++++++++++++++++++++++++++++\n sysdeps/unix/sysv/linux/arm/Versions     |  3 +++\n sysdeps/unix/sysv/linux/arm/init-first.c | 15 +++++++++++\n sysdeps/unix/sysv/linux/arm/libc-vdso.h  |  1 +\n sysdeps/unix/sysv/linux/clock_gettime.c  | 44 ++++++++++++++++++++++++++++++\n 6 files changed, 117 insertions(+)","diff":"diff --git a/include/time.h b/include/time.h\nindex c436c44539..eeefbb4e98 100644\n--- a/include/time.h\n+++ b/include/time.h\n@@ -20,6 +20,11 @@ libc_hidden_proto (localtime)\n libc_hidden_proto (strftime)\n libc_hidden_proto (strptime)\n \n+/* Indicates whether the underlying kernel has 64-bit time support.\n+   This is required for e.g. librt, which cannot directly check the\n+   flag variable that init-first.c sets when detecting support. */\n+extern int __y2038_kernel_support (void);\n+\n #if BYTE_ORDER == BIG_ENDIAN\n struct __timespec64\n {\n@@ -43,6 +48,9 @@ extern __typeof (clock_settime) __clock_settime;\n extern __typeof (clock_nanosleep) __clock_nanosleep;\n extern __typeof (clock_getcpuclockid) __clock_getcpuclockid;\n \n+extern int __clock_gettime64 (clockid_t __clock_id,\n+\t\t\t      struct __timespec64 *__tp) __THROW;\n+\n /* Now define the internal interfaces.  */\n struct tm;\n \ndiff --git a/sysdeps/unix/clock_gettime.c b/sysdeps/unix/clock_gettime.c\nindex 5262066f51..ac224c919b 100644\n--- a/sysdeps/unix/clock_gettime.c\n+++ b/sysdeps/unix/clock_gettime.c\n@@ -134,3 +134,49 @@ __clock_gettime (clockid_t clock_id, struct timespec *tp)\n }\n weak_alias (__clock_gettime, clock_gettime)\n libc_hidden_def (__clock_gettime)\n+\n+/* Get current value of CLOCK and store it in TP, 64-bit version.  */\n+int\n+__clock_gettime64 (clockid_t clock_id, struct __timespec64 *tp)\n+{\n+  int retval = -1;\n+\n+  switch (clock_id)\n+    {\n+#ifdef SYSDEP_GETTIME64\n+      SYSDEP_GETTIME64;\n+#endif\n+\n+#ifndef HANDLED_REALTIME\n+    case CLOCK_REALTIME:\n+      {\n+\tstruct timeval tv;\n+\tretval = gettimeofday (&tv, NULL);\n+\tif (retval == 0)\n+\t  TIMEVAL_TO_TIMESPEC (&tv, tp);\n+      }\n+      break;\n+#endif\n+\n+    default:\n+#ifdef SYSDEP_GETTIME64_CPU\n+      SYSDEP_GETTIME64_CPU (clock_id, tp);\n+#endif\n+#if HP_TIMING_AVAIL\n+      if ((clock_id & ((1 << CLOCK_IDFIELD_SIZE) - 1))\n+\t  == CLOCK_THREAD_CPUTIME_ID)\n+\tretval = hp_timing_gettime (clock_id, tp);\n+      else\n+#endif\n+\t__set_errno (EINVAL);\n+      break;\n+\n+#if HP_TIMING_AVAIL && !defined HANDLED_CPUTIME\n+    case CLOCK_PROCESS_CPUTIME_ID:\n+      retval = hp_timing_gettime (clock_id, tp);\n+      break;\n+#endif\n+    }\n+\n+  return retval;\n+}\ndiff --git a/sysdeps/unix/sysv/linux/arm/Versions b/sysdeps/unix/sysv/linux/arm/Versions\nindex f7feda3650..a2655d6262 100644\n--- a/sysdeps/unix/sysv/linux/arm/Versions\n+++ b/sysdeps/unix/sysv/linux/arm/Versions\n@@ -27,5 +27,8 @@ libc {\n     __localtime64; __localtime64_r;\n     __mktime64; __timelocal64_r;\n     __timegm64;\n+    __clock_gettime64;\n+    __vdso_clock_gettime64;\n+    __y2038_kernel_support;\n   }\n }\ndiff --git a/sysdeps/unix/sysv/linux/arm/init-first.c b/sysdeps/unix/sysv/linux/arm/init-first.c\nindex 3c289c2a25..61c01a56a7 100644\n--- a/sysdeps/unix/sysv/linux/arm/init-first.c\n+++ b/sysdeps/unix/sysv/linux/arm/init-first.c\n@@ -23,6 +23,14 @@\n \n int (*VDSO_SYMBOL(gettimeofday)) (struct timeval *, void *) attribute_hidden;\n int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *);\n+long (*VDSO_SYMBOL(clock_gettime64)) (clockid_t, struct __timespec64 *);\n+\n+int __y2038_linux_support;\n+\n+int __y2038_kernel_support (void)\n+{\n+  return __y2038_linux_support;\n+}\n \n static inline void\n _libc_vdso_platform_setup (void)\n@@ -36,6 +44,13 @@ _libc_vdso_platform_setup (void)\n   p = _dl_vdso_vsym (\"__vdso_clock_gettime\", &linux26);\n   PTR_MANGLE (p);\n   VDSO_SYMBOL (clock_gettime) = p;\n+\n+  /* (aaribaud) TODO: map to version where clock_gettime64 officially appears */\n+  p = _dl_vdso_vsym (\"__vdso_clock_gettime64\", NULL);\n+  PTR_MANGLE (p);\n+  VDSO_SYMBOL (clock_gettime64) = p;\n+\n+  __y2038_linux_support = (p != NULL) ? 1 : 0;\n }\n \n # define VDSO_SETUP _libc_vdso_platform_setup\ndiff --git a/sysdeps/unix/sysv/linux/arm/libc-vdso.h b/sysdeps/unix/sysv/linux/arm/libc-vdso.h\nindex ae37b574e1..ee0e5941c0 100644\n--- a/sysdeps/unix/sysv/linux/arm/libc-vdso.h\n+++ b/sysdeps/unix/sysv/linux/arm/libc-vdso.h\n@@ -27,6 +27,7 @@\n extern int (*VDSO_SYMBOL(gettimeofday)) (struct timeval *, void *)\n    attribute_hidden;\n extern int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *);\n+extern long (*VDSO_SYMBOL(clock_gettime64)) (clockid_t, struct __timespec64 *);\n \n #endif\n \ndiff --git a/sysdeps/unix/sysv/linux/clock_gettime.c b/sysdeps/unix/sysv/linux/clock_gettime.c\nindex e232f69a4f..df4e16e6db 100644\n--- a/sysdeps/unix/sysv/linux/clock_gettime.c\n+++ b/sysdeps/unix/sysv/linux/clock_gettime.c\n@@ -44,4 +44,48 @@\n   break\n #define SYSDEP_GETTIME_CPUTIME\t/* Default catches them too.  */\n \n+/* 64-bit versions */\n+\n+/* The REALTIME and MONOTONIC clock are definitely supported in the\n+   kernel.  */\n+#define SYSDEP_GETTIME64 \\\n+  SYSDEP_GETTIME64_CPUTIME;\t\t\t\t\t\t      \\\n+  case CLOCK_REALTIME:\t\t\t\t\t\t\t      \\\n+  case CLOCK_MONOTONIC:\t\t\t\t\t\t\t      \\\n+    if (__y2038_linux_support)\t\t\t\t\t\t      \\\n+      {\t\t\t\t\t\t\t\t\t      \\\n+        retval = INLINE_VSYSCALL (clock_gettime64, 2, clock_id, tp);\t      \\\n+      }\t\t\t\t\t\t\t\t\t      \\\n+    else\t\t\t\t\t\t\t\t      \\\n+      {\t\t\t\t\t\t\t\t\t      \\\n+        retval = INLINE_VSYSCALL (clock_gettime, 2, clock_id, &ts32);\t      \\\n+        if (retval==0)\t\t\t\t\t\t\t      \\\n+          {\t\t\t\t\t\t\t\t      \\\n+            tp->tv_sec = ts32.tv_sec;\t\t\t\t\t      \\\n+            tp->tv_nsec = ts32.tv_nsec;\t\t\t\t\t      \\\n+            tp->tv_pad = 0;\t\t\t\t\t\t      \\\n+          }\t\t\t\t\t\t\t\t      \\\n+      }\t\t\t\t\t\t\t\t\t      \\\n+    break\n+\n+#define SYSDEP_GETTIME64_CPU(clock_id, tp) \\\n+  if (__y2038_linux_support)\t\t\t\t\t\t      \\\n+    {\t\t\t\t\t\t\t\t\t      \\\n+      retval = INLINE_VSYSCALL (clock_gettime64, 2, clock_id, tp);\t      \\\n+    }\t\t\t\t\t\t\t\t\t      \\\n+  else\t\t\t\t\t\t\t\t\t      \\\n+    {\t\t\t\t\t\t\t\t\t      \\\n+      retval = INLINE_VSYSCALL (clock_gettime, 2, clock_id, &ts32);\t      \\\n+      if (retval==0)\t\t\t\t\t\t\t      \\\n+        {\t\t\t\t\t\t\t\t      \\\n+          tp->tv_sec = ts32.tv_sec;\t\t\t\t\t      \\\n+          tp->tv_nsec = ts32.tv_nsec;\t\t\t\t\t      \\\n+          tp->tv_pad = 0;\t\t\t\t\t\t      \\\n+        }\t\t\t\t\t\t\t\t      \\\n+    }\t\t\t\t\t\t\t\t\t      \\\n+  break\n+#define SYSDEP_GETTIME64_CPUTIME \\\n+  struct timespec ts32;\t\t\t\t\t\t\t      \\\n+  extern int __y2038_linux_support;\n+\n #include <sysdeps/unix/clock_gettime.c>\n","prefixes":["RFC","07/52"]}