public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [[PATCH RFC 2]  05/63] Y2038: add function __localtime64_r
  2018-04-18 20:18       ` [[PATCH RFC 2] 04/63] Y2038: add function __localtime64 Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:18         ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:19           ` [[PATCH RFC 2] 06/63] Y2038: add function __gmtime64 Albert ARIBAUD (3ADEV)
  0 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:18 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

---
 include/time.h   | 3 +++
 time/Versions    | 2 +-
 time/localtime.c | 8 ++++++++
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/include/time.h b/include/time.h
index 1d8f76f0c3..81cb0fbc00 100644
--- a/include/time.h
+++ b/include/time.h
@@ -64,6 +64,9 @@ extern time_t __mktime_internal (struct tm *__tp,
 extern struct tm *__localtime_r (const time_t *__timer,
 				 struct tm *__tp) attribute_hidden;
 
+extern struct tm *__localtime64_r (const __time64_t *__timer,
+				   struct tm *__tp) attribute_hidden;
+
 extern struct tm *__gmtime_r (const time_t *__restrict __timer,
 			      struct tm *__restrict __tp);
 libc_hidden_proto (__gmtime_r)
diff --git a/time/Versions b/time/Versions
index 48d545b8c8..723a03cd13 100644
--- a/time/Versions
+++ b/time/Versions
@@ -67,6 +67,6 @@ libc {
   }
   GLIBC_2.27 {
     __difftime64;
-    __localtime64;
+    __localtime64; __localtime64_r;
   }
 }
diff --git a/time/localtime.c b/time/localtime.c
index 74f7ad6807..0a9a826a6a 100644
--- a/time/localtime.c
+++ b/time/localtime.c
@@ -53,6 +53,14 @@ libc_hidden_def (localtime)
 
 /* 64-bit-time versions */
 
+/* Return the `struct tm' representation of *T in local time,
+   using *TP to store the result.  */
+struct tm *
+__localtime64_r (const __time64_t *t, struct tm *tp)
+{
+  return __tz_convert (*t, 1, tp);
+}
+
 /* Return the `struct tm' representation of *T in local time.  */
 struct tm *
 __localtime64 (const __time64_t *t)
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  03/63] Y2038: make __tz_convert compatible with 64-bit-time
  2018-04-18 20:18   ` [[PATCH RFC 2] 02/63] Y2038: add function __difftime64 Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:18     ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:18       ` [[PATCH RFC 2] 04/63] Y2038: add function __localtime64 Albert ARIBAUD (3ADEV)
                         ` (2 more replies)
  2018-04-18 20:37     ` [[PATCH RFC 2] 02/63] Y2038: add function __difftime64 Paul Eggert
  2018-04-18 21:50     ` Joseph Myers
  2 siblings, 3 replies; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:18 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

__tz_convert is used by six API functions. Making
it compatible with 64-bit time allows reusing it for
implementing 64-bit-time versions of theses six APIs.
---
 include/time.h   | 12 ++++++------
 time/gmtime.c    | 15 +++++++++++++--
 time/localtime.c | 15 +++++++++++++--
 time/offtime.c   |  8 ++++----
 time/tzfile.c    |  4 ++--
 time/tzset.c     | 24 +++++++++---------------
 6 files changed, 47 insertions(+), 31 deletions(-)

diff --git a/include/time.h b/include/time.h
index ba2c67a829..6ffa9b2efc 100644
--- a/include/time.h
+++ b/include/time.h
@@ -40,14 +40,14 @@ extern int __use_tzfile attribute_hidden;
 
 extern void __tzfile_read (const char *file, size_t extra,
 			   char **extrap) attribute_hidden;
-extern void __tzfile_compute (time_t timer, int use_localtime,
+extern void __tzfile_compute (__time64_t timer, int use_localtime,
 			      long int *leap_correct, int *leap_hit,
 			      struct tm *tp) attribute_hidden;
 extern void __tzfile_default (const char *std, const char *dst,
 			      long int stdoff, long int dstoff)
   attribute_hidden;
 extern void __tzset_parse_tz (const char *tz) attribute_hidden;
-extern void __tz_compute (time_t timer, struct tm *tm, int use_localtime)
+extern void __tz_compute (__time64_t timer, struct tm *tm, int use_localtime)
   __THROW attribute_hidden;
 
 /* Subroutine of `mktime'.  Return the `time_t' representation of TP and
@@ -64,11 +64,11 @@ extern struct tm *__gmtime_r (const time_t *__restrict __timer,
 			      struct tm *__restrict __tp);
 libc_hidden_proto (__gmtime_r)
 
-/* Compute the `struct tm' representation of *T,
+/* Compute the `struct tm' representation of T,
    offset OFFSET seconds east of UTC,
    and store year, yday, mon, mday, wday, hour, min, sec into *TP.
    Return nonzero if successful.  */
-extern int __offtime (const time_t *__timer,
+extern int __offtime (const __time64_t __timer,
 		      long int __offset,
 		      struct tm *__tp) attribute_hidden;
 
@@ -77,8 +77,8 @@ extern char *__asctime_r (const struct tm *__tp, char *__buf)
 extern void __tzset (void) attribute_hidden;
 
 /* Prototype for the internal function to get information based on TZ.  */
-extern struct tm *__tz_convert (const time_t *timer, int use_localtime,
-				struct tm *tp) attribute_hidden;
+extern struct tm *__tz_convert (const __time64_t timer, int use_localtime,
+			        struct tm *tp) attribute_hidden;
 
 extern int __nanosleep (const struct timespec *__requested_time,
 			struct timespec *__remaining);
diff --git a/time/gmtime.c b/time/gmtime.c
index dc33b3e68a..e38f0cbcc0 100644
--- a/time/gmtime.c
+++ b/time/gmtime.c
@@ -17,13 +17,19 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include <time.h>
+#include <errno.h>
 
 /* Return the `struct tm' representation of *T in UTC,
    using *TP to store the result.  */
 struct tm *
 __gmtime_r (const time_t *t, struct tm *tp)
 {
-  return __tz_convert (t, 0, tp);
+  if (t == NULL)
+    {
+      __set_errno (EINVAL);
+      return NULL;
+    }
+  return __tz_convert (*t, 0, tp);
 }
 libc_hidden_def (__gmtime_r)
 weak_alias (__gmtime_r, gmtime_r)
@@ -33,5 +39,10 @@ weak_alias (__gmtime_r, gmtime_r)
 struct tm *
 gmtime (const time_t *t)
 {
-  return __tz_convert (t, 0, &_tmbuf);
+  if (t == NULL)
+    {
+      __set_errno (EINVAL);
+      return NULL;
+    }
+  return __tz_convert (*t, 0, &_tmbuf);
 }
diff --git a/time/localtime.c b/time/localtime.c
index 8684a8a971..362fdb3c21 100644
--- a/time/localtime.c
+++ b/time/localtime.c
@@ -17,6 +17,7 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include <time.h>
+#include <errno.h>
 
 /* The C Standard says that localtime and gmtime return the same pointer.  */
 struct tm _tmbuf;
@@ -27,7 +28,12 @@ struct tm _tmbuf;
 struct tm *
 __localtime_r (const time_t *t, struct tm *tp)
 {
-  return __tz_convert (t, 1, tp);
+  if (t == NULL)
+    {
+      __set_errno (EINVAL);
+      return NULL;
+    }
+  return __tz_convert (*t, 1, tp);
 }
 weak_alias (__localtime_r, localtime_r)
 
@@ -36,6 +42,11 @@ weak_alias (__localtime_r, localtime_r)
 struct tm *
 localtime (const time_t *t)
 {
-  return __tz_convert (t, 1, &_tmbuf);
+  if (t == NULL)
+    {
+      __set_errno (EINVAL);
+      return NULL;
+    }
+  return __tz_convert (*t, 1, &_tmbuf);
 }
 libc_hidden_def (localtime)
diff --git a/time/offtime.c b/time/offtime.c
index 04c48389fc..59ed38f9fa 100644
--- a/time/offtime.c
+++ b/time/offtime.c
@@ -21,18 +21,18 @@
 #define	SECS_PER_HOUR	(60 * 60)
 #define	SECS_PER_DAY	(SECS_PER_HOUR * 24)
 
-/* Compute the `struct tm' representation of *T,
+/* Compute the `struct tm' representation of T,
    offset OFFSET seconds east of UTC,
    and store year, yday, mon, mday, wday, hour, min, sec into *TP.
    Return nonzero if successful.  */
 int
-__offtime (const time_t *t, long int offset, struct tm *tp)
+__offtime (const __time64_t t, long int offset, struct tm *tp)
 {
   time_t days, rem, y;
   const unsigned short int *ip;
 
-  days = *t / SECS_PER_DAY;
-  rem = *t % SECS_PER_DAY;
+  days = t / SECS_PER_DAY;
+  rem = t % SECS_PER_DAY;
   rem += offset;
   while (rem < 0)
     {
diff --git a/time/tzfile.c b/time/tzfile.c
index 3e39723148..9560eda8b4 100644
--- a/time/tzfile.c
+++ b/time/tzfile.c
@@ -630,7 +630,7 @@ __tzfile_default (const char *std, const char *dst,
 }
 \f
 void
-__tzfile_compute (time_t timer, int use_localtime,
+__tzfile_compute (__time64_t timer, int use_localtime,
 		  long int *leap_correct, int *leap_hit,
 		  struct tm *tp)
 {
@@ -685,7 +685,7 @@ __tzfile_compute (time_t timer, int use_localtime,
 
 	  /* Convert to broken down structure.  If this fails do not
 	     use the string.  */
-	  if (__glibc_unlikely (! __offtime (&timer, 0, tp)))
+	  if (__glibc_unlikely (! __offtime (timer, 0, tp)))
 	    goto use_last;
 
 	  /* Use the rules from the TZ string to compute the change.  */
diff --git a/time/tzset.c b/time/tzset.c
index b51786704a..efbb47716f 100644
--- a/time/tzset.c
+++ b/time/tzset.c
@@ -16,7 +16,6 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include <ctype.h>
-#include <errno.h>
 #include <libc-lock.h>
 #include <stdbool.h>
 #include <stddef.h>
@@ -55,7 +54,7 @@ typedef struct
 
     /* We cache the computed time of change for a
        given year so we don't have to recompute it.  */
-    time_t change;	/* When to change to this zone.  */
+    __time64_t change;	/* When to change to this zone.  */
     int computed_for;	/* Year above is computed for.  */
   } tz_rule;
 
@@ -416,7 +415,7 @@ tzset_internal (int always)
       tz_rules[0].name = tz_rules[1].name = "UTC";
       if (J0 != 0)
 	tz_rules[0].type = tz_rules[1].type = J0;
-      tz_rules[0].change = tz_rules[1].change = (time_t) -1;
+      tz_rules[0].change = tz_rules[1].change = (__time64_t) -1;
       update_vars ();
       return;
     }
@@ -514,9 +513,10 @@ compute_change (tz_rule *rule, int year)
 
 
 /* Figure out the correct timezone for TM and set `__tzname',
-   `__timezone', and `__daylight' accordingly.  */
+   `__timezone', and `__daylight' accordingly.
+   NOTE: this takes a __time64_t value, so passing a __time_t value is OK. */
 void
-__tz_compute (time_t timer, struct tm *tm, int use_localtime)
+__tz_compute (__time64_t timer, struct tm *tm, int use_localtime)
 {
   compute_change (&tz_rules[0], 1900 + tm->tm_year);
   compute_change (&tz_rules[1], 1900 + tm->tm_year);
@@ -562,20 +562,14 @@ __tzset (void)
 }
 weak_alias (__tzset, tzset)
 \f
-/* Return the `struct tm' representation of *TIMER in the local timezone.
+/* Return the `struct tm' representation of TIMER in the local timezone.
    Use local time if USE_LOCALTIME is nonzero, UTC otherwise.  */
 struct tm *
-__tz_convert (const time_t *timer, int use_localtime, struct tm *tp)
+__tz_convert (const __time64_t timer, int use_localtime, struct tm *tp)
 {
   long int leap_correction;
   int leap_extra_secs;
 
-  if (timer == NULL)
-    {
-      __set_errno (EINVAL);
-      return NULL;
-    }
-
   __libc_lock_lock (tzset_lock);
 
   /* Update internal database according to current TZ setting.
@@ -584,14 +578,14 @@ __tz_convert (const time_t *timer, int use_localtime, struct tm *tp)
   tzset_internal (tp == &_tmbuf && use_localtime);
 
   if (__use_tzfile)
-    __tzfile_compute (*timer, use_localtime, &leap_correction,
+    __tzfile_compute (timer, use_localtime, &leap_correction,
 		      &leap_extra_secs, tp);
   else
     {
       if (! __offtime (timer, 0, tp))
 	tp = NULL;
       else
-	__tz_compute (*timer, tp, use_localtime);
+	__tz_compute (timer, tp, use_localtime);
       leap_correction = 0L;
       leap_extra_secs = 0;
     }
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  04/63] Y2038: add function __localtime64
  2018-04-18 20:18     ` [[PATCH RFC 2] 03/63] Y2038: make __tz_convert compatible with 64-bit-time Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:18       ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:18         ` [[PATCH RFC 2] 05/63] Y2038: add function __localtime64_r Albert ARIBAUD (3ADEV)
  2018-04-19  1:02       ` [[PATCH RFC 2] 03/63] Y2038: make __tz_convert compatible with 64-bit-time Paul Eggert
  2018-04-19  1:08       ` Paul Eggert
  2 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:18 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

---
 include/time.h   | 4 ++++
 time/Versions    | 1 +
 time/localtime.c | 9 +++++++++
 3 files changed, 14 insertions(+)

diff --git a/include/time.h b/include/time.h
index 6ffa9b2efc..1d8f76f0c3 100644
--- a/include/time.h
+++ b/include/time.h
@@ -9,6 +9,8 @@ extern __typeof (strftime_l) __strftime_l;
 libc_hidden_proto (__strftime_l)
 extern __typeof (strptime_l) __strptime_l;
 
+extern struct tm *__localtime64 (const __time64_t *__timer);
+
 libc_hidden_proto (time)
 libc_hidden_proto (asctime)
 libc_hidden_proto (mktime)
@@ -17,6 +19,8 @@ libc_hidden_proto (localtime)
 libc_hidden_proto (strftime)
 libc_hidden_proto (strptime)
 
+libc_hidden_proto (__localtime64)
+
 extern __typeof (clock_getres) __clock_getres;
 extern __typeof (clock_gettime) __clock_gettime;
 libc_hidden_proto (__clock_gettime)
diff --git a/time/Versions b/time/Versions
index 57314b98c8..48d545b8c8 100644
--- a/time/Versions
+++ b/time/Versions
@@ -67,5 +67,6 @@ libc {
   }
   GLIBC_2.27 {
     __difftime64;
+    __localtime64;
   }
 }
diff --git a/time/localtime.c b/time/localtime.c
index 362fdb3c21..74f7ad6807 100644
--- a/time/localtime.c
+++ b/time/localtime.c
@@ -50,3 +50,12 @@ localtime (const time_t *t)
   return __tz_convert (*t, 1, &_tmbuf);
 }
 libc_hidden_def (localtime)
+
+/* 64-bit-time versions */
+
+/* Return the `struct tm' representation of *T in local time.  */
+struct tm *
+__localtime64 (const __time64_t *t)
+{
+  return __tz_convert (*t, 1, &_tmbuf);
+}
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  00/63] Make GLIBC Y2038-proof
@ 2018-04-18 20:18 Albert ARIBAUD (3ADEV)
  2018-04-18 20:18 ` [[PATCH RFC 2] 01/63] Y2038: add type __time64_t Albert ARIBAUD (3ADEV)
  0 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:18 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

This series implements Y2038-proof types, implementation, internal
functions, and APIs. For more information, see documentation at
https://sourceware.org/glibc/wiki/Y2038ProofnessDesign

Each patch in this series except the last add one type or function,
with a few exception where several functions are implemented as a whole.

Right now, this series provides a 64-bit time API to application code
but does not use 64-bit Linux syscalls, only 32-bit ones. This means
application code will most probably not run properly if times involved
go beyond Y2038, but should work fine otherwise.

These patches are currently tested using an ad hoc framework published
at https://github.com/3adev/y2038 which runs functional tests of the
APIS below, at and beyond the Y2038 limit. The tests are run on the
ARM and PPC architecture.

These patches have also been subjected to a 'make (x)check' on the ARM
architexcture and the results compared to those obtained without the
patches; no new failure is introduced by the series.

The last patch enables the _TIME_BITS mechanism. Once this patch is
applied, API header files will will use 64-bit time if _TIME_BITS is
defined and equal to 64 prior to their inclusion, and conversively,
will use 32-bit time if _TIME_BITS is different from 64 or does not
exist.

Albert ARIBAUD (3ADEV) (63):
  Y2038: add type __time64_t
  Y2038: add function __difftime64
  Y2038: make __tz_convert compatible with 64-bit-time
  Y2038: add function __localtime64
  Y2038: add function __localtime64_r
  Y2038: add function __gmtime64
  Y2038: add function __gmtime64_r
  Y2038: add function __ctime64
  Y2038: add function __ctime64_r
  Y2038: implement 64-bit-time __mktime64() and timelocal()
  Y2038: implement 64-bit-time __timegm64()
  Y2038: add struct __timespec64
  Y2038: add function __clock_gettime64
  Y2038: arm: implement clock_gettime64 as a VDSO symbol
  Y2038: powerpc: implement clock_gettime64 as a VDSO symbol
  Y2038: add function __clock_settime64
  Y2038: add function __clock_getres64
  Y2038: add function __clock_nanosleep64
  Y2038: add function __timespec_get64
  Y2038: add function __futimens64
  Y2038: add function __utimensat64
  Y2038: add function __sigtimedwait64
  Y2038: add struct __timeval64
  Y2038: add function __futimes64
  Y2038: add function __lutimes64
  Y2038: add struct __itimerspec64
  Y2038: add function __timer_gettime64
  Y2038: add function __timer_settime64
  Y2038: add function __timerfd_gettime64
  Y2038: add function __timerfd_settime64
  Y2038: add struct __stat64_t64
  Y2038: add function __fstat64_t64 (and __fxstat64_t64)
  Y2038: add function __stat64_t64 (and __xstat64_t64)
  Y2038: add function __lstat64_t64 (and __lxstat64_t64)
  Y2038: add function __fstatat64_t64 (and __fxstatat_t64)
  Y2038: add function __gettimeofday64
  Y2038: add function __settimeofday64
  Y2038: add function __time64
  Y2038: add function __stime64
  Y2038: add function __utimes64
  Y2038: add function __mq_timedreceived64
  Y2038: add function __mq_timedsend64
  Y2038: add function __msgctl64
  Y2038: add function __sched_rr_get_interval64
  Y2038: add function __nanosleep64
  Y2038: add function __adjtime64
  Y2038: add function __utime64
  Y2038: add struct __itimerval64
  Y2038: add function __getitimer64
  Y2038: add function __setitimer64
  Y2038: add functions using futexes
  Y2038: add function __getrusage64
  Y2038: add struct __ntp_timeval64
  Y2038: add function __ntp_gettime64
  Y2038: add function __ntp_gettimex64
  Y2038: add struct __timex64
  Y2038: add function __adjtimex64 (and __ntp_adjtime64)
  Y2038: add function pselect64
  Y2038: add function select64
  Y2038: add function __clntudp_create64
  Y2038: add function __clntudp_bufcreate64
  Y2038: add function __pmap_rmtcall64
  Y2038: add _TIME_BITS support

 bits/typesizes.h                                   |   1 +
 include/features.h                                 |  19 +
 include/sys/select.h                               |  13 +
 include/sys/stat.h                                 |  35 ++
 include/sys/time.h                                 |   4 +
 include/time.h                                     | 188 +++++-
 include/utime.h                                    |   7 +
 io/Makefile                                        |   2 +-
 io/Versions                                        |   5 +
 io/fstat64.c                                       |   7 +
 io/fstatat64.c                                     |   7 +
 io/futimens.c                                      |   8 +
 io/lstat64.c                                       |   7 +
 io/stat64.c                                        |   7 +
 io/sys/stat.h                                      |  75 ++-
 io/utime.c                                         |  16 +
 io/utime.h                                         |  16 +-
 io/utimensat.c                                     |   9 +
 manual/creature.texi                               |  28 +
 misc/Makefile                                      |   3 +-
 misc/futimes.c                                     |   9 +
 misc/lutimes.c                                     |   8 +
 misc/sys/select.h                                  |  25 +
 misc/utimes.c                                      |  15 +
 nptl/Versions                                      |   8 +
 nptl/lll_timedlock_wait.c                          |  37 ++
 nptl/pthread_cond_wait.c                           | 285 +++++++++
 nptl/pthread_mutex_timedlock.c                     | 636 +++++++++++++++++++++
 nptl/pthread_rwlock_common.c                       | 591 +++++++++++++++++++
 nptl/pthread_rwlock_timedrdlock.c                  |  19 +
 nptl/pthread_rwlock_timedwrlock.c                  |  19 +
 nptl/sem_timedwait.c                               |  18 +
 nptl/sem_wait.c                                    |  24 +
 nptl/sem_waitcommon.c                              | 172 ++++++
 posix/Makefile                                     |   3 +-
 posix/Versions                                     |   2 +
 posix/bits/types.h                                 |   3 +-
 posix/nanosleep64.c                                |  63 ++
 posix/sched.h                                      |   9 +
 posix/sched_rr_gi64.c                              |  51 ++
 resource/Makefile                                  |   2 +-
 resource/Versions                                  |   3 +
 resource/getrusage64.c                             | 187 ++++++
 resource/sys/resource.h                            |   9 +
 rt/Makefile                                        |   6 +-
 rt/Versions                                        |   9 +
 rt/mq_timedreceive64.c                             |  46 ++
 rt/mq_timedsend64.c                                |  45 ++
 rt/mqueue.h                                        |  22 +
 rt/timerfd_gettime64.c                             |  29 +
 rt/timerfd_settime64.c                             |  30 +
 signal/signal.h                                    |  10 +
 signal/sigtimedwait.c                              |  10 +
 sunrpc/clnt_udp.c                                  |  37 ++
 sunrpc/pmap_rmt.c                                  |  23 +
 sunrpc/rpc/clnt.h                                  |  24 +
 sunrpc/rpc/pmap_clnt.h                             |  15 +
 sysdeps/nptl/aio_misc.h                            |  39 ++
 sysdeps/nptl/lowlevellock.h                        |  17 +
 sysdeps/nptl/pthread.h                             |  41 ++
 sysdeps/posix/clock_getres.c                       |  96 +++-
 sysdeps/posix/time64.c                             |  43 ++
 sysdeps/posix/utime64.c                            |  46 ++
 sysdeps/powerpc/powerpc32/backtrace.c              |   1 +
 sysdeps/pthread/aio_suspend.c                      | 164 ++++++
 sysdeps/pthread/semaphore.h                        |  10 +
 sysdeps/unix/clock_gettime.c                       |  54 ++
 sysdeps/unix/clock_settime.c                       |  56 +-
 sysdeps/unix/stime64.c                             |  47 ++
 sysdeps/unix/sysv/linux/Versions                   |   2 +
 sysdeps/unix/sysv/linux/adjtime.c                  | 124 ++++
 sysdeps/unix/sysv/linux/arm/init-first.c           |  15 +
 sysdeps/unix/sysv/linux/arm/libc-vdso.h            |   1 +
 sysdeps/unix/sysv/linux/arm/libpthread.abilist     |   4 +
 sysdeps/unix/sysv/linux/arm/librt.abilist          |   8 +
 sysdeps/unix/sysv/linux/bits/msq.h                 |  20 +
 sysdeps/unix/sysv/linux/bits/stat.h                |   6 +-
 sysdeps/unix/sysv/linux/clock_getres.c             |  60 ++
 sysdeps/unix/sysv/linux/clock_gettime.c            |  81 +++
 sysdeps/unix/sysv/linux/clock_nanosleep.c          |  42 +-
 sysdeps/unix/sysv/linux/clock_settime.c            |  60 ++
 sysdeps/unix/sysv/linux/futex-internal.h           | 123 ++++
 sysdeps/unix/sysv/linux/futimens.c                 |  48 ++
 sysdeps/unix/sysv/linux/futimes.c                  |  59 ++
 sysdeps/unix/sysv/linux/fxstat64.c                 |  50 ++
 sysdeps/unix/sysv/linux/fxstatat64.c               |  54 ++
 sysdeps/unix/sysv/linux/gettimeofday64.c           |  48 ++
 sysdeps/unix/sysv/linux/lowlevellock-futex.h       |  22 +
 sysdeps/unix/sysv/linux/lutimes.c                  |  58 ++
 sysdeps/unix/sysv/linux/lxstat64.c                 |  50 ++
 sysdeps/unix/sysv/linux/msgctl.c                   |  72 +++
 sysdeps/unix/sysv/linux/ntp_gettime.c              |  25 +
 sysdeps/unix/sysv/linux/ntp_gettimex.c             |  31 +
 sysdeps/unix/sysv/linux/powerpc/init-first.c       |  16 +
 sysdeps/unix/sysv/linux/powerpc/libc-vdso.h        |   2 +
 .../linux/powerpc/powerpc32/libpthread.abilist     |   4 +
 .../sysv/linux/powerpc/powerpc32/librt.abilist     |   8 +
 sysdeps/unix/sysv/linux/pselect.c                  |  61 ++
 sysdeps/unix/sysv/linux/select.c                   |  66 +++
 sysdeps/unix/sysv/linux/settimeofday64.c           |  39 ++
 sysdeps/unix/sysv/linux/sigtimedwait.c             |  76 +++
 sysdeps/unix/sysv/linux/sys/timerfd.h              |  19 +
 sysdeps/unix/sysv/linux/sys/timex.h                |  45 +-
 sysdeps/unix/sysv/linux/timer_gettime.c            |  22 +
 sysdeps/unix/sysv/linux/timer_settime.c            |  39 ++
 sysdeps/unix/sysv/linux/timerfd_gettime64.c        |  43 ++
 sysdeps/unix/sysv/linux/timerfd_settime64.c        |  61 ++
 sysdeps/unix/sysv/linux/timespec_get.c             |  41 ++
 sysdeps/unix/sysv/linux/utimensat.c                |  58 ++
 sysdeps/unix/sysv/linux/utimes64.c                 |  54 ++
 sysdeps/unix/sysv/linux/xstat64.c                  |  50 ++
 sysvipc/Versions                                   |   3 +
 sysvipc/sys/msg.h                                  |   9 +
 time/Makefile                                      |   3 +
 time/Versions                                      |  29 +
 time/adjtime.c                                     |  10 +
 time/bits/types/struct_itimerspec.h                |  13 +
 time/bits/types/struct_timespec.h                  |  30 +
 time/bits/types/struct_timeval.h                   |  15 +
 time/bits/types/time_t.h                           |   4 +
 time/ctime.c                                       |  10 +
 time/ctime_r.c                                     |   9 +
 time/difftime.c                                    |   9 +
 time/getitimer64.c                                 |  53 ++
 time/gettimeofday.c                                |  11 +-
 time/gmtime.c                                      |  30 +-
 time/localtime.c                                   |  32 +-
 time/mktime.c                                      | 403 +++++++++++++
 time/offtime.c                                     |   8 +-
 time/setitimer64.c                                 |  71 +++
 time/settimeofday.c                                |   8 +
 time/stime.c                                       |  17 +
 time/sys/time.h                                    |  84 +++
 time/time.c                                        |  13 +
 time/time.h                                        | 161 +++++-
 time/timegm.c                                      |  11 +
 time/tzfile.c                                      |   4 +-
 time/tzset.c                                       |  24 +-
 138 files changed, 6359 insertions(+), 57 deletions(-)
 create mode 100644 posix/nanosleep64.c
 create mode 100644 posix/sched_rr_gi64.c
 create mode 100644 resource/getrusage64.c
 create mode 100644 rt/mq_timedreceive64.c
 create mode 100644 rt/mq_timedsend64.c
 create mode 100644 rt/timerfd_gettime64.c
 create mode 100644 rt/timerfd_settime64.c
 create mode 100644 sysdeps/posix/time64.c
 create mode 100644 sysdeps/posix/utime64.c
 create mode 100644 sysdeps/unix/stime64.c
 create mode 100644 sysdeps/unix/sysv/linux/gettimeofday64.c
 create mode 100644 sysdeps/unix/sysv/linux/settimeofday64.c
 create mode 100644 sysdeps/unix/sysv/linux/timerfd_gettime64.c
 create mode 100644 sysdeps/unix/sysv/linux/timerfd_settime64.c
 create mode 100644 sysdeps/unix/sysv/linux/utimes64.c
 create mode 100644 time/getitimer64.c
 create mode 100644 time/setitimer64.c

-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  01/63] Y2038: add type __time64_t
  2018-04-18 20:18 [[PATCH RFC 2] 00/63] Make GLIBC Y2038-proof Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:18 ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:18   ` [[PATCH RFC 2] 02/63] Y2038: add function __difftime64 Albert ARIBAUD (3ADEV)
  0 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:18 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

This type is public, so that time_t can be a typedef of it
when we switch the public API to 64-bit time.

Also, provide a function to check if a __time64_t value
fits in a (32-bit) __time_t.
---
 bits/typesizes.h   | 1 +
 include/time.h     | 9 ++++++++-
 posix/bits/types.h | 3 ++-
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/bits/typesizes.h b/bits/typesizes.h
index 85eacf2518..0b6a19c230 100644
--- a/bits/typesizes.h
+++ b/bits/typesizes.h
@@ -48,6 +48,7 @@
 #define	__ID_T_TYPE		__U32_TYPE
 #define __CLOCK_T_TYPE		__SLONGWORD_TYPE
 #define __TIME_T_TYPE		__SLONGWORD_TYPE
+#define __TIME64_T_TYPE		__SQUAD_TYPE
 #define __USECONDS_T_TYPE	__U32_TYPE
 #define __SUSECONDS_T_TYPE	__SLONGWORD_TYPE
 #define __DADDR_T_TYPE		__S32_TYPE
diff --git a/include/time.h b/include/time.h
index aab26d7768..7eda265a66 100644
--- a/include/time.h
+++ b/include/time.h
@@ -3,6 +3,7 @@
 
 #ifndef _ISOMAC
 # include <bits/types/locale_t.h>
+# include <stdbool.h>
 
 extern __typeof (strftime_l) __strftime_l;
 libc_hidden_proto (__strftime_l)
@@ -97,10 +98,16 @@ extern char * __strptime_internal (const char *rp, const char *fmt,
 
 extern double __difftime (time_t time1, time_t time0);
 
-
 /* Use in the clock_* functions.  Size of the field representing the
    actual clock ID.  */
 #define CLOCK_IDFIELD_SIZE	3
 
+/* check whether a time64_t value fits in a time_t */
+static inline bool
+fits_in_time_t (__time64_t t)
+{
+  return t == (time_t) t;
+}
+
 #endif
 #endif
diff --git a/posix/bits/types.h b/posix/bits/types.h
index 5e22ce41bf..4c6553a266 100644
--- a/posix/bits/types.h
+++ b/posix/bits/types.h
@@ -155,7 +155,8 @@ __STD_TYPE __CLOCK_T_TYPE __clock_t;	/* Type of CPU usage counts.  */
 __STD_TYPE __RLIM_T_TYPE __rlim_t;	/* Type for resource measurement.  */
 __STD_TYPE __RLIM64_T_TYPE __rlim64_t;	/* Type for resource measurement (LFS).  */
 __STD_TYPE __ID_T_TYPE __id_t;		/* General type for IDs.  */
-__STD_TYPE __TIME_T_TYPE __time_t;	/* Seconds since the Epoch.  */
+__STD_TYPE __TIME_T_TYPE __time_t;	/* Seconds since the Epoch, Y2038-unsafe.  */
+__STD_TYPE __TIME64_T_TYPE __time64_t;	/* Seconds since the Epoch, Y2038-safe.  */
 __STD_TYPE __USECONDS_T_TYPE __useconds_t; /* Count of microseconds.  */
 __STD_TYPE __SUSECONDS_T_TYPE __suseconds_t; /* Signed count of microseconds.  */
 
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  02/63] Y2038: add function __difftime64
  2018-04-18 20:18 ` [[PATCH RFC 2] 01/63] Y2038: add type __time64_t Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:18   ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:18     ` [[PATCH RFC 2] 03/63] Y2038: make __tz_convert compatible with 64-bit-time Albert ARIBAUD (3ADEV)
                       ` (2 more replies)
  0 siblings, 3 replies; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:18 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

Note:

1. The implementation expects __time64_t arguments, and could,
   in theory, require 64 bits to express the difference accurately;
   but it returns a double, which only provides about 55 significant
   bits.

   We could make it return a long double, which would be more than
   enough for 64 bits accuracy. But then, existing source code which
   uses difftime, and therefore stores difftime results in doubles,
   would need to change to long doubles. However, we want 64-bit time
   support to work without any application source code change.

   Besides, 55 bits allow for counting seconds accurately over 417
   billion years, which is arguably enough for most actual uses of
   difftime.

2. The implementation is simpler than its 32-bit counterpart, as it
   assumes that all __time64_t implementations are 64-bit integers.
---
 include/time.h  | 2 ++
 time/Versions   | 3 +++
 time/difftime.c | 9 +++++++++
 3 files changed, 14 insertions(+)

diff --git a/include/time.h b/include/time.h
index 7eda265a66..ba2c67a829 100644
--- a/include/time.h
+++ b/include/time.h
@@ -98,6 +98,8 @@ extern char * __strptime_internal (const char *rp, const char *fmt,
 
 extern double __difftime (time_t time1, time_t time0);
 
+extern double __difftime64 (__time64_t time1, __time64_t time0);
+
 /* Use in the clock_* functions.  Size of the field representing the
    actual clock ID.  */
 #define CLOCK_IDFIELD_SIZE	3
diff --git a/time/Versions b/time/Versions
index fd838181e4..57314b98c8 100644
--- a/time/Versions
+++ b/time/Versions
@@ -65,4 +65,7 @@ libc {
   GLIBC_2.16 {
     timespec_get;
   }
+  GLIBC_2.27 {
+    __difftime64;
+  }
 }
diff --git a/time/difftime.c b/time/difftime.c
index 7c5dd9898b..e68b9a2c81 100644
--- a/time/difftime.c
+++ b/time/difftime.c
@@ -119,3 +119,12 @@ __difftime (time_t time1, time_t time0)
   return time1 < time0 ? - subtract (time0, time1) : subtract (time1, time0);
 }
 strong_alias (__difftime, difftime)
+
+/* Return the difference between 64-bit TIME1 and TIME0.  */
+double
+__difftime64 (__time64_t time1, __time64_t time0)
+{
+  /* Subtract the smaller integer from the larger, convert the difference to
+     double, and then negate if needed.  */
+  return time1 < time0 ? - (time0 - time1) : (time1 - time0);
+}
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  13/63] Y2038: add function __clock_gettime64
  2018-04-18 20:19                       ` [[PATCH RFC 2] 12/63] Y2038: add struct __timespec64 Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:19                         ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:19                           ` [[PATCH RFC 2] 14/63] Y2038: arm: implement clock_gettime64 as a VDSO symbol Albert ARIBAUD (3ADEV)
  0 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:19 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

The Unix implementation uses 32-bit calls and converts to
64-bit time.

The Linux implementation uses the 64-bit time syscall if
available, otherwise it falls back to 32-bit syscall and
conversion.

This implementation depends on the clock_gettime64 syscall
being provided in the kernel headers at build time.
---
 include/time.h                          |  8 ++++
 sysdeps/unix/clock_gettime.c            | 54 ++++++++++++++++++++++
 sysdeps/unix/sysv/linux/clock_gettime.c | 81 +++++++++++++++++++++++++++++++++
 time/Versions                           |  3 ++
 4 files changed, 146 insertions(+)

diff --git a/include/time.h b/include/time.h
index 16286178e1..e085fa5162 100644
--- a/include/time.h
+++ b/include/time.h
@@ -21,6 +21,11 @@ libc_hidden_proto (strptime)
 
 libc_hidden_proto (__localtime64)
 
+/* Indicates whether the underlying kernel has 64-bit time support.
+   This is required for e.g. librt, which cannot directly check the
+   flag variable that init-first.c sets when detecting support. */
+extern int __y2038_kernel_support (void);
+
 extern __typeof (clock_getres) __clock_getres;
 extern __typeof (clock_gettime) __clock_gettime;
 libc_hidden_proto (__clock_gettime)
@@ -28,6 +33,9 @@ extern __typeof (clock_settime) __clock_settime;
 extern __typeof (clock_nanosleep) __clock_nanosleep;
 extern __typeof (clock_getcpuclockid) __clock_getcpuclockid;
 
+extern int __clock_gettime64 (clockid_t __clock_id,
+			      struct __timespec64 *__tp) __THROW;
+
 /* Now define the internal interfaces.  */
 struct tm;
 
diff --git a/sysdeps/unix/clock_gettime.c b/sysdeps/unix/clock_gettime.c
index 96df78ab1e..f8e96487e3 100644
--- a/sysdeps/unix/clock_gettime.c
+++ b/sysdeps/unix/clock_gettime.c
@@ -134,3 +134,57 @@ __clock_gettime (clockid_t clock_id, struct timespec *tp)
 }
 weak_alias (__clock_gettime, clock_gettime)
 libc_hidden_def (__clock_gettime)
+
+/* Get current value of CLOCK and store it in TP, 64-bit version.  */
+int
+__clock_gettime64 (clockid_t clock_id, struct __timespec64 *tp)
+{
+  int retval = -1;
+#if HP_TIMING_AVAIL || !defined HANDLED_REALTIME
+  struct timeval tv32;
+#endif
+
+  switch (clock_id)
+    {
+#ifdef SYSDEP_GETTIME64
+      SYSDEP_GETTIME64;
+#endif
+
+#ifndef HANDLED_REALTIME
+    case CLOCK_REALTIME:
+      {
+	retval = gettimeofday (&tv32, NULL);
+	if (retval == 0)
+	  valid_timeval_to_timespec64 (&tv32, tp);
+      }
+      break;
+#endif
+
+    default:
+#ifdef SYSDEP_GETTIME64_CPU
+      SYSDEP_GETTIME64_CPU (clock_id, tp);
+#endif
+#if HP_TIMING_AVAIL
+      if ((clock_id & ((1 << CLOCK_IDFIELD_SIZE) - 1))
+	  == CLOCK_THREAD_CPUTIME_ID)
+        {
+	  retval = hp_timing_gettime (clock_id, &tv32);
+          if (retval == 0)
+            valid_timeval_to_timespec64 (&tv32, tp);
+        }
+      else
+#endif
+	__set_errno (EINVAL);
+      break;
+
+#if HP_TIMING_AVAIL && !defined HANDLED_CPUTIME
+    case CLOCK_PROCESS_CPUTIME_ID:
+      retval = hp_timing_gettime (clock_id, &tv32);
+      if (retval == 0)
+        valid_timeval_to_timespec64 (&tv32, tp);
+      break;
+#endif
+    }
+
+  return retval;
+}
diff --git a/sysdeps/unix/sysv/linux/clock_gettime.c b/sysdeps/unix/sysv/linux/clock_gettime.c
index d837fa36b1..a0da479ea6 100644
--- a/sysdeps/unix/sysv/linux/clock_gettime.c
+++ b/sysdeps/unix/sysv/linux/clock_gettime.c
@@ -44,4 +44,85 @@
   break
 #define SYSDEP_GETTIME_CPUTIME	/* Default catches them too.  */
 
+/* 64-bit versions */
+
+/* Check that we are builing on a 64-bit-time kernel, otherwise
+   clock_gettime64 syscall will fail to compile */
+#ifdef __NR_clock_gettime64
+
+/* The REALTIME and MONOTONIC clock are definitely supported in the
+   kernel.  */
+#define SYSDEP_GETTIME64 \
+  SYSDEP_GETTIME64_CPUTIME;						      \
+  case CLOCK_REALTIME:							      \
+  case CLOCK_MONOTONIC:							      \
+    if (__y2038_linux_support)						      \
+      {									      \
+        retval = INLINE_VSYSCALL (clock_gettime64, 2, clock_id, tp);	      \
+      }									      \
+    else								      \
+      {									      \
+        retval = -1;                                                          \
+        __set_errno(ENOSYS);                                                  \
+      }									      \
+    if (retval == -1 && errno == ENOSYS)				      \
+      {									      \
+        retval = INLINE_VSYSCALL (clock_gettime, 2, clock_id, &ts32);	      \
+        if (retval==0)							      \
+          {								      \
+            valid_timespec_to_timespec64(&ts32, tp);			      \
+          }								      \
+      }									      \
+    break
+
+#define SYSDEP_GETTIME64_CPU(clock_id, tp) \
+  if (__y2038_linux_support)						      \
+    {									      \
+      retval = INLINE_VSYSCALL (clock_gettime64, 2, clock_id, tp);	      \
+    }									      \
+  else								              \
+    {									      \
+      retval = -1;                                                            \
+      __set_errno(ENOSYS);                                                    \
+    }									      \
+  if (retval == -1 && errno == ENOSYS)  			              \
+    {									      \
+      retval = INLINE_VSYSCALL (clock_gettime, 2, clock_id, &ts32);	      \
+      if (retval==0)							      \
+        {								      \
+          valid_timespec_to_timespec64(&ts32, tp);			      \
+        }								      \
+    }									      \
+  break
+#define SYSDEP_GETTIME64_CPUTIME \
+  struct timespec ts32;							      \
+  extern int __y2038_linux_support;
+
+#else
+
+/* The REALTIME and MONOTONIC clock are definitely supported in the
+   kernel.  */
+#define SYSDEP_GETTIME64 \
+  SYSDEP_GETTIME64_CPUTIME;						      \
+  case CLOCK_REALTIME:							      \
+  case CLOCK_MONOTONIC:							      \
+    retval = INLINE_VSYSCALL (clock_gettime, 2, clock_id, &ts32);	      \
+    if (retval==0)							      \
+      {								      \
+        valid_timespec_to_timespec64(&ts32, tp);			      \
+      }								      \
+    break
+
+#define SYSDEP_GETTIME64_CPU(clock_id, tp) \
+  retval = INLINE_VSYSCALL (clock_gettime, 2, clock_id, &ts32);	      \
+  if (retval==0)							      \
+    {								      \
+      valid_timespec_to_timespec64(&ts32, tp);			      \
+    }								      \
+  break
+#define SYSDEP_GETTIME64_CPUTIME \
+  struct timespec ts32;							      \
+
+#endif
+
 #include <sysdeps/unix/clock_gettime.c>
diff --git a/time/Versions b/time/Versions
index 7cfae8760c..27c46fc023 100644
--- a/time/Versions
+++ b/time/Versions
@@ -72,5 +72,8 @@ libc {
     __localtime64; __localtime64_r;
     __mktime64; __timelocal64_r;
     __timegm64;
+    __clock_gettime64;
+    __vdso_clock_gettime64;
+    __y2038_kernel_support;
   }
 }
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  12/63] Y2038: add struct __timespec64
  2018-04-18 20:19                     ` [[PATCH RFC 2] 11/63] Y2038: implement 64-bit-time __timegm64() Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:19                       ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:19                         ` [[PATCH RFC 2] 13/63] Y2038: add function __clock_gettime64 Albert ARIBAUD (3ADEV)
  0 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:19 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

To be Y2038-proof, struct __timespec64 needs its tv_sec field to
be a __time64_t rather than a __time_t. However, the question is
which type should the tv_nsec field be.

Keeping tv_nsec a long (32-bit) would be compatible with Posix
requirements but would result in the GLIBC struct timespec being
binary-incompatible with the Linux 64-bit struct timespec, which
contains a 64-bit, not 32-bit, signed tv_nsec field.

In order to maintain Posix compatibility yet simplify conversion
between Posix and Linux struct timespec values, the Y2038-proof
struct time stores its tv_nsec field as a 32-bit signed integer
plus a padding which can serve as a 64-bit sign extension. This
both meets Posix requirements and makes the GLIBC and Linux
struct timespec binary compatible.

Note that in the API (which is not modified here, and will be
later alongside all Y2038-sensitive APIs), this padding is made
'invisible' by defining it as an anonymous bitfield, whereas
the struct __timespec64 introduced here has a named field for
the padding, allowing implementations to read and write it.

Also, provide static inline functions and macros for checking
and converting between 32-bit and 64-bit timespecs.
---
 include/time.h                    | 49 +++++++++++++++++++++++++++++++++++++++
 time/bits/types/struct_timespec.h | 23 ++++++++++++++++++
 2 files changed, 72 insertions(+)

diff --git a/include/time.h b/include/time.h
index d74f66e7c6..16286178e1 100644
--- a/include/time.h
+++ b/include/time.h
@@ -130,5 +130,54 @@ fits_in_time_t (__time64_t t)
   return t == (time_t) t;
 }
 
+/* convert a known valid struct timespec into a struct __timespec64 */
+static inline void
+valid_timespec_to_timespec64(const struct timespec *ts32,
+			     struct __timespec64 *ts64)
+{
+  ts64->tv_sec = ts32->tv_sec;
+  ts64->tv_nsec = ts32->tv_nsec;
+  /* we only need to zero ts64->tv_pad if we pass it to the kernel */
+}
+
+/* convert a known valid struct __timespec64 into a struct timespec */
+static inline void
+valid_timespec64_to_timespec(const struct __timespec64 *ts64,
+			     struct timespec *ts32)
+{
+  ts32->tv_sec = (time_t) ts64->tv_sec;
+  ts32->tv_nsec = ts64->tv_nsec;
+}
+
+/* check if a value lies with the valid nanoseconds range */
+#define IS_VALID_NANOSECONDS(ns) (ns >= 0 && ns <= 999999999)
+
+/* check and convert a struct timespec into a struct __timespec64 */
+static inline bool timespec_to_timespec64(const struct timespec *ts32,
+					  struct __timespec64 *ts64)
+{
+  /* check that ts32 holds a valid count of nanoseconds */
+  if (! IS_VALID_NANOSECONDS(ts32->tv_nsec))
+    return false;
+  /* all ts32 fields can fit in ts64, so copy them */
+  valid_timespec_to_timespec64(ts32, ts64);
+  /* we only need to zero ts64->tv_pad if we pass it to the kernel */
+  return true;
+}
+
+/* check and convert a struct __timespec64 into a struct timespec */
+static inline bool timespec64_to_timespec(const struct __timespec64 *ts64,
+					  struct timespec *ts32)
+{
+  /* check that tv_nsec holds a valid count of nanoseconds */
+  if (! IS_VALID_NANOSECONDS(ts64->tv_nsec))
+    return false;
+  /* check that tv_sec can fit in a __time_t */
+  if (! fits_in_time_t(ts64->tv_sec))
+    return false;
+  /* all ts64 fields can fit in ts32, so copy them */
+  valid_timespec64_to_timespec(ts64, ts32);
+  return true;
+}
 #endif
 #endif
diff --git a/time/bits/types/struct_timespec.h b/time/bits/types/struct_timespec.h
index 644db9fdb6..7461ac0836 100644
--- a/time/bits/types/struct_timespec.h
+++ b/time/bits/types/struct_timespec.h
@@ -2,6 +2,7 @@
 #define __timespec_defined 1
 
 #include <bits/types.h>
+#include <endian.h>
 
 /* POSIX.1b structure for a time value.  This is like a `struct timeval' but
    has nanoseconds instead of microseconds.  */
@@ -11,4 +12,26 @@ struct timespec
   __syscall_slong_t tv_nsec;	/* Nanoseconds.  */
 };
 
+/* 64-bit time version. To keep tings Posix-ish, we keep the nanoseconds
+   field a signed long, but since Linux has a 64-bit signed int, we pad it
+   with a 32-bit int, which should always be 0.
+   Note that the public type has an anonymous bitfield as padding, so that
+   it cannot be written into (or read from). */ 
+#if BYTE_ORDER == BIG_ENDIAN
+struct __timespec64
+{
+  __time64_t tv_sec;		/* Seconds */
+  int tv_pad: 32;		/* Padding named for checking/setting */
+  __syscall_slong_t tv_nsec;	/* Nanoseconds */
+};
+#else
+struct __timespec64
+{
+  __time64_t tv_sec;		/* Seconds */
+  __syscall_slong_t tv_nsec;	/* Nanoseconds */
+  int tv_pad: 32;		/* Padding named for checking/setting */
+};
+
+#endif
+
 #endif
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  17/63] Y2038: add function __clock_getres64
  2018-04-18 20:19                               ` [[PATCH RFC 2] 16/63] Y2038: add function __clock_settime64 Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:19                                 ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:19                                   ` [[PATCH RFC 2] 18/63] Y2038: add function __clock_nanosleep64 Albert ARIBAUD (3ADEV)
  0 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:19 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

---
 include/time.h                         |  2 +
 sysdeps/posix/clock_getres.c           | 96 +++++++++++++++++++++++++++++++++-
 sysdeps/unix/sysv/linux/clock_getres.c | 60 +++++++++++++++++++++
 time/Versions                          |  1 +
 4 files changed, 158 insertions(+), 1 deletion(-)

diff --git a/include/time.h b/include/time.h
index 8101b638c6..37909fae9a 100644
--- a/include/time.h
+++ b/include/time.h
@@ -37,6 +37,8 @@ extern int __clock_gettime64 (clockid_t __clock_id,
 			      struct __timespec64 *__tp) __THROW;
 extern int __clock_settime64 (clockid_t __clock_id,
 			       const struct __timespec64 *__tp) __THROW;
+extern int __clock_getres64 (clockid_t __clock_id,
+			      struct __timespec64 *__res) __THROW;
 
 /* Now define the internal interfaces.  */
 struct tm;
diff --git a/sysdeps/posix/clock_getres.c b/sysdeps/posix/clock_getres.c
index e7924e0891..28b16a6529 100644
--- a/sysdeps/posix/clock_getres.c
+++ b/sysdeps/posix/clock_getres.c
@@ -23,7 +23,6 @@
 #include <sys/param.h>
 #include <libc-internal.h>
 
-
 #if HP_TIMING_AVAIL
 static long int nsec;		/* Clock frequency of the processor.  */
 
@@ -53,6 +52,33 @@ hp_timing_getres (struct timespec *res)
 
   return 0;
 }
+
+static int
+hp_timing_getres64 (struct __timespec64 *res)
+{
+  if (__glibc_unlikely (nsec == 0))
+    {
+      hp_timing_t freq;
+
+      /* This can only happen if we haven't initialized the `nsec'
+	 variable yet.  Do this now.  We don't have to protect this
+	 code against multiple execution since all of them should
+	 lead to the same result.  */
+      freq = __get_clockfreq ();
+      if (__glibc_unlikely (freq == 0))
+	/* Something went wrong.  */
+	return -1;
+
+      nsec = MAX (UINT64_C (1000000000) / freq, 1);
+    }
+
+  /* Fill in the values.
+     The seconds are always zero (unless we have a 1Hz machine).  */
+  res->tv_sec = 0;
+  res->tv_nsec = nsec;
+
+  return 0;
+}
 #endif
 
 static inline int
@@ -73,6 +99,28 @@ realtime_getres (struct timespec *res)
   return -1;
 }
 
