This is the mail archive of the
glibc-cvs@sourceware.org
mailing list for the glibc project.
[glibc] y2038: Introduce struct __timespec64 - new internal glibc type
- From: Lukasz Majewski <lukma at sourceware dot org>
- To: glibc-cvs at sourceware dot org
- Date: 26 Sep 2019 21:39:52 -0000
- Subject: [glibc] y2038: Introduce struct __timespec64 - new internal glibc type
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=464cd3a9d5f505d92bae9a941bb75b0d91ac14ee
commit 464cd3a9d5f505d92bae9a941bb75b0d91ac14ee
Author: Lukasz Majewski <lukma@denx.de>
Date: Fri Mar 22 11:53:45 2019 +0100
y2038: Introduce struct __timespec64 - new internal glibc type
This type is a glibc's "internal" type similar to struct timespec but
whose tv_sec field is a __time64_t rather than a time_t, which makes it
Y2038-proof and usable to pass syscalls between user code and Y2038-proof
kernel.
To support passing this structure to the kernel - the unnamed 32 bit
padding bit-field has been introduced. The placement of it depends on
the endianness of the SoC.
Tested on x86_64 and ARM.
Diff:
---
ChangeLog | 4 ++++
include/time.h | 24 ++++++++++++++++++++++++
2 files changed, 28 insertions(+)
diff --git a/ChangeLog b/ChangeLog
index bb53a33..31e4976 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2019-09-26 Lukasz Majewski <lukma@denx.de>
+
+ * include/time.h: Add struct __timespec64 definition
+
2019-09-26 Siddhesh Poyarekar <siddhesh@gotplt.org>
* scripts/vcs_to_changelog/misc_util.py (decode): Remove latin1
diff --git a/include/time.h b/include/time.h
index dcf9185..9727786 100644
--- a/include/time.h
+++ b/include/time.h
@@ -5,6 +5,7 @@
# include <bits/types/locale_t.h>
# include <stdbool.h>
# include <time/mktime-internal.h>
+# include <endian.h>
extern __typeof (strftime_l) __strftime_l;
libc_hidden_proto (__strftime_l)
@@ -50,6 +51,29 @@ extern void __tz_compute (__time64_t timer, struct tm *tm, int use_localtime)
__THROW attribute_hidden;
#if __TIMESIZE == 64
+# define __timespec64 timespec
+#else
+/* The glibc Y2038-proof struct __timespec64 structure for a time value.
+ To keep things Posix-ish, we keep the nanoseconds field a 32-bit
+ signed long, but since the Linux field is a 64-bit signed int, we
+ pad our tv_nsec with a 32-bit unnamed bit-field padding.
+
+ As a general rule the Linux kernel is ignoring upper 32 bits of
+ tv_nsec field. */
+struct __timespec64
+{
+ __time64_t tv_sec; /* Seconds */
+# if BYTE_ORDER == BIG_ENDIAN
+ __int32_t :32; /* Padding */
+ __int32_t tv_nsec; /* Nanoseconds */
+# else
+ __int32_t tv_nsec; /* Nanoseconds */
+ __int32_t :32; /* Padding */
+# endif
+};
+#endif
+
+#if __TIMESIZE == 64
# define __ctime64 ctime
#else
extern char *__ctime64 (const __time64_t *__timer) __THROW;