This is the mail archive of the
glibc-cvs@sourceware.org
mailing list for the glibc project.
GNU C Library master sources branch aaribaud/y2038 created. glibc-2.24-346-gf235d84
- From: aaribaud at sourceware dot org
- To: glibc-cvs at sourceware dot org
- Date: 8 Nov 2016 08:52:45 -0000
- Subject: GNU C Library master sources branch aaribaud/y2038 created. glibc-2.24-346-gf235d84
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".
The branch, aaribaud/y2038 has been created
at f235d842d53ef2ece2a4d2fc30c9b327ca8e3268 (commit)
- Log -----------------------------------------------------------------
http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=f235d842d53ef2ece2a4d2fc30c9b327ca8e3268
commit f235d842d53ef2ece2a4d2fc30c9b327ca8e3268
Author: Albert ARIBAUD (3ADEV) <albert.aribaud@3adev.fr>
Date: Sun Nov 6 18:36:51 2016 +0100
WIP: Y2038: support 64-bit clock_gettime and clock_settime
diff --git a/bits/types.h b/bits/types.h
index 01753bd..596f4e5 100644
--- a/bits/types.h
+++ b/bits/types.h
@@ -136,7 +136,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. */
@@ -175,6 +176,8 @@ __STD_TYPE __SSIZE_T_TYPE __ssize_t; /* Type of a byte count, or error. */
__STD_TYPE __SYSCALL_SLONG_TYPE __syscall_slong_t;
/* Unsigned long type used in system calls. */
__STD_TYPE __SYSCALL_ULONG_TYPE __syscall_ulong_t;
+/* Signed quad type used in system calls. */
+__STD_TYPE __SYSCALL_SQUAD_TYPE __syscall_squad_t;
/* These few don't really vary by system, they always correspond
to one of the other defined types. */
diff --git a/bits/typesizes.h b/bits/typesizes.h
index 53047b8..3b07647 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
@@ -59,6 +60,7 @@
#define __SSIZE_T_TYPE __SWORD_TYPE
#define __SYSCALL_SLONG_TYPE __SLONGWORD_TYPE
#define __SYSCALL_ULONG_TYPE __ULONGWORD_TYPE
+#define __SYSCALL_SQUAD_TYPE __SQUAD_TYPE
#define __CPU_MASK_TYPE __ULONGWORD_TYPE
#ifdef __LP64__
diff --git a/include/features.h b/include/features.h
index 650d4c5..d35f7b0 100644
--- a/include/features.h
+++ b/include/features.h
@@ -339,6 +339,10 @@
# define __USE_FILE_OFFSET64 1
#endif
+#if defined _TIME_BITS && _TIME_BITS == 64
+# define __USE_TIME_BITS64 1
+#endif
+
#if defined _DEFAULT_SOURCE
# define __USE_MISC 1
#endif
diff --git a/include/time.h b/include/time.h
index 684ceb8..10c327e 100644
--- a/include/time.h
+++ b/include/time.h
@@ -21,7 +21,14 @@ libc_hidden_proto (strptime)
extern __typeof (clock_getres) __clock_getres;
extern __typeof (clock_gettime) __clock_gettime;
libc_hidden_proto (__clock_gettime)
+extern __typeof (clock_gettime64) __clock_gettime64;
+libc_hidden_proto (__clock_gettime64)
extern __typeof (clock_settime) __clock_settime;
+extern __typeof (clock_settime64) __clock_settime64;
+#ifdef __USE_TIME_BITS64
+#define clock_gettime clock_gettime64
+#define clock_settime clock_settime64
+#endif /* __USE_TIME_BITS64 */
extern __typeof (clock_nanosleep) __clock_nanosleep;
extern __typeof (clock_getcpuclockid) __clock_getcpuclockid;
diff --git a/sysdeps/unix/clock_gettime.c b/sysdeps/unix/clock_gettime.c
index ffd6426..f11f663 100644
--- a/sysdeps/unix/clock_gettime.c
+++ b/sysdeps/unix/clock_gettime.c
@@ -134,3 +134,51 @@ __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;
+
+ switch (clock_id)
+ {
+#ifdef SYSDEP_GETTIME
+ SYSDEP_GETTIME64;
+#endif
+
+#ifndef HANDLED_REALTIME
+ case CLOCK_REALTIME:
+ {
+ struct timeval tv;
+ retval = gettimeofday (&tv, NULL);
+ if (retval == 0)
+ TIMEVAL_TO_TIMESPEC (&tv, 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, 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, tp);
+ break;
+#endif
+ }
+
+ return retval;
+}
+weak_alias (__clock_gettime64, clock_gettime64)
+libc_hidden_def (__clock_gettime64)
diff --git a/sysdeps/unix/clock_settime.c b/sysdeps/unix/clock_settime.c
index a3fd267..22044e7 100644
--- a/sysdeps/unix/clock_settime.c
+++ b/sysdeps/unix/clock_settime.c
@@ -69,8 +69,77 @@ hp_timing_settime (clockid_t clock_id, const struct timespec *tp)
}
#endif
+/*
+ * We define the 64- and 32-bit versions of clock_gettime. The client
+ * code determines which one is called:
+ *
+ * - if client code defines ___USE_TIME_BITS64, then GLIBC defines
+ * _TIME_BITS equal to 64, and the 64-bit version of clock_gettime
+ * gets declared and used.
+ *
+ * - if client code does not define ___USE_TIME_BITS64, then GLIBC does
+ * not define _TIME_BITS and the 32-bit version of clock_gettime gets
+ * declared and used.
+ */
+
+
+/* Set CLOCK to value TP, 64-bit Y2038-safe version. */
+int
+__clock_settime64 (clockid_t clock_id, const struct timespec64 *tp)
+{
+ int retval;
+
+ /* Make sure the time cvalue is OK. */
+ if (tp->tv_nsec < 0 || tp->tv_nsec >= 1000000000)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ switch (clock_id)
+ {
+#define HANDLE_REALTIME \
+ 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_REALTIME;
+ 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;
+}
+weak_alias (__clock_settime64, clock_settime64)
-/* Set CLOCK to value TP. */
+/* Set CLOCK to value TP, 64-bit Y2038-safe version. */
int
__clock_settime (clockid_t clock_id, const struct timespec *tp)
{
diff --git a/sysdeps/unix/sysv/linux/arm/Versions b/sysdeps/unix/sysv/linux/arm/Versions
index 7e5ba53..7d01d59 100644
--- a/sysdeps/unix/sysv/linux/arm/Versions
+++ b/sysdeps/unix/sysv/linux/arm/Versions
@@ -15,5 +15,7 @@ libc {
__default_sa_restorer; __default_rt_sa_restorer;
# nptl/pthread_cond_timedwait.c uses INTERNAL_VSYSCALL(clock_gettime).
__vdso_clock_gettime;
+ # (aaribaud) do we need this?
+ __vdso_clock_gettime64;
}
}
diff --git a/sysdeps/unix/sysv/linux/arm/init-first.c b/sysdeps/unix/sysv/linux/arm/init-first.c
index 6338200..b99c24b 100644
--- a/sysdeps/unix/sysv/linux/arm/init-first.c
+++ b/sysdeps/unix/sysv/linux/arm/init-first.c
@@ -23,6 +23,7 @@
int (*VDSO_SYMBOL(gettimeofday)) (struct timeval *, void *) attribute_hidden;
int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *);
+int (*VDSO_SYMBOL(clock_gettime64)) (clockid_t, struct timespec64 *);
static inline void
_libc_vdso_platform_setup (void)
@@ -36,6 +37,11 @@ _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;
}
# 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 bf5f012..1c86b90 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 int (*VDSO_SYMBOL(clock_gettime64)) (clockid_t, struct timespec64 *);
#endif
diff --git a/sysdeps/unix/sysv/linux/clock_gettime.c b/sysdeps/unix/sysv/linux/clock_gettime.c
index f6be61b..19458ba 100644
--- a/sysdeps/unix/sysv/linux/clock_gettime.c
+++ b/sysdeps/unix/sysv/linux/clock_gettime.c
@@ -44,4 +44,24 @@
break
#define SYSDEP_GETTIME_CPUTIME /* Default catches them too. */
+/* 64-bit versions */
+
+/* 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_gettime64, 2, clock_id, tp); \
+ break
+
+/* We handled the REALTIME clock here. */
+#define HANDLED_REALTIME 1
+#define HANDLED_CPUTIME 1
+
+#define SYSDEP_GETTIME64_CPU(clock_id, tp) \
+ retval = INLINE_VSYSCALL (clock_gettime64, 2, clock_id, tp); \
+ break
+#define SYSDEP_GETTIME64_CPUTIME /* Default catches them too. */
+
#include <sysdeps/unix/clock_gettime.c>
diff --git a/sysdeps/unix/sysv/linux/clock_settime.c b/sysdeps/unix/sysv/linux/clock_settime.c
index bfd3064..01c5989 100644
--- a/sysdeps/unix/sysv/linux/clock_settime.c
+++ b/sysdeps/unix/sysv/linux/clock_settime.c
@@ -23,6 +23,11 @@
/* The REALTIME clock is definitely supported in the kernel. */
+#define SYSDEP_SETTIME64 \
+ case CLOCK_REALTIME: \
+ retval = INLINE_SYSCALL (clock_settime64, 2, clock_id, tp); \
+ break
+
#define SYSDEP_SETTIME \
case CLOCK_REALTIME: \
retval = INLINE_SYSCALL (clock_settime, 2, clock_id, tp); \
@@ -32,6 +37,9 @@
#define HANDLED_REALTIME 1
#define HANDLED_CPUTIME 1
+#define SYSDEP_SETTIME64_CPU \
+ retval = INLINE_SYSCALL (clock_settime64, 2, clock_id, tp)
+
#define SYSDEP_SETTIME_CPU \
retval = INLINE_SYSCALL (clock_settime, 2, clock_id, tp)
diff --git a/time/bits/types/struct_timespec.h b/time/bits/types/struct_timespec.h
index 644db9f..dcb0ab5 100644
--- a/time/bits/types/struct_timespec.h
+++ b/time/bits/types/struct_timespec.h
@@ -11,4 +11,11 @@ struct timespec
__syscall_slong_t tv_nsec; /* Nanoseconds. */
};
+/* This one is for holding a Y2038-safe time value. */
+struct timespec64
+{
+ __time64_t tv_sec; /* Seconds. */
+ __syscall_squad_t tv_nsec; /* Nanoseconds. */
+};
+
#endif
diff --git a/time/time.h b/time/time.h
index c38fac7..06d3eb5 100644
--- a/time/time.h
+++ b/time/time.h
@@ -223,10 +223,13 @@ extern int clock_getres (clockid_t __clock_id, struct timespec *__res) __THROW;
/* Get current value of clock CLOCK_ID and store it in TP. */
extern int clock_gettime (clockid_t __clock_id, struct timespec *__tp) __THROW;
+extern int clock_gettime64 (clockid_t __clock_id, struct timespec64 *__tp) __THROW;
/* Set clock CLOCK_ID to value TP. */
extern int clock_settime (clockid_t __clock_id, const struct timespec *__tp)
__THROW;
+extern int clock_settime64 (clockid_t __clock_id, const struct timespec64 *__tp)
+ __THROW;
# ifdef __USE_XOPEN2K
/* High-resolution sleep with the specified clock.
-----------------------------------------------------------------------
hooks/post-receive
--
GNU C Library master sources