+/* Check that we are built with a 64-bit-time kernel */
+#ifdef __NR_clock_getres64
+
+static inline int
+realtime_getres64 (struct __timespec64 *res)
+{
+  long int clk_tck = sysconf (_SC_CLK_TCK);
+
+  if (__glibc_likely (clk_tck != -1))
+    {
+      /* This implementation assumes that the realtime clock has a
+	 resolution higher than 1 second.  This is the case for any
+	 reasonable implementation.  */
+      res->tv_sec = 0;
+      res->tv_nsec = 1000000000 / clk_tck;
+      return 0;
+    }
+
+  return -1;
+}
+
+#endif
 
 /* Get resolution of clock.  */
 int
@@ -116,3 +164,49 @@ __clock_getres (clockid_t clock_id, struct timespec *res)
   return retval;
 }
 weak_alias (__clock_getres, clock_getres)
+
+int
+__clock_getres64 (clockid_t clock_id, struct __timespec64 *res)
+{
+  int retval = -1;
+
+  switch (clock_id)
+    {
+#ifdef SYSDEP_GETRES64
+      SYSDEP_GETRES64;
+#endif
+
+/* Check that we are built with a 64-bit-time kernel */
+#ifdef __NR_clock_getres64
+
+# ifndef HANDLED_REALTIME64
+    case CLOCK_REALTIME64:
+      retval = realtime_getres64 (res);
+      break;
+# endif	/* handled REALTIME */
+
+#endif
+
+    default:
+#ifdef SYSDEP_GETRES_CPU64
+      SYSDEP_GETRES_CPU64;
+#endif
+#if HP_TIMING_AVAIL
+      if ((clock_id & ((1 << CLOCK_IDFIELD_SIZE) - 1))
+	  == CLOCK_THREAD_CPUTIME_ID)
+	retval = hp_timing_getres64 (res);
+      else
+#endif
+	__set_errno (EINVAL);
+      break;
+
+#if HP_TIMING_AVAIL && !defined HANDLED_CPUTIME
+    case CLOCK_PROCESS_CPUTIME_ID:
+    case CLOCK_THREAD_CPUTIME_ID:
+      retval = hp_timing_getres64 (res);
+      break;
+#endif
+    }
+
+  return retval;
+}
diff --git a/sysdeps/unix/sysv/linux/clock_getres.c b/sysdeps/unix/sysv/linux/clock_getres.c
index 5d94f59afe..ecea873afe 100644
--- a/sysdeps/unix/sysv/linux/clock_getres.c
+++ b/sysdeps/unix/sysv/linux/clock_getres.c
@@ -48,4 +48,64 @@
 #define SYSDEP_GETRES_CPU SYSCALL_GETRES
 #define SYSDEP_GETRES_CPUTIME	/* Default catches them too.  */
 
+/* The 64-bit version */
+
+/* Check that we are built with a 64-bit-time kernel */
+#ifdef __NR_clock_getres64
+
+extern int __y2038_linux_support;
+
+#define SYSCALL_GETRES64 \
+  if (__y2038_linux_support)						      \
+    {									      \
+      retval = INLINE_VSYSCALL (clock_getres64, 2, clock_id, res);  	      \
+    }									      \
+  else									      \
+    {									      \
+      retval = -1;                                                 	      \
+      errno = ENOSYS;                                                 	      \
+    }									      \
+  if (retval == -1 && errno == ENOSYS)					      \
+    {									      \
+      retval = INLINE_VSYSCALL (clock_getres, 2, clock_id, &ts32);	      \
+        if (retval==0)							      \
+        {								      \
+          timespec_to_timespec64(&ts32, res);	                	      \
+          res->tv_pad = 0;				               	      \
+        }								      \
+    }									      \
+  break
+
+#else
+
+#define SYSCALL_GETRES64 \
+  retval = INLINE_VSYSCALL (clock_getres, 2, clock_id, &ts32);	      \
+    if (retval==0)							      \
+    {								      \
+      timespec_to_timespec64(&ts32, res);	                	      \
+      res->tv_pad = 0;				               	      \
+    }								      \
+  break
+
+#endif
+
+/* The REALTIME and MONOTONIC clock are definitely supported in the
+   kernel.  */
+#define SYSDEP_GETRES64							      \
+  SYSDEP_GETRES_CPUTIME64						      \
+  case CLOCK_REALTIME:							      \
+  case CLOCK_MONOTONIC:							      \
+  case CLOCK_MONOTONIC_RAW:						      \
+  case CLOCK_REALTIME_COARSE:						      \
+  case CLOCK_MONOTONIC_COARSE:						      \
+    SYSCALL_GETRES64
+
+/* We handled the REALTIME clock here.  */
+#define HANDLED_REALTIME64	1
+#define HANDLED_CPUTIME64	1
+
+#define SYSDEP_GETRES_CPU64 SYSCALL_GETRES64
+#define SYSDEP_GETRES_CPUTIME64 \
+  struct timespec ts32;
+
 #include <sysdeps/posix/clock_getres.c>
diff --git a/time/Versions b/time/Versions
index a00184daae..98ac0abfbe 100644
--- a/time/Versions
+++ b/time/Versions
@@ -76,5 +76,6 @@ libc {
     __vdso_clock_gettime64;
     __y2038_kernel_support;
     __clock_settime64;
+    __clock_getres64;
   }
 }
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  10/63] Y2038: implement 64-bit-time __mktime64() and timelocal()
  2018-04-18 20:19                 ` [[PATCH RFC 2] 09/63] Y2038: add function __ctime64_r Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:19                   ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:19                     ` [[PATCH RFC 2] 11/63] Y2038: implement 64-bit-time __timegm64() Albert ARIBAUD (3ADEV)
  2018-04-18 21:51                     ` [[PATCH RFC 2] 10/63] Y2038: implement 64-bit-time __mktime64() and timelocal() Joseph Myers
  0 siblings, 2 replies; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:19 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

__mktime64 is designed similar to mktime, including checks on (64-bit)
integer limits, and respects the same Posix requirements as __mktime does,
i.e. calls tzset().

timelocal is a macro which evaluates to mktime, so when APIs are enabled,
both mktime and timelocal will become Y2038-proof.
---
 include/time.h |   9 ++
 time/Versions  |   1 +
 time/mktime.c  | 403 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 413 insertions(+)

diff --git a/include/time.h b/include/time.h
index b0a1199308..d74f66e7c6 100644
--- a/include/time.h
+++ b/include/time.h
@@ -61,6 +61,15 @@ extern time_t __mktime_internal (struct tm *__tp,
 				 struct tm *(*__func) (const time_t *,
 						       struct tm *),
 				 time_t *__offset) attribute_hidden;
+
+/* Subroutine of `__mktime64'.  Return the `__time64_t' representation of TP and
+   normalize TP, given that a `struct tm *' maps to a `__time64_t' as performed
+   by FUNC.  Keep track of next guess for __time64_t offset in *OFFSET.  */
+extern __time64_t __mktime64_internal (struct tm *__tp,
+				 struct tm *(*__func) (const __time64_t *,
+						       struct tm *),
+				 __time64_t *__offset) attribute_hidden;
+
 extern struct tm *__localtime_r (const time_t *__timer,
 				 struct tm *__tp) attribute_hidden;
 
diff --git a/time/Versions b/time/Versions
index 0ad2749f2c..f5ccacc759 100644
--- a/time/Versions
+++ b/time/Versions
@@ -70,5 +70,6 @@ libc {
     __ctime64; __ctime64_r;
     __gmtime64; __gmtime64_r;
     __localtime64; __localtime64_r;
+    __mktime64; __timelocal64_r;
   }
 }
diff --git a/time/mktime.c b/time/mktime.c
index 5f038a212f..d85a2a3704 100644
--- a/time/mktime.c
+++ b/time/mktime.c
@@ -599,6 +599,409 @@ weak_alias (mktime, timelocal)
 libc_hidden_def (mktime)
 libc_hidden_weak (timelocal)
 #endif
