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-345-gee6238e
- From: aaribaud at sourceware dot org
- To: glibc-cvs at sourceware dot org
- Date: 7 Nov 2016 23:12:28 -0000
- Subject: GNU C Library master sources branch aaribaud/y2038 created. glibc-2.24-345-gee6238e
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 ee6238e1fb7b7bc9b3d47d9d0dd10150699fbbbe (commit)
- Log -----------------------------------------------------------------
http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=ee6238e1fb7b7bc9b3d47d9d0dd10150699fbbbe
commit ee6238e1fb7b7bc9b3d47d9d0dd10150699fbbbe
Author: Albert ARIBAUD (3ADEV) <albert.aribaud@3adev.fr>
Date: Sun Nov 6 18:36:51 2016 +0100
WIP: Y2038: support 64-bit clock_gettime
diff --git a/bits/types.h b/bits/types.h
index 01753bd..db04f19 100644
--- a/bits/types.h
+++ b/bits/types.h
@@ -136,7 +136,10 @@ __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. */
+#ifdef __USE_TIME_BITS64
+__STD_TYPE __TIME64_T_TYPE __time64_t; /* Seconds since the Epoch, Y2038-safe. */
+#endif /* __USE_TIME_BITS64 */
__STD_TYPE __USECONDS_T_TYPE __useconds_t; /* Count of microseconds. */
__STD_TYPE __SUSECONDS_T_TYPE __suseconds_t; /* Signed count of microseconds. */
@@ -175,6 +178,10 @@ __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. */
+#ifdef __USE_TIME_BITS64
+__STD_TYPE __SYSCALL_SQUAD_TYPE __syscall_squad_t;
+#endif /* __USE_TIME_BITS64 */
/* 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..aa3919a 100644
--- a/bits/typesizes.h
+++ b/bits/typesizes.h
@@ -48,6 +48,9 @@
#define __ID_T_TYPE __U32_TYPE
#define __CLOCK_T_TYPE __SLONGWORD_TYPE
#define __TIME_T_TYPE __SLONGWORD_TYPE
+#ifdef __USE_TIME_BITS64
+#define __TIME64_T_TYPE __SQUAD_TYPE
+#endif /* __USE_TIME_BITS64 */
#define __USECONDS_T_TYPE __U32_TYPE
#define __SUSECONDS_T_TYPE __SLONGWORD_TYPE
#define __DADDR_T_TYPE __S32_TYPE
@@ -59,6 +62,9 @@
#define __SSIZE_T_TYPE __SWORD_TYPE
#define __SYSCALL_SLONG_TYPE __SLONGWORD_TYPE
#define __SYSCALL_ULONG_TYPE __ULONGWORD_TYPE
+#ifdef __USE_TIME_BITS64
+#define __SYSCALL_SQUAD_TYPE __SQUAD_TYPE
+#endif /* __USE_TIME_BITS64 */
#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..2398a4e 100644
--- a/include/time.h
+++ b/include/time.h
@@ -22,6 +22,10 @@ extern __typeof (clock_getres) __clock_getres;
extern __typeof (clock_gettime) __clock_gettime;
libc_hidden_proto (__clock_gettime)
extern __typeof (clock_settime) __clock_settime;
+extern __typeof (clock_settime64) __clock_settime64;
+#ifdef __USE_TIME_BITS64
+#define clock_gettime clock_gettime64
+#endif /* __USE_TIME_BITS64 */
extern __typeof (clock_nanosleep) __clock_nanosleep;
extern __typeof (clock_getcpuclockid) __clock_getcpuclockid;
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/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..b575d75 100644
--- a/time/time.h
+++ b/time/time.h
@@ -225,6 +225,8 @@ extern int clock_getres (clockid_t __clock_id, struct timespec *__res) __THROW;
extern int clock_gettime (clockid_t __clock_id, struct timespec *__tp) __THROW;
/* Set clock CLOCK_ID to value TP. */
+extern int clock_settime64 (clockid_t __clock_id, const struct timespec64 *__tp)
+ __THROW;
extern int clock_settime (clockid_t __clock_id, const struct timespec *__tp)
__THROW;
-----------------------------------------------------------------------
hooks/post-receive
--
GNU C Library master sources