This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[RFC v2 01/20] y2038: Introduce internal for glibc struct __timespec64
- From: Alistair Francis <alistair dot francis at wdc dot com>
- To: libc-alpha at sourceware dot org
- Cc: arnd at arndb dot de, adhemerval dot zanella at linaro dot org, fweimer at redhat dot com, palmer at sifive dot com, macro at wdc dot com, zongbox at gmail dot com, zong at andestech dot com, alistair dot francis at wdc dot com, alistair23 at gmail dot com
- Date: Mon, 24 Jun 2019 17:08:46 -0700
- Subject: [RFC v2 01/20] y2038: Introduce internal for glibc struct __timespec64
- Ironport-sdr: 88QNhIZLfFbOTD2JM4pi5c6VtOVvIecnXW6hzmRQ8FfVZf/f6Rz9Tyb/fWWEGDa2v8+svT89eP p8Fy7+xsJzUskQunR9Adm7s8tI2NMXV7sIvqgqSm/NfalOzzrzFjv727BvGg2/xwFiEIdCpe8u YBD2HX0k4FsR7z+hTWEf1BKPc2POCkESwdc7NrGjN+zdHNOD9SyW6oJiF4KTbPd1SFQW9MBPUF G2zIvdq1a6YYySs3GBi6akK4Pu52QI4xHPJpGuX5I71z75OC65RU2HR3mM1a/SLyFR8L8PdNgX /u6ukuFugg3E4uDSsll4j66u
- Ironport-sdr: gHwm6brEPxva5NzLLGG3yqAo9vlVYtGqUbuj6fwN1I/1ztlxNlptV9MW5sqmntD6L8Cb62de02 MmJpGUOC80IOeOx+2y0KyaoDHK2IbNHb5cuagsb822DVLjEjdFGpjJVjFQ456WPFvfw6rCN+mk nGw7q26THcf61aKinaCZGQwKdPijrmzpguq1EMtFlVbdvFhVPsO8F1Zd41G1ShvjHOBR1Bm6GO B472+AJb1yH5Q8JIshN+YQGGot0xWJcCUlaeZQR18CKz4blL1+rTA8YDKFoZtJR2+vHsT14Ypg WC4=
- References: <cover.1561421042.git.alistair.francis@wdc.com>
From: Lukasz Majewski <lukma@denx.de>
This type is a glibc's 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 tv_pad, 32 bit int,
has been introduced. The placement of it depends on endianness of the SoC.
Tested on x86_64 and ARM.
* include/time.h: Add struct __timespec64 definition
---
include/time.h | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/include/time.h b/include/time.h
index ac3163c2a5..33d0fcb0fe 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)
@@ -51,6 +52,30 @@ extern void __tzset_parse_tz (const char *tz) attribute_hidden;
extern void __tz_compute (__time64_t timer, struct tm *tm, int use_localtime)
__THROW attribute_hidden;
+#if __WORDSIZE == 64 \
+ || (defined __SYSCALL_WORDSIZE && __SYSCALL_WORDSIZE == 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 int.
+
+ 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 tv_pad; /* Padding */
+ __int32_t tv_nsec; /* Nanoseconds */
+# else
+ __int32_t tv_nsec; /* Nanoseconds */
+ __int32_t tv_pad; /* Padding */
+# endif
+};
+#endif
+
#if __TIMESIZE == 64
# define __ctime64 ctime
#else
--
2.22.0