+
+/* Return an integer value measuring (YEAR1-YDAY1 HOUR1:MIN1:SEC1) -
+   (YEAR0-YDAY0 HOUR0:MIN0:SEC0) in seconds, assuming that the clocks
+   were not adjusted between the time stamps.
+
+   The YEAR values uses the same numbering as TP->tm_year.  Values
+   need not be in the usual range.  However, YEAR1 must not be less
+   than 2 * INT_MIN or greater than 2 * INT_MAX.
+
+   The result may overflow.  It is the caller's responsibility to
+   detect overflow.  */
+
+static __time64_t
+ydhms64_diff (long_int year1, long_int yday1, int hour1, int min1, int sec1,
+	    int year0, int yday0, int hour0, int min0, int sec0)
+{
+  verify (C99_integer_division, -1 / 2 == 0);
+
+  /* Compute intervening leap days correctly even if year is negative.
+     Take care to avoid integer overflow here.  */
+  int a4 = SHR (year1, 2) + SHR (TM_YEAR_BASE, 2) - ! (year1 & 3);
+  int b4 = SHR (year0, 2) + SHR (TM_YEAR_BASE, 2) - ! (year0 & 3);
+  int a100 = a4 / 25 - (a4 % 25 < 0);
+  int b100 = b4 / 25 - (b4 % 25 < 0);
+  int a400 = SHR (a100, 2);
+  int b400 = SHR (b100, 2);
+  int intervening_leap_days = (a4 - b4) - (a100 - b100) + (a400 - b400);
+
+  /* Compute the desired time in __time64_t precision.  Overflow might
+     occur here.  */
+  __time64_t tyear1 = year1;
+  __time64_t years = tyear1 - year0;
+  __time64_t days = 365 * years + yday1 - yday0 + intervening_leap_days;
+  __time64_t hours = 24 * days + hour1 - hour0;
+  __time64_t minutes = 60 * hours + min1 - min0;
+  __time64_t seconds = 60 * minutes + sec1 - sec0;
+  return seconds;
+}
+
+/* Return the average of A and B, even if A + B would overflow.  */
+static __time64_t
+time64_t_avg (__time64_t a, __time64_t b)
+{
+  return SHR (a, 1) + SHR (b, 1) + (a & b & 1);
+}
+
+/* Return 1 if A + B does not overflow.  If __time64_t is unsigned and if
+   B's top bit is set, assume that the sum represents A - -B, and
+   return 1 if the subtraction does not wrap around.  */
+static int
+time64_t_add_ok (__time64_t a, __time64_t b)
+{
+  if (! TYPE_SIGNED (__time64_t))
+    {
+      __time64_t sum = a + b;
+      return (sum < a) == (TIME_T_MIDPOINT <= b);
+    }
+  else if (WRAPV)
+    {
+      __time64_t sum = a + b;
+      return (sum < a) == (b < 0);
+    }
+  else
+    {
+      __time64_t avg = time64_t_avg (a, b);
+      return TIME_T_MIN / 2 <= avg && avg <= TIME_T_MAX / 2;
+    }
+}
+
+/* Return 1 if A + B does not overflow.  */
+static int
+time64_t_int_add_ok (__time64_t a, int b)
+{
+  verify (int_no_wider_than_time64_t, INT_MAX <= TIME_T_MAX);
+  if (WRAPV)
+    {
+      __time64_t sum = a + b;
+      return (sum < a) == (b < 0);
+    }
+  else
+    {
+      int a_odd = a & 1;
+      __time64_t avg = SHR (a, 1) + (SHR (b, 1) + (a_odd & b));
+      return TIME_T_MIN / 2 <= avg && avg <= TIME_T_MAX / 2;
+    }
+}
+
+/* Return a __time64_t value corresponding to (YEAR-YDAY HOUR:MIN:SEC),
+   assuming that *T corresponds to *TP and that no clock adjustments
+   occurred between *TP and the desired time.
+   If TP is null, return a value not equal to *T; this avoids false matches.
+   If overflow occurs, yield the minimal or maximal value, except do not
+   yield a value equal to *T.  */
+static __time64_t
+guess_time64_tm (long_int year, long_int yday, int hour, int min, int sec,
+	       const __time64_t *t, const struct tm *tp)
+{
+  if (tp)
+    {
+      __time64_t d = ydhms64_diff (year, yday, hour, min, sec,
+			     tp->tm_year, tp->tm_yday,
+			     tp->tm_hour, tp->tm_min, tp->tm_sec);
+      if (time64_t_add_ok (*t, d))
+	return *t + d;
+    }
+
+  /* Overflow occurred one way or another.  Return the nearest result
+     that is actually in range, except don't report a zero difference
+     if the actual difference is nonzero, as that would cause a false
+     match; and don't oscillate between two values, as that would
+     confuse the spring-forward gap detector.  */
+  return (*t < TIME_T_MIDPOINT
+	  ? (*t <= TIME_T_MIN + 1 ? *t + 1 : TIME_T_MIN)
+	  : (TIME_T_MAX - 1 <= *t ? *t - 1 : TIME_T_MAX));
+}
+
+/* Use CONVERT to convert *T to a broken down time in *TP.
+   If *T is out of range for conversion, adjust it so that
+   it is the nearest in-range value and then convert that.  */
+static struct tm *
+ranged64_convert (struct tm *(*convert) (const __time64_t *, struct tm *),
+		__time64_t *t, struct tm *tp)
+{
+  struct tm *r = convert (t, tp);
+
+  if (!r && *t)
+    {
+      __time64_t bad = *t;
+      __time64_t ok = 0;
+
+      /* BAD is a known unconvertible __time64_t, and OK is a known good one.
+	 Use binary search to narrow the range between BAD and OK until
+	 they differ by 1.  */
+      while (bad != ok + (bad < 0 ? -1 : 1))
+	{
+	  __time64_t mid = *t = time64_t_avg (ok, bad);
+	  r = convert (t, tp);
+	  if (r)
+	    ok = mid;
+	  else
+	    bad = mid;
+	}
+
+      if (!r && ok)
+	{
+	  /* The last conversion attempt failed;
+	     revert to the most recent successful attempt.  */
+	  *t = ok;
+	  r = convert (t, tp);
+	}
+    }
+
+  return r;
+}
+
+
+/* Convert *TP to a __time64_t value, inverting
+   the monotonic and mostly-unit-linear conversion function CONVERT.
+   Use *OFFSET to keep track of a guess at the offset of the result,
+   compared to what the result would be for UTC without leap seconds.
+   If *OFFSET's guess is correct, only one CONVERT call is needed.
+   This function is external because it is used also by timegm.c.  */
+__time64_t
+__mktime64_internal (struct tm *tp,
+		   struct tm *(*convert) (const __time64_t *, struct tm *),
+		   __time64_t *offset)
+{
+  __time64_t t, gt, t0, t1, t2;
+  struct tm tm;
+
+  /* The maximum number of probes (calls to CONVERT) should be enough
+     to handle any combinations of time zone rule changes, solar time,
+     leap seconds, and oscillations around a spring-forward gap.
+     POSIX.1 prohibits leap seconds, but some hosts have them anyway.  */
+  int remaining_probes = 6;
+
+  /* Time requested.  Copy it in case CONVERT modifies *TP; this can
+     occur if TP is localtime's returned value and CONVERT is localtime.  */
+  int sec = tp->tm_sec;
+  int min = tp->tm_min;
+  int hour = tp->tm_hour;
+  int mday = tp->tm_mday;
+  int mon = tp->tm_mon;
+  int year_requested = tp->tm_year;
+  int isdst = tp->tm_isdst;
+
+  /* 1 if the previous probe was DST.  */
+  int dst2;
+
+  /* Ensure that mon is in range, and set year accordingly.  */
+  int mon_remainder = mon % 12;
+  int negative_mon_remainder = mon_remainder < 0;
+  int mon_years = mon / 12 - negative_mon_remainder;
+  long_int lyear_requested = year_requested;
+  long_int year = lyear_requested + mon_years;
+
+  /* The other values need not be in range:
+     the remaining code handles minor overflows correctly,
+     assuming int and __time64_t arithmetic wraps around.
+     Major overflows are caught at the end.  */
+
+  /* Calculate day of year from year, month, and day of month.
+     The result need not be in range.  */
+  int mon_yday = ((__mon_yday[leapyear (year)]
+		   [mon_remainder + 12 * negative_mon_remainder])
+		  - 1);
+  long_int lmday = mday;
+  long_int yday = mon_yday + lmday;
+
+  __time64_t guessed_offset = *offset;
+
+  int sec_requested = sec;
+
+  if (LEAP_SECONDS_POSSIBLE)
+    {
+      /* Handle out-of-range seconds specially,
+	 since ydhms_tm_diff assumes every minute has 60 seconds.  */
+      if (sec < 0)
+	sec = 0;
+      if (59 < sec)
+	sec = 59;
+    }
+
+  /* Invert CONVERT by probing.  First assume the same offset as last
+     time.  */
+
+  t0 = ydhms64_diff (year, yday, hour, min, sec,
+		   EPOCH_YEAR - TM_YEAR_BASE, 0, 0, 0, - guessed_offset);
+
+  if (TIME_T_MAX / INT_MAX / 366 / 24 / 60 / 60 < 3)
+    {
+      /* __time64_t isn't large enough to rule out overflows, so check
+	 for major overflows.  A gross check suffices, since if t0
+	 has overflowed, it is off by a multiple of TIME_T_MAX -
+	 TIME_T_MIN + 1.  So ignore any component of the difference
+	 that is bounded by a small value.  */
+
+      /* Approximate log base 2 of the number of time units per
+	 biennium.  A biennium is 2 years; use this unit instead of
+	 years to avoid integer overflow.  For example, 2 average
+	 Gregorian years are 2 * 365.2425 * 24 * 60 * 60 seconds,
+	 which is 63113904 seconds, and rint (log2 (63113904)) is
+	 26.  */
+      int ALOG2_SECONDS_PER_BIENNIUM = 26;
+      int ALOG2_MINUTES_PER_BIENNIUM = 20;
+      int ALOG2_HOURS_PER_BIENNIUM = 14;
+      int ALOG2_DAYS_PER_BIENNIUM = 10;
+      int LOG2_YEARS_PER_BIENNIUM = 1;
+
+      int approx_requested_biennia =
+	(SHR (year_requested, LOG2_YEARS_PER_BIENNIUM)
+	 - SHR (EPOCH_YEAR - TM_YEAR_BASE, LOG2_YEARS_PER_BIENNIUM)
+	 + SHR (mday, ALOG2_DAYS_PER_BIENNIUM)
+	 + SHR (hour, ALOG2_HOURS_PER_BIENNIUM)
+	 + SHR (min, ALOG2_MINUTES_PER_BIENNIUM)
+	 + (LEAP_SECONDS_POSSIBLE
+	    ? 0
+	    : SHR (sec, ALOG2_SECONDS_PER_BIENNIUM)));
+
+      int approx_biennia = SHR (t0, ALOG2_SECONDS_PER_BIENNIUM);
+      int diff = approx_biennia - approx_requested_biennia;
+      int approx_abs_diff = diff < 0 ? -1 - diff : diff;
+
+      /* IRIX 4.0.5 cc miscalculates TIME_T_MIN / 3: it erroneously
+	 gives a positive value of 715827882.  Setting a variable
+	 first then doing math on it seems to work.
+	 (ghazi@caip.rutgers.edu) */
+      __time64_t time64_t_max = TIME_T_MAX;
+      __time64_t time64_t_min = TIME_T_MIN;
+      __time64_t overflow_threshold =
+	(time64_t_max / 3 - time64_t_min / 3) >> ALOG2_SECONDS_PER_BIENNIUM;
+
+      if (overflow_threshold < approx_abs_diff)
+	{
+	  /* Overflow occurred.  Try repairing it; this might work if
+	     the time zone offset is enough to undo the overflow.  */
+	  __time64_t repaired_t0 = -1 - t0;
+	  approx_biennia = SHR (repaired_t0, ALOG2_SECONDS_PER_BIENNIUM);
+	  diff = approx_biennia - approx_requested_biennia;
+	  approx_abs_diff = diff < 0 ? -1 - diff : diff;
+	  if (overflow_threshold < approx_abs_diff)
+	    return -1;
+	  guessed_offset += repaired_t0 - t0;
+	  t0 = repaired_t0;
+	}
+    }
+
+  /* Repeatedly use the error to improve the guess.  */
+
+  for (t = t1 = t2 = t0, dst2 = 0;
+       (gt = guess_time64_tm (year, yday, hour, min, sec, &t,
+			    ranged64_convert (convert, &t, &tm)),
+	t != gt);
+       t1 = t2, t2 = t, t = gt, dst2 = tm.tm_isdst != 0)
+    if (t == t1 && t != t2
+	&& (tm.tm_isdst < 0
+	    || (isdst < 0
+		? dst2 <= (tm.tm_isdst != 0)
+		: (isdst != 0) != (tm.tm_isdst != 0))))
+      /* We can't possibly find a match, as we are oscillating
+	 between two values.  The requested time probably falls
+	 within a spring-forward gap of size GT - T.  Follow the common
+	 practice in this case, which is to return a time that is GT - T
+	 away from the requested time, preferring a time whose
+	 tm_isdst differs from the requested value.  (If no tm_isdst
+	 was requested and only one of the two values has a nonzero
+	 tm_isdst, prefer that value.)  In practice, this is more
+	 useful than returning -1.  */
+      goto offset_found;
+    else if (--remaining_probes == 0)
+      return -1;
+
+  /* We have a match.  Check whether tm.tm_isdst has the requested
+     value, if any.  */
+  if (isdst_differ (isdst, tm.tm_isdst))
+    {
+      /* tm.tm_isdst has the wrong value.  Look for a neighboring
+	 time with the right value, and use its UTC offset.
+
+	 Heuristic: probe the adjacent timestamps in both directions,
+	 looking for the desired isdst.  This should work for all real
+	 time zone histories in the tz database.  */
+
+      /* Distance between probes when looking for a DST boundary.  In
+	 tzdata2003a, the shortest period of DST is 601200 seconds
+	 (e.g., America/Recife starting 2000-10-08 01:00), and the
+	 shortest period of non-DST surrounded by DST is 694800
+	 seconds (Africa/Tunis starting 1943-04-17 01:00).  Use the
+	 minimum of these two values, so we don't miss these short
+	 periods when probing.  */
+      int stride = 601200;
+
+      /* The longest period of DST in tzdata2003a is 536454000 seconds
+	 (e.g., America/Jujuy starting 1946-10-01 01:00).  The longest
+	 period of non-DST is much longer, but it makes no real sense
+	 to search for more than a year of non-DST, so use the DST
+	 max.  */
+      int duration_max = 536454000;
+
+      /* Search in both directions, so the maximum distance is half
+	 the duration; add the stride to avoid off-by-1 problems.  */
+      int delta_bound = duration_max / 2 + stride;
+
+      int delta, direction;
+
+      for (delta = stride; delta < delta_bound; delta += stride)
+	for (direction = -1; direction <= 1; direction += 2)
+	  if (time64_t_int_add_ok (t, delta * direction))
+	    {
+	      __time64_t ot = t + delta * direction;
+	      struct tm otm;
+	      ranged64_convert (convert, &ot, &otm);
+	      if (! isdst_differ (isdst, otm.tm_isdst))
+		{
+		  /* We found the desired tm_isdst.
+		     Extrapolate back to the desired time.  */
+		  t = guess_time64_tm (year, yday, hour, min, sec, &ot, &otm);
+		  ranged64_convert (convert, &t, &tm);
+		  goto offset_found;
+		}
+	    }
+    }
+
+ offset_found:
+  *offset = guessed_offset + t - t0;
+
+  if (LEAP_SECONDS_POSSIBLE && sec_requested != tm.tm_sec)
+    {
+      /* Adjust time to reflect the tm_sec requested, not the normalized value.
+	 Also, repair any damage from a false match due to a leap second.  */
+      int sec_adjustment = (sec == 0 && tm.tm_sec == 60) - sec;
+      if (! time64_t_int_add_ok (t, sec_requested))
+	return -1;
+      t1 = t + sec_requested;
+      if (! time64_t_int_add_ok (t1, sec_adjustment))
+	return -1;
+      t2 = t1 + sec_adjustment;
+      if (! convert (&t2, &tm))
+	return -1;
+      t = t2;
+    }
+
+  *tp = tm;
+  return t;
+}
+
+
+/* This uses a signed type wide enough to hold any UTC offset in seconds. */
+static __time64_t localtime64_offset;
+
+/* Convert *TP to a __time64_t value.  */
+__time64_t
+__mktime64 (struct tm *tp)
+{
+#ifdef _LIBC
+  /* POSIX.1 8.1.1 requires that whenever mktime() is called, the
+     time zone names contained in the external variable 'tzname' shall
+     be set as if the tzset() function had been called.  */
+  __tzset ();
+#endif
+
+  return __mktime64_internal (tp, __localtime64_r, &localtime64_offset);
+}
 \f
 #if defined DEBUG_MKTIME && DEBUG_MKTIME
 
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  11/63] Y2038: implement 64-bit-time __timegm64()
  2018-04-18 20:19                   ` [[PATCH RFC 2] 10/63] Y2038: implement 64-bit-time __mktime64() and timelocal() Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:19                     ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:19                       ` [[PATCH RFC 2] 12/63] Y2038: add struct __timespec64 Albert ARIBAUD (3ADEV)
  2018-04-18 21:51                     ` [[PATCH RFC 2] 10/63] Y2038: implement 64-bit-time __mktime64() and timelocal() Joseph Myers
  1 sibling, 1 reply; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:19 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

Implementation is based on the same __mktime64_internal function
which was introduced in the '__mktime64' implementation change.
---
 time/Versions |  1 +
 time/timegm.c | 11 +++++++++++
 2 files changed, 12 insertions(+)

diff --git a/time/Versions b/time/Versions
index f5ccacc759..7cfae8760c 100644
--- a/time/Versions
+++ b/time/Versions
@@ -71,5 +71,6 @@ libc {
     __gmtime64; __gmtime64_r;
     __localtime64; __localtime64_r;
     __mktime64; __timelocal64_r;
+    __timegm64;
   }
 }
diff --git a/time/timegm.c b/time/timegm.c
index fb720e2d7d..8ac9b0b78e 100644
--- a/time/timegm.c
+++ b/time/timegm.c
@@ -36,6 +36,9 @@
 time_t __mktime_internal (struct tm *,
 			  struct tm * (*) (time_t const *, struct tm *),
 			  time_t *);
+__time64_t __mktime64_internal (struct tm *,
+				struct tm * (*) (__time64_t const *, struct tm *),
+				__time64_t *);
 #endif
 
 time_t
@@ -45,3 +48,11 @@ timegm (struct tm *tmp)
   tmp->tm_isdst = 0;
   return __mktime_internal (tmp, __gmtime_r, &gmtime_offset);
 }
+
+__time64_t
+__timegm64 (struct tm *tmp)
+{
+  static __time64_t gmtime64_offset;
+  tmp->tm_isdst = 0;
+  return __mktime64_internal (tmp, __gmtime64_r, &gmtime64_offset);
+}
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  06/63] Y2038: add function __gmtime64
  2018-04-18 20:18         ` [[PATCH RFC 2] 05/63] Y2038: add function __localtime64_r Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:19           ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:19             ` [[PATCH RFC 2] 07/63] Y2038: add function __gmtime64_r Albert ARIBAUD (3ADEV)
  0 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:19 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

---
 time/Versions | 1 +
 time/gmtime.c | 7 +++++++
 2 files changed, 8 insertions(+)

diff --git a/time/Versions b/time/Versions
index 723a03cd13..511580b6d8 100644
--- a/time/Versions
+++ b/time/Versions
@@ -67,6 +67,7 @@ libc {
   }
   GLIBC_2.27 {
     __difftime64;
+    __gmtime64;
     __localtime64; __localtime64_r;
   }
 }
diff --git a/time/gmtime.c b/time/gmtime.c
index e38f0cbcc0..4a8c0cbfd7 100644
--- a/time/gmtime.c
+++ b/time/gmtime.c
@@ -46,3 +46,10 @@ gmtime (const time_t *t)
     }
   return __tz_convert (*t, 0, &_tmbuf);
 }
+
+/* Return the `struct tm' representation of 64-bit-time *T in UTC.	*/
+struct tm *
+__gmtime64 (const __time64_t *t)
+{
+  return __tz_convert (*t, 0, &_tmbuf);
+}
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  09/63] Y2038: add function __ctime64_r
  2018-04-18 20:19               ` [[PATCH RFC 2] 08/63] Y2038: add function __ctime64 Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:19                 ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:19                   ` [[PATCH RFC 2] 10/63] Y2038: implement 64-bit-time __mktime64() and timelocal() Albert ARIBAUD (3ADEV)
  0 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:19 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

---
 time/Versions  | 2 +-
 time/ctime_r.c | 9 +++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/time/Versions b/time/Versions
index b625c55c82..0ad2749f2c 100644
--- a/time/Versions
+++ b/time/Versions
@@ -67,7 +67,7 @@ libc {
   }
   GLIBC_2.27 {
     __difftime64;
-    __ctime64;
+    __ctime64; __ctime64_r;
     __gmtime64; __gmtime64_r;
     __localtime64; __localtime64_r;
   }
diff --git a/time/ctime_r.c b/time/ctime_r.c
index c111146d76..742a967fdd 100644
--- a/time/ctime_r.c
+++ b/time/ctime_r.c
@@ -27,3 +27,12 @@ ctime_r (const time_t *t, char *buf)
   struct tm tm;
   return __asctime_r (__localtime_r (t, &tm), buf);
 }
+
+/* Return a string as returned by asctime which is the representation
+   of *T in that form.  Reentrant Y2038-proof version.  */
+char *
+__ctime64_r (const __time64_t *t, char *buf)
+{
+  struct tm tm;
+  return __asctime_r (__localtime64_r (t, &tm), buf);
+}
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  15/63] Y2038: powerpc: implement clock_gettime64 as a VDSO symbol
  2018-04-18 20:19                           ` [[PATCH RFC 2] 14/63] Y2038: arm: implement clock_gettime64 as a VDSO symbol Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:19                             ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:19                               ` [[PATCH RFC 2] 16/63] Y2038: add function __clock_settime64 Albert ARIBAUD (3ADEV)
  0 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:19 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

---
 sysdeps/powerpc/powerpc32/backtrace.c        |  1 +
 sysdeps/unix/sysv/linux/powerpc/init-first.c | 16 ++++++++++++++++
 sysdeps/unix/sysv/linux/powerpc/libc-vdso.h  |  2 ++
 3 files changed, 19 insertions(+)

diff --git a/sysdeps/powerpc/powerpc32/backtrace.c b/sysdeps/powerpc/powerpc32/backtrace.c
index 5422fdd50d..6db460dbc1 100644
--- a/sysdeps/powerpc/powerpc32/backtrace.c
+++ b/sysdeps/powerpc/powerpc32/backtrace.c
@@ -20,6 +20,7 @@
 #include <stddef.h>
 #include <string.h>
 #include <signal.h>
+#include <dl-vdso.h>
 #include <libc-vdso.h>
 
 /* This is the stack layout we see with every stack frame.
diff --git a/sysdeps/unix/sysv/linux/powerpc/init-first.c b/sysdeps/unix/sysv/linux/powerpc/init-first.c
index 0a4becbed6..b17ea92a1f 100644
--- a/sysdeps/unix/sysv/linux/powerpc/init-first.c
+++ b/sysdeps/unix/sysv/linux/powerpc/init-first.c
@@ -28,6 +28,15 @@ unsigned long long (*VDSO_SYMBOL(get_tbfreq)) (void);
 int (*VDSO_SYMBOL(getcpu)) (unsigned *, unsigned *);
 time_t (*VDSO_SYMBOL(time)) (time_t *);
 
+long (*VDSO_SYMBOL(clock_gettime64)) (clockid_t, struct __timespec64 *);
+
+int __y2038_linux_support;
+
+int __y2038_kernel_support (void)
+{
+  return __y2038_linux_support;
+}
+ 
 #if defined(__PPC64__) || defined(__powerpc64__)
 void *VDSO_SYMBOL(sigtramp_rt64);
 #else
@@ -64,6 +73,13 @@ _libc_vdso_platform_setup (void)
   PTR_MANGLE (p);
   VDSO_SYMBOL (time) = p;
 
+  /* (aaribaud) TODO: map to version where clock_gettime64 officially appears */
+  p = _dl_vdso_vsym ("__vdso_clock_gettime64", NULL);
+  PTR_MANGLE (p);
+  VDSO_SYMBOL (clock_gettime64) = p;
+
+  __y2038_linux_support = (p != NULL) ? 1 : 0;
+
   /* PPC64 uses only one signal trampoline symbol, while PPC32 will use
      two depending if SA_SIGINFO is used (__kernel_sigtramp_rt32) or not
      (__kernel_sigtramp32).
diff --git a/sysdeps/unix/sysv/linux/powerpc/libc-vdso.h b/sysdeps/unix/sysv/linux/powerpc/libc-vdso.h
index 5fe817d6cb..de8d44e95e 100644
--- a/sysdeps/unix/sysv/linux/powerpc/libc-vdso.h
+++ b/sysdeps/unix/sysv/linux/powerpc/libc-vdso.h
@@ -32,6 +32,8 @@ extern unsigned long long (*VDSO_SYMBOL(get_tbfreq)) (void);
 extern int (*VDSO_SYMBOL(getcpu)) (unsigned *, unsigned *);
 extern time_t (*VDSO_SYMBOL(time)) (time_t *);
 
+extern long (*VDSO_SYMBOL(clock_gettime64)) (clockid_t, struct __timespec64 *);
+
 #if defined(__PPC64__) || defined(__powerpc64__)
 extern void *VDSO_SYMBOL(sigtramp_rt64);
 #else
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  07/63] Y2038: add function __gmtime64_r
  2018-04-18 20:19           ` [[PATCH RFC 2] 06/63] Y2038: add function __gmtime64 Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:19             ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:19               ` [[PATCH RFC 2] 08/63] Y2038: add function __ctime64 Albert ARIBAUD (3ADEV)
  0 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:19 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

---
 include/time.h | 3 +++
 time/Versions  | 2 +-
 time/gmtime.c  | 8 ++++++++
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/include/time.h b/include/time.h
index 81cb0fbc00..b0a1199308 100644
--- a/include/time.h
+++ b/include/time.h
@@ -71,6 +71,9 @@ extern struct tm *__gmtime_r (const time_t *__restrict __timer,
 			      struct tm *__restrict __tp);
 libc_hidden_proto (__gmtime_r)
 
+extern struct tm *__gmtime64_r (const __time64_t *__restrict __timer,
+			        struct tm *__restrict __tp);
+
 /* Compute the `struct tm' representation of T,
    offset OFFSET seconds east of UTC,
    and store year, yday, mon, mday, wday, hour, min, sec into *TP.
diff --git a/time/Versions b/time/Versions
index 511580b6d8..d226a8557f 100644
--- a/time/Versions
+++ b/time/Versions
@@ -67,7 +67,7 @@ libc {
   }
   GLIBC_2.27 {
     __difftime64;
-    __gmtime64;
+    __gmtime64; __gmtime64_r;
     __localtime64; __localtime64_r;
   }
 }
diff --git a/time/gmtime.c b/time/gmtime.c
index 4a8c0cbfd7..b66ab3f853 100644
--- a/time/gmtime.c
+++ b/time/gmtime.c
@@ -47,6 +47,14 @@ gmtime (const time_t *t)
   return __tz_convert (*t, 0, &_tmbuf);
 }
 
+/* Return the `struct tm' representation of 64-bit-time *T
+   in UTC, using *TP to store the result.  */
+struct tm *
+__gmtime64_r (const __time64_t *t, struct tm *tp)
+{
+  return __tz_convert (*t, 0, tp);
+}
+
 /* Return the `struct tm' representation of 64-bit-time *T in UTC.	*/
 struct tm *
 __gmtime64 (const __time64_t *t)
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  18/63] Y2038: add function __clock_nanosleep64
  2018-04-18 20:19                                 ` [[PATCH RFC 2] 17/63] Y2038: add function __clock_getres64 Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:19                                   ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:20                                     ` [[PATCH RFC 2] 19/63] Y2038: add function __timespec_get64 Albert ARIBAUD (3ADEV)
  0 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:19 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

---
 include/time.h                            |  3 +++
 sysdeps/unix/sysv/linux/clock_nanosleep.c | 42 ++++++++++++++++++++++++++++++-
 time/Versions                             |  1 +
 3 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/include/time.h b/include/time.h
index 37909fae9a..82932f9afd 100644
--- a/include/time.h
+++ b/include/time.h
@@ -39,6 +39,9 @@ extern int __clock_settime64 (clockid_t __clock_id,
 			       const struct __timespec64 *__tp) __THROW;
 extern int __clock_getres64 (clockid_t __clock_id,
 			      struct __timespec64 *__res) __THROW;
+extern int __clock_nanosleep64 (clockid_t __clock_id, int __flags,
+				const struct __timespec64 *__req,
+				struct __timespec64 *__rem);
 
 /* Now define the internal interfaces.  */
 struct tm;
diff --git a/sysdeps/unix/sysv/linux/clock_nanosleep.c b/sysdeps/unix/sysv/linux/clock_nanosleep.c
index 93d5d6ef12..4249ccd3ff 100644
--- a/sysdeps/unix/sysv/linux/clock_nanosleep.c
+++ b/sysdeps/unix/sysv/linux/clock_nanosleep.c
@@ -21,7 +21,6 @@
 #include <sysdep-cancel.h>
 #include "kernel-posix-cpu-timers.h"
 
-
 /* We can simply use the syscall.  The CPU clocks are not supported
    with this function.  */
 int
@@ -52,3 +51,44 @@ __clock_nanosleep (clockid_t clock_id, int flags, const struct timespec *req,
 	  ? INTERNAL_SYSCALL_ERRNO (r, err) : 0);
 }
 weak_alias (__clock_nanosleep, clock_nanosleep)
+
+/* 64-bit time version */
+
+extern int __y2038_linux_support;
+
+int
+__clock_nanosleep64 (clockid_t clock_id, int flags,
+		   const struct __timespec64 *req,
+                   struct __timespec64 *rem)
+{
+  /* Until Linux provides a 64-bit syscall, use the 32-bit one */
+  INTERNAL_SYSCALL_DECL (err);
+  int r;
+  struct timespec req32, rem32, *rem32p = NULL;
+
+  if (req == NULL)
+    {
+      __set_errno(EFAULT);
+      return -1;
+    }
+
+  if (req->tv_sec > INT32_MAX || req->tv_sec < INT32_MIN)
+    {
+      __set_errno(EOVERFLOW);
+      return -1;
+    }
+
+  req32.tv_sec = req->tv_sec;
+  req32.tv_nsec = req->tv_nsec;
+  if (rem !=NULL) rem32p = &rem32;
+
+  r = clock_nanosleep(clock_id, flags, &req32, rem32p);
+
+  if (r == 0 && rem != NULL)
+    {
+      rem->tv_sec = rem32.tv_sec;
+      rem->tv_nsec = rem32.tv_nsec;
+    }
+
+  return r;
+}
diff --git a/time/Versions b/time/Versions
index 98ac0abfbe..6fe9373913 100644
--- a/time/Versions
+++ b/time/Versions
@@ -77,5 +77,6 @@ libc {
     __y2038_kernel_support;
     __clock_settime64;
     __clock_getres64;
+    __clock_nanosleep64;
   }
 }
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  14/63] Y2038: arm: implement clock_gettime64 as a VDSO symbol
  2018-04-18 20:19                         ` [[PATCH RFC 2] 13/63] Y2038: add function __clock_gettime64 Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:19                           ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:19                             ` [[PATCH RFC 2] 15/63] Y2038: powerpc: " Albert ARIBAUD (3ADEV)
  0 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:19 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

---
 sysdeps/unix/sysv/linux/arm/init-first.c | 15 +++++++++++++++
 sysdeps/unix/sysv/linux/arm/libc-vdso.h  |  1 +
 2 files changed, 16 insertions(+)

diff --git a/sysdeps/unix/sysv/linux/arm/init-first.c b/sysdeps/unix/sysv/linux/arm/init-first.c
index f4293b1cf8..76528bf194 100644
--- a/sysdeps/unix/sysv/linux/arm/init-first.c
+++ b/sysdeps/unix/sysv/linux/arm/init-first.c
@@ -23,6 +23,14 @@
 
 int (*VDSO_SYMBOL(gettimeofday)) (struct timeval *, void *) attribute_hidden;
 int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *);
+long (*VDSO_SYMBOL(clock_gettime64)) (clockid_t, struct __timespec64 *);
+
+int __y2038_linux_support;
+
+int __y2038_kernel_support (void)
+{
+  return __y2038_linux_support;
+}
 
 static inline void
 _libc_vdso_platform_setup (void)
@@ -36,6 +44,13 @@ _libc_vdso_platform_setup (void)
   p = _dl_vdso_vsym ("__vdso_clock_gettime", &linux26);
   PTR_MANGLE (p);
   VDSO_SYMBOL (clock_gettime) = p;
+
+  /* (aaribaud) TODO: map to version where clock_gettime64 officially appears */
+  p = _dl_vdso_vsym ("__vdso_clock_gettime64", NULL);
+  PTR_MANGLE (p);
+  VDSO_SYMBOL (clock_gettime64) = p;
+
+  __y2038_linux_support = (p != NULL) ? 1 : 0;
 }
 
 # define VDSO_SETUP _libc_vdso_platform_setup
diff --git a/sysdeps/unix/sysv/linux/arm/libc-vdso.h b/sysdeps/unix/sysv/linux/arm/libc-vdso.h
index 52dd355818..dc616244c6 100644
--- a/sysdeps/unix/sysv/linux/arm/libc-vdso.h
+++ b/sysdeps/unix/sysv/linux/arm/libc-vdso.h
@@ -27,6 +27,7 @@
 extern int (*VDSO_SYMBOL(gettimeofday)) (struct timeval *, void *)
    attribute_hidden;
 extern int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *);
+extern long (*VDSO_SYMBOL(clock_gettime64)) (clockid_t, struct __timespec64 *);
 
 #endif
 
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  16/63] Y2038: add function __clock_settime64
  2018-04-18 20:19                             ` [[PATCH RFC 2] 15/63] Y2038: powerpc: " Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:19                               ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:19                                 ` [[PATCH RFC 2] 17/63] Y2038: add function __clock_getres64 Albert ARIBAUD (3ADEV)
  0 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:19 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

---
 include/time.h                          |  2 ++
 sysdeps/unix/clock_settime.c            | 56 +++++++++++++++++++++++++++++-
 sysdeps/unix/sysv/linux/clock_settime.c | 60 +++++++++++++++++++++++++++++++++
 time/Versions                           |  1 +
 4 files changed, 118 insertions(+), 1 deletion(-)

diff --git a/include/time.h b/include/time.h
index e085fa5162..8101b638c6 100644
--- a/include/time.h
+++ b/include/time.h
@@ -35,6 +35,8 @@ extern __typeof (clock_getcpuclockid) __clock_getcpuclockid;
 
 extern int __clock_gettime64 (clockid_t __clock_id,
 			      struct __timespec64 *__tp) __THROW;
+extern int __clock_settime64 (clockid_t __clock_id,
+			       const struct __timespec64 *__tp) __THROW;
 
 /* Now define the internal interfaces.  */
 struct tm;
diff --git a/sysdeps/unix/clock_settime.c b/sysdeps/unix/clock_settime.c
index 38813eddf7..15626ee3e9 100644
--- a/sysdeps/unix/clock_settime.c
+++ b/sysdeps/unix/clock_settime.c
@@ -68,8 +68,62 @@ hp_timing_settime (clockid_t clock_id, const struct timespec *tp)
 }
 #endif
 
+/* Set CLOCK to value TP, 64-bit Y2038-safe version.  */
+int
+__clock_settime64 (clockid_t clock_id, const struct __timespec64 *tp)
+{
+  int retval = -1;
+
+  /* Make sure the time cvalue is OK.  */
+  if (! IS_VALID_NANOSECONDS(tp->tv_nsec))
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+  switch (clock_id)
+    {
+#define HANDLE_REALTIME64 \
+      do {								      \
+	struct timeval tv;						      \
+	TIMESPEC_TO_TIMEVAL (&tv, tp);					      \
+									      \
+	retval = __settimeofday (&tv, NULL);				      \
+      } while (0)
+
+#ifdef SYSDEP_SETTIME64
+      SYSDEP_SETTIME64;
+#endif
+
+#ifndef HANDLED_REALTIME
+    case CLOCK_REALTIME:
+      HANDLE_REALTIME64;
+      break;
+#endif
+
+    default:
+#ifdef SYSDEP_SETTIME64_CPU
+      SYSDEP_SETTIME64_CPU;
+#endif
+#ifndef HANDLED_CPUTIME
+# if HP_TIMING_AVAIL
+      if (CPUCLOCK_WHICH (clock_id) == CLOCK_PROCESS_CPUTIME_ID
+	  || CPUCLOCK_WHICH (clock_id) == CLOCK_THREAD_CPUTIME_ID)
+	retval = hp_timing_settime (clock_id, tp);
+      else
+# endif
+	{
+	  __set_errno (EINVAL);
+	  retval = -1;
+	}
+#endif
+      break;
+    }
+
+  return retval;
+}
 
-/* Set CLOCK to value TP.  */
+/* Set CLOCK to value TP, 64-bit Y2038-unsafe version.  */
 int
 __clock_settime (clockid_t clock_id, const struct timespec *tp)
 {
diff --git a/sysdeps/unix/sysv/linux/clock_settime.c b/sysdeps/unix/sysv/linux/clock_settime.c
index 5f3f22f74b..70ddb9e5ff 100644
--- a/sysdeps/unix/sysv/linux/clock_settime.c
+++ b/sysdeps/unix/sysv/linux/clock_settime.c
@@ -35,4 +35,64 @@
 #define SYSDEP_SETTIME_CPU \
   retval = INLINE_SYSCALL (clock_settime, 2, clock_id, tp)
 
+/* 64-bit time version */
+
+#ifdef __NR_clock_settime64
+/* We know the clock_gettime64 syscall, so use it or else clock_gettime */
+
+extern int __y2038_linux_support;
+
+#define SYSDEP_SETTIME64 \
+  SYSDEP_SETTIME64_CPUTIME;						      \
+  case CLOCK_REALTIME:							      \
+    if (__y2038_linux_support)						      \
+      {									      \
+        ts64.tv_sec = tp->tv_sec;					      \
+        ts64.tv_nsec = tp->tv_nsec;					      \
+        ts64.tv_pad = 0;						      \
+        retval = INLINE_SYSCALL (clock_settime64, 2, clock_id, &ts64);	      \
+      }									      \
+    else                         					      \
+      {									      \
+        retval = -1;                                                          \
+        __set_errno (EOVERFLOW);                                              \
+      }									      \
+    if (retval == -1 && errno == ENOSYS)				      \
+      {									      \
+        if (! fits_in_time_t(tp->tv_sec))                                     \
+         {                                                                    \
+           __set_errno (EOVERFLOW);                                           \
+         }                                                                    \
+        else                                                                  \
+          {                                                                   \
+            valid_timespec64_to_timespec(tp, &ts32);  			      \
+            retval = INLINE_SYSCALL (clock_settime, 2, clock_id, &ts32);      \
+          }                                                                   \
+      }                                                                       \
+    break
+#define SYSDEP_SETTIME64_CPUTIME \
+  struct __timespec64 ts64;						      \
+  struct timespec ts32;
+
+#else
+/* We don't know the clock_gettime64 syscall, so only use clock_gettime */
+
+#define SYSDEP_SETTIME64 \
+  SYSDEP_SETTIME64_CPUTIME;						      \
+  case CLOCK_REALTIME:							      \
+    if (! fits_in_time_t(tp->tv_sec))                                         \
+     {                                                                        \
+       __set_errno (EOVERFLOW);                                               \
+     }                                                                        \
+    else                                                                      \
+      {                                                                       \
+        valid_timespec64_to_timespec(tp, &ts32);  			      \
+        retval = INLINE_SYSCALL (clock_settime, 2, clock_id, &ts32);          \
+      }                                                                       \
+    break
+#define SYSDEP_SETTIME64_CPUTIME \
+  struct timespec ts32;
+
+#endif
+
 #include <sysdeps/unix/clock_settime.c>
diff --git a/time/Versions b/time/Versions
index 27c46fc023..a00184daae 100644
--- a/time/Versions
+++ b/time/Versions
@@ -75,5 +75,6 @@ libc {
     __clock_gettime64;
     __vdso_clock_gettime64;
     __y2038_kernel_support;
+    __clock_settime64;
   }
 }
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  08/63] Y2038: add function __ctime64
  2018-04-18 20:19             ` [[PATCH RFC 2] 07/63] Y2038: add function __gmtime64_r Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:19               ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:19                 ` [[PATCH RFC 2] 09/63] Y2038: add function __ctime64_r Albert ARIBAUD (3ADEV)
  0 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:19 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

---
 time/Versions |  1 +
 time/ctime.c  | 10 ++++++++++
 2 files changed, 11 insertions(+)

diff --git a/time/Versions b/time/Versions
index d226a8557f..b625c55c82 100644
--- a/time/Versions
+++ b/time/Versions
@@ -67,6 +67,7 @@ libc {
   }
   GLIBC_2.27 {
     __difftime64;
+    __ctime64;
     __gmtime64; __gmtime64_r;
     __localtime64; __localtime64_r;
   }
diff --git a/time/ctime.c b/time/ctime.c
index 1222614f29..fbfb61fcd6 100644
--- a/time/ctime.c
+++ b/time/ctime.c
@@ -26,3 +26,13 @@ ctime (const time_t *t)
      In particular, ctime and asctime must yield the same pointer.  */
   return asctime (localtime (t));
 }
+
+/* Return a string as returned by asctime which
+   is the representation of *T in that form.  */
+char *
+__ctime64 (const __time64_t *t)
+{
+  /* Apply the same rule as ctime:
+     make ctime64 (t) is equivalent to asctime (localtime64 (t)).  */
+  return asctime (__localtime64 (t));
+}
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  29/63] Y2038: add function __timerfd_gettime64
  2018-04-18 20:20                                                       ` [[PATCH RFC 2] 28/63] Y2038: add function __timer_settime64 Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:20                                                         ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:20                                                           ` [[PATCH RFC 2] 30/63] Y2038: add function __timerfd_settime64 Albert ARIBAUD (3ADEV)
  0 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:20 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

For Linux this uses the 32-bit time syscall so it converts the
syscall output from 32-bit time to 64-bit time.
---
 rt/Makefile                                        |  3 +-
 rt/Versions                                        |  1 +
 rt/timerfd_gettime64.c                             | 29 +++++++++++++++
 sysdeps/unix/sysv/linux/arm/librt.abilist          |  1 +
 .../sysv/linux/powerpc/powerpc32/librt.abilist     |  1 +
 sysdeps/unix/sysv/linux/timerfd_gettime64.c        | 43 ++++++++++++++++++++++
 6 files changed, 77 insertions(+), 1 deletion(-)
 create mode 100644 rt/timerfd_gettime64.c
 create mode 100644 sysdeps/unix/sysv/linux/timerfd_gettime64.c

diff --git a/rt/Makefile b/rt/Makefile
index 6d6b896ee9..c0aad5d8e2 100644
--- a/rt/Makefile
+++ b/rt/Makefile
@@ -32,7 +32,8 @@ clock-routines := get_clockfreq clock_getcpuclockid			\
 		  clock_getres clock_gettime clock_settime		\
 		  clock_nanosleep
 timer-routines := timer_create timer_delete timer_getoverr		\
-		  timer_gettime timer_settime
+		  timer_gettime timer_settime                           \
+		  timerfd_gettime64
 shm-routines   := shm_open shm_unlink
 mq-routines    := mq_open mq_close mq_unlink mq_getattr mq_setattr	\
 		  mq_notify mq_send mq_receive mq_timedsend		\
diff --git a/rt/Versions b/rt/Versions
index 181e5e16ad..ad1e50748a 100644
--- a/rt/Versions
+++ b/rt/Versions
@@ -40,5 +40,6 @@ librt {
   GLIBC_2.27 {
    __timer_gettime64;
    __timer_settime64;
+   __timerfd_gettime64;
   }
 }
diff --git a/rt/timerfd_gettime64.c b/rt/timerfd_gettime64.c
new file mode 100644
index 0000000000..72d0b68a4a
--- /dev/null
+++ b/rt/timerfd_gettime64.c
@@ -0,0 +1,29 @@
+/* Get current value of timer TIMERID and store it in VALUE.
+
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <time.h>
+
+int
+__timerfd_gettime64 (int fd, struct itimerspec *value)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+stub_warning (__timerfd_gettime64)
diff --git a/sysdeps/unix/sysv/linux/arm/librt.abilist b/sysdeps/unix/sysv/linux/arm/librt.abilist
index d76ec99c0a..a329b25661 100644
--- a/sysdeps/unix/sysv/linux/arm/librt.abilist
+++ b/sysdeps/unix/sysv/linux/arm/librt.abilist
@@ -1,6 +1,7 @@
 GLIBC_2.27 GLIBC_2.27 A
 GLIBC_2.27 __timer_gettime64 F
 GLIBC_2.27 __timer_settime64 F
+GLIBC_2.27 __timerfd_gettime64 F
 GLIBC_2.4 GLIBC_2.4 A
 GLIBC_2.4 aio_cancel F
 GLIBC_2.4 aio_cancel64 F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/librt.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/librt.abilist
index cd7b5f1b97..ec80f749ae 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/librt.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/librt.abilist
@@ -32,6 +32,7 @@ GLIBC_2.2 timer_settime F
 GLIBC_2.27 GLIBC_2.27 A
 GLIBC_2.27 __timer_gettime64 F
 GLIBC_2.27 __timer_settime64 F
+GLIBC_2.27 __timerfd_gettime64 F
 GLIBC_2.3.4 GLIBC_2.3.4 A
 GLIBC_2.3.4 mq_close F
 GLIBC_2.3.4 mq_getattr F
diff --git a/sysdeps/unix/sysv/linux/timerfd_gettime64.c b/sysdeps/unix/sysv/linux/timerfd_gettime64.c
new file mode 100644
index 0000000000..0c79ba41f1
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/timerfd_gettime64.c
@@ -0,0 +1,43 @@
+/* Get current value of timer TIMERID and store it in VALUE.
+
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public License as
+   published by the Free Software Foundation; either version 2.1 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If
+   not, see <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <stdlib.h>
+#include <time.h>
+#include <sysdep.h>
+#include "kernel-posix-timers.h"
+
+int
+__timerfd_gettime64 (int fd, struct __itimerspec64 *value)
+{
+  int res;
+  struct itimerspec value32;
+
+  res = INLINE_SYSCALL (timerfd_gettime, 2, fd, &value32);
+
+  if (res == 0)
+    {
+      value->it_value.tv_sec = value32.it_value.tv_sec;
+      value->it_value.tv_nsec = value32.it_value.tv_nsec;
+      value->it_interval.tv_sec = value32.it_interval.tv_sec;
+      value->it_interval.tv_nsec = value32.it_interval.tv_nsec;
+    }
+
+  return res;
+}
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  30/63] Y2038: add function __timerfd_settime64
  2018-04-18 20:20                                                         ` [[PATCH RFC 2] 29/63] Y2038: add function __timerfd_gettime64 Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:20                                                           ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:21                                                             ` [[PATCH RFC 2] 31/63] Y2038: add struct __stat64_t64 Albert ARIBAUD (3ADEV)
  0 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:20 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

For Linux this uses the 32-bit time syscal, so it converts
syscall input from 64-bit time into 32-bit time and syscall
output from 32-bit time to 64-bit time.
---
 rt/Makefile                                        |  2 +-
 rt/Versions                                        |  1 +
 rt/timerfd_settime64.c                             | 30 +++++++++++
 sysdeps/unix/sysv/linux/arm/librt.abilist          |  1 +
 .../sysv/linux/powerpc/powerpc32/librt.abilist     |  1 +
 sysdeps/unix/sysv/linux/timerfd_settime64.c        | 61 ++++++++++++++++++++++
 6 files changed, 95 insertions(+), 1 deletion(-)
 create mode 100644 rt/timerfd_settime64.c
 create mode 100644 sysdeps/unix/sysv/linux/timerfd_settime64.c

diff --git a/rt/Makefile b/rt/Makefile
index c0aad5d8e2..994891e42d 100644
--- a/rt/Makefile
+++ b/rt/Makefile
@@ -33,7 +33,7 @@ clock-routines := get_clockfreq clock_getcpuclockid			\
 		  clock_nanosleep
 timer-routines := timer_create timer_delete timer_getoverr		\
 		  timer_gettime timer_settime                           \
-		  timerfd_gettime64
+		  timerfd_gettime64 timerfd_settime64
 shm-routines   := shm_open shm_unlink
 mq-routines    := mq_open mq_close mq_unlink mq_getattr mq_setattr	\
 		  mq_notify mq_send mq_receive mq_timedsend		\
diff --git a/rt/Versions b/rt/Versions
index ad1e50748a..156df9f647 100644
--- a/rt/Versions
+++ b/rt/Versions
@@ -41,5 +41,6 @@ librt {
    __timer_gettime64;
    __timer_settime64;
    __timerfd_gettime64;
+   __timerfd_settime64;
   }
 }
diff --git a/rt/timerfd_settime64.c b/rt/timerfd_settime64.c
new file mode 100644
index 0000000000..39ce88bbf7
--- /dev/null
+++ b/rt/timerfd_settime64.c
@@ -0,0 +1,30 @@
+/* Set timer TIMERID to VALUE, returning old value in OVALUE.
+
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <time.h>
+
+int
+__timerfd_settime64 (int fd, int flags, const struct itimerspec *value,
+	       struct itimerspec *ovalue)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+stub_warning (__timerfd_settime64)
diff --git a/sysdeps/unix/sysv/linux/arm/librt.abilist b/sysdeps/unix/sysv/linux/arm/librt.abilist
index a329b25661..4ca48fc2a6 100644
--- a/sysdeps/unix/sysv/linux/arm/librt.abilist
+++ b/sysdeps/unix/sysv/linux/arm/librt.abilist
@@ -2,6 +2,7 @@ GLIBC_2.27 GLIBC_2.27 A
 GLIBC_2.27 __timer_gettime64 F
 GLIBC_2.27 __timer_settime64 F
 GLIBC_2.27 __timerfd_gettime64 F
+GLIBC_2.27 __timerfd_settime64 F
 GLIBC_2.4 GLIBC_2.4 A
 GLIBC_2.4 aio_cancel F
 GLIBC_2.4 aio_cancel64 F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/librt.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/librt.abilist
index ec80f749ae..1d6dd33e52 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/librt.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/librt.abilist
@@ -33,6 +33,7 @@ GLIBC_2.27 GLIBC_2.27 A
 GLIBC_2.27 __timer_gettime64 F
 GLIBC_2.27 __timer_settime64 F
 GLIBC_2.27 __timerfd_gettime64 F
+GLIBC_2.27 __timerfd_settime64 F
 GLIBC_2.3.4 GLIBC_2.3.4 A
 GLIBC_2.3.4 mq_close F
 GLIBC_2.3.4 mq_getattr F
diff --git a/sysdeps/unix/sysv/linux/timerfd_settime64.c b/sysdeps/unix/sysv/linux/timerfd_settime64.c
new file mode 100644
index 0000000000..4651f7d97e
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/timerfd_settime64.c
@@ -0,0 +1,61 @@
+/* Set timer TIMERID to VALUE, returning old value in OVALUE.
+
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public License as
+   published by the Free Software Foundation; either version 2.1 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If
+   not, see <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <stdlib.h>
+#include <time.h>
+#include <sysdep.h>
+#include "kernel-posix-timers.h"
+
+int
+__timerfd_settime64 (int fd, int flags, const struct __itimerspec64 *value,
+	             struct __itimerspec64 *ovalue)
+{
+  int res;
+  struct itimerspec value32;
+  struct itimerspec ovalue32;
+
+  if (value == NULL)
+    return EFAULT;
+
+  if (value->it_value.tv_sec > INT_MAX
+      || value->it_interval.tv_sec > INT_MAX)
+    {
+      __set_errno(EOVERFLOW);
+      return -1;
+    }
+
+  value32.it_value.tv_sec = value->it_value.tv_sec;
+  value32.it_value.tv_nsec = value->it_value.tv_nsec;
+  value32.it_interval.tv_sec = value->it_interval.tv_sec;
+  value32.it_interval.tv_nsec = value->it_interval.tv_nsec;
+
+  res = INLINE_SYSCALL (timerfd_settime, 4, fd, flags,
+                        &value32, &ovalue32);
+
+  if (res == 0 && ovalue != NULL)
+    {
+      ovalue->it_value.tv_sec = ovalue32.it_value.tv_sec;
+      ovalue->it_value.tv_nsec = ovalue32.it_value.tv_nsec;
+      ovalue->it_interval.tv_sec = ovalue32.it_interval.tv_sec;
+      ovalue->it_interval.tv_nsec = ovalue32.it_interval.tv_nsec;
+    }
+
+  return res;
+}
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  21/63] Y2038: add function __utimensat64
  2018-04-18 20:20                                       ` [[PATCH RFC 2] 20/63] Y2038: add function __futimens64 Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:20                                         ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:20                                           ` [[PATCH RFC 2] 22/63] Y2038: add function __sigtimedwait64 Albert ARIBAUD (3ADEV)
  2018-04-18 21:53                                         ` [[PATCH RFC 2] 20/63] Y2038: add function __futimens64 Joseph Myers
  1 sibling, 1 reply; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:20 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

---
 io/utimensat.c                      |  9 ++++++
 sysdeps/unix/sysv/linux/utimensat.c | 58 +++++++++++++++++++++++++++++++++++++
 time/Versions                       |  1 +
 3 files changed, 68 insertions(+)

diff --git a/io/utimensat.c b/io/utimensat.c
index 6b67a52e9e..2116b3d0a3 100644
--- a/io/utimensat.c
+++ b/io/utimensat.c
@@ -30,3 +30,12 @@ utimensat (int fd, const char *file, const struct timespec tsp[2],
   return -1;
 }
 stub_warning (utimensat)
+
+int
+__utimensat64 (int fd, const char *file, const struct __timespec64 tsp[2],
+	   int flags)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+stub_warning (__utimensat64)
diff --git a/sysdeps/unix/sysv/linux/utimensat.c b/sysdeps/unix/sysv/linux/utimensat.c
index 108d3bc55b..bef4765e0c 100644
--- a/sysdeps/unix/sysv/linux/utimensat.c
+++ b/sysdeps/unix/sysv/linux/utimensat.c
@@ -34,3 +34,61 @@ utimensat (int fd, const char *file, const struct timespec tsp[2],
   /* Avoid implicit array coercion in syscall macros.  */
   return INLINE_SYSCALL (utimensat, 4, fd, file, &tsp[0], flags);
 }
+
+/* 64-bit time version */
+
+extern int __y2038_linux_support;
+
+int
+__utimensat64 (int fd, const char *file, const struct __timespec64 tsp[2],
+	   int flags)
+{
+  struct timespec ts32[2], *ts32p = NULL;
+/* Only try and use this syscall if defined by kernel */
+#ifdef __NR_utimensat64
+  struct __timespec64 ts64[2], *ts64p = NULL;
+  int res;
+#endif
+
+  if (file == NULL)
+    return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
+
+/* Only try and use this syscall if defined by kernel */
+#ifdef __NR_utimensat64
+  if (__y2038_linux_support)
+    {
+      if (tsp)
+        {
+          ts64[0].tv_sec = tsp[0].tv_sec;
+          ts64[0].tv_nsec = tsp[0].tv_nsec;
+          ts64[0].tv_pad = 0;
+          ts64[1].tv_sec = tsp[1].tv_sec;
+          ts64[1].tv_nsec = tsp[1].tv_nsec;
+          ts64[1].tv_pad = 0;
+          ts64p = ts64;
+        }
+
+      res = INLINE_SYSCALL (utimensat64, 4, fd, file, ts64p, flags);
+      if (res == 0 || errno != ENOSYS)
+        return res;
+    }
+#endif
+
+  if (tsp)
+    {
+      if (! timespec64_to_timespec(&tsp[0], &ts32[0]))
+        {
+          __set_errno(EOVERFLOW);
+          return -1;
+        }
+
+      if (! timespec64_to_timespec(&tsp[1], &ts32[1]))
+        {
+          __set_errno(EOVERFLOW);
+          return -1;
+        }
+      ts32p = ts32;
+    }
+
+  return INLINE_SYSCALL (utimensat, 4, fd, file, ts32p, flags);
+}
diff --git a/time/Versions b/time/Versions
index 6105da5cb9..e41c661970 100644
--- a/time/Versions
+++ b/time/Versions
@@ -80,5 +80,6 @@ libc {
     __clock_nanosleep64;
     __timespec_get64;
     __futimens64;
+    __utimensat64;
   }
 }
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  28/63] Y2038: add function __timer_settime64
  2018-04-18 20:20                                                     ` [[PATCH RFC 2] 27/63] Y2038: add function __timer_gettime64 Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:20                                                       ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:20                                                         ` [[PATCH RFC 2] 29/63] Y2038: add function __timerfd_gettime64 Albert ARIBAUD (3ADEV)
  0 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:20 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

For Linux this uses a 32-bit syscall, so it converts the syscall
input from 64-bit time into 32-bit time, and the syscall output
from 32-bit time into 64-bit time.
---
 rt/Versions                                        |  1 +
 sysdeps/unix/sysv/linux/arm/librt.abilist          |  1 +
 .../sysv/linux/powerpc/powerpc32/librt.abilist     |  1 +
 sysdeps/unix/sysv/linux/timer_settime.c            | 39 ++++++++++++++++++++++
 4 files changed, 42 insertions(+)

diff --git a/rt/Versions b/rt/Versions
index 8fcfba84fe..181e5e16ad 100644
--- a/rt/Versions
+++ b/rt/Versions
@@ -39,5 +39,6 @@ librt {
   }
   GLIBC_2.27 {
    __timer_gettime64;
+   __timer_settime64;
   }
 }
diff --git a/sysdeps/unix/sysv/linux/arm/librt.abilist b/sysdeps/unix/sysv/linux/arm/librt.abilist
index f942d47058..d76ec99c0a 100644
--- a/sysdeps/unix/sysv/linux/arm/librt.abilist
+++ b/sysdeps/unix/sysv/linux/arm/librt.abilist
@@ -1,5 +1,6 @@
 GLIBC_2.27 GLIBC_2.27 A
 GLIBC_2.27 __timer_gettime64 F
+GLIBC_2.27 __timer_settime64 F
 GLIBC_2.4 GLIBC_2.4 A
 GLIBC_2.4 aio_cancel F
 GLIBC_2.4 aio_cancel64 F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/librt.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/librt.abilist
index 519a6f7657..cd7b5f1b97 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/librt.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/librt.abilist
@@ -31,6 +31,7 @@ GLIBC_2.2 timer_gettime F
 GLIBC_2.2 timer_settime F
 GLIBC_2.27 GLIBC_2.27 A
 GLIBC_2.27 __timer_gettime64 F
+GLIBC_2.27 __timer_settime64 F
 GLIBC_2.3.4 GLIBC_2.3.4 A
 GLIBC_2.3.4 mq_close F
 GLIBC_2.3.4 mq_getattr F
diff --git a/sysdeps/unix/sysv/linux/timer_settime.c b/sysdeps/unix/sysv/linux/timer_settime.c
index 7c938bd4a4..653cca2c55 100644
--- a/sysdeps/unix/sysv/linux/timer_settime.c
+++ b/sysdeps/unix/sysv/linux/timer_settime.c
@@ -41,3 +41,42 @@ timer_settime (timer_t timerid, int flags, const struct itimerspec *value,
 
   return res;
 }
+
+/* 64-bit time version */
+
+int
+__timer_settime64 (timer_t timerid, int flags, const struct itimerspec *value,
+                   struct itimerspec *ovalue)
+{
+  int res;
+  struct timer *kt = (struct timer *) timerid;
+  struct itimerspec value32, ovalue32;
+
+  if (value == NULL)
+  {
+    __set_errno(EFAULT);
+    return -1;
+  }
+
+  if (value->it_value.tv_sec > INT_MAX
+      || value->it_interval.tv_sec > INT_MAX)
+    return EOVERFLOW;
+
+  value32.it_value.tv_sec = value->it_value.tv_sec;
+  value32.it_value.tv_nsec = value->it_value.tv_nsec;
+  value32.it_interval.tv_sec = value->it_interval.tv_sec;
+  value32.it_interval.tv_nsec = value->it_interval.tv_nsec;
+
+  res = INLINE_SYSCALL (timer_settime, 4, kt->ktimerid, flags,
+        &value32, &ovalue32);
+
+  if (res == 0 && ovalue != NULL)
+    {
+      ovalue->it_value.tv_sec = ovalue32.it_value.tv_sec;
+      ovalue->it_value.tv_nsec = ovalue32.it_value.tv_nsec;
+      ovalue->it_interval.tv_sec = ovalue32.it_interval.tv_sec;
+      ovalue->it_interval.tv_nsec = ovalue32.it_interval.tv_nsec;
+    }
+
+  return res;
+}
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  27/63] Y2038: add function __timer_gettime64
  2018-04-18 20:20                                                   ` [[PATCH RFC 2] 26/63] Y2038: add struct __itimerspec64 Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:20                                                     ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:20                                                       ` [[PATCH RFC 2] 28/63] Y2038: add function __timer_settime64 Albert ARIBAUD (3ADEV)
  2018-04-18 21:54                                                     ` [[PATCH RFC 2] 26/63] Y2038: add struct __itimerspec64 Joseph Myers
  1 sibling, 1 reply; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:20 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

For Linux this uses the 32-bit time syscall, so it
converts the syscall output into 64-bit time.
---
 rt/Versions                                        |  3 +++
 sysdeps/unix/sysv/linux/arm/librt.abilist          |  2 ++
 .../sysv/linux/powerpc/powerpc32/librt.abilist     |  2 ++
 sysdeps/unix/sysv/linux/timer_gettime.c            | 22 ++++++++++++++++++++++
 4 files changed, 29 insertions(+)

diff --git a/rt/Versions b/rt/Versions
index 91e3fd2a20..8fcfba84fe 100644
--- a/rt/Versions
+++ b/rt/Versions
@@ -37,4 +37,7 @@ librt {
   GLIBC_2.7 {
    __mq_open_2;
   }
+  GLIBC_2.27 {
+   __timer_gettime64;
+  }
 }
diff --git a/sysdeps/unix/sysv/linux/arm/librt.abilist b/sysdeps/unix/sysv/linux/arm/librt.abilist
index b47aa0cc9c..f942d47058 100644
--- a/sysdeps/unix/sysv/linux/arm/librt.abilist
+++ b/sysdeps/unix/sysv/linux/arm/librt.abilist
@@ -1,3 +1,5 @@
+GLIBC_2.27 GLIBC_2.27 A
+GLIBC_2.27 __timer_gettime64 F
 GLIBC_2.4 GLIBC_2.4 A
 GLIBC_2.4 aio_cancel F
 GLIBC_2.4 aio_cancel64 F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/librt.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/librt.abilist
index 15e4418863..519a6f7657 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/librt.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/librt.abilist
@@ -29,6 +29,8 @@ GLIBC_2.2 timer_delete F
 GLIBC_2.2 timer_getoverrun F
 GLIBC_2.2 timer_gettime F
 GLIBC_2.2 timer_settime F
+GLIBC_2.27 GLIBC_2.27 A
+GLIBC_2.27 __timer_gettime64 F
 GLIBC_2.3.4 GLIBC_2.3.4 A
 GLIBC_2.3.4 mq_close F
 GLIBC_2.3.4 mq_getattr F
diff --git a/sysdeps/unix/sysv/linux/timer_gettime.c b/sysdeps/unix/sysv/linux/timer_gettime.c
index 10a19d9ee7..94be3af4a2 100644
--- a/sysdeps/unix/sysv/linux/timer_gettime.c
+++ b/sysdeps/unix/sysv/linux/timer_gettime.c
@@ -39,3 +39,25 @@ timer_gettime (timer_t timerid, struct itimerspec *value)
 
   return res;
 }
+
+/* 64-bit time version */
+
+int
+__timer_gettime64 (timer_t timerid, struct __itimerspec64 *value)
+{
+  struct itimerspec value32;
+  struct timer *kt = (struct timer *) timerid;
+  int res;
+
+  res = INLINE_SYSCALL (timer_gettime, 2, kt->ktimerid, &value32);
+
+  if (res == 0)
+    {
+      value->it_value.tv_sec = value32.it_value.tv_sec;
+      value->it_value.tv_nsec = value32.it_value.tv_nsec;
+      value->it_interval.tv_sec = value32.it_interval.tv_sec;
+      value->it_interval.tv_nsec = value32.it_interval.tv_nsec;
+    }
+
+  return res;
+}
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  23/63] Y2038: add struct __timeval64
  2018-04-18 20:20                                           ` [[PATCH RFC 2] 22/63] Y2038: add function __sigtimedwait64 Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:20                                             ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:20                                               ` [[PATCH RFC 2] 24/63] Y2038: add function __futimes64 Albert ARIBAUD (3ADEV)
  0 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:20 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

Also, provide static inline functions and macros for checking
and converting between 32-bit and 64-bit timevals.
---
 include/time.h                   | 50 ++++++++++++++++++++++++++++++++++++++++
 time/bits/types/struct_timeval.h |  8 +++++++
 2 files changed, 58 insertions(+)

diff --git a/include/time.h b/include/time.h
index 82932f9afd..68c52220fd 100644
--- a/include/time.h
+++ b/include/time.h
@@ -194,5 +194,55 @@ static inline bool timespec64_to_timespec(const struct __timespec64 *ts64,
   valid_timespec64_to_timespec(ts64, ts32);
   return true;
 }
+
+/* convert a known valid struct timeval into a struct __timeval64 */
+static inline void valid_timeval_to_timeval64(const struct timeval *tv32,
+                                              struct __timeval64 *tv64)
+{
+  tv64->tv_sec = tv32->tv_sec;
+  tv64->tv_usec = tv32->tv_usec;
+}
+
+/* convert a known valid struct timeval into a struct __timeval64 */
+static inline void valid_timeval64_to_timeval(const struct __timeval64 *tv64,
+					      struct timeval *tv32)
+{
+  tv32->tv_sec = (time_t) tv64->tv_sec;
+  tv32->tv_usec = tv64->tv_usec;
+}
+
+/* check if a struct timeval/__timeval64 is valid */
+#define IS_VALID_TIMEVAL(ts) \
+  ((ts).tv_usec >= 0 && (ts).tv_usec <= 999999)
+
+/* check if a struct timeval/__timeval64 is a valid 32-bit timeval */
+#define IS_VALID_TIMEVAL32(ts) \
+  (fits_in_time_t((ts).tv_sec) && (ts).tv_usec >= 0 && (ts).tv_usec <= 999999)
+
+/* check and convert a struct timeval into a struct __timeval64 */
+static inline bool timeval_to_timeval64(const struct timeval *tv32,
+                                        struct __timeval64 *tv64)
+{
+  /* check that tv_usec holds a valid count of nanoseconds */
+  if (! IS_VALID_TIMEVAL(*tv32))
+    return false;
+  /* all ts32 fields can fit in ts64, so copy them */
+  valid_timeval_to_timeval64(tv32, tv64);
+  /* we will only zero ts64->tv_pad if we pass it to the kernel */
+  return true;
+}
+
+/* check and convert a struct __timeval64 into a struct timeval */
+static inline bool timeval64_to_timeval(const struct __timeval64 *tv64,
+                                        struct timeval *tv32)
+{
+  /* check that tv_usec holds a valid count of nanoseconds */
+  if (! IS_VALID_TIMEVAL32(*tv64))
+    return false;
+  /* all ts64 fields can fit in ts32, so copy them */
+  valid_timeval64_to_timeval(tv64, tv32);
+  return true;
+}
+
 #endif
 #endif
diff --git a/time/bits/types/struct_timeval.h b/time/bits/types/struct_timeval.h
index 70394ce886..13fd48e686 100644
--- a/time/bits/types/struct_timeval.h
+++ b/time/bits/types/struct_timeval.h
@@ -10,4 +10,12 @@ struct timeval
   __time_t tv_sec;		/* Seconds.  */
   __suseconds_t tv_usec;	/* Microseconds.  */
 };
+
+/* 64-bit time version. Here we can simply use 64-bit signed ints and
+   still keep tings Posix-ish. */ 
+struct __timeval64
+{
+  __time64_t tv_sec;		/* Seconds */
+  __int64_t tv_usec;		/* Microseconds */
+};
 #endif
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  32/63] Y2038: add function __fstat64_t64 (and __fxstat64_t64)
  2018-04-18 20:21                                                             ` [[PATCH RFC 2] 31/63] Y2038: add struct __stat64_t64 Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:20                                                               ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:21                                                                 ` [[PATCH RFC 2] 33/63] Y2038: add function __stat64_t64 (and __xstat64_t64) Albert ARIBAUD (3ADEV)
  0 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:20 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

There is no Y2038-proof linux struct stat for now, so these
implementations just use the existing syscalls and convert from kernel
32-bit-time struct stat64 to GLIBC Y2038-ready struct __stat64_t64.
---
 include/sys/stat.h                 |  3 +++
 io/Versions                        |  1 +
 io/fstat64.c                       |  7 ++++++
 sysdeps/unix/sysv/linux/fxstat64.c | 50 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 61 insertions(+)

diff --git a/include/sys/stat.h b/include/sys/stat.h
index 72f627f247..0d755c7398 100644
--- a/include/sys/stat.h
+++ b/include/sys/stat.h
@@ -38,6 +38,9 @@ extern int __mkdir (const char *__path, __mode_t __mode);
 libc_hidden_proto (__mkdir)
 extern int __mknod (const char *__path,
 		    __mode_t __mode, __dev_t __dev);
+extern int __fxstat64_t64 (int __ver, int __fildes,
+                           struct __stat64_t64 *__stat_buf);
+
 #if IS_IN (libc) || (IS_IN (rtld) && !defined NO_RTLD_HIDDEN)
 hidden_proto (__fxstat)
 hidden_proto (__fxstat64)
diff --git a/io/Versions b/io/Versions
index 98898cb9d5..a2857c7754 100644
--- a/io/Versions
+++ b/io/Versions
@@ -127,5 +127,6 @@ libc {
   }
   GLIBC_2.27 {
     copy_file_range;
+    __fxstat64_t64;
   }
 }
diff --git a/io/fstat64.c b/io/fstat64.c
index 0f4de02cee..60f8a74178 100644
--- a/io/fstat64.c
+++ b/io/fstat64.c
@@ -50,3 +50,10 @@ fstat64 (int fd, struct stat64 *buf)
 {
   return __fxstat64 (_STAT_VER, fd, buf);
 }
+
+int
+attribute_hidden
+__fstat64_t64 (int fd, struct __stat64_t64 *buf)
+{
+  return __fxstat64_t64 (_STAT_VER, fd, buf);
+}
diff --git a/sysdeps/unix/sysv/linux/fxstat64.c b/sysdeps/unix/sysv/linux/fxstat64.c
index 0d053897a0..705e47a120 100644
--- a/sysdeps/unix/sysv/linux/fxstat64.c
+++ b/sysdeps/unix/sysv/linux/fxstat64.c
@@ -51,3 +51,53 @@ hidden_ver (___fxstat64, __fxstat64)
 strong_alias (___fxstat64, __fxstat64)
 hidden_def (__fxstat64)
 #endif
+
+/* 64-bit time version */
+
+extern int __y2038_linux_support;
+
+int
+__fxstat64_t64 (int vers, int fd, struct __stat64_t64 *buf)
+{
+  int result;
+  struct stat64 st64;
+
+  if (__y2038_linux_support)
+    {
+      // TODO: use 64-bit syscalls when they become available
+    }
+
+  result = INLINE_SYSCALL (fstat64, 2, fd, &st64);
+#if defined _HAVE_STAT64___ST_INO && !__ASSUME_ST_INO_64_BIT
+  if (__builtin_expect (!result, 1) && st64.__st_ino != (__ino_t) st64.st_ino)
+    st64.st_ino = st64.__st_ino;
+#endif
+  if (!result)
+    {
+      buf->st_dev          = st64.st_dev;
+      //buf->__pad1		     = st64.__pad1;
+    
+#if defined _HAVE_STAT64___ST_INO
+      buf->__st_ino        = st64.__st_ino;
+#endif
+      buf->st_mode         = st64.st_mode;
+      buf->st_nlink        = st64.st_nlink;
+      buf->st_uid          = st64.st_uid;		 
+      buf->st_gid          = st64.st_gid;		 
+      buf->st_rdev         = st64.st_rdev;		 
+      buf->__pad2          = st64.__pad2;
+      buf->st_size         = st64.st_size;		 
+      buf->st_blksize      = st64.st_blksize;
+    
+      buf->st_blocks       = st64.st_blocks;		
+      buf->st_atim.tv_sec  = st64.st_atim.tv_sec;	
+      buf->st_atim.tv_nsec = st64.st_atim.tv_nsec;	
+      buf->st_mtim.tv_sec  = st64.st_mtim.tv_sec;	
+      buf->st_mtim.tv_nsec = st64.st_mtim.tv_nsec;	
+      buf->st_ctim.tv_sec  = st64.st_ctim.tv_sec;	
+      buf->st_ctim.tv_nsec = st64.st_ctim.tv_nsec;	
+    
+      buf->st_ino          = st64.st_ino;
+    }
+  return result;
+}
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  22/63] Y2038: add function __sigtimedwait64
  2018-04-18 20:20                                         ` [[PATCH RFC 2] 21/63] Y2038: add function __utimensat64 Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:20                                           ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:20                                             ` [[PATCH RFC 2] 23/63] Y2038: add struct __timeval64 Albert ARIBAUD (3ADEV)
  0 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:20 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

---
 signal/sigtimedwait.c                  | 10 +++++
 sysdeps/unix/sysv/linux/sigtimedwait.c | 76 ++++++++++++++++++++++++++++++++++
 time/Versions                          |  1 +
 3 files changed, 87 insertions(+)

diff --git a/signal/sigtimedwait.c b/signal/sigtimedwait.c
index 308b9b95d7..d8d7165375 100644
--- a/signal/sigtimedwait.c
+++ b/signal/sigtimedwait.c
@@ -30,3 +30,13 @@ libc_hidden_def (__sigtimedwait)
 weak_alias (__sigtimedwait, sigtimedwait)
 
 stub_warning (sigtimedwait)
+
+int
+__sigtimedwait64 (const sigset_t *set, siginfo_t *info,
+		const struct __timespec64 *timeout)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+
+stub_warning (__sigtimedwait64)
diff --git a/sysdeps/unix/sysv/linux/sigtimedwait.c b/sysdeps/unix/sysv/linux/sigtimedwait.c
index b4de8856dd..4fe1b66517 100644
--- a/sysdeps/unix/sysv/linux/sigtimedwait.c
+++ b/sysdeps/unix/sysv/linux/sigtimedwait.c
@@ -18,6 +18,9 @@
 #include <errno.h>
 #include <signal.h>
 #include <string.h>
+//#include <stdint.h>
+
+//#include <nptl/pthreadP.h>
 #include <sysdep-cancel.h>
 
 int
@@ -39,3 +42,76 @@ __sigtimedwait (const sigset_t *set, siginfo_t *info,
 }
 libc_hidden_def (__sigtimedwait)
 weak_alias (__sigtimedwait, sigtimedwait)
+
+/* 64-bit time version */
+
+extern int __y2038_linux_support;
+
+int
+__sigtimedwait64 (const sigset_t *set, siginfo_t *info,
+		const struct __timespec64 *timeout)
+{
+  int result;
+  struct __timespec64 ts64;
+  struct timespec ts32;
+
+#ifdef SIGCANCEL
+  sigset_t tmpset;
+  if (set != NULL
+      && (__builtin_expect (__sigismember (set, SIGCANCEL), 0)
+# ifdef SIGSETXID
+	  || __builtin_expect (__sigismember (set, SIGSETXID), 0)
+# endif
+	  ))
+    {
+      /* Create a temporary mask without the bit for SIGCANCEL set.  */
+      // We are not copying more than we have to.
+      memcpy (&tmpset, set, _NSIG / 8);
+      __sigdelset (&tmpset, SIGCANCEL);
+# ifdef SIGSETXID
+      __sigdelset (&tmpset, SIGSETXID);
+# endif
+      set = &tmpset;
+    }
+#endif
+
+    /* XXX The size argument hopefully will have to be changed to the
+       real size of the user-level sigset_t.  */
+
+  if (__y2038_linux_support)
+    {
+      if (timeout)
+        {
+          ts64.tv_sec = timeout->tv_sec;
+          ts64.tv_nsec = timeout->tv_nsec;
+          ts64.tv_pad = 0;
+          result = SYSCALL_CANCEL (rt_sigtimedwait, set, info, &ts64, _NSIG / 8);
+        }
+      else
+        result = SYSCALL_CANCEL (rt_sigtimedwait, set, info, NULL, _NSIG / 8);
+    }
+  else
+    {
+      if (timeout)
+        {
+          if (! timespec64_to_timespec(timeout, &ts32))
+            {
+              errno = EOVERFLOW;
+              return -1;
+            }
+          result = SYSCALL_CANCEL (rt_sigtimedwait, set, info, &ts32, _NSIG / 8);
+        }
+      else
+        result = SYSCALL_CANCEL (rt_sigtimedwait, set, info, NULL, _NSIG / 8);
+    }
+
+  /* The kernel generates a SI_TKILL code in si_code in case tkill is
+     used.  tkill is transparently used in raise().  Since having
+     SI_TKILL as a code is useful in general we fold the results
+     here.  */
+  if (result != -1 && info != NULL && info->si_code == SI_TKILL)
+    info->si_code = SI_USER;
+
+  return result;
+}
+
diff --git a/time/Versions b/time/Versions
index e41c661970..eec5f95610 100644
--- a/time/Versions
+++ b/time/Versions
@@ -81,5 +81,6 @@ libc {
     __timespec_get64;
     __futimens64;
     __utimensat64;
+    __sigtimedwait64;
   }
 }
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  25/63] Y2038: add function __lutimes64
  2018-04-18 20:20                                               ` [[PATCH RFC 2] 24/63] Y2038: add function __futimes64 Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:20                                                 ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:20                                                   ` [[PATCH RFC 2] 26/63] Y2038: add struct __itimerspec64 Albert ARIBAUD (3ADEV)
  0 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:20 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

---
 misc/lutimes.c                    |  8 ++++++
 sysdeps/unix/sysv/linux/lutimes.c | 58 +++++++++++++++++++++++++++++++++++++++
 time/Versions                     |  1 +
 3 files changed, 67 insertions(+)

diff --git a/misc/lutimes.c b/misc/lutimes.c
index b241c14c56..e4368999e1 100644
--- a/misc/lutimes.c
+++ b/misc/lutimes.c
@@ -31,3 +31,11 @@ __lutimes (const char *file, const struct timeval tvp[2])
 weak_alias (__lutimes, lutimes)
 
 stub_warning (lutimes)
+
+int
+__lutimes64 (const char *file, const struct __timeval64 tvp[2])
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+stub_warning (__lutimes64)
diff --git a/sysdeps/unix/sysv/linux/lutimes.c b/sysdeps/unix/sysv/linux/lutimes.c
index 4f2f9ec7d6..175563e3b8 100644
--- a/sysdeps/unix/sysv/linux/lutimes.c
+++ b/sysdeps/unix/sysv/linux/lutimes.c
@@ -42,3 +42,61 @@ lutimes (const char *file, const struct timeval tvp[2])
   return INLINE_SYSCALL (utimensat, 4, AT_FDCWD, file, tvp ? ts : NULL,
 			 AT_SYMLINK_NOFOLLOW);
 }
+
+/* 64-bit time version */
+
+extern int __y2038_linux_support;
+
+int
+__lutimes64 (const char *file, const struct __timeval64 tvp[2])
+{
+  struct timespec ts32[2], *ts32p = NULL;;
+/* Only try and use this syscall if defined by kernel */
+#ifdef __NR_utimensat64
+  /* The system call expects timespec, not timeval.  */
+  struct __timespec64 ts64[2], *ts64p = NULL;
+  int result;
+#endif
+
+/* Only try and use this syscall if defined by kernel */
+#ifdef __NR_utimensat64
+  if (__y2038_linux_support)
+    {
+      if (tvp != NULL)
+        {
+          if (tvp[0].tv_usec < 0 || tvp[0].tv_usec >= 1000000
+              || tvp[1].tv_usec < 0 || tvp[1].tv_usec >= 1000000)
+  	    return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
+        
+          ts64[0].tv_sec = tvp[0].tv_sec;
+          ts64[0].tv_nsec = tvp[0].tv_usec * 1000;
+          ts64[0].tv_pad = 0;
+          ts64[1].tv_sec = tvp[1].tv_sec;
+          ts64[1].tv_nsec = tvp[1].tv_usec * 1000;
+          ts64[1].tv_pad = 0;
+          ts64p = ts64;
+        }
+    
+      result = INLINE_SYSCALL (utimensat64, 4, AT_FDCWD, file, ts64p,
+  	  		     AT_SYMLINK_NOFOLLOW);
+      if (result == 0 || errno == ENOSYS)
+        return result;
+    }
+#endif
+
+  if (tvp != NULL)
+    {
+      if (tvp[0].tv_usec < 0 || tvp[0].tv_usec >= 1000000
+          || tvp[1].tv_usec < 0 || tvp[1].tv_usec >= 1000000)
+        return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
+    
+      ts32[0].tv_sec = tvp[0].tv_sec;
+      ts32[0].tv_nsec = tvp[0].tv_usec * 1000;
+      ts32[1].tv_sec = tvp[1].tv_sec;
+      ts32[1].tv_nsec = tvp[1].tv_usec * 1000;
+      ts32p = ts32;
+    }
+
+  return INLINE_SYSCALL (utimensat, 4, AT_FDCWD, file, ts32p,
+                             AT_SYMLINK_NOFOLLOW);
+}
diff --git a/time/Versions b/time/Versions
index 40557720bf..ac92d742c3 100644
--- a/time/Versions
+++ b/time/Versions
@@ -83,5 +83,6 @@ libc {
     __utimensat64;
     __sigtimedwait64;
     __futimes64;
+    __lutimes64;
   }
 }
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  20/63] Y2038: add function __futimens64
  2018-04-18 20:20                                     ` [[PATCH RFC 2] 19/63] Y2038: add function __timespec_get64 Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:20                                       ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:20                                         ` [[PATCH RFC 2] 21/63] Y2038: add function __utimensat64 Albert ARIBAUD (3ADEV)
  2018-04-18 21:53                                         ` [[PATCH RFC 2] 20/63] Y2038: add function __futimens64 Joseph Myers
  0 siblings, 2 replies; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:20 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

---
 io/futimens.c                      |  8 +++++++
 sysdeps/unix/sysv/linux/futimens.c | 48 ++++++++++++++++++++++++++++++++++++++
 time/Versions                      |  1 +
 3 files changed, 57 insertions(+)

diff --git a/io/futimens.c b/io/futimens.c
index fb170ffc3c..2e9648a16e 100644
--- a/io/futimens.c
+++ b/io/futimens.c
@@ -32,3 +32,11 @@ futimens (int fd, const struct timespec tsp[2])
   return -1;
 }
 stub_warning (futimens)
+
+int
+__futimens64 (int fd, const struct __timespec64 tsp[2])
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+stub_warning (__futimens64)
diff --git a/sysdeps/unix/sysv/linux/futimens.c b/sysdeps/unix/sysv/linux/futimens.c
index bc7fe54331..fb338b92ea 100644
--- a/sysdeps/unix/sysv/linux/futimens.c
+++ b/sysdeps/unix/sysv/linux/futimens.c
@@ -36,3 +36,51 @@ futimens (int fd, const struct timespec tsp[2])
   /* Avoid implicit array coercion in syscall macros.  */
   return INLINE_SYSCALL (utimensat, 4, fd, NULL, &tsp[0], 0);
 }
+
+/* 64-bit time version */
+
+extern int __y2038_linux_support;
+
+int
+__futimens64 (int fd, const struct __timespec64 tsp[2])
+{
+  struct timespec ts32[2];
+/* Only try and use this syscall if defined by kernel */
+#ifdef __NR_utimesat64
+  struct __timespec64 ts64[2];
+  int res;
+#endif
+
+  if (fd < 0)
+    return INLINE_SYSCALL_ERROR_RETURN_VALUE (EBADF);
+
+/* Only try and use this syscall if defined by kernel */
+#ifdef __NR_utimesat64
+  if (__y2038_linux_support)
+    {
+      ts64[0].tv_sec = tsp[0].tv_sec;
+      ts64[0].tv_nsec = tsp[0].tv_nsec;
+      ts64[0].tv_pad = 0;
+      ts64[1].tv_sec = tsp[1].tv_sec;
+      ts64[1].tv_nsec = tsp[1].tv_nsec;
+      ts64[1].tv_pad = 0;
+      res = INLINE_SYSCALL (utimensat64, 4, fd, NULL, &ts64[0], 0);
+      if (res == 0 || errno != ENOSYS)
+        return res;
+    }
+#endif
+
+  if (! timespec64_to_timespec(&tsp[0], &ts32[0]))
+    {
+      __set_errno(EOVERFLOW);
+      return -1;
+    }
+
+  if (! timespec64_to_timespec(&tsp[1], &ts32[1]))
+    {
+      __set_errno(EOVERFLOW);
+      return -1;
+    }
+
+  return INLINE_SYSCALL (utimensat, 4, fd, NULL, &ts32[0], 0);
+}
diff --git a/time/Versions b/time/Versions
index 668c134f12..6105da5cb9 100644
--- a/time/Versions
+++ b/time/Versions
@@ -79,5 +79,6 @@ libc {
     __clock_getres64;
     __clock_nanosleep64;
     __timespec_get64;
+    __futimens64;
   }
 }
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  26/63] Y2038: add struct __itimerspec64
  2018-04-18 20:20                                                 ` [[PATCH RFC 2] 25/63] Y2038: add function __lutimes64 Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:20                                                   ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:20                                                     ` [[PATCH RFC 2] 27/63] Y2038: add function __timer_gettime64 Albert ARIBAUD (3ADEV)
  2018-04-18 21:54                                                     ` [[PATCH RFC 2] 26/63] Y2038: add struct __itimerspec64 Joseph Myers
  0 siblings, 2 replies; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:20 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

---
 time/bits/types/struct_itimerspec.h | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/time/bits/types/struct_itimerspec.h b/time/bits/types/struct_itimerspec.h
index 17cc1ac86d..1f8fff439f 100644
--- a/time/bits/types/struct_itimerspec.h
+++ b/time/bits/types/struct_itimerspec.h
@@ -11,4 +11,11 @@ struct itimerspec
     struct timespec it_value;
   };
 
+/* 64-bit interval timer spec */
+struct __itimerspec64
+{
+  struct __timespec64 it_interval;
+  struct __timespec64 it_value;
+};
+
 #endif
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  24/63] Y2038: add function __futimes64
  2018-04-18 20:20                                             ` [[PATCH RFC 2] 23/63] Y2038: add struct __timeval64 Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:20                                               ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:20                                                 ` [[PATCH RFC 2] 25/63] Y2038: add function __lutimes64 Albert ARIBAUD (3ADEV)
  0 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:20 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

---
 misc/futimes.c                    |  9 ++++++
 sysdeps/unix/sysv/linux/futimes.c | 59 +++++++++++++++++++++++++++++++++++++++
 time/Versions                     |  1 +
 3 files changed, 69 insertions(+)

diff --git a/misc/futimes.c b/misc/futimes.c
index 3ffa40b0b1..c8756a01d2 100644
--- a/misc/futimes.c
+++ b/misc/futimes.c
@@ -30,3 +30,12 @@ __futimes (int fd, const struct timeval tvp[2])
 weak_alias (__futimes, futimes)
 
 stub_warning (futimes)
+
+int
+__futimes64 (int fd, const struct __timeval64 tvp[2])
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+
+stub_warning (__futimes64)
diff --git a/sysdeps/unix/sysv/linux/futimes.c b/sysdeps/unix/sysv/linux/futimes.c
index 9e6267cda7..fb644d79af 100644
--- a/sysdeps/unix/sysv/linux/futimes.c
+++ b/sysdeps/unix/sysv/linux/futimes.c
@@ -49,3 +49,62 @@ __futimes (int fd, const struct timeval tvp[2])
   return INLINE_SYSCALL (utimensat, 4, fd, NULL, tvp ? &ts : NULL, 0);
 }
 weak_alias (__futimes, futimes)
+
+/* 64-bit time version */
+
+extern int __y2038_linux_support;
+
+int
+__futimes64 (int fd, const struct __timeval64 tvp[2])
+{
+  struct timespec ts32[2], *ts32p = NULL;
+/* Only try and use this syscall if defined by kernel */
+#ifdef __NR_utimensat64
+  /* The utimensat system call expects timespec not timeval.  */
+  struct __timespec64 ts64[2], *ts64p = NULL;
+  int result;
+#endif
+
+/* Only try and use this syscall if defined by kernel */
+#ifdef __NR_utimensat64
+  if (__y2038_linux_support)
+    {
+      if (tvp != NULL)
+        {
+          if (tvp[0].tv_usec < 0 || tvp[0].tv_usec >= 1000000
+              || tvp[1].tv_usec < 0 || tvp[1].tv_usec >= 1000000)
+  	    return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
+        
+          ts64[0].tv_sec = tvp[0].tv_sec;
+          ts64[0].tv_nsec = tvp[0].tv_usec * 1000;
+          ts64[0].tv_pad = 0;
+          ts64[1].tv_sec = tvp[1].tv_sec;
+          ts64[1].tv_nsec = tvp[1].tv_usec * 1000;
+          ts64[1].tv_pad = 0;
+          ts64p = ts64;
+        }
+    
+      result = INLINE_SYSCALL (utimensat64, 4, fd, NULL, ts64p, 0);
+      if (result == 0 || errno != ENOSYS)
+        return result;
+    }
+#endif
+
+  if (tvp != NULL)
+    {
+      if (tvp[0].tv_usec < 0 || tvp[0].tv_usec >= 1000000
+          || tvp[1].tv_usec < 0 || tvp[1].tv_usec >= 1000000)
+        return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
+    
+      if (tvp[0].tv_sec > INT_MAX || tvp[1].tv_sec > INT_MAX)
+        return INLINE_SYSCALL_ERROR_RETURN_VALUE (EOVERFLOW);
+    
+      ts32[0].tv_sec = tvp[0].tv_sec;
+      ts32[0].tv_nsec = tvp[0].tv_usec * 1000;
+      ts32[1].tv_sec = tvp[1].tv_sec;
+      ts32[1].tv_nsec = tvp[1].tv_usec * 1000;
+      ts32p = ts32;
+    }
+
+  return INLINE_SYSCALL (utimensat, 4, fd, NULL, ts32p, 0);
+}
diff --git a/time/Versions b/time/Versions
index eec5f95610..40557720bf 100644
--- a/time/Versions
+++ b/time/Versions
@@ -82,5 +82,6 @@ libc {
     __futimens64;
     __utimensat64;
     __sigtimedwait64;
+    __futimes64;
   }
 }
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  19/63] Y2038: add function __timespec_get64
  2018-04-18 20:19                                   ` [[PATCH RFC 2] 18/63] Y2038: add function __clock_nanosleep64 Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:20                                     ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:20                                       ` [[PATCH RFC 2] 20/63] Y2038: add function __futimens64 Albert ARIBAUD (3ADEV)
  0 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:20 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

---
 sysdeps/unix/sysv/linux/timespec_get.c | 41 ++++++++++++++++++++++++++++++++++
 time/Versions                          |  1 +
 2 files changed, 42 insertions(+)

diff --git a/sysdeps/unix/sysv/linux/timespec_get.c b/sysdeps/unix/sysv/linux/timespec_get.c
index b14a302ee9..b40bdedb57 100644
--- a/sysdeps/unix/sysv/linux/timespec_get.c
+++ b/sysdeps/unix/sysv/linux/timespec_get.c
@@ -44,3 +44,44 @@ timespec_get (struct timespec *ts, int base)
 
   return base;
 }
+
+/* 64-bit time version */
+
+extern int __y2038_linux_support;
+
+int
+__timespec_get64 (struct __timespec64 *ts, int base)
+{
+  switch (base)
+    {
+      int res;
+      INTERNAL_SYSCALL_DECL (err);
+    case TIME_UTC:
+      if (__y2038_linux_support)
+/* Check that we are built with a 64-bit-time kernel */
+#ifdef __NR_clock_nanosleep64
+        {
+          res = INTERNAL_VSYSCALL (clock_gettime64, err, 2, CLOCK_REALTIME, ts);
+        }
+      else
+#endif
+        {
+          res = -1;
+          __set_errno(ENOSYS);
+        }
+      if (res == -1 && errno == ENOSYS)
+        {
+          struct timespec ts32;
+          res = INTERNAL_VSYSCALL (clock_gettime, err, 2, CLOCK_REALTIME, &ts32);
+          if (INTERNAL_SYSCALL_ERROR_P (res, err))
+	    return 0;
+          timespec_to_timespec64(&ts32, ts);
+        }
+      break;
+
+    default:
+      return 0;
+    }
+
+  return base;
+}
diff --git a/time/Versions b/time/Versions
index 6fe9373913..668c134f12 100644
--- a/time/Versions
+++ b/time/Versions
@@ -78,5 +78,6 @@ libc {
     __clock_settime64;
     __clock_getres64;
     __clock_nanosleep64;
+    __timespec_get64;
   }
 }
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  37/63] Y2038: add function __settimeofday64
  2018-04-18 20:21                                                                       ` [[PATCH RFC 2] 36/63] Y2038: add function __gettimeofday64 Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:21                                                                         ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:21                                                                           ` [[PATCH RFC 2] 38/63] Y2038: add function __time64 Albert ARIBAUD (3ADEV)
  0 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:21 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

Implementing a 64-bit settimeofday requires adding a new
file to build under time/ and we cannot name that new file
'settimeofday.c' or it will break the 32-bit settimeofday
file symbol, so we call it 'settimeofday64.c'.
---
 include/sys/time.h                       |  2 ++
 sysdeps/unix/sysv/linux/settimeofday64.c | 39 ++++++++++++++++++++++++++++++++
 time/Makefile                            |  2 +-
 time/Versions                            |  1 +
 time/settimeofday.c                      |  8 +++++++
 5 files changed, 51 insertions(+), 1 deletion(-)
 create mode 100644 sysdeps/unix/sysv/linux/settimeofday64.c

diff --git a/include/sys/time.h b/include/sys/time.h
index ed73a445bf..792fe84568 100644
--- a/include/sys/time.h
+++ b/include/sys/time.h
@@ -29,6 +29,8 @@ extern int __gettimeofday64 (struct __timeval64 *__tv,
 extern int __settimeofday (const struct timeval *__tv,
 			   const struct timezone *__tz)
 	attribute_hidden;
+extern int __settimeofday64 (const struct __timeval64 *__tv,
+			     const struct timezone *__tz);
 extern int __adjtime (const struct timeval *__delta,
 		      struct timeval *__olddelta);
 extern int __getitimer (enum __itimer_which __which,
diff --git a/sysdeps/unix/sysv/linux/settimeofday64.c b/sysdeps/unix/sysv/linux/settimeofday64.c
new file mode 100644
index 0000000000..1a9fa23911
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/settimeofday64.c
@@ -0,0 +1,39 @@
+/* Set the current time of day and timezone information.
+
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sysdep.h>
+#include <errno.h>
+#include <sys/time.h>
+
+int __settimeofday64(const struct __timeval64 *tv,
+                       const struct timezone *tz)
+{
+  struct timeval tv32;
+
+  if (tv && tv->tv_sec > INT_MAX)
+    {
+      __set_errno(EOVERFLOW);
+      return -1;
+    }
+
+  tv32.tv_sec = tv->tv_sec;
+  tv32.tv_usec = tv->tv_usec;
+
+  return __settimeofday(&tv32, tz);
+}
diff --git a/time/Makefile b/time/Makefile
index f71847f2b3..7657debc72 100644
--- a/time/Makefile
+++ b/time/Makefile
@@ -32,7 +32,7 @@ headers := time.h sys/time.h sys/timeb.h bits/time.h			\
 routines := offtime asctime clock ctime ctime_r difftime \
 	    gmtime localtime mktime time		 \
 	    gettimeofday settimeofday adjtime tzset	 \
-	    gettimeofday64				 \
+	    gettimeofday64 settimeofday64		 \
 	    tzfile getitimer setitimer			 \
 	    stime dysize timegm ftime			 \
 	    getdate strptime strptime_l			 \
diff --git a/time/Versions b/time/Versions
index dff4717af9..bbb6403f3c 100644
--- a/time/Versions
+++ b/time/Versions
@@ -85,5 +85,6 @@ libc {
     __futimes64;
     __lutimes64;
     __gettimeofday64;
+    __settimeofday64;
   }
 }
diff --git a/time/settimeofday.c b/time/settimeofday.c
index 01bf4b032d..000ed21849 100644
--- a/time/settimeofday.c
+++ b/time/settimeofday.c
@@ -29,3 +29,11 @@ __settimeofday (const struct timeval *tv, const struct timezone *tz)
 stub_warning (settimeofday)
 
 weak_alias (__settimeofday, settimeofday)
+
+int
+__settimeofday64 (const struct timeval *tv, const struct timezone *tz)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+stub_warning (__settimeofday64)
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  31/63] Y2038: add struct __stat64_t64
  2018-04-18 20:20                                                           ` [[PATCH RFC 2] 30/63] Y2038: add function __timerfd_settime64 Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:21                                                             ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:20                                                               ` [[PATCH RFC 2] 32/63] Y2038: add function __fstat64_t64 (and __fxstat64_t64) Albert ARIBAUD (3ADEV)
  0 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:21 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

---
 include/sys/stat.h | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/include/sys/stat.h b/include/sys/stat.h
index b82d452780..72f627f247 100644
--- a/include/sys/stat.h
+++ b/include/sys/stat.h
@@ -2,6 +2,30 @@
 #include <io/sys/stat.h>
 
 #ifndef _ISOMAC
+
+/* Used for 64-bit time implementations */
+struct __stat64_t64
+  {
+    __dev_t st_dev;			/* Device.  */
+    unsigned int __pad1;
+
+    __ino_t __st_ino;			/* 32bit file serial number.	*/
+    __mode_t st_mode;			/* File mode.  */
+    __nlink_t st_nlink;			/* Link count.  */
+    __uid_t st_uid;			/* User ID of the file's owner.	*/
+    __gid_t st_gid;			/* Group ID of the file's group.*/
+    __dev_t st_rdev;			/* Device number, if device.  */
+    unsigned int __pad2;
+    __off64_t st_size;			/* Size of file, in bytes.  */
+    __blksize_t st_blksize;		/* Optimal block size for I/O.  */
+
+    __blkcnt64_t st_blocks;		/* Number 512-byte blocks allocated. */
+    struct __timespec64 st_atim;		/* Time of last access.  */
+    struct __timespec64 st_mtim;		/* Time of last modification.  */
+    struct __timespec64 st_ctim;		/* Time of last status change.  */
+    __ino64_t st_ino;			/* File serial number.		*/
+  };
+
 /* Now define the internal interfaces. */
 extern int __stat (const char *__file, struct stat *__buf);
 extern int __fstat (int __fd, struct stat *__buf);
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  39/63] Y2038: add function __stime64
  2018-04-18 20:21                                                                           ` [[PATCH RFC 2] 38/63] Y2038: add function __time64 Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:21                                                                             ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:21                                                                               ` [[PATCH RFC 2] 40/63] Y2038: add function __utimes64 Albert ARIBAUD (3ADEV)
  0 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:21 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

This implementation uses __settimeofday64.
Therefore, on a system where current time-of-day is 32 bits, this
implementation will fail for dates beyond Y2038.
---
 sysdeps/unix/stime64.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 time/Makefile          |  2 +-
 time/Versions          |  1 +
 time/stime.c           | 17 +++++++++++++++++
 4 files changed, 66 insertions(+), 1 deletion(-)
 create mode 100644 sysdeps/unix/stime64.c

diff --git a/sysdeps/unix/stime64.c b/sysdeps/unix/stime64.c
new file mode 100644
index 0000000000..2506227395
--- /dev/null
+++ b/sysdeps/unix/stime64.c
@@ -0,0 +1,47 @@
+/* Set the system clock on a unix system 
+
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <stddef.h>		/* For NULL.  */
+#include <sys/time.h>
+#include <time.h>
+
+/* Set the system clock to *WHEN.  */
+
+int
+__stime64 (const __time64_t *when)
+{
+  struct __timeval64 tv;
+
+  if (when == NULL)
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+  if (*when > INT_MAX)
+    {
+      __set_errno (EOVERFLOW);
+      return -1;
+    }
+
+  tv.tv_sec = *when;
+  tv.tv_usec = 0;
+  return __settimeofday64 (&tv, (struct timezone *) 0);
+}
diff --git a/time/Makefile b/time/Makefile
index 23da9805ef..fac49865a2 100644
--- a/time/Makefile
+++ b/time/Makefile
@@ -31,7 +31,7 @@ headers := time.h sys/time.h sys/timeb.h bits/time.h			\
 
 routines := offtime asctime clock ctime ctime_r difftime \
 	    gmtime localtime mktime time		 \
-	    time64					 \
+	    time64 stime64				 \
 	    gettimeofday settimeofday adjtime tzset	 \
 	    gettimeofday64 settimeofday64		 \
 	    tzfile getitimer setitimer			 \
diff --git a/time/Versions b/time/Versions
index 9baff82719..6b1ca80c1e 100644
--- a/time/Versions
+++ b/time/Versions
@@ -87,5 +87,6 @@ libc {
     __gettimeofday64;
     __settimeofday64;
     __time64;
+    __stime64;
   }
 }
diff --git a/time/stime.c b/time/stime.c
index 0378e23888..5d22aaae61 100644
--- a/time/stime.c
+++ b/time/stime.c
@@ -35,3 +35,20 @@ stime (const time_t *when)
 }
 
 stub_warning (stime)
+
+/* 64-bit time version */
+
+int
+__stime64 (const __time64_t *when)
+{
+  if (when == NULL)
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+  __set_errno (ENOSYS);
+  return -1;
+}
+
+stub_warning (__stime64)
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  38/63] Y2038: add function __time64
  2018-04-18 20:21                                                                         ` [[PATCH RFC 2] 37/63] Y2038: add function __settimeofday64 Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:21                                                                           ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:21                                                                             ` [[PATCH RFC 2] 39/63] Y2038: add function __stime64 Albert ARIBAUD (3ADEV)
  0 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:21 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

This provides a generic Posix implementation based on calling
__gettimeofday64().
---
 sysdeps/posix/time64.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 time/Makefile          |  1 +
 time/Versions          |  1 +
 time/time.c            | 13 +++++++++++++
 4 files changed, 58 insertions(+)
 create mode 100644 sysdeps/posix/time64.c

diff --git a/sysdeps/posix/time64.c b/sysdeps/posix/time64.c
new file mode 100644
index 0000000000..4a58228d8a
--- /dev/null
+++ b/sysdeps/posix/time64.c
@@ -0,0 +1,43 @@
+/* Get the 64-bit current time
+ * 
+   Copyright (C) 1991-2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <stddef.h>		/* For NULL.  */
+#include <time.h>
+#include <sys/time.h>
+
+
+/* Return the current time as a `time_t' and also put it in *T if T is
+   not NULL.  Time is represented as seconds from Jan 1 00:00:00 1970.  */
+
+__time64_t
+__time64 (__time64_t *t)
+{
+  struct __timeval64 tv;
+  __time64_t result;
+
+  if (__gettimeofday64 (&tv, (struct timezone *) NULL))
+    result = (__time64_t) -1;
+  else
+    result = tv.tv_sec;
+
+  if (t != NULL)
+    *t = result;
+
+  return result;
+}
diff --git a/time/Makefile b/time/Makefile
index 7657debc72..23da9805ef 100644
--- a/time/Makefile
+++ b/time/Makefile
@@ -31,6 +31,7 @@ headers := time.h sys/time.h sys/timeb.h bits/time.h			\
 
 routines := offtime asctime clock ctime ctime_r difftime \
 	    gmtime localtime mktime time		 \
+	    time64					 \
 	    gettimeofday settimeofday adjtime tzset	 \
 	    gettimeofday64 settimeofday64		 \
 	    tzfile getitimer setitimer			 \
diff --git a/time/Versions b/time/Versions
index bbb6403f3c..9baff82719 100644
--- a/time/Versions
+++ b/time/Versions
@@ -86,5 +86,6 @@ libc {
     __lutimes64;
     __gettimeofday64;
     __settimeofday64;
+    __time64;
   }
 }
diff --git a/time/time.c b/time/time.c
index 4996d26f13..9703c72464 100644
--- a/time/time.c
+++ b/time/time.c
@@ -31,3 +31,16 @@ time (time_t *timer)
 libc_hidden_def (time)
 
 stub_warning (time)
+
+/* 64-bit time version */
+
+__time64_t
+__time64 (__time64_ *timer)
+{
+  __set_errno (ENOSYS);
+
+  if (timer != NULL)
+    *timer = (__time64_t) -1;
+  return (__time64_t) -1;
+}
+libc_hidden_def (__time64)
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  43/63] Y2038: add function __msgctl64
  2018-04-18 20:21                                                                                   ` [[PATCH RFC 2] 42/63] Y2038: add function __mq_timedsend64 Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:21                                                                                     ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:22                                                                                       ` [[PATCH RFC 2] 44/63] Y2038: add function __sched_rr_get_interval64 Albert ARIBAUD (3ADEV)
  0 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:21 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

---
 sysdeps/unix/sysv/linux/msgctl.c | 72 ++++++++++++++++++++++++++++++++++++++++
 sysvipc/Versions                 |  3 ++
 2 files changed, 75 insertions(+)

diff --git a/sysdeps/unix/sysv/linux/msgctl.c b/sysdeps/unix/sysv/linux/msgctl.c
index 7280cba31a..49f76f75d1 100644
--- a/sysdeps/unix/sysv/linux/msgctl.c
+++ b/sysdeps/unix/sysv/linux/msgctl.c
@@ -69,3 +69,75 @@ __old_msgctl (int msqid, int cmd, struct __old_msqid_ds *buf)
 }
 compat_symbol (libc, __old_msgctl, msgctl, GLIBC_2_0);
 #endif
+
+/* 64-bit time version */
+
+struct __msqid_ds64
+{
+  struct ipc_perm msg_perm;	/* structure describing operation permission */
+  __time64_t msg_stime;		/* time of last msgsnd command */
+  unsigned long int __glibc_reserved1;
+  __time64_t msg_rtime;		/* time of last msgrcv command */
+  unsigned long int __glibc_reserved2;
+  __time64_t msg_ctime;		/* time of last change */
+  unsigned long int __glibc_reserved3;
+  unsigned long int __msg_cbytes; /* current number of bytes on queue */
+  msgqnum_t msg_qnum;		/* number of messages currently on queue */
+  msglen_t msg_qbytes;		/* max number of bytes allowed on queue */
+  __pid_t msg_lspid;		/* pid of last msgsnd() */
+  __pid_t msg_lrpid;		/* pid of last msgrcv() */
+  unsigned long int __glibc_reserved4;
+  unsigned long int __glibc_reserved5;
+};
+
+extern int __y2038_linux_support;
+
+int
+__msgctl64 (int msqid, int cmd, struct __msqid_ds64 *buf)
+{
+  int result;
+  struct msqid_ds buf32, *pbuf32 = NULL;
+
+  if (__y2038_linux_support)
+    {
+      /* TODO: use 64-bit syscalls */
+    }
+
+  if (cmd == IPC_SET && buf != NULL)
+    {
+      buf32.msg_qbytes = buf->msg_qbytes;
+      buf32.msg_perm.uid = buf->msg_perm.uid;
+      buf32.msg_perm.gid = buf->msg_perm.gid;
+      buf32.msg_perm.mode = buf->msg_perm.mode;
+    }
+
+  if (cmd == IPC_SET || cmd == IPC_STAT)
+    pbuf32 = &buf32;
+
+#ifdef __ASSUME_DIRECT_SYSVIPC_SYSCALLS
+  result = INLINE_SYSCALL_CALL (msgctl, msqid, cmd | __IPC_64, pbuf32);
+#else
+  result = INLINE_SYSCALL_CALL (ipc, IPCOP_msgctl, msqid, cmd | __IPC_64,
+                                0, pbuf32);
+#endif
+
+  if (cmd == IPC_STAT && result == 0 && buf != NULL)
+    {
+      buf->msg_perm = buf32.msg_perm;
+      buf->msg_stime = buf32.msg_stime;
+      buf->__glibc_reserved1 = buf32.__glibc_reserved1;
+      buf->msg_rtime = buf32.msg_rtime;
+      buf->__glibc_reserved2 = buf32.__glibc_reserved2;
+      buf->msg_ctime = buf32.msg_ctime;
+      buf->__glibc_reserved3 = buf32.__glibc_reserved3;
+      buf->__msg_cbytes = buf32.__msg_cbytes;
+      buf->msg_qnum = buf32.msg_qnum;
+      buf->msg_qbytes = buf32.msg_qbytes;
+      buf->msg_lspid = buf32.msg_lspid;
+      buf->msg_lrpid = buf32.msg_lrpid;
+      buf->__glibc_reserved4 = buf32.__glibc_reserved4;
+      buf->__glibc_reserved5 = buf32.__glibc_reserved5;
+    }
+
+  return result;
+}
diff --git a/sysvipc/Versions b/sysvipc/Versions
index 4c797e25ce..eb7281407c 100644
--- a/sysvipc/Versions
+++ b/sysvipc/Versions
@@ -13,6 +13,9 @@ libc {
     # Non-standard function.
     semtimedop;
   }
+  GLIBC_2.27 {
+    __msgctl64;
+  }
   GLIBC_PRIVATE {
     # Cancellation point entries.
     __libc_msgrcv; __libc_msgsnd;
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  40/63] Y2038: add function __utimes64
  2018-04-18 20:21                                                                             ` [[PATCH RFC 2] 39/63] Y2038: add function __stime64 Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:21                                                                               ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:21                                                                                 ` [[PATCH RFC 2] 41/63] Y2038: add function __mq_timedreceived64 Albert ARIBAUD (3ADEV)
  0 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:21 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

---
 include/time.h                     |  3 +++
 misc/Makefile                      |  3 ++-
 misc/utimes.c                      | 15 +++++++++++
 sysdeps/unix/sysv/linux/utimes64.c | 54 ++++++++++++++++++++++++++++++++++++++
 time/Versions                      |  1 +
 5 files changed, 75 insertions(+), 1 deletion(-)
 create mode 100644 sysdeps/unix/sysv/linux/utimes64.c

diff --git a/include/time.h b/include/time.h
index 68c52220fd..5e601adbd4 100644
--- a/include/time.h
+++ b/include/time.h
@@ -43,6 +43,9 @@ extern int __clock_nanosleep64 (clockid_t __clock_id, int __flags,
 				const struct __timespec64 *__req,
 				struct __timespec64 *__rem);
 
+extern int __utimes64 (const char *file,
+                       const struct __timeval64 tvp[2]);
+
 /* Now define the internal interfaces.  */
 struct tm;
 
diff --git a/misc/Makefile b/misc/Makefile
index a5076b3672..f3463620fb 100644
--- a/misc/Makefile
+++ b/misc/Makefile
@@ -70,7 +70,8 @@ routines := brk sbrk sstk ioctl \
 	    getloadavg getclktck \
 	    fgetxattr flistxattr fremovexattr fsetxattr getxattr \
 	    listxattr lgetxattr llistxattr lremovexattr lsetxattr \
-	    removexattr setxattr getauxval ifunc-impl-list makedev
+	    removexattr setxattr getauxval ifunc-impl-list makedev \
+	    utimes64
 
 generated += tst-error1.mtrace tst-error1-mem.out
 
diff --git a/misc/utimes.c b/misc/utimes.c
index 0ae6946142..cdb43f6688 100644
--- a/misc/utimes.c
+++ b/misc/utimes.c
@@ -38,3 +38,18 @@ __utimes (const char *file, const struct timeval tvp[2])
 weak_alias (__utimes, utimes)
 
 stub_warning (utimes)
+
+int
+__utimes64 (const char *file, const struct __timeval64 tvp[2])
+{
+  if (file == NULL)
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+  __set_errno (ENOSYS);
+  return -1;
+}
+
+stub_warning (__utimes64)
diff --git a/sysdeps/unix/sysv/linux/utimes64.c b/sysdeps/unix/sysv/linux/utimes64.c
new file mode 100644
index 0000000000..eb9022a2d9
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/utimes64.c
@@ -0,0 +1,54 @@
+/* Copyright (C) 1995-2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <stddef.h>
+#include <utime.h>
+#include <sys/time.h>
+#include <sysdep.h>
+
+
+/* Consider moving to syscalls.list.  */
+
+extern int __y2038_linux_support;
+
+int
+__utimes64 (const char *file, const struct __timeval64 tvp[2])
+{
+  struct timeval tv32[2], *tvp32 = NULL;
+
+  if (__y2038_linux_support)
+    {
+      /* TODO: implement using 64-bit time syscall */
+    }
+
+  if (tvp != NULL)
+    {
+      if (tvp[0].tv_sec > INT_MAX || tvp[1].tv_sec > INT_MAX)
+        {
+          __set_errno(EOVERFLOW);
+          return -1;
+        }
+      tv32[0].tv_sec = tvp[0].tv_sec;
+      tv32[0].tv_usec = tvp[0].tv_usec;
+      tv32[1].tv_sec = tvp[1].tv_sec;
+      tv32[1].tv_usec = tvp[1].tv_usec;
+      tvp32 = tv32;
+    }
+
+  return INLINE_SYSCALL (utimes, 2, file, tvp32);
+}
diff --git a/time/Versions b/time/Versions
index 6b1ca80c1e..86ced5a7c7 100644
--- a/time/Versions
+++ b/time/Versions
@@ -88,5 +88,6 @@ libc {
     __settimeofday64;
     __time64;
     __stime64;
+    __utimes64;
   }
 }
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  36/63] Y2038: add function __gettimeofday64
  2018-04-18 20:21                                                                     ` [[PATCH RFC 2] 35/63] Y2038: add function __fstatat64_t64 (and __fxstatat_t64) Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:21                                                                       ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:21                                                                         ` [[PATCH RFC 2] 37/63] Y2038: add function __settimeofday64 Albert ARIBAUD (3ADEV)
  0 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:21 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

Implementing a 64-bit settimeofday requires adding a new
file to build under time/ and we cannot name that new file
'settimeofday.c' or it will break the 32-bit settimeofday
symbol, so we call it 'settimeofday64.c'.
---
 include/sys/time.h                       |  2 ++
 sysdeps/unix/sysv/linux/gettimeofday64.c | 48 ++++++++++++++++++++++++++++++++
 time/Makefile                            |  1 +
 time/Versions                            |  1 +
 time/gettimeofday.c                      | 11 +++++++-
 5 files changed, 62 insertions(+), 1 deletion(-)
 create mode 100644 sysdeps/unix/sysv/linux/gettimeofday64.c

diff --git a/include/sys/time.h b/include/sys/time.h
index 98f6b6b2cc..ed73a445bf 100644
--- a/include/sys/time.h
+++ b/include/sys/time.h
@@ -24,6 +24,8 @@ extern int __gettimeofday (struct timeval *__tv,
 			   struct timezone *__tz);
 libc_hidden_proto (__gettimeofday)
 libc_hidden_proto (gettimeofday)
+extern int __gettimeofday64 (struct __timeval64 *__tv,
+			     struct timezone *__tz);
 extern int __settimeofday (const struct timeval *__tv,
 			   const struct timezone *__tz)
 	attribute_hidden;
diff --git a/sysdeps/unix/sysv/linux/gettimeofday64.c b/sysdeps/unix/sysv/linux/gettimeofday64.c
new file mode 100644
index 0000000000..bde2a7e973
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/gettimeofday64.c
@@ -0,0 +1,48 @@
+/* Copyright (C) 2015-2018 Free Software Foundation, Inc.
+
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public License as
+   published by the Free Software Foundation; either version 2.1 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <sys/time.h>
+
+#undef __gettimeofday
+
+#ifdef HAVE_GETTIMEOFDAY_VSYSCALL
+# define HAVE_VSYSCALL
+#endif
+#include <sysdep-vdso.h>
+
+/* Get the current time of day and timezone information,
+   putting it into *tv and *tz.  If tz is null, *tz is not filled.
+   Returns 0 on success, -1 on errors.  */
+
+int
+__gettimeofday64 (struct __timeval64 *tv, struct timezone *tz)
+{
+  struct timeval tv32;
+  int result;
+
+  result = INLINE_VSYSCALL (gettimeofday, 2, &tv32, tz);
+
+  if (result == 0)
+    {
+      tv->tv_sec = tv32.tv_sec;
+      tv->tv_usec = tv32.tv_usec;
+    }
+
+  return result;
+}
diff --git a/time/Makefile b/time/Makefile
index 0db1206820..f71847f2b3 100644
--- a/time/Makefile
+++ b/time/Makefile
@@ -32,6 +32,7 @@ headers := time.h sys/time.h sys/timeb.h bits/time.h			\
 routines := offtime asctime clock ctime ctime_r difftime \
 	    gmtime localtime mktime time		 \
 	    gettimeofday settimeofday adjtime tzset	 \
+	    gettimeofday64				 \
 	    tzfile getitimer setitimer			 \
 	    stime dysize timegm ftime			 \
 	    getdate strptime strptime_l			 \
diff --git a/time/Versions b/time/Versions
index ac92d742c3..dff4717af9 100644
--- a/time/Versions
+++ b/time/Versions
@@ -84,5 +84,6 @@ libc {
     __sigtimedwait64;
     __futimes64;
     __lutimes64;
+    __gettimeofday64;
   }
 }
diff --git a/time/gettimeofday.c b/time/gettimeofday.c
index d1ab9acd17..e4a67c6d99 100644
--- a/time/gettimeofday.c
+++ b/time/gettimeofday.c
@@ -16,7 +16,6 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include <errno.h>
-#include <sys/time.h>
 
 /* Get the current time of day and timezone information,
    putting it into *TV and *TZ.  If TZ is NULL, *TZ is not filled.
@@ -32,3 +31,13 @@ weak_alias (__gettimeofday, gettimeofday)
 libc_hidden_weak (gettimeofday)
 
 stub_warning (gettimeofday)
+
+/* 64-bit time version */
+
+int
+__gettimeofday64 (struct timeval *tv, struct timezone *tz)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+stub_warning (__gettimeofday64)
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  41/63] Y2038: add function __mq_timedreceived64
  2018-04-18 20:21                                                                               ` [[PATCH RFC 2] 40/63] Y2038: add function __utimes64 Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:21                                                                                 ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:21                                                                                   ` [[PATCH RFC 2] 42/63] Y2038: add function __mq_timedsend64 Albert ARIBAUD (3ADEV)
  0 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:21 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

---
 rt/Makefile                                        |  3 +-
 rt/Versions                                        |  1 +
 rt/mq_timedreceive64.c                             | 46 ++++++++++++++++++++++
 sysdeps/unix/sysv/linux/arm/librt.abilist          |  1 +
 .../sysv/linux/powerpc/powerpc32/librt.abilist     |  1 +
 5 files changed, 51 insertions(+), 1 deletion(-)
 create mode 100644 rt/mq_timedreceive64.c

diff --git a/rt/Makefile b/rt/Makefile
index 994891e42d..293918a3c9 100644
--- a/rt/Makefile
+++ b/rt/Makefile
@@ -37,7 +37,8 @@ timer-routines := timer_create timer_delete timer_getoverr		\
 shm-routines   := shm_open shm_unlink
 mq-routines    := mq_open mq_close mq_unlink mq_getattr mq_setattr	\
 		  mq_notify mq_send mq_receive mq_timedsend		\
-		  mq_timedreceive
+		  mq_timedreceive					\
+		  mq_timedreceive64
 
 routines = $(clock-routines)
 
diff --git a/rt/Versions b/rt/Versions
index 156df9f647..23d759a727 100644
--- a/rt/Versions
+++ b/rt/Versions
@@ -42,5 +42,6 @@ librt {
    __timer_settime64;
    __timerfd_gettime64;
    __timerfd_settime64;
+   __mq_timedreceive64;
   }
 }
diff --git a/rt/mq_timedreceive64.c b/rt/mq_timedreceive64.c
new file mode 100644
index 0000000000..e8853864c9
--- /dev/null
+++ b/rt/mq_timedreceive64.c
@@ -0,0 +1,46 @@
+/* Receive the oldest from highest priority messages in message queue
+   MQDES, stop waiting if ABS_TIMEOUT expires.
+
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <mqueue.h>
+
+/* 64-bit time version */
+
+extern int __y2038_linux_support;
+
+ssize_t
+__mq_timedreceive64 (mqd_t mqdes, char *__restrict msg_ptr, size_t msg_len,
+		 unsigned int *__restrict msg_prio,
+		 const struct __timespec64 *__restrict abs_timeout)
+{
+  struct timespec ts32, *tsp32 = NULL;
+  if (__y2038_linux_support)
+    {
+      /* TODO: use 64-bit syscall */
+    }
+
+  if (abs_timeout)
+    {
+      ts32.tv_sec = abs_timeout->tv_sec;
+      ts32.tv_nsec = abs_timeout->tv_nsec;
+      tsp32 = &ts32;
+    }
+  return mq_timedreceive(mqdes, msg_ptr, msg_len, msg_prio, tsp32);
+}
diff --git a/sysdeps/unix/sysv/linux/arm/librt.abilist b/sysdeps/unix/sysv/linux/arm/librt.abilist
index 4ca48fc2a6..ff68d1e19d 100644
--- a/sysdeps/unix/sysv/linux/arm/librt.abilist
+++ b/sysdeps/unix/sysv/linux/arm/librt.abilist
@@ -1,4 +1,5 @@
 GLIBC_2.27 GLIBC_2.27 A
+GLIBC_2.27 __mq_timedreceive64 F
 GLIBC_2.27 __timer_gettime64 F
 GLIBC_2.27 __timer_settime64 F
 GLIBC_2.27 __timerfd_gettime64 F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/librt.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/librt.abilist
index 1d6dd33e52..5a9d06731e 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/librt.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/librt.abilist
@@ -30,6 +30,7 @@ GLIBC_2.2 timer_getoverrun F
 GLIBC_2.2 timer_gettime F
 GLIBC_2.2 timer_settime F
 GLIBC_2.27 GLIBC_2.27 A
+GLIBC_2.27 __mq_timedreceive64 F
 GLIBC_2.27 __timer_gettime64 F
 GLIBC_2.27 __timer_settime64 F
 GLIBC_2.27 __timerfd_gettime64 F
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  45/63] Y2038: add function __nanosleep64
  2018-04-18 20:22                                                                                       ` [[PATCH RFC 2] 44/63] Y2038: add function __sched_rr_get_interval64 Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:21                                                                                         ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:22                                                                                           ` [[PATCH RFC 2] 46/63] Y2038: add function __adjtime64 Albert ARIBAUD (3ADEV)
  0 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:21 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

---
 posix/Makefile      |  2 +-
 posix/Versions      |  1 +
 posix/nanosleep64.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 65 insertions(+), 1 deletion(-)
 create mode 100644 posix/nanosleep64.c

diff --git a/posix/Makefile b/posix/Makefile
index 0adb57653f..c7ee41d8c2 100644
--- a/posix/Makefile
+++ b/posix/Makefile
@@ -63,7 +63,7 @@ routines :=								      \
 	spawnattr_setsigmask spawnattr_setschedpolicy spawnattr_setschedparam \
 	posix_madvise							      \
 	get_child_max sched_cpucount sched_cpualloc sched_cpufree	      \
-	sched_rr_gi64
+	sched_rr_gi64 nanosleep64
 
 aux		:= init-posix environ
 tests		:= test-errno tstgetopt testfnm runtests runptests \
diff --git a/posix/Versions b/posix/Versions
index 813c765a98..7a3f5a2dd9 100644
--- a/posix/Versions
+++ b/posix/Versions
@@ -137,6 +137,7 @@ libc {
   GLIBC_2.27 {
     glob; glob64;
     __sched_rr_get_interval64;
+    __nanosleep64;
   }
   GLIBC_PRIVATE {
     __libc_fork; __libc_pread; __libc_pwrite;
diff --git a/posix/nanosleep64.c b/posix/nanosleep64.c
new file mode 100644
index 0000000000..dcb8d55540
--- /dev/null
+++ b/posix/nanosleep64.c
@@ -0,0 +1,63 @@
+/* Pause execution for a number of nanoseconds
+
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <time.h>
+
+extern int __y2038_linux_support;
+
+/* Pause execution for a number of nanoseconds.  */
+int
+__nanosleep64 (const struct __timespec64 *requested_time,
+	         struct __timespec64 *remaining)
+{
+  struct timespec treq32, *treqp32 = NULL;
+  struct timespec trem32, *tremp32 = NULL;
+
+  if (__y2038_linux_support)
+    {
+      /* TODO: use 64-bit time syscalls */
+    }
+
+  if (requested_time)
+    {
+      if (requested_time->tv_sec > INT_MAX)
+        {
+          __set_errno(EOVERFLOW);
+          return -1;
+        }
+      treq32.tv_sec = requested_time->tv_sec;
+      treq32.tv_nsec = requested_time->tv_nsec;
+      treqp32 = & treq32;
+    }
+
+  if (remaining)
+    tremp32 = &trem32;
+
+  int result = __nanosleep(treqp32, tremp32);
+
+  if (result == 1 && errno == EINTR && remaining)
+    {
+      remaining->tv_sec = trem32.tv_sec;
+      remaining->tv_nsec = trem32.tv_nsec;
+      remaining->tv_pad = 0;
+    }
+
+  return result;
+}
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  33/63] Y2038: add function __stat64_t64 (and __xstat64_t64)
  2018-04-18 20:20                                                               ` [[PATCH RFC 2] 32/63] Y2038: add function __fstat64_t64 (and __fxstat64_t64) Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:21                                                                 ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:21                                                                   ` [[PATCH RFC 2] 34/63] Y2038: add function __lstat64_t64 (and __lxstat64_t64) Albert ARIBAUD (3ADEV)
  0 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:21 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

There is no Y2038-proof linux struct stat for now, so these
implementations just use the existing syscalls and convert from kernel
32-bit-time struct stat64 to GLIBC Y2038-ready struct __stat64_t64.
---
 include/sys/stat.h                |  2 ++
 io/Versions                       |  1 +
 io/stat64.c                       |  7 ++++++
 sysdeps/unix/sysv/linux/xstat64.c | 50 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 60 insertions(+)

diff --git a/include/sys/stat.h b/include/sys/stat.h
index 0d755c7398..b2a0fb594f 100644
--- a/include/sys/stat.h
+++ b/include/sys/stat.h
@@ -40,6 +40,8 @@ extern int __mknod (const char *__path,
 		    __mode_t __mode, __dev_t __dev);
 extern int __fxstat64_t64 (int __ver, int __fildes,
                            struct __stat64_t64 *__stat_buf);
+extern int __xstat64_t64 (int __ver, const char *__filename,
+                          struct __stat64_t64 *__stat_buf);
 
 #if IS_IN (libc) || (IS_IN (rtld) && !defined NO_RTLD_HIDDEN)
 hidden_proto (__fxstat)
diff --git a/io/Versions b/io/Versions
index a2857c7754..c00f9849c2 100644
--- a/io/Versions
+++ b/io/Versions
@@ -128,5 +128,6 @@ libc {
   GLIBC_2.27 {
     copy_file_range;
     __fxstat64_t64;
+    __xstat64_t64;
   }
 }
diff --git a/io/stat64.c b/io/stat64.c
index 5020551c0f..bca8b739d7 100644
--- a/io/stat64.c
+++ b/io/stat64.c
@@ -50,3 +50,10 @@ stat64 (const char *file, struct stat64 *buf)
 {
   return __xstat64 (_STAT_VER, file, buf);
 }
+
+int
+attribute_hidden
+__stat64_t64 (const char *file, struct __stat64_t64 *buf)
+{
+  return __xstat64_t64 (_STAT_VER, file, buf);
+}
diff --git a/sysdeps/unix/sysv/linux/xstat64.c b/sysdeps/unix/sysv/linux/xstat64.c
index afc9ba2cb7..8627d2f886 100644
--- a/sysdeps/unix/sysv/linux/xstat64.c
+++ b/sysdeps/unix/sysv/linux/xstat64.c
@@ -52,3 +52,53 @@ hidden_ver (___xstat64, __xstat64)
 strong_alias (___xstat64, __xstat64)
 hidden_def (__xstat64)
 #endif
+
+/* 64-bit time version */
+
+extern int __y2038_linux_support;
+
+int
+__xstat64_t64 (int vers, const char *name, struct __stat64_t64 *buf)
+{
+  int result;
+  struct stat64 st64;
+
+  if (__y2038_linux_support)
+    {
+      // TODO: use 64-bit syscalls when they become available
+    }
+
+  result = INLINE_SYSCALL (stat64, 2, name, &st64);
+#if defined _HAVE_STAT64___ST_INO && !__ASSUME_ST_INO_64_BIT
+  if (__builtin_expect (!result, 1) && st64.__st_ino != (__ino_t) st64.st_ino)
+    st64.st_ino = st64.__st_ino;
+#endif
+  if (!result)
+    {
+      buf->st_dev          = st64.st_dev;
+      //buf->__pad1		     = st64.__pad1;
+    
+#if defined _HAVE_STAT64___ST_INO
+      buf->__st_ino        = st64.__st_ino;
+#endif
+      buf->st_mode         = st64.st_mode;
+      buf->st_nlink        = st64.st_nlink;
+      buf->st_uid          = st64.st_uid;		 
+      buf->st_gid          = st64.st_gid;		 
+      buf->st_rdev         = st64.st_rdev;		 
+      buf->__pad2          = st64.__pad2;
+      buf->st_size         = st64.st_size;		 
+      buf->st_blksize      = st64.st_blksize;
+    
+      buf->st_blocks       = st64.st_blocks;
+      buf->st_atim.tv_sec  = st64.st_atim.tv_sec;
+      buf->st_atim.tv_nsec = st64.st_atim.tv_nsec;
+      buf->st_mtim.tv_sec  = st64.st_mtim.tv_sec;
+      buf->st_mtim.tv_nsec = st64.st_mtim.tv_nsec;
+      buf->st_ctim.tv_sec  = st64.st_ctim.tv_sec;
+      buf->st_ctim.tv_nsec = st64.st_ctim.tv_nsec;
+    
+      buf->st_ino          = st64.st_ino;
+    }
+  return result;
+}
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  35/63] Y2038: add function __fstatat64_t64 (and __fxstatat_t64)
  2018-04-18 20:21                                                                   ` [[PATCH RFC 2] 34/63] Y2038: add function __lstat64_t64 (and __lxstat64_t64) Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:21                                                                     ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:21                                                                       ` [[PATCH RFC 2] 36/63] Y2038: add function __gettimeofday64 Albert ARIBAUD (3ADEV)
  0 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:21 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

There is no Y2038-proof linux struct stat for now, so these
implementations just use the existing syscalls and convert from kernel
32-bit-time struct stat64 to GLIBC Y2038-ready struct __stat64_t64.
---
 include/sys/stat.h                   |  4 +++
 io/Versions                          |  1 +
 io/fstatat64.c                       |  7 +++++
 sysdeps/unix/sysv/linux/fxstatat64.c | 54 ++++++++++++++++++++++++++++++++++++
 4 files changed, 66 insertions(+)

diff --git a/include/sys/stat.h b/include/sys/stat.h
index b83189a22c..3b93d22c69 100644
--- a/include/sys/stat.h
+++ b/include/sys/stat.h
@@ -44,6 +44,10 @@ extern int __xstat64_t64 (int __ver, const char *__filename,
                           struct __stat64_t64 *__stat_buf);
 extern int __lxstat64_t64 (int __ver, const char *__filename,
 		           struct __stat64_t64 *__stat_buf);
+extern int __fxstatat64_t64 (int __ver, int __fildes,
+                             const char *__filename,
+			     struct __stat64_t64 *__stat_buf,
+                             int __flag);
 
 #if IS_IN (libc) || (IS_IN (rtld) && !defined NO_RTLD_HIDDEN)
 hidden_proto (__fxstat)
diff --git a/io/Versions b/io/Versions
index e71167e932..13334f07fb 100644
--- a/io/Versions
+++ b/io/Versions
@@ -130,5 +130,6 @@ libc {
     __fxstat64_t64;
     __xstat64_t64;
     __lxstat64_t64;
+    __fxstatat64_t64;
   }
 }
diff --git a/io/fstatat64.c b/io/fstatat64.c
index f4f46a9574..9a427d553f 100644
--- a/io/fstatat64.c
+++ b/io/fstatat64.c
@@ -50,3 +50,10 @@ fstatat64 (int fd, const char *file, struct stat64 *buf, int flag)
 {
   return __fxstatat64 (_STAT_VER, fd, file, buf, flag);
 }
+
+int
+attribute_hidden
+__fstatat64_t64 (int fd, const char *file, struct __stat64_t64 *buf, int flag)
+{
+  return __fxstatat64_t64 (_STAT_VER, fd, file, buf, flag);
+}
diff --git a/sysdeps/unix/sysv/linux/fxstatat64.c b/sysdeps/unix/sysv/linux/fxstatat64.c
index baa9a60a66..a5db35a7a1 100644
--- a/sysdeps/unix/sysv/linux/fxstatat64.c
+++ b/sysdeps/unix/sysv/linux/fxstatat64.c
@@ -45,3 +45,57 @@ __fxstatat64 (int vers, int fd, const char *file, struct stat64 *st, int flag)
 								      err));
 }
 libc_hidden_def (__fxstatat64)
+
+/* 64-bit time version */
+
+extern int __y2038_linux_support;
+
+int
+__fxstatat64_t64 (int vers, int fd, const char *file, struct __stat64_t64 *buf, int flag)
+{
+  if (__glibc_unlikely (vers != _STAT_VER_LINUX))
+    return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
+
+  int result;
+  struct stat64 st64;
+  INTERNAL_SYSCALL_DECL (err);
+
+  if (__y2038_linux_support)
+    {
+      // TODO: use 64-bit syscalls when they become available
+    }
+
+  result = INTERNAL_SYSCALL (fstatat64, err, 4, fd, file, &st64, flag);
+  if (!__builtin_expect (INTERNAL_SYSCALL_ERROR_P (result, err), 1))
+    {
+      buf->st_dev          = st64.st_dev;
+      //buf->__pad1		     = st64.__pad1;
+    
+#if defined _HAVE_STAT64___ST_INO
+      buf->__st_ino        = st64.__st_ino;
+#endif
+      buf->st_mode         = st64.st_mode;
+      buf->st_nlink        = st64.st_nlink;
+      buf->st_uid          = st64.st_uid;		 
+      buf->st_gid          = st64.st_gid;		 
+      buf->st_rdev         = st64.st_rdev;		 
+      buf->__pad2          = st64.__pad2;
+      buf->st_size         = st64.st_size;		 
+      buf->st_blksize      = st64.st_blksize;
+    
+      buf->st_blocks       = st64.st_blocks;		
+      buf->st_atim.tv_sec  = st64.st_atim.tv_sec;	
+      buf->st_atim.tv_nsec = st64.st_atim.tv_nsec;	
+      buf->st_mtim.tv_sec  = st64.st_mtim.tv_sec;	
+      buf->st_mtim.tv_nsec = st64.st_mtim.tv_nsec;	
+      buf->st_ctim.tv_sec  = st64.st_ctim.tv_sec;	
+      buf->st_ctim.tv_nsec = st64.st_ctim.tv_nsec;	
+    
+      buf->st_ino          = st64.st_ino;
+    
+      return 0;
+    }
+  else
+    return INLINE_SYSCALL_ERROR_RETURN_VALUE (INTERNAL_SYSCALL_ERRNO (result,
+								      err));
+}
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  42/63] Y2038: add function __mq_timedsend64
  2018-04-18 20:21                                                                                 ` [[PATCH RFC 2] 41/63] Y2038: add function __mq_timedreceived64 Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:21                                                                                   ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:21                                                                                     ` [[PATCH RFC 2] 43/63] Y2038: add function __msgctl64 Albert ARIBAUD (3ADEV)
  0 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:21 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

---
 rt/Makefile                                        |  2 +-
 rt/Versions                                        |  1 +
 rt/mq_timedsend64.c                                | 45 ++++++++++++++++++++++
 sysdeps/unix/sysv/linux/arm/librt.abilist          |  1 +
 .../sysv/linux/powerpc/powerpc32/librt.abilist     |  1 +
 5 files changed, 49 insertions(+), 1 deletion(-)
 create mode 100644 rt/mq_timedsend64.c

diff --git a/rt/Makefile b/rt/Makefile
index 293918a3c9..b5b51372ff 100644
--- a/rt/Makefile
+++ b/rt/Makefile
@@ -38,7 +38,7 @@ shm-routines   := shm_open shm_unlink
 mq-routines    := mq_open mq_close mq_unlink mq_getattr mq_setattr	\
 		  mq_notify mq_send mq_receive mq_timedsend		\
 		  mq_timedreceive					\
-		  mq_timedreceive64
+		  mq_timedreceive64 mq_timedsend64
 
 routines = $(clock-routines)
 
diff --git a/rt/Versions b/rt/Versions
index 23d759a727..a3b65cb4e7 100644
--- a/rt/Versions
+++ b/rt/Versions
@@ -43,5 +43,6 @@ librt {
    __timerfd_gettime64;
    __timerfd_settime64;
    __mq_timedreceive64;
+   __mq_timedsend64;
   }
 }
diff --git a/rt/mq_timedsend64.c b/rt/mq_timedsend64.c
new file mode 100644
index 0000000000..3320e37022
--- /dev/null
+++ b/rt/mq_timedsend64.c
@@ -0,0 +1,45 @@
+/* Add message pointed by MSG_PTR to message queue MQDES, stop blocking
+   on full message queue if ABS_TIMEOUT expires.
+
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <mqueue.h>
+
+/* 64-bit time version */
+
+extern int __y2038_linux_support;
+
+int
+__mq_timedsend64 (mqd_t mqdes, const char *msg_ptr, size_t msg_len,
+	      unsigned int msg_prio, const struct __timespec64 *abs_timeout)
+{
+  struct timespec ts32, *tsp32 = NULL;
+  if (__y2038_linux_support)
+    {
+      /* TODO: use 64-bit syscall */
+    }
+
+  if (abs_timeout)
+    {
+      ts32.tv_sec = abs_timeout->tv_sec;
+      ts32.tv_nsec = abs_timeout->tv_nsec;
+      tsp32 = &ts32;
+    }
+  return mq_timedsend(mqdes, msg_ptr, msg_len, msg_prio, tsp32);
+}
diff --git a/sysdeps/unix/sysv/linux/arm/librt.abilist b/sysdeps/unix/sysv/linux/arm/librt.abilist
index ff68d1e19d..546683c3c6 100644
--- a/sysdeps/unix/sysv/linux/arm/librt.abilist
+++ b/sysdeps/unix/sysv/linux/arm/librt.abilist
@@ -1,5 +1,6 @@
 GLIBC_2.27 GLIBC_2.27 A
 GLIBC_2.27 __mq_timedreceive64 F
+GLIBC_2.27 __mq_timedsend64 F
 GLIBC_2.27 __timer_gettime64 F
 GLIBC_2.27 __timer_settime64 F
 GLIBC_2.27 __timerfd_gettime64 F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/librt.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/librt.abilist
index 5a9d06731e..05cafc095b 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/librt.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/librt.abilist
@@ -31,6 +31,7 @@ GLIBC_2.2 timer_gettime F
 GLIBC_2.2 timer_settime F
 GLIBC_2.27 GLIBC_2.27 A
 GLIBC_2.27 __mq_timedreceive64 F
+GLIBC_2.27 __mq_timedsend64 F
 GLIBC_2.27 __timer_gettime64 F
 GLIBC_2.27 __timer_settime64 F
 GLIBC_2.27 __timerfd_gettime64 F
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  34/63] Y2038: add function __lstat64_t64 (and __lxstat64_t64)
  2018-04-18 20:21                                                                 ` [[PATCH RFC 2] 33/63] Y2038: add function __stat64_t64 (and __xstat64_t64) Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:21                                                                   ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:21                                                                     ` [[PATCH RFC 2] 35/63] Y2038: add function __fstatat64_t64 (and __fxstatat_t64) Albert ARIBAUD (3ADEV)
  0 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:21 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

There is no Y2038-proof linux struct stat for now, so these
implementations just use the existing syscalls and convert from kernel
32-bit-time struct stat64 to GLIBC Y2038-ready struct __stat64_t64.
---
 include/sys/stat.h                 |  2 ++
 io/Versions                        |  1 +
 io/lstat64.c                       |  7 ++++++
 sysdeps/unix/sysv/linux/lxstat64.c | 50 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 60 insertions(+)

diff --git a/include/sys/stat.h b/include/sys/stat.h
index b2a0fb594f..b83189a22c 100644
--- a/include/sys/stat.h
+++ b/include/sys/stat.h
@@ -42,6 +42,8 @@ extern int __fxstat64_t64 (int __ver, int __fildes,
                            struct __stat64_t64 *__stat_buf);
 extern int __xstat64_t64 (int __ver, const char *__filename,
                           struct __stat64_t64 *__stat_buf);
+extern int __lxstat64_t64 (int __ver, const char *__filename,
+		           struct __stat64_t64 *__stat_buf);
 
 #if IS_IN (libc) || (IS_IN (rtld) && !defined NO_RTLD_HIDDEN)
 hidden_proto (__fxstat)
diff --git a/io/Versions b/io/Versions
index c00f9849c2..e71167e932 100644
--- a/io/Versions
+++ b/io/Versions
@@ -129,5 +129,6 @@ libc {
     copy_file_range;
     __fxstat64_t64;
     __xstat64_t64;
+    __lxstat64_t64;
   }
 }
diff --git a/io/lstat64.c b/io/lstat64.c
index c3eb7a76f5..549208c153 100644
--- a/io/lstat64.c
+++ b/io/lstat64.c
@@ -50,3 +50,10 @@ lstat64 (const char *file, struct stat64 *buf)
 {
   return __lxstat64 (_STAT_VER, file, buf);
 }
+
+int
+attribute_hidden
+__lstat64_t64 (const char *file, struct __stat64_t64 *buf)
+{
+  return __lxstat64_t64 (_STAT_VER, file, buf);
+}
diff --git a/sysdeps/unix/sysv/linux/lxstat64.c b/sysdeps/unix/sysv/linux/lxstat64.c
index d05fa14537..d98b1d5909 100644
--- a/sysdeps/unix/sysv/linux/lxstat64.c
+++ b/sysdeps/unix/sysv/linux/lxstat64.c
@@ -50,3 +50,53 @@ hidden_ver (___lxstat64, __lxstat64)
 strong_alias (___lxstat64, __lxstat64);
 hidden_def (__lxstat64)
 #endif
+
+/* 64-bit time version */
+
+extern int __y2038_linux_support;
+
+int
+__lxstat64_t64 (int vers, const char *name, struct __stat64_t64 *buf)
+{
+  int result;
+  struct stat64 st64;
+
+  if (__y2038_linux_support)
+    {
+      // TODO: use 64-bit syscalls when they become available
+    }
+
+  result = INLINE_SYSCALL (lstat64, 2, name, &st64);
+#if defined _HAVE_STAT64___ST_INO && !__ASSUME_ST_INO_64_BIT
+  if (__builtin_expect (!result, 1) && st64.__st_ino != (__ino_t) st64.st_ino)
+    st64.st_ino = st64.__st_ino;
+#endif
+  if (!result)
+    {
+      buf->st_dev          = st64.st_dev;
+      //buf->__pad1		     = st64.__pad1;
+    
+#if defined _HAVE_STAT64___ST_INO
+      buf->__st_ino        = st64.__st_ino;
+#endif
+      buf->st_mode         = st64.st_mode;
+      buf->st_nlink        = st64.st_nlink;
+      buf->st_uid          = st64.st_uid;		 
+      buf->st_gid          = st64.st_gid;		 
+      buf->st_rdev         = st64.st_rdev;		 
+      buf->__pad2          = st64.__pad2;
+      buf->st_size         = st64.st_size;		 
+      buf->st_blksize      = st64.st_blksize;
+    
+      buf->st_blocks       = st64.st_blocks;		
+      buf->st_atim.tv_sec  = st64.st_atim.tv_sec;	
+      buf->st_atim.tv_nsec = st64.st_atim.tv_nsec;	
+      buf->st_mtim.tv_sec  = st64.st_mtim.tv_sec;	
+      buf->st_mtim.tv_nsec = st64.st_mtim.tv_nsec;	
+      buf->st_ctim.tv_sec  = st64.st_ctim.tv_sec;	
+      buf->st_ctim.tv_nsec = st64.st_ctim.tv_nsec;	
+    
+      buf->st_ino          = st64.st_ino;
+    }
+  return result;
+}
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  46/63] Y2038: add function __adjtime64
  2018-04-18 20:21                                                                                         ` [[PATCH RFC 2] 45/63] Y2038: add function __nanosleep64 Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:22                                                                                           ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:22                                                                                             ` [[PATCH RFC 2] 47/63] Y2038: add function __utime64 Albert ARIBAUD (3ADEV)
  0 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:22 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

---
 sysdeps/unix/sysv/linux/adjtime.c | 43 +++++++++++++++++++++++++++++++++++++++
 time/Versions                     |  1 +
 time/adjtime.c                    | 10 +++++++++
 3 files changed, 54 insertions(+)

diff --git a/sysdeps/unix/sysv/linux/adjtime.c b/sysdeps/unix/sysv/linux/adjtime.c
index 6edecb70e8..9e9a4b4176 100644
--- a/sysdeps/unix/sysv/linux/adjtime.c
+++ b/sysdeps/unix/sysv/linux/adjtime.c
@@ -90,3 +90,46 @@ ADJTIME (const struct TIMEVAL *itv, struct TIMEVAL *otv)
 #ifdef NO_LOCAL_ADJTIME
 weak_alias (__adjtime, adjtime)
 #endif
+
+/* 64-bit time version */
+
+extern int __y2038_linux_support;
+
+int __adjtime64 (const struct __timeval64 *itv,
+                 struct __timeval64 *otv)
+{
+  struct TIMEX tntx;
+
+  if (itv)
+    {
+      struct TIMEVAL tmp;
+
+      /* We will do some check here. */
+      tmp.tv_sec = itv->tv_sec + itv->tv_usec / 1000000L;
+      tmp.tv_usec = itv->tv_usec % 1000000L;
+      if (tmp.tv_sec > MAX_SEC || tmp.tv_sec < MIN_SEC)
+	return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
+      tntx.offset = tmp.tv_usec + tmp.tv_sec * 1000000L;
+      tntx.modes = ADJ_OFFSET_SINGLESHOT;
+    }
+  else
+    tntx.modes = ADJ_OFFSET_SS_READ;
+
+  if (__glibc_unlikely (ADJTIMEX (&tntx) < 0))
+    return -1;
+
+  if (otv)
+    {
+      if (tntx.offset < 0)
+	{
+	  otv->tv_usec = -(-tntx.offset % 1000000);
+	  otv->tv_sec  = -(-tntx.offset / 1000000);
+	}
+      else
+	{
+	  otv->tv_usec = tntx.offset % 1000000;
+	  otv->tv_sec  = tntx.offset / 1000000;
+	}
+    }
+  return 0;
+}
diff --git a/time/Versions b/time/Versions
index 86ced5a7c7..c7e9379243 100644
--- a/time/Versions
+++ b/time/Versions
@@ -89,5 +89,6 @@ libc {
     __time64;
     __stime64;
     __utimes64;
+    __adjtime64;
   }
 }
diff --git a/time/adjtime.c b/time/adjtime.c
index 4a972d66cd..800715c016 100644
--- a/time/adjtime.c
+++ b/time/adjtime.c
@@ -31,3 +31,13 @@ __adjtime (const struct timeval *delta, struct timeval *olddelta)
 stub_warning (adjtime)
 
 weak_alias (__adjtime, adjtime)
+
+/* 64-bit time version */
+
+int
+__adjtime64 (const struct __timeval64 *delta, struct __timeval64 *olddelta)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+stub_warning (__adjtime64)
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  48/63] Y2038: add struct __itimerval64
  2018-04-18 20:22                                                                                             ` [[PATCH RFC 2] 47/63] Y2038: add function __utime64 Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:22                                                                                               ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:22                                                                                                 ` [[PATCH RFC 2] 49/63] Y2038: add function __getitimer64 Albert ARIBAUD (3ADEV)
  0 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:22 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

---
 time/sys/time.h | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/time/sys/time.h b/time/sys/time.h
index 4166a5b10f..b82194898c 100644
--- a/time/sys/time.h
+++ b/time/sys/time.h
@@ -109,6 +109,16 @@ struct itimerval
     struct timeval it_value;
   };
 
+/* 64-BIT-TIME Type of the second argument to `getitimer' and
+   the second and third arguments `setitimer'.  */
+struct __itimerval64
+  {
+    /* Value to put into `it_value' when the timer expires.  */
+    struct __timeval64 it_interval;
+    /* Time to the next timer expiration.  */
+    struct __timeval64 it_value;
+  };
+
 #if defined __USE_GNU && !defined __cplusplus
 /* Use the nicer parameter type only in GNU mode and not for C++ since the
    strict C++ rules prevent the automatic promotion.  */
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  47/63] Y2038: add function __utime64
  2018-04-18 20:22                                                                                           ` [[PATCH RFC 2] 46/63] Y2038: add function __adjtime64 Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:22                                                                                             ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:22                                                                                               ` [[PATCH RFC 2] 48/63] Y2038: add struct __itimerval64 Albert ARIBAUD (3ADEV)
  0 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:22 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

---
 include/utime.h         |  7 +++++++
 io/Makefile             |  2 +-
 io/Versions             |  1 +
 io/utime.c              | 16 ++++++++++++++++
 sysdeps/posix/utime64.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 71 insertions(+), 1 deletion(-)
 create mode 100644 sysdeps/posix/utime64.c

diff --git a/include/utime.h b/include/utime.h
index 5049251311..eb907f7472 100644
--- a/include/utime.h
+++ b/include/utime.h
@@ -6,4 +6,11 @@
 libc_hidden_proto (utime)
 #endif
 
+/* Structure describing file times, 64-bit time version.  */
+struct __utimbuf64
+  {
+    __time64_t actime;		/* Access time.  */
+    __time64_t modtime;		/* Modification time.  */
+  };
+
 #endif /* utime.h */
diff --git a/io/Makefile b/io/Makefile
index 2117cb6b62..85dafd3429 100644
--- a/io/Makefile
+++ b/io/Makefile
@@ -28,7 +28,7 @@ headers := sys/stat.h bits/stat.h sys/statfs.h bits/statfs.h sys/vfs.h \
 	   utime.h ftw.h fts.h sys/sendfile.h
 
 routines :=								\
-	utime								\
+	utime utime64							\
 	mkfifo mkfifoat							\
 	stat fstat lstat stat64 fstat64 lstat64 fstatat fstatat64	\
 	xstat fxstat lxstat xstat64 fxstat64 lxstat64			\
diff --git a/io/Versions b/io/Versions
index 13334f07fb..73eca4d065 100644
--- a/io/Versions
+++ b/io/Versions
@@ -131,5 +131,6 @@ libc {
     __xstat64_t64;
     __lxstat64_t64;
     __fxstatat64_t64;
+    __utime64;
   }
 }
diff --git a/io/utime.c b/io/utime.c
index 3f3c03c92d..b33296b7ee 100644
--- a/io/utime.c
+++ b/io/utime.c
@@ -38,3 +38,19 @@ utime (const char *file, const struct utimbuf *times)
 libc_hidden_def (utime)
 
 stub_warning (utime)
+
+/* 64-bit time version */
+
+int
+__utime64 (const char *file, const struct __utimbuf64 *times)
+{
+  if (file == NULL)
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+  __set_errno (ENOSYS);
+  return -1;
+}
+stub_warning (__utime64)
diff --git a/sysdeps/posix/utime64.c b/sysdeps/posix/utime64.c
new file mode 100644
index 0000000000..1f043da0ce
--- /dev/null
+++ b/sysdeps/posix/utime64.c
@@ -0,0 +1,46 @@
+/* Copyright (C) 1991-2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sysdep.h>
+#include <errno.h>
+#include <utime.h>
+#include <time.h>
+#include <sys/types.h>
+#include <sys/time.h>
+
+
+/* Set the access and modification times of FILE to those given in TIMES.
+   If TIMES is NULL, set them to the current time.  */
+int
+__utime64 (const char *file, const struct __utimbuf64 *times)
+{
+  struct __timeval64 timevals[2];
+  struct __timeval64 *tvp;
+
+  if (times != NULL)
+    {
+      timevals[0].tv_sec = (time_t) times->actime;
+      timevals[0].tv_usec = 0L;
+      timevals[1].tv_sec = (time_t) times->modtime;
+      timevals[1].tv_usec = 0L;
+      tvp = timevals;
+    }
+  else
+    tvp = NULL;
+
+  return __utimes64 (file, tvp);
+}
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  49/63] Y2038: add function __getitimer64
  2018-04-18 20:22                                                                                               ` [[PATCH RFC 2] 48/63] Y2038: add struct __itimerval64 Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:22                                                                                                 ` Albert ARIBAUD (3ADEV)
  0 siblings, 0 replies; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:22 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

---
 time/Makefile      |  1 +
 time/Versions      |  1 +
 time/getitimer64.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 55 insertions(+)
 create mode 100644 time/getitimer64.c

diff --git a/time/Makefile b/time/Makefile
index fac49865a2..b1b026d163 100644
--- a/time/Makefile
+++ b/time/Makefile
@@ -35,6 +35,7 @@ routines := offtime asctime clock ctime ctime_r difftime \
 	    gettimeofday settimeofday adjtime tzset	 \
 	    gettimeofday64 settimeofday64		 \
 	    tzfile getitimer setitimer			 \
+	    getitimer64					 \
 	    stime dysize timegm ftime			 \
 	    getdate strptime strptime_l			 \
 	    strftime wcsftime strftime_l wcsftime_l	 \
diff --git a/time/Versions b/time/Versions
index c7e9379243..b97d3f8449 100644
--- a/time/Versions
+++ b/time/Versions
@@ -90,5 +90,6 @@ libc {
     __stime64;
     __utimes64;
     __adjtime64;
+    __getitimer64;
   }
 }
diff --git a/time/getitimer64.c b/time/getitimer64.c
new file mode 100644
index 0000000000..e6f5443e33
--- /dev/null
+++ b/time/getitimer64.c
@@ -0,0 +1,53 @@
+/* Get the current value of an interval timer
+
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <stddef.h>
+#include <errno.h>
+#include <sys/time.h>
+
+extern int __y2038_linux_support;
+
+/* Set *VALUE to the current setting of timer WHICH.
+   Return 0 on success, -1 on errors.  */
+int
+__getitimer64 (enum __itimer_which which,
+                 struct __itimerval64 *value)
+{
+  struct itimerval value32, *value32p= NULL;
+
+  if (__y2038_linux_support)
+    {
+      /* TODO: use 64-bit syscall */
+    }
+ 
+  if (value != NULL)
+    value32p = &value32;
+
+  int result = __getitimer(which, value32p);
+
+  if (result == 0 && value != NULL)
+    {
+      value->it_interval.tv_sec = value32.it_interval.tv_sec;
+      value->it_interval.tv_usec = value32.it_interval.tv_usec;
+      value->it_value.tv_sec = value32.it_value.tv_sec;
+      value->it_value.tv_usec = value32.it_value.tv_usec;
+    }
+
+  return result;
+}
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* [[PATCH RFC 2]  44/63] Y2038: add function __sched_rr_get_interval64
  2018-04-18 20:21                                                                                     ` [[PATCH RFC 2] 43/63] Y2038: add function __msgctl64 Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:22                                                                                       ` Albert ARIBAUD (3ADEV)
  2018-04-18 20:21                                                                                         ` [[PATCH RFC 2] 45/63] Y2038: add function __nanosleep64 Albert ARIBAUD (3ADEV)
  0 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD (3ADEV) @ 2018-04-18 20:22 UTC (permalink / raw)
  To: libc-alpha; +Cc: Albert ARIBAUD (3ADEV)

---
 posix/Makefile        |  3 ++-
 posix/Versions        |  1 +
 posix/sched_rr_gi64.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 54 insertions(+), 1 deletion(-)
 create mode 100644 posix/sched_rr_gi64.c

diff --git a/posix/Makefile b/posix/Makefile
index 51dcf129ec..0adb57653f 100644
--- a/posix/Makefile
+++ b/posix/Makefile
@@ -62,7 +62,8 @@ routines :=								      \
 	spawnattr_getsigmask spawnattr_getschedpolicy spawnattr_getschedparam \
 	spawnattr_setsigmask spawnattr_setschedpolicy spawnattr_setschedparam \
 	posix_madvise							      \
-	get_child_max sched_cpucount sched_cpualloc sched_cpufree
+	get_child_max sched_cpucount sched_cpualloc sched_cpufree	      \
+	sched_rr_gi64
 
 aux		:= init-posix environ
 tests		:= test-errno tstgetopt testfnm runtests runptests \
diff --git a/posix/Versions b/posix/Versions
index 65e96870e1..813c765a98 100644
--- a/posix/Versions
+++ b/posix/Versions
@@ -136,6 +136,7 @@ libc {
   }
   GLIBC_2.27 {
     glob; glob64;
+    __sched_rr_get_interval64;
   }
   GLIBC_PRIVATE {
     __libc_fork; __libc_pread; __libc_pwrite;
diff --git a/posix/sched_rr_gi64.c b/posix/sched_rr_gi64.c
new file mode 100644
index 0000000000..0e76e1a618
--- /dev/null
+++ b/posix/sched_rr_gi64.c
@@ -0,0 +1,51 @@
+/* Get the SCHED_RR interval for the named process.
+  
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <sched.h>
+#include <sys/types.h>
+
+extern int __y2038_linux_support;
+
+int
+__sched_rr_get_interval64 (pid_t pid, struct __timespec64 *t)
+{
+  struct timespec ts32;
+  int result;
+
+  if (t == NULL)
+    {
+      __set_errno(EINVAL);
+      return -1;
+    }
+
+  if (__y2038_linux_support)
+    {
+      /* TODO: use 64-bit syscall */
+    }
+
+  result = __sched_rr_get_interval(pid, &ts32);
+  if (result == 0)
+    {
+      t->tv_sec = ts32.tv_sec;
+      t->tv_nsec = ts32.tv_nsec;
+      t->tv_pad = 0;
+    }
+  return result;
+}
-- 
2.14.1

^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [[PATCH RFC 2] 02/63] Y2038: add function __difftime64
  2018-04-18 20:18   ` [[PATCH RFC 2] 02/63] Y2038: add function __difftime64 Albert ARIBAUD (3ADEV)
  2018-04-18 20:18     ` [[PATCH RFC 2] 03/63] Y2038: make __tz_convert compatible with 64-bit-time Albert ARIBAUD (3ADEV)
@ 2018-04-18 20:37     ` Paul Eggert
  2018-04-19 13:04       ` Albert ARIBAUD
  2018-04-18 21:50     ` Joseph Myers
  2 siblings, 1 reply; 78+ messages in thread
From: Paul Eggert @ 2018-04-18 20:37 UTC (permalink / raw)
  To: Albert ARIBAUD (3ADEV), libc-alpha

On 04/18/2018 01:17 PM, Albert ARIBAUD (3ADEV) wrote:
> +/* Return the difference between 64-bit TIME1 and TIME0.  */
> +double
> +__difftime64 (__time64_t time1, __time64_t time0)
> +{
> +  /* Subtract the smaller integer from the larger, convert the difference to
> +     double, and then negate if needed.  */
> +  return time1 < time0 ? - (time0 - time1) : (time1 - time0);
> +}

This does not work correctly if there is an integer overflow in any of 
the three subtractions. Also, the comment disagrees with the code.

How about if you just #include difftime.c after defining a couple of 
macros, and then have difftime.c do its thing? That'd avoid problems 
like this. difftime.c would also need to be generalized a bit.

^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [[PATCH RFC 2]  02/63] Y2038: add function __difftime64
  2018-04-18 20:18   ` [[PATCH RFC 2] 02/63] Y2038: add function __difftime64 Albert ARIBAUD (3ADEV)
  2018-04-18 20:18     ` [[PATCH RFC 2] 03/63] Y2038: make __tz_convert compatible with 64-bit-time Albert ARIBAUD (3ADEV)
  2018-04-18 20:37     ` [[PATCH RFC 2] 02/63] Y2038: add function __difftime64 Paul Eggert
@ 2018-04-18 21:50     ` Joseph Myers
  2018-04-19 12:27       ` Albert ARIBAUD
  2 siblings, 1 reply; 78+ messages in thread
From: Joseph Myers @ 2018-04-18 21:50 UTC (permalink / raw)
  To: Albert ARIBAUD (3ADEV); +Cc: libc-alpha

On Wed, 18 Apr 2018, Albert ARIBAUD (3ADEV) wrote:

> diff --git a/time/Versions b/time/Versions
> index fd838181e4..57314b98c8 100644
> --- a/time/Versions
> +++ b/time/Versions
> @@ -65,4 +65,7 @@ libc {
>    GLIBC_2.16 {
>      timespec_get;
>    }
> +  GLIBC_2.27 {
> +    __difftime64;
> +  }

Please send any such patches as appropriate for current master, which 
means new symbols need to be at the version for the *next* release, 
currently 2.28.

Each patch should avoid regressions, meaning that it should include 
updates to all affected ABI baselines, unless there is a reason the series 
would need to be squashed for commit (the series as a whole should also be 
tested with build-many-glibcs.py).  Since there are no ABI baseline 
updates whatever in the series byeond two librt.abilist files and two 
libpthread.abilist files, but new ABIs are added to other libraries such 
as libc, either the series is seriously broken or the claim of no test 
regressions is incorrect.

As previously discussed, new ABI additions should be avoided for platforms 
where time_t is already 64-bit.  Obviously testing on such platforms is 
needed to make sure they continue to work just as they do now.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [[PATCH RFC 2]  10/63] Y2038: implement 64-bit-time __mktime64() and timelocal()
  2018-04-18 20:19                   ` [[PATCH RFC 2] 10/63] Y2038: implement 64-bit-time __mktime64() and timelocal() Albert ARIBAUD (3ADEV)
  2018-04-18 20:19                     ` [[PATCH RFC 2] 11/63] Y2038: implement 64-bit-time __timegm64() Albert ARIBAUD (3ADEV)
@ 2018-04-18 21:51                     ` Joseph Myers
  1 sibling, 0 replies; 78+ messages in thread
From: Joseph Myers @ 2018-04-18 21:51 UTC (permalink / raw)
  To: Albert ARIBAUD (3ADEV); +Cc: libc-alpha

On Wed, 18 Apr 2018, Albert ARIBAUD (3ADEV) wrote:

> __mktime64 is designed similar to mktime, including checks on (64-bit)
> integer limits, and respects the same Posix requirements as __mktime does,
> i.e. calls tzset().

As per comments on previous versions of these patches, such duplication of 
large, complicated pieces of code must be avoided; you want a main 
function that uses the 64-bit types and the 32-bit function should be a 
simple wrapper around it.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [[PATCH RFC 2]  20/63] Y2038: add function __futimens64
  2018-04-18 20:20                                       ` [[PATCH RFC 2] 20/63] Y2038: add function __futimens64 Albert ARIBAUD (3ADEV)
  2018-04-18 20:20                                         ` [[PATCH RFC 2] 21/63] Y2038: add function __utimensat64 Albert ARIBAUD (3ADEV)
@ 2018-04-18 21:53                                         ` Joseph Myers
  1 sibling, 0 replies; 78+ messages in thread
From: Joseph Myers @ 2018-04-18 21:53 UTC (permalink / raw)
  To: Albert ARIBAUD (3ADEV); +Cc: libc-alpha

On Wed, 18 Apr 2018, Albert ARIBAUD (3ADEV) wrote:

> +  if (! timespec64_to_timespec(&tsp[0], &ts32[0]))
> +    {
> +      __set_errno(EOVERFLOW);

Globally in this patch series, you need to fix code to follow the GNU 
Coding Standards (spaces before '(' in this case).

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [[PATCH RFC 2]  26/63] Y2038: add struct __itimerspec64
  2018-04-18 20:20                                                   ` [[PATCH RFC 2] 26/63] Y2038: add struct __itimerspec64 Albert ARIBAUD (3ADEV)
  2018-04-18 20:20                                                     ` [[PATCH RFC 2] 27/63] Y2038: add function __timer_gettime64 Albert ARIBAUD (3ADEV)
@ 2018-04-18 21:54                                                     ` Joseph Myers
  1 sibling, 0 replies; 78+ messages in thread
From: Joseph Myers @ 2018-04-18 21:54 UTC (permalink / raw)
  To: Albert ARIBAUD (3ADEV); +Cc: libc-alpha

On Wed, 18 Apr 2018, Albert ARIBAUD (3ADEV) wrote:

> ---
>  time/bits/types/struct_itimerspec.h | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/time/bits/types/struct_itimerspec.h b/time/bits/types/struct_itimerspec.h
> index 17cc1ac86d..1f8fff439f 100644
> --- a/time/bits/types/struct_itimerspec.h
> +++ b/time/bits/types/struct_itimerspec.h
> @@ -11,4 +11,11 @@ struct itimerspec
>      struct timespec it_value;
>    };
>  
> +/* 64-bit interval timer spec */
> +struct __itimerspec64
> +{
> +  struct __timespec64 it_interval;
> +  struct __timespec64 it_value;
> +};

No, bits/types/* are for exactly one type per header.  You need a separate 
bits/types/struct___itimerspec64.h to define struct __itimerspec64 (and 
likewise for any other such type, and with Makefiles modified to install 
any new such headers).

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [[PATCH RFC 2] 03/63] Y2038: make __tz_convert compatible with 64-bit-time
  2018-04-18 20:18     ` [[PATCH RFC 2] 03/63] Y2038: make __tz_convert compatible with 64-bit-time Albert ARIBAUD (3ADEV)
  2018-04-18 20:18       ` [[PATCH RFC 2] 04/63] Y2038: add function __localtime64 Albert ARIBAUD (3ADEV)
@ 2018-04-19  1:02       ` Paul Eggert
  2018-04-19  1:08       ` Paul Eggert
  2 siblings, 0 replies; 78+ messages in thread
From: Paul Eggert @ 2018-04-19  1:02 UTC (permalink / raw)
  To: Albert ARIBAUD (3ADEV), libc-alpha

On 04/18/2018 01:17 PM, Albert ARIBAUD (3ADEV) wrote:
>   int
> -__offtime (const time_t *t, long int offset, struct tm *tp)
> +__offtime (const __time64_t t, long int offset, struct tm *tp)
>   {
>     time_t days, rem, y;
>     const unsigned short int *ip;
>   
> -  days = *t / SECS_PER_DAY;
> -  rem = *t % SECS_PER_DAY;
> +  days = t / SECS_PER_DAY;
> +  rem = t % SECS_PER_DAY;

This can overflow when time_t is 32 bits, because dividing a 64-bit 
integer by SECS_PER_DAY (i.e., by 86400) can yield an integer that does 
not fit into 32 bits. To fix this, you'll need to change the locals 
'days', 'y', 'yg' to be of type __time64_t rather than time_t.

Similarly, the local variable 't' in compute_change needs to be 
__time64_t, not time_t.

By the way, please add test cases to catch these bugs, and the bug I 
reported earlier today.

> -      tz_rules[0].change = tz_rules[1].change = (time_t) -1;
> +      tz_rules[0].change = tz_rules[1].change = (__time64_t) -1;
Instead, please just omit the cast; the cast is not needed and is more 
maintenance hassle than it is worth.

^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [[PATCH RFC 2] 03/63] Y2038: make __tz_convert compatible with 64-bit-time
  2018-04-18 20:18     ` [[PATCH RFC 2] 03/63] Y2038: make __tz_convert compatible with 64-bit-time Albert ARIBAUD (3ADEV)
  2018-04-18 20:18       ` [[PATCH RFC 2] 04/63] Y2038: add function __localtime64 Albert ARIBAUD (3ADEV)
  2018-04-19  1:02       ` [[PATCH RFC 2] 03/63] Y2038: make __tz_convert compatible with 64-bit-time Paul Eggert
@ 2018-04-19  1:08       ` Paul Eggert
  2018-04-19  6:52         ` Florian Weimer
  2 siblings, 1 reply; 78+ messages in thread
From: Paul Eggert @ 2018-04-19  1:08 UTC (permalink / raw)
  To: Albert ARIBAUD (3ADEV), libc-alpha

The patches to tzfile.c seem to be incomplete. Every use of time_t in 
that file (including tzfile_mtime) should be changed to __time64_t, no? 
And yet almost no instances where changed.

^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [[PATCH RFC 2] 03/63] Y2038: make __tz_convert compatible with 64-bit-time
  2018-04-19  1:08       ` Paul Eggert
@ 2018-04-19  6:52         ` Florian Weimer
  2018-05-02  9:11           ` Albert ARIBAUD
  0 siblings, 1 reply; 78+ messages in thread
From: Florian Weimer @ 2018-04-19  6:52 UTC (permalink / raw)
  To: Paul Eggert, Albert ARIBAUD (3ADEV), libc-alpha

On 04/19/2018 03:08 AM, Paul Eggert wrote:
> The patches to tzfile.c seem to be incomplete. Every use of time_t in 
> that file (including tzfile_mtime) should be changed to __time64_t, no? 
> And yet almost no instances where changed.

The resulting parser simplification should be a separate, preliminary patch.

Albert, if you do not want to work on this, I think I have a patch for 
this somewhere.

Thanks,
Florian

^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [[PATCH RFC 2]  02/63] Y2038: add function __difftime64
  2018-04-18 21:50     ` Joseph Myers
@ 2018-04-19 12:27       ` Albert ARIBAUD
  2018-04-19 13:18         ` Joseph Myers
  0 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD @ 2018-04-19 12:27 UTC (permalink / raw)
  To: Joseph Myers; +Cc: libc-alpha

Hi Joseph,

On Wed, 18 Apr 2018 21:50:17 +0000, Joseph Myers
<joseph@codesourcery.com> wrote :

> On Wed, 18 Apr 2018, Albert ARIBAUD (3ADEV) wrote:
> 
> > diff --git a/time/Versions b/time/Versions
> > index fd838181e4..57314b98c8 100644
> > --- a/time/Versions
> > +++ b/time/Versions
> > @@ -65,4 +65,7 @@ libc {
> >    GLIBC_2.16 {
> >      timespec_get;
> >    }
> > +  GLIBC_2.27 {
> > +    __difftime64;
> > +  }  
> 
> Please send any such patches as appropriate for current master, which 
> means new symbols need to be at the version for the *next* release, 
> currently 2.28.

That's an overlook on my side; I'll bump up to 2.28.

> Each patch should avoid regressions, meaning that it should include 
> updates to all affected ABI baselines, unless there is a reason the series 
> would need to be squashed for commit (the series as a whole should also be 
> tested with build-many-glibcs.py).  Since there are no ABI baseline 
> updates whatever in the series byeond two librt.abilist files and two 
> libpthread.abilist files, but new ABIs are added to other libraries such 
> as libc, either the series is seriously broken or the claim of no test 
> regressions is incorrect.

The series is presented as a lot of small patches for clarity, with
only the final patch potentially modifying the public API (i.e., until
that patch, 'time_t' is always 32-bit, and only after the final patch
'time_t' /may/ be 32- /or/ 64-bit depending on _TIME_BITS). I expect
that the final series can and will be squashed indeed.

Re: test regressions: what I did was, on a target system, e.g. native
on an ARM system, to create two GLIBC trees, one with and one without
the patch set, configure them identically (except of course for the
build destination), run "make" and then run "make check" on both trees,
and compare the lists of errors, assuming that when the lists of errors
are the same there is no make check regression -- and then same for
'make xcheck'.

> As previously discussed, new ABI additions should be avoided for platforms 
> where time_t is already 64-bit.  Obviously testing on such platforms is 
> needed to make sure they continue to work just as they do now.

I'll add a 64-bit platform test on next run.

Cordialement,
Albert ARIBAUD
3ADEV

^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [[PATCH RFC 2] 02/63] Y2038: add function __difftime64
  2018-04-18 20:37     ` [[PATCH RFC 2] 02/63] Y2038: add function __difftime64 Paul Eggert
@ 2018-04-19 13:04       ` Albert ARIBAUD
  2018-04-19 21:36         ` Paul Eggert
  0 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD @ 2018-04-19 13:04 UTC (permalink / raw)
  To: Paul Eggert; +Cc: libc-alpha

Hi Paul,

On Wed, 18 Apr 2018 13:37:41 -0700, Paul Eggert <eggert@cs.ucla.edu>
wrote :

> On 04/18/2018 01:17 PM, Albert ARIBAUD (3ADEV) wrote:
> > +/* Return the difference between 64-bit TIME1 and TIME0.  */
> > +double
> > +__difftime64 (__time64_t time1, __time64_t time0)
> > +{
> > +  /* Subtract the smaller integer from the larger, convert the difference to
> > +     double, and then negate if needed.  */
> > +  return time1 < time0 ? - (time0 - time1) : (time1 - time0);
> > +}  
> 
> This does not work correctly if there is an integer overflow in any of 
> the three subtractions. Also, the comment disagrees with the code.

Correct -- I'll fix this (and add the tests to cover the overflow
cases).

> How about if you just #include difftime.c after defining a couple of 
> macros, and then have difftime.c do its thing? That'd avoid problems 
> like this. difftime.c would also need to be generalized a bit.

One reason to have a separated implementation is that difftime.c has
quite complex logic covering many different implementations of time_t
(signed, unsigned, with padding bits) whereas here we only have signed
64-bit integer.

Cordialement,
Albert ARIBAUD
3ADEV

^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [[PATCH RFC 2]  02/63] Y2038: add function __difftime64
  2018-04-19 12:27       ` Albert ARIBAUD
@ 2018-04-19 13:18         ` Joseph Myers
  2018-05-02  7:25           ` Albert ARIBAUD
  0 siblings, 1 reply; 78+ messages in thread
From: Joseph Myers @ 2018-04-19 13:18 UTC (permalink / raw)
  To: Albert ARIBAUD; +Cc: libc-alpha

On Thu, 19 Apr 2018, Albert ARIBAUD wrote:

> Re: test regressions: what I did was, on a target system, e.g. native
> on an ARM system, to create two GLIBC trees, one with and one without
> the patch set, configure them identically (except of course for the
> build destination), run "make" and then run "make check" on both trees,
> and compare the lists of errors, assuming that when the lists of errors
> are the same there is no make check regression -- and then same for
> 'make xcheck'.

That only works if you have a good baseline set of results.  If your 
baseline includes failures that aren't on the known list at 
<https://sourceware.org/glibc/wiki/Release/2.27>, they could hide problems 
in the testing of the patched glibc.

In particular, the baseline should have *no* ABI test failures (you need 
to configure --prefix=/usr to get the correct ABI).  And then you need to 
update the ABI test baselines (for *all* supported glibc platforms that 
currently have 32-bit time_t) to avoid introducing ABI test failures.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [[PATCH RFC 2] 02/63] Y2038: add function __difftime64
  2018-04-19 13:04       ` Albert ARIBAUD
@ 2018-04-19 21:36         ` Paul Eggert
  2018-05-02  7:22           ` Albert ARIBAUD
  0 siblings, 1 reply; 78+ messages in thread
From: Paul Eggert @ 2018-04-19 21:36 UTC (permalink / raw)
  To: Albert ARIBAUD; +Cc: libc-alpha

On 04/19/2018 06:04 AM, Albert ARIBAUD wrote:
> One reason to have a separated implementation is that difftime.c has
> quite complex logic covering many different implementations of time_t
> (signed, unsigned, with padding bits) whereas here we only have signed
> 64-bit integer.

difftime.c is a general implementation that works regardless of the 
widths of time_t, int, long, etc. You tried reinventing its wheel but 
the reinvention was buggy. Although you could try reinventing its wheel 
again, I am afraid there will be another bug with reasonably high 
probability. Instead, let's reuse the wheel that we already have; that 
will be more likely to be correct, and will be easier to maintain in the 
future.

It's not just difftime.c. The same argument applies to mktime, etc. We 
shouldn't have two copies of these functions' source code: we should 
have just one generic copy, and then compile it once for 64-bit 
__time64_t and once for 32-bit time_t. The generic code already works 
for both 64-bit and 32-bit time_t, so it should also work for 64-bit 
__time64_t.

At bottom I am repeating the comment that Joseph Myers made here:

https://sourceware.org/ml/libc-alpha/2018-04/msg00376.html

^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [[PATCH RFC 2] 02/63] Y2038: add function __difftime64
  2018-04-19 21:36         ` Paul Eggert
@ 2018-05-02  7:22           ` Albert ARIBAUD
  2018-05-02  7:40             ` Albert ARIBAUD
                               ` (3 more replies)
  0 siblings, 4 replies; 78+ messages in thread
From: Albert ARIBAUD @ 2018-05-02  7:22 UTC (permalink / raw)
  To: Paul Eggert; +Cc: libc-alpha

Hi Paul,

On Thu, 19 Apr 2018 14:36:20 -0700, Paul Eggert <eggert@cs.ucla.edu>
wrote :

> On 04/19/2018 06:04 AM, Albert ARIBAUD wrote:
> > One reason to have a separated implementation is that difftime.c has
> > quite complex logic covering many different implementations of time_t
> > (signed, unsigned, with padding bits) whereas here we only have signed
> > 64-bit integer.  
> 
> difftime.c is a general implementation that works regardless of the 
> widths of time_t, int, long, etc. You tried reinventing its wheel but 
> the reinvention was buggy. Although you could try reinventing its wheel 
> again, I am afraid there will be another bug with reasonably high 
> probability. Instead, let's reuse the wheel that we already have; that 
> will be more likely to be correct, and will be easier to maintain in the 
> future.

I'd argue that the wheel we already have was built for the roads we
intended it to run on, but this change might be the occasion to update
to a wheel which will only run on a subset of roads where some of the
current wheel's properties become unneeded.

IOW: does the set of 32-bit architectures on which we will use
64-bit with 32-bit time need all the complexities of current difftime?
I'm thinking for instance about padding bits.

> It's not just difftime.c. The same argument applies to mktime, etc. We 
> shouldn't have two copies of these functions' source code: we should 
> have just one generic copy, and then compile it once for 64-bit 
> __time64_t and once for 32-bit time_t. The generic code already works 
> for both 64-bit and 32-bit time_t, so it should also work for 64-bit 
> __time64_t.

OK, so let me rephrase this to see if I am getting this :

1) Keep the original file untouched as the 32-bit-time compilation unit.
Compiling this file as it is now ensures that the ABI is untouched.

2) Compile the same original file with -D_TIME_BITS=64 (just like
application code would be compiled under 64-bit-time), producing a
second compilation unit which provides new symbols.

The problem with this approach is that it can be applied to some
implementations but that for many, the 64-bit version is *not*
functionally identical with the 32-bit one. At least the
syscall-dependent ones work differently: the 32-bit impelmentations
just use the 32-bit syscalls, while the 64-bit implementations have to
use the 64-bit syscalls *if availaible at run-time*, and be able to
fallback on the 32-bit syscalls if they have to.

Using a single source code for both 32-bit time and 64-bit time
would mean that 32-bit syscall-based implementation behavior would
change, which is contrary to one of the goals of Y2038; existing
GLIBC 32-bit time code should be unchanged.

I can respin the changes so that I apply your proposal for cases
where no syscalls are involved [1].

(Note: some time-related implementations are for protocols and file
formats. These will probably require extra care because we need to make
sure the protocol and file structures are actually independent on the
size of time_t.)

> At bottom I am repeating the comment that Joseph Myers made here:
> 
> https://sourceware.org/ml/libc-alpha/2018-04/msg00376.html

Cordialement,
Albert ARIBAUD
3ADEV

^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [[PATCH RFC 2]  02/63] Y2038: add function __difftime64
  2018-04-19 13:18         ` Joseph Myers
@ 2018-05-02  7:25           ` Albert ARIBAUD
  0 siblings, 0 replies; 78+ messages in thread
From: Albert ARIBAUD @ 2018-05-02  7:25 UTC (permalink / raw)
  To: Joseph Myers; +Cc: libc-alpha

Hi Joseph,

On Thu, 19 Apr 2018 13:18:38 +0000, Joseph Myers
<joseph@codesourcery.com> wrote :

> On Thu, 19 Apr 2018, Albert ARIBAUD wrote:
> 
> > Re: test regressions: what I did was, on a target system, e.g. native
> > on an ARM system, to create two GLIBC trees, one with and one without
> > the patch set, configure them identically (except of course for the
> > build destination), run "make" and then run "make check" on both trees,
> > and compare the lists of errors, assuming that when the lists of errors
> > are the same there is no make check regression -- and then same for
> > 'make xcheck'.  
> 
> That only works if you have a good baseline set of results.  If your 
> baseline includes failures that aren't on the known list at 
> <https://sourceware.org/glibc/wiki/Release/2.27>, they could hide problems 
> in the testing of the patched glibc.

Noted. If I do a 'make check' from the git commit which corresponds to
this release, I should get the exact same list of failures as in the
release notes, right?

> In particular, the baseline should have *no* ABI test failures (you need 
> to configure --prefix=/usr to get the correct ABI).  And then you need to 
> update the ABI test baselines (for *all* supported glibc platforms that 
> currently have 32-bit time_t) to avoid introducing ABI test failures.

Will do in future tests.

Cordialement,
Albert ARIBAUD
3ADEV

^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [[PATCH RFC 2] 02/63] Y2038: add function __difftime64
  2018-05-02  7:22           ` Albert ARIBAUD
@ 2018-05-02  7:40             ` Albert ARIBAUD
  2018-05-02  7:46             ` Florian Weimer
                               ` (2 subsequent siblings)
  3 siblings, 0 replies; 78+ messages in thread
From: Albert ARIBAUD @ 2018-05-02  7:40 UTC (permalink / raw)
  To: Paul Eggert; +Cc: libc-alpha

On Wed, 2 May 2018 09:22:09 +0200, Albert ARIBAUD
<albert.aribaud@3adev.fr> wrote :

> OK, so let me rephrase this to see if I am getting this :
> 
> 1) Keep the original file untouched as the 32-bit-time compilation unit.
> Compiling this file as it is now ensures that the ABI is untouched.
> 
> 2) Compile the same original file with -D_TIME_BITS=64 (just like
> application code would be compiled under 64-bit-time), producing a
> second compilation unit which provides new symbols.

more to the point, it would be compiled *as if* under -D_TIME_BITS=64,
because TIME_BITS and __USE_TIME_BITS64 are public API macros which
are not defined at GLIBC build time -- and a git grep shows that no
GLIBC '.c' file ever references a __USE_* or _*_BITS macro defined in
features.h.

> The problem with this approach is that it can be applied to some
> implementations but that for many, the 64-bit version is *not*
> functionally identical with the 32-bit one. At least the
> syscall-dependent ones work differently: the 32-bit impelmentations
> just use the 32-bit syscalls, while the 64-bit implementations have to
> use the 64-bit syscalls *if availaible at run-time*, and be able to
> fallback on the 32-bit syscalls if they have to.

Also, 64-bit time types are not simply 32-bit time types with time_t
promoted to 64-bit signed, so there too, simply compiling the source
code would not always work.

Cordialement,
Albert ARIBAUD
3ADEV

^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [[PATCH RFC 2] 02/63] Y2038: add function __difftime64
  2018-05-02  7:22           ` Albert ARIBAUD
  2018-05-02  7:40             ` Albert ARIBAUD
@ 2018-05-02  7:46             ` Florian Weimer
  2018-05-02 11:26               ` Albert ARIBAUD
  2018-05-02 19:07               ` Paul Eggert
  2018-05-02 15:45             ` Joseph Myers
  2018-05-02 19:14             ` Paul Eggert
  3 siblings, 2 replies; 78+ messages in thread
From: Florian Weimer @ 2018-05-02  7:46 UTC (permalink / raw)
  To: Albert ARIBAUD, Paul Eggert; +Cc: libc-alpha

On 05/02/2018 09:22 AM, Albert ARIBAUD wrote:
> IOW: does the set of 32-bit architectures on which we will use
> 64-bit with 32-bit time need all the complexities of current difftime?
> I'm thinking for instance about padding bits.

Yes, you can simplify the code if you want, assuming that time_t doesn't 
have padding bits, and even hard-code the matching unsigned type.

Thanks,
Florian

^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [[PATCH RFC 2] 03/63] Y2038: make __tz_convert compatible with 64-bit-time
  2018-04-19  6:52         ` Florian Weimer
@ 2018-05-02  9:11           ` Albert ARIBAUD
  0 siblings, 0 replies; 78+ messages in thread
From: Albert ARIBAUD @ 2018-05-02  9:11 UTC (permalink / raw)
  To: Florian Weimer; +Cc: Paul Eggert, libc-alpha

Hi Florian,

On Thu, 19 Apr 2018 08:52:15 +0200, Florian Weimer <fweimer@redhat.com>
wrote :

> On 04/19/2018 03:08 AM, Paul Eggert wrote:
> > The patches to tzfile.c seem to be incomplete. Every use of time_t in 
> > that file (including tzfile_mtime) should be changed to __time64_t, no? 
> > And yet almost no instances where changed.  
> 
> The resulting parser simplification should be a separate, preliminary patch.
> 
> Albert, if you do not want to work on this, I think I have a patch for 
> this somewhere.

Florian, if you have such a patch, please post it. Unless it's already
gotten pulled in by the time I post RFC 3, I will include it.

> Thanks,
> Florian

Cordialement,
Albert ARIBAUD
3ADEV

^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [[PATCH RFC 2] 02/63] Y2038: add function __difftime64
  2018-05-02  7:46             ` Florian Weimer
@ 2018-05-02 11:26               ` Albert ARIBAUD
  2018-05-02 19:07               ` Paul Eggert
  1 sibling, 0 replies; 78+ messages in thread
From: Albert ARIBAUD @ 2018-05-02 11:26 UTC (permalink / raw)
  To: Florian Weimer; +Cc: Paul Eggert, libc-alpha

Hi Florian,

On Wed, 2 May 2018 09:46:19 +0200, Florian Weimer <fweimer@redhat.com>
wrote :

> On 05/02/2018 09:22 AM, Albert ARIBAUD wrote:
> > IOW: does the set of 32-bit architectures on which we will use
> > 64-bit with 32-bit time need all the complexities of current difftime?
> > I'm thinking for instance about padding bits.  
> 
> Yes, you can simplify the code if you want, assuming that time_t doesn't 
> have padding bits, and even hard-code the matching unsigned type.

Watch out __time64_t is signed, not unsigned (if it were unsigned, that
would really simplify things, and we could just use subtraction).

> Thanks,
> Florian

Cordialement,
Albert ARIBAUD
3ADEV

^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [[PATCH RFC 2] 02/63] Y2038: add function __difftime64
  2018-05-02  7:22           ` Albert ARIBAUD
  2018-05-02  7:40             ` Albert ARIBAUD
  2018-05-02  7:46             ` Florian Weimer
@ 2018-05-02 15:45             ` Joseph Myers
  2018-05-02 19:14             ` Paul Eggert
  3 siblings, 0 replies; 78+ messages in thread
From: Joseph Myers @ 2018-05-02 15:45 UTC (permalink / raw)
  To: Albert ARIBAUD; +Cc: Paul Eggert, libc-alpha

On Wed, 2 May 2018, Albert ARIBAUD wrote:

> 1) Keep the original file untouched as the 32-bit-time compilation unit.
> Compiling this file as it is now ensures that the ABI is untouched.
> 
> 2) Compile the same original file with -D_TIME_BITS=64 (just like
> application code would be compiled under 64-bit-time), producing a
> second compilation unit which provides new symbols.

3. Make the main implementation the 64-bit one.  Make difftime into a thin 
wrapper round __difftime64.  (In the case where time_t is already 64-bit, 
the function would just be built directly as difftime without any wrapper 
being involved.)

That's what I think it appropriate in all the cases where the function 
implementations are nontrivial.  It avoids duplication of complicated code 
in the sources, and reduces the code size increase from duplication in the 
binaries.

That's particularly important for e.g. the pthread functions where a 
previous patch series was duplicating hundreds of lines of code in some 
cases.

It would mean times sometimes go through two levels of validation / 
conversion, from 32-bit to 64-bit and then back to 32-bit if the kernel 
doesn't support the 64-bit interfaces, but I think the cost of that is 
negligible.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [[PATCH RFC 2] 02/63] Y2038: add function __difftime64
  2018-05-02  7:46             ` Florian Weimer
  2018-05-02 11:26               ` Albert ARIBAUD
@ 2018-05-02 19:07               ` Paul Eggert
  2018-05-03 17:31                 ` Albert ARIBAUD
  1 sibling, 1 reply; 78+ messages in thread
From: Paul Eggert @ 2018-05-02 19:07 UTC (permalink / raw)
  To: Florian Weimer, Albert ARIBAUD; +Cc: libc-alpha

On 05/02/2018 12:46 AM, Florian Weimer wrote:
>
> Yes, you can simplify the code if you want, assuming that time_t 
> doesn't have padding bits, and even hard-code the matching unsigned type.

The simplified code is already in difftime.c. All he needs to do is to 
compile difftime.c with the right flags, and perhaps make some trivial 
changes to it that won't affect its current use.

I'd be more impressed by his request to rewrite the code from scratch if 
his attempt to do so hadn't been so buggy. Really, we'll all be better 
off using the code we already have, as that code should work in this new 
environment with only trivial changes, and we can then focus on what our 
main problem is rather than have to delve back into the intricacies of 
time_t arithmetic and calendars and whatnot.

^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [[PATCH RFC 2] 02/63] Y2038: add function __difftime64
  2018-05-02  7:22           ` Albert ARIBAUD
                               ` (2 preceding siblings ...)
  2018-05-02 15:45             ` Joseph Myers
@ 2018-05-02 19:14             ` Paul Eggert
  3 siblings, 0 replies; 78+ messages in thread
From: Paul Eggert @ 2018-05-02 19:14 UTC (permalink / raw)
  To: Albert ARIBAUD; +Cc: libc-alpha

On 05/02/2018 12:22 AM, Albert ARIBAUD wrote:
> At least the
> syscall-dependent ones work differently: the 32-bit impelmentations
> just use the 32-bit syscalls, while the 64-bit implementations have to
> use the 64-bit syscalls *if availaible at run-time*, and be able to
> fallback on the 32-bit syscalls if they have to.

That's fine, and we can have code protected by ifdef to do that as 
needed for the special case where the system has multiple time_t flavors 
some of which might not work. This doesn't mean we need to have separate 
copies of the entire module that needs to use such code.

And for functions like difftime that do not use time_t-related syscalls, 
things should be even simpler, as we shouldn't need to worry about this 
issue in those functions.

> Using a single source code for both 32-bit time and 64-bit time
> would mean that 32-bit syscall-based implementation behavior would
> change,

I don't see why it would, at least not if things were done as suggested 
above.

^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [[PATCH RFC 2] 02/63] Y2038: add function __difftime64
  2018-05-02 19:07               ` Paul Eggert
@ 2018-05-03 17:31                 ` Albert ARIBAUD
  2018-05-03 17:53                   ` Paul Eggert
  0 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD @ 2018-05-03 17:31 UTC (permalink / raw)
  To: Paul Eggert; +Cc: Florian Weimer, libc-alpha

Hi Paul,

On Wed, 2 May 2018 12:07:32 -0700, Paul Eggert <eggert@cs.ucla.edu>
wrote :

> On 05/02/2018 12:46 AM, Florian Weimer wrote:
> >
> > Yes, you can simplify the code if you want, assuming that time_t 
> > doesn't have padding bits, and even hard-code the matching unsigned type.  
> 
> The simplified code is already in difftime.c. All he needs to do is to 
> compile difftime.c with the right flags, and perhaps make some trivial 
> changes to it that won't affect its current use.

Actually, the simpler code in difftime.c which 64-bit signed integer
needs is enclosed in run-time conditionals, not compile-time
conditionals, so there are no flags that can make the code compile to a
simpler form. It just does a lot of run-time tests (*) which only some
architectures or some time_t implementations actually need.

> I'd be more impressed by his request to rewrite the code from scratch if 
> his attempt to do so hadn't been so buggy. Really, we'll all be better 
> off using the code we already have, as that code should work in this new 
> environment with only trivial changes, and we can then focus on what our 
> main problem is rather than have to delve back into the intricacies of 
> time_t arithmetic and calendars and whatnot.

I would love that too, and one way of not delving into intricacies is
to remove them if this can be done safely in a given context. I will
gladly admit I might have removed slightly too much of the difftime
intricacies in 64-bit signed time context, and I do believe in the
"don't fix it if it ain't broken" approach, but I'm not aiming to fix
32-bit time here with all its implementations, integer or floating,
signed or unsigned, padded or not; I'm aiming to make 64-bit, integer,
unpadded time as devoid of undue intricacies as it can be.

(*) Which might possibly, but not will not necessarily, be optimized
away by some compilers based on the target architecture's time_t type
and/or signedness and/or size, or even on known architecture quirks --
I am choosing not to assume how clever compilers can be, and I consider
that putting a run-time test in some source code will be costlier in
execution time than not putting it there.

Cordialement,
Albert ARIBAUD
3ADEV

^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [[PATCH RFC 2] 02/63] Y2038: add function __difftime64
  2018-05-03 17:31                 ` Albert ARIBAUD
@ 2018-05-03 17:53                   ` Paul Eggert
  2018-05-22 20:58                     ` Albert ARIBAUD
  0 siblings, 1 reply; 78+ messages in thread
From: Paul Eggert @ 2018-05-03 17:53 UTC (permalink / raw)
  To: Albert ARIBAUD; +Cc: Florian Weimer, libc-alpha

On 05/03/2018 10:30 AM, Albert ARIBAUD wrote:
> the simpler code in difftime.c which 64-bit signed integer
> needs is enclosed in run-time conditionals, not compile-time
> conditionals


These run-time conditionals are optimized away, and have zero run-time 
overhead.

Really, you should use difftime.c and see what it does (look at the 
machine code that is generated if you like). You will see that it does 
the right thing and generates the same instructions that your copy 
would. Similarly for many of the other routines that you incorrectly 
think we need to make source-code copies of.


> I am choosing not to assume how clever compilers can be, and I consider
> that putting a run-time test in some source code will be costlier in
> execution time than not putting it there.

This is completely, 100%, backwards. It is routine in high-quality 
software nowadays to assume decent optimizing compilers; for example, 
that's why we now use functions rather than macros, since simple 
functions are routinely inlined. The glibc implementation assumes GCC, 
it is not our job to second-guess GCC, and we should not add complexity 
to glibc when GCC does a perfectly good job of optimizing simpler code.

^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [[PATCH RFC 2] 02/63] Y2038: add function __difftime64
  2018-05-03 17:53                   ` Paul Eggert
@ 2018-05-22 20:58                     ` Albert ARIBAUD
  2018-05-22 21:15                       ` Paul Eggert
  0 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD @ 2018-05-22 20:58 UTC (permalink / raw)
  To: Paul Eggert; +Cc: Florian Weimer, libc-alpha

Hi Paul,

On Thu, 3 May 2018 10:53:06 -0700, Paul Eggert <eggert@cs.ucla.edu>
wrote :

> On 05/03/2018 10:30 AM, Albert ARIBAUD wrote:
> > the simpler code in difftime.c which 64-bit signed integer
> > needs is enclosed in run-time conditionals, not compile-time
> > conditionals  
> 
> 
> These run-time conditionals are optimized away, and have zero run-time 
> overhead.
> 
> Really, you should use difftime.c and see what it does (look at the 
> machine code that is generated if you like). You will see that it does 
> the right thing and generates the same instructions that your copy 
> would. Similarly for many of the other routines that you incorrectly 
> think we need to make source-code copies of.
> 
> 
> > I am choosing not to assume how clever compilers can be, and I consider
> > that putting a run-time test in some source code will be costlier in
> > execution time than not putting it there.  
> 
> This is completely, 100%, backwards. It is routine in high-quality 
> software nowadays to assume decent optimizing compilers; for example, 
> that's why we now use functions rather than macros, since simple 
> functions are routinely inlined. The glibc implementation assumes GCC, 
> it is not our job to second-guess GCC, and we should not add complexity 
> to glibc when GCC does a perfectly good job of optimizing simpler code.

I make a difference between optimizing and optimizing *away*.

Optimizing: no problem -- let the compiler reorganize the code, factor
it, tweak it in whatever way preserves its semantics while making it
smaller or faster or both, I'm happy with it, and nowadays compilers do
a very good job of it indeed, I can see that whenever I'm trying to
step-debug with -O3.

But here we're talking about optimizing *away* code which the
compiler finds it won't use at all any more.

With the 32-bit time implementation, I do understand that it is
intended to work with different time_t types, and this implies the
presence of source code intended for one implementation but seen as
dead code for others. Simplifying the 32-bit difftime would indeed
imply removing some functionality required by some existing time_t
implementation, and is therefore out of question (plus, that's not on
my plate).

OTOH, the 64-bit implementation uses a single, well-enough-defined,
64-bit, signed integer time_t implementation across all architectures
where it will exist (endianness notwithstanding, and that's not an
issue for difftime) which can and should benefit from a single
implementation simpler that the 32-bit one. Any code in the 64-bit
difftime which assumes a time_t implementation other than a 64-bit
signed int is simply dead code in*all* cases, and it won't *ever* be
used. Yes, the compiler can optimize it away again and again, but why
keep true dead source code when we know it is truly dead? That's
keeping source code complexity where we could remove it, IMO.

[that is, of course, assuming that we *know* it is dead -- again, I may
have oversimplified my previous attempt. I am going through the code
again and triple-checking that the implementation works with a 64-bit
signed time_t.]

Cordialement,
Albert ARIBAUD
3ADEV

^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [[PATCH RFC 2] 02/63] Y2038: add function __difftime64
  2018-05-22 20:58                     ` Albert ARIBAUD
@ 2018-05-22 21:15                       ` Paul Eggert
  2018-05-22 22:10                         ` Joseph Myers
  0 siblings, 1 reply; 78+ messages in thread
From: Paul Eggert @ 2018-05-22 21:15 UTC (permalink / raw)
  To: Albert ARIBAUD; +Cc: Florian Weimer, libc-alpha

On 05/22/2018 01:58 PM, Albert ARIBAUD wrote:
> But here we're talking about optimizing*away*  code which the
> compiler finds it won't use at all any more.

That's fine. GCC does this sort of thing all the time. It is a normal 
thing to write portable code that contains portions executed only on 
some platforms.

The proposed hand-optimization does not improve efficiency at all, so 
there is no good reason to insist on doing it by hand. Maintaining two 
copies of the source code would cause more maintenance work in the long 
run, and would increase the probability of bugs like the bug we already 
found in the "optimized" version. Although whether one should do an 
optimization is often a judgment call that could go either way, this 
particular case is a slam-dunk: we should let GCC do the optimization, 
and we should keep the overall source code simpler rather than maintain 
two copies of it, one "optimized" (but no faster).

As I recall, there were other unnecessary duplications in the proposed 
set of patches, so this is not just an issue of difftime.

^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [[PATCH RFC 2] 02/63] Y2038: add function __difftime64
  2018-05-22 21:15                       ` Paul Eggert
@ 2018-05-22 22:10                         ` Joseph Myers
  2018-06-11 22:24                           ` Albert ARIBAUD
  0 siblings, 1 reply; 78+ messages in thread
From: Joseph Myers @ 2018-05-22 22:10 UTC (permalink / raw)
  To: Paul Eggert; +Cc: Albert ARIBAUD, Florian Weimer, libc-alpha

On Tue, 22 May 2018, Paul Eggert wrote:

> As I recall, there were other unnecessary duplications in the proposed set of
> patches, so this is not just an issue of difftime.

Indeed.  The global approach should be: the main implementation of any 
functionality that involves nontrivial implementation code in glibc is the 
one that uses 64-bit time, unconditionally, on all platforms.  On 
platforms that currently have 32-bit time_t, the public interfaces for 
32-bit times would become thin wrappers round those for 64-bit times while 
new public ABIs are added for 64-bit times (on platforms that currently 
have 64-bit time_t, there would be no new ABIs).  If kernel support for 
64-bit times is not known to be available for the (architecture, kernel 
version) pair for which glibc is built, the implementations in terms of 
64-bit times may then need to translate back to 32-bit times, with 
overflow checks, to call into the kernel.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [[PATCH RFC 2] 02/63] Y2038: add function __difftime64
  2018-05-22 22:10                         ` Joseph Myers
@ 2018-06-11 22:24                           ` Albert ARIBAUD
  2018-06-11 22:39                             ` Joseph Myers
  0 siblings, 1 reply; 78+ messages in thread
From: Albert ARIBAUD @ 2018-06-11 22:24 UTC (permalink / raw)
  To: Joseph Myers; +Cc: Paul Eggert, Florian Weimer, libc-alpha

Hi Joseph,

On Tue, 22 May 2018 22:09:55 +0000, Joseph Myers
<joseph@codesourcery.com> wrote :

> On Tue, 22 May 2018, Paul Eggert wrote:
> 
> > As I recall, there were other unnecessary duplications in the proposed set of
> > patches, so this is not just an issue of difftime.  
> 
> Indeed.  The global approach should be: the main implementation of any 
> functionality that involves nontrivial implementation code in glibc is the 
> one that uses 64-bit time, unconditionally, on all platforms.  On 
> platforms that currently have 32-bit time_t, the public interfaces for 
> 32-bit times would become thin wrappers round those for 64-bit times while 
> new public ABIs are added for 64-bit times (on platforms that currently 
> have 64-bit time_t, there would be no new ABIs).  If kernel support for 
> 64-bit times is not known to be available for the (architecture, kernel 
> version) pair for which glibc is built, the implementations in terms of 
> 64-bit times may then need to translate back to 32-bit times, with 
> overflow checks, to call into the kernel.

When a 64-bit time implementation needs to translate back to 32-bit
times before calling to the kernel, would it not be counter-productive
to make the 32-bit interface a wrapper around it? This would hit the
32-bit client code with two conversions (from the 32-bit interface
to the 64-bit implementation, and from the implementation to the 32-
bit kernel syscall) when the original 32-bit interface would make none
and call the kernel (as) directly (as possible).

Cordialement,
Albert ARIBAUD
3ADEV

^ permalink raw reply	[flat|nested] 78+ messages in thread

* Re: [[PATCH RFC 2] 02/63] Y2038: add function __difftime64
  2018-06-11 22:24                           ` Albert ARIBAUD
@ 2018-06-11 22:39                             ` Joseph Myers
  0 siblings, 0 replies; 78+ messages in thread
From: Joseph Myers @ 2018-06-11 22:39 UTC (permalink / raw)
  To: Albert ARIBAUD; +Cc: Paul Eggert, Florian Weimer, libc-alpha

On Tue, 12 Jun 2018, Albert ARIBAUD wrote:

> When a 64-bit time implementation needs to translate back to 32-bit
> times before calling to the kernel, would it not be counter-productive
> to make the 32-bit interface a wrapper around it? This would hit the
> 32-bit client code with two conversions (from the 32-bit interface
> to the 64-bit implementation, and from the implementation to the 32-
> bit kernel syscall) when the original 32-bit interface would make none
> and call the kernel (as) directly (as possible).

If you're calling into the kernel, the cost of conversions is negligible.  
Even if you aren't calling into the kernel it's still a very small cost (a 
few instructions).  Increased code size from duplicate implementations 
also has a performance cost from increased cache usage.  And the interests 
of maintainability of glibc code point very strongly to having single 
implementations using 64-bit times, and thin wrappers round them for 
32-bit times - especially for complicated code such as some of the 
pthreads functions.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 78+ messages in thread

end of thread, other threads:[~2018-06-11 22:39 UTC | newest]

Thread overview: 78+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-18 20:18 [[PATCH RFC 2] 00/63] Make GLIBC Y2038-proof Albert ARIBAUD (3ADEV)
2018-04-18 20:18 ` [[PATCH RFC 2] 01/63] Y2038: add type __time64_t Albert ARIBAUD (3ADEV)
2018-04-18 20:18   ` [[PATCH RFC 2] 02/63] Y2038: add function __difftime64 Albert ARIBAUD (3ADEV)
2018-04-18 20:18     ` [[PATCH RFC 2] 03/63] Y2038: make __tz_convert compatible with 64-bit-time Albert ARIBAUD (3ADEV)
2018-04-18 20:18       ` [[PATCH RFC 2] 04/63] Y2038: add function __localtime64 Albert ARIBAUD (3ADEV)
2018-04-18 20:18         ` [[PATCH RFC 2] 05/63] Y2038: add function __localtime64_r Albert ARIBAUD (3ADEV)
2018-04-18 20:19           ` [[PATCH RFC 2] 06/63] Y2038: add function __gmtime64 Albert ARIBAUD (3ADEV)
2018-04-18 20:19             ` [[PATCH RFC 2] 07/63] Y2038: add function __gmtime64_r Albert ARIBAUD (3ADEV)
2018-04-18 20:19               ` [[PATCH RFC 2] 08/63] Y2038: add function __ctime64 Albert ARIBAUD (3ADEV)
2018-04-18 20:19                 ` [[PATCH RFC 2] 09/63] Y2038: add function __ctime64_r Albert ARIBAUD (3ADEV)
2018-04-18 20:19                   ` [[PATCH RFC 2] 10/63] Y2038: implement 64-bit-time __mktime64() and timelocal() Albert ARIBAUD (3ADEV)
2018-04-18 20:19                     ` [[PATCH RFC 2] 11/63] Y2038: implement 64-bit-time __timegm64() Albert ARIBAUD (3ADEV)
2018-04-18 20:19                       ` [[PATCH RFC 2] 12/63] Y2038: add struct __timespec64 Albert ARIBAUD (3ADEV)
2018-04-18 20:19                         ` [[PATCH RFC 2] 13/63] Y2038: add function __clock_gettime64 Albert ARIBAUD (3ADEV)
2018-04-18 20:19                           ` [[PATCH RFC 2] 14/63] Y2038: arm: implement clock_gettime64 as a VDSO symbol Albert ARIBAUD (3ADEV)
2018-04-18 20:19                             ` [[PATCH RFC 2] 15/63] Y2038: powerpc: " Albert ARIBAUD (3ADEV)
2018-04-18 20:19                               ` [[PATCH RFC 2] 16/63] Y2038: add function __clock_settime64 Albert ARIBAUD (3ADEV)
2018-04-18 20:19                                 ` [[PATCH RFC 2] 17/63] Y2038: add function __clock_getres64 Albert ARIBAUD (3ADEV)
2018-04-18 20:19                                   ` [[PATCH RFC 2] 18/63] Y2038: add function __clock_nanosleep64 Albert ARIBAUD (3ADEV)
2018-04-18 20:20                                     ` [[PATCH RFC 2] 19/63] Y2038: add function __timespec_get64 Albert ARIBAUD (3ADEV)
2018-04-18 20:20                                       ` [[PATCH RFC 2] 20/63] Y2038: add function __futimens64 Albert ARIBAUD (3ADEV)
2018-04-18 20:20                                         ` [[PATCH RFC 2] 21/63] Y2038: add function __utimensat64 Albert ARIBAUD (3ADEV)
2018-04-18 20:20                                           ` [[PATCH RFC 2] 22/63] Y2038: add function __sigtimedwait64 Albert ARIBAUD (3ADEV)
2018-04-18 20:20                                             ` [[PATCH RFC 2] 23/63] Y2038: add struct __timeval64 Albert ARIBAUD (3ADEV)
2018-04-18 20:20                                               ` [[PATCH RFC 2] 24/63] Y2038: add function __futimes64 Albert ARIBAUD (3ADEV)
2018-04-18 20:20                                                 ` [[PATCH RFC 2] 25/63] Y2038: add function __lutimes64 Albert ARIBAUD (3ADEV)
2018-04-18 20:20                                                   ` [[PATCH RFC 2] 26/63] Y2038: add struct __itimerspec64 Albert ARIBAUD (3ADEV)
2018-04-18 20:20                                                     ` [[PATCH RFC 2] 27/63] Y2038: add function __timer_gettime64 Albert ARIBAUD (3ADEV)
2018-04-18 20:20                                                       ` [[PATCH RFC 2] 28/63] Y2038: add function __timer_settime64 Albert ARIBAUD (3ADEV)
2018-04-18 20:20                                                         ` [[PATCH RFC 2] 29/63] Y2038: add function __timerfd_gettime64 Albert ARIBAUD (3ADEV)
2018-04-18 20:20                                                           ` [[PATCH RFC 2] 30/63] Y2038: add function __timerfd_settime64 Albert ARIBAUD (3ADEV)
2018-04-18 20:21                                                             ` [[PATCH RFC 2] 31/63] Y2038: add struct __stat64_t64 Albert ARIBAUD (3ADEV)
2018-04-18 20:20                                                               ` [[PATCH RFC 2] 32/63] Y2038: add function __fstat64_t64 (and __fxstat64_t64) Albert ARIBAUD (3ADEV)
2018-04-18 20:21                                                                 ` [[PATCH RFC 2] 33/63] Y2038: add function __stat64_t64 (and __xstat64_t64) Albert ARIBAUD (3ADEV)
2018-04-18 20:21                                                                   ` [[PATCH RFC 2] 34/63] Y2038: add function __lstat64_t64 (and __lxstat64_t64) Albert ARIBAUD (3ADEV)
2018-04-18 20:21                                                                     ` [[PATCH RFC 2] 35/63] Y2038: add function __fstatat64_t64 (and __fxstatat_t64) Albert ARIBAUD (3ADEV)
2018-04-18 20:21                                                                       ` [[PATCH RFC 2] 36/63] Y2038: add function __gettimeofday64 Albert ARIBAUD (3ADEV)
2018-04-18 20:21                                                                         ` [[PATCH RFC 2] 37/63] Y2038: add function __settimeofday64 Albert ARIBAUD (3ADEV)
2018-04-18 20:21                                                                           ` [[PATCH RFC 2] 38/63] Y2038: add function __time64 Albert ARIBAUD (3ADEV)
2018-04-18 20:21                                                                             ` [[PATCH RFC 2] 39/63] Y2038: add function __stime64 Albert ARIBAUD (3ADEV)
2018-04-18 20:21                                                                               ` [[PATCH RFC 2] 40/63] Y2038: add function __utimes64 Albert ARIBAUD (3ADEV)
2018-04-18 20:21                                                                                 ` [[PATCH RFC 2] 41/63] Y2038: add function __mq_timedreceived64 Albert ARIBAUD (3ADEV)
2018-04-18 20:21                                                                                   ` [[PATCH RFC 2] 42/63] Y2038: add function __mq_timedsend64 Albert ARIBAUD (3ADEV)
2018-04-18 20:21                                                                                     ` [[PATCH RFC 2] 43/63] Y2038: add function __msgctl64 Albert ARIBAUD (3ADEV)
2018-04-18 20:22                                                                                       ` [[PATCH RFC 2] 44/63] Y2038: add function __sched_rr_get_interval64 Albert ARIBAUD (3ADEV)
2018-04-18 20:21                                                                                         ` [[PATCH RFC 2] 45/63] Y2038: add function __nanosleep64 Albert ARIBAUD (3ADEV)
2018-04-18 20:22                                                                                           ` [[PATCH RFC 2] 46/63] Y2038: add function __adjtime64 Albert ARIBAUD (3ADEV)
2018-04-18 20:22                                                                                             ` [[PATCH RFC 2] 47/63] Y2038: add function __utime64 Albert ARIBAUD (3ADEV)
2018-04-18 20:22                                                                                               ` [[PATCH RFC 2] 48/63] Y2038: add struct __itimerval64 Albert ARIBAUD (3ADEV)
2018-04-18 20:22                                                                                                 ` [[PATCH RFC 2] 49/63] Y2038: add function __getitimer64 Albert ARIBAUD (3ADEV)
2018-04-18 21:54                                                     ` [[PATCH RFC 2] 26/63] Y2038: add struct __itimerspec64 Joseph Myers
2018-04-18 21:53                                         ` [[PATCH RFC 2] 20/63] Y2038: add function __futimens64 Joseph Myers
2018-04-18 21:51                     ` [[PATCH RFC 2] 10/63] Y2038: implement 64-bit-time __mktime64() and timelocal() Joseph Myers
2018-04-19  1:02       ` [[PATCH RFC 2] 03/63] Y2038: make __tz_convert compatible with 64-bit-time Paul Eggert
2018-04-19  1:08       ` Paul Eggert
2018-04-19  6:52         ` Florian Weimer
2018-05-02  9:11           ` Albert ARIBAUD
2018-04-18 20:37     ` [[PATCH RFC 2] 02/63] Y2038: add function __difftime64 Paul Eggert
2018-04-19 13:04       ` Albert ARIBAUD
2018-04-19 21:36         ` Paul Eggert
2018-05-02  7:22           ` Albert ARIBAUD
2018-05-02  7:40             ` Albert ARIBAUD
2018-05-02  7:46             ` Florian Weimer
2018-05-02 11:26               ` Albert ARIBAUD
2018-05-02 19:07               ` Paul Eggert
2018-05-03 17:31                 ` Albert ARIBAUD
2018-05-03 17:53                   ` Paul Eggert
2018-05-22 20:58                     ` Albert ARIBAUD
2018-05-22 21:15                       ` Paul Eggert
2018-05-22 22:10                         ` Joseph Myers
2018-06-11 22:24                           ` Albert ARIBAUD
2018-06-11 22:39                             ` Joseph Myers
2018-05-02 15:45             ` Joseph Myers
2018-05-02 19:14             ` Paul Eggert
2018-04-18 21:50     ` Joseph Myers
2018-04-19 12:27       ` Albert ARIBAUD
2018-04-19 13:18         ` Joseph Myers
2018-05-02  7:25           ` Albert ARIBAUD

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).