public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2 2/5] y2038: Introduce struct __timeval64 - new internal glibc type
  2020-01-26 14:53 [PATCH v2 1/5] y2038: Define __suseconds64_t type to be used with struct __timeval64 Lukasz Majewski
@ 2020-01-26 14:53 ` Lukasz Majewski
  2020-01-28  0:47   ` Alistair Francis
  2020-01-26 14:53 ` [PATCH v2 4/5] y2038: Provide conversion helpers for struct __timeval64 Lukasz Majewski
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Lukasz Majewski @ 2020-01-26 14:53 UTC (permalink / raw)
  To: Joseph Myers, Paul Eggert, Adhemerval Zanella
  Cc: Alistair Francis, Alistair Francis, GNU C Library,
	Siddhesh Poyarekar, Florian Weimer, Florian Weimer,
	Zack Weinberg, Carlos O'Donell, Andreas Schwab,
	Lukasz Majewski

This type is a glibc's "internal" type similar to struct timeval but
whose tv_sec field is a __time64_t rather than a time_t, which makes it
Y2038-proof. This struct is NOT supposed to be passed to the kernel -
instead it shall be converted to struct __timespec64 and clock_[sg]ettime
syscalls shall be used (which are now Y2038 safe).

Build tests:
./src/scripts/build-many-glibcs.py glibcs

---
Changes for v2:
- Replace __suseconds_t with __suseconds64_t
---
 include/time.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/include/time.h b/include/time.h
index 047f431a1a..99492a1577 100644
--- a/include/time.h
+++ b/include/time.h
@@ -93,6 +93,20 @@ struct __itimerspec64
 };
 #endif
 
+#if __TIMESIZE == 64
+# define __timeval64 timeval
+#else
+/* The glibc Y2038-proof struct __timeval64 structure for a time value.
+   This structure is NOT supposed to be passed to the Linux kernel.
+   Instead, it shall be converted to struct __timespec64 and time shall
+   be [sg]et via clock_[sg]ettime (which are now Y2038 safe).  */
+struct __timeval64
+{
+  __time64_t tv_sec;         /* Seconds */
+  __suseconds64_t tv_usec;       /* Microseconds */
+};
+#endif
+
 #if __TIMESIZE == 64
 # define __ctime64 ctime
 #else
-- 
2.20.1

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

* [PATCH v2 4/5] y2038: Provide conversion helpers for struct __timeval64
  2020-01-26 14:53 [PATCH v2 1/5] y2038: Define __suseconds64_t type to be used with struct __timeval64 Lukasz Majewski
  2020-01-26 14:53 ` [PATCH v2 2/5] y2038: Introduce struct __timeval64 - new internal glibc type Lukasz Majewski
@ 2020-01-26 14:53 ` Lukasz Majewski
  2020-01-26 14:53 ` [PATCH v2 3/5] y2038: alpha: Rename valid_timeval_to_timeval64 to valid_timeval32_to_timeval Lukasz Majewski
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 11+ messages in thread
From: Lukasz Majewski @ 2020-01-26 14:53 UTC (permalink / raw)
  To: Joseph Myers, Paul Eggert, Adhemerval Zanella
  Cc: Alistair Francis, Alistair Francis, GNU C Library,
	Siddhesh Poyarekar, Florian Weimer, Florian Weimer,
	Zack Weinberg, Carlos O'Donell, Andreas Schwab,
	Lukasz Majewski

Those functions allow easy conversion between Y2038 safe, glibc internal
struct __timeval64 and other time related data structures (like struct timeval
or struct __timespec64).

Build tests:
./src/scripts/build-many-glibcs.py glibcs

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

---
Changes for v2:
- None
---
 include/time.h | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/include/time.h b/include/time.h
index 99492a1577..9166354150 100644
--- a/include/time.h
+++ b/include/time.h
@@ -304,6 +304,30 @@ valid_timeval_to_timespec64 (const struct timeval tv)
   return ts64;
 }
 
+/* Convert a known valid struct timeval into a struct __timeval64.  */
+static inline struct __timeval64
+valid_timeval_to_timeval64 (const struct timeval tv)
+{
+  struct __timeval64 tv64;
+
+  tv64.tv_sec = tv.tv_sec;
+  tv64.tv_usec = tv.tv_usec;
+
+  return tv64;
+}
+
+/* Convert a struct __timeval64 into a struct __timespec64.  */
+static inline struct __timespec64
+timeval64_to_timespec64 (const struct __timeval64 tv64)
+{
+  struct __timespec64 ts64;
+
+  ts64.tv_sec = tv64.tv_sec;
+  ts64.tv_nsec = tv64.tv_usec * 1000;
+
+  return ts64;
+}
+
 /* Convert a known valid struct timespec into a struct __timespec64.  */
 static inline struct __timespec64
 valid_timespec_to_timespec64 (const struct timespec ts)
@@ -342,6 +366,18 @@ valid_timespec64_to_timeval (const struct __timespec64 ts64)
   return tv;
 }
 
+/* Convert a struct __timespec64 into a struct __timeval64.  */
+static inline struct __timeval64
+timespec64_to_timeval64 (const struct __timespec64 ts64)
+{
+  struct __timeval64 tv64;
+
+  tv64.tv_sec = ts64.tv_sec;
+  tv64.tv_usec = ts64.tv_nsec / 1000;
+
+  return tv64;
+}
+
 /* Check if a value is in the valid nanoseconds range. Return true if
    it is, false otherwise.  */
 static inline bool
-- 
2.20.1

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

* [PATCH v2 3/5] y2038: alpha: Rename valid_timeval_to_timeval64 to valid_timeval32_to_timeval
  2020-01-26 14:53 [PATCH v2 1/5] y2038: Define __suseconds64_t type to be used with struct __timeval64 Lukasz Majewski
  2020-01-26 14:53 ` [PATCH v2 2/5] y2038: Introduce struct __timeval64 - new internal glibc type Lukasz Majewski
  2020-01-26 14:53 ` [PATCH v2 4/5] y2038: Provide conversion helpers for struct __timeval64 Lukasz Majewski
@ 2020-01-26 14:53 ` Lukasz Majewski
  2020-01-27  8:39 ` [PATCH v2 5/5] y2038: linux: Provide __settimeofday64 implementation Lukasz Majewski
  2020-01-27 10:03 ` [PATCH v2 1/5] y2038: Define __suseconds64_t type to be used with struct __timeval64 Andreas Schwab
  4 siblings, 0 replies; 11+ messages in thread
From: Lukasz Majewski @ 2020-01-26 14:53 UTC (permalink / raw)
  To: Joseph Myers, Paul Eggert, Adhemerval Zanella
  Cc: Alistair Francis, Alistair Francis, GNU C Library,
	Siddhesh Poyarekar, Florian Weimer, Florian Weimer,
	Zack Weinberg, Carlos O'Donell, Andreas Schwab,
	Lukasz Majewski

Without this patch the naming convention for functions to convert
struct timeval32 to struct timeval (which supports 64 bit time on Alpha) was
a bit misleading. The name 'valid_timeval_to_timeval64' suggest conversion
of struct timeval to struct __timeval64 (as in ./include/time.h).

As on alpha the struct timeval supports 64 bit time it seems more readable
to emphasis struct timeval32 in the conversion function name.

Hence the helper function naming change to 'valid_timeval32_to_timeval'.

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

---
Changes for v2:
- None
---
 sysdeps/unix/sysv/linux/alpha/osf_adjtime.c   | 4 ++--
 sysdeps/unix/sysv/linux/alpha/osf_setitimer.c | 4 ++--
 sysdeps/unix/sysv/linux/alpha/osf_utimes.c    | 4 ++--
 sysdeps/unix/sysv/linux/alpha/tv32-compat.h   | 2 +-
 4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/sysdeps/unix/sysv/linux/alpha/osf_adjtime.c b/sysdeps/unix/sysv/linux/alpha/osf_adjtime.c
index cd864686f6..5ac72e252f 100644
--- a/sysdeps/unix/sysv/linux/alpha/osf_adjtime.c
+++ b/sysdeps/unix/sysv/linux/alpha/osf_adjtime.c
@@ -57,7 +57,7 @@ int
 attribute_compat_text_section
 __adjtime_tv32 (const struct timeval32 *itv, struct timeval32 *otv)
 {
-  struct timeval itv64 = valid_timeval_to_timeval64 (*itv);
+  struct timeval itv64 = valid_timeval32_to_timeval (*itv);
   struct timeval otv64;
 
   if (__adjtime (&itv64, &otv64) == -1)
@@ -91,7 +91,7 @@ __adjtimex_tv32 (struct timex32 *tx)
   tx64.calcnt    = tx->calcnt;
   tx64.errcnt    = tx->errcnt;
   tx64.stbcnt    = tx->stbcnt;
-  tx64.time      = valid_timeval_to_timeval64 (tx->time);
+  tx64.time      = valid_timeval32_to_timeval (tx->time);
 
   int status = __adjtimex (&tx64);
   if (status < 0)
diff --git a/sysdeps/unix/sysv/linux/alpha/osf_setitimer.c b/sysdeps/unix/sysv/linux/alpha/osf_setitimer.c
index 418efbf546..3935d1cfb5 100644
--- a/sysdeps/unix/sysv/linux/alpha/osf_setitimer.c
+++ b/sysdeps/unix/sysv/linux/alpha/osf_setitimer.c
@@ -30,9 +30,9 @@ __setitimer_tv32 (int which, const struct itimerval32 *restrict new_value,
 {
   struct itimerval new_value_64;
   new_value_64.it_interval
-    = valid_timeval_to_timeval64 (new_value->it_interval);
+    = valid_timeval32_to_timeval (new_value->it_interval);
   new_value_64.it_value
-    = valid_timeval_to_timeval64 (new_value->it_value);
+    = valid_timeval32_to_timeval (new_value->it_value);
 
   if (old_value == NULL)
     return __setitimer (which, &new_value_64, NULL);
diff --git a/sysdeps/unix/sysv/linux/alpha/osf_utimes.c b/sysdeps/unix/sysv/linux/alpha/osf_utimes.c
index 423c2a8ef2..6c3fad0132 100644
--- a/sysdeps/unix/sysv/linux/alpha/osf_utimes.c
+++ b/sysdeps/unix/sysv/linux/alpha/osf_utimes.c
@@ -28,8 +28,8 @@ attribute_compat_text_section
 __utimes_tv32 (const char *filename, const struct timeval32 times32[2])
 {
   struct timeval times[2];
-  times[0] = valid_timeval_to_timeval64 (times32[0]);
-  times[1] = valid_timeval_to_timeval64 (times32[1]);
+  times[0] = valid_timeval32_to_timeval (times32[0]);
+  times[1] = valid_timeval32_to_timeval (times32[1]);
   return __utimes (filename, times);
 }
 
diff --git a/sysdeps/unix/sysv/linux/alpha/tv32-compat.h b/sysdeps/unix/sysv/linux/alpha/tv32-compat.h
index 6076d2ec05..7169909259 100644
--- a/sysdeps/unix/sysv/linux/alpha/tv32-compat.h
+++ b/sysdeps/unix/sysv/linux/alpha/tv32-compat.h
@@ -70,7 +70,7 @@ struct rusage32
    overflow, they write { INT32_MAX, TV_USEC_MAX } to the output.  */
 
 static inline struct timeval
-valid_timeval_to_timeval64 (const struct timeval32 tv)
+valid_timeval32_to_timeval (const struct timeval32 tv)
 {
   return (struct timeval) { tv.tv_sec, tv.tv_usec };
 }
-- 
2.20.1

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

* [PATCH v2 1/5] y2038: Define __suseconds64_t type to be used with struct __timeval64
@ 2020-01-26 14:53 Lukasz Majewski
  2020-01-26 14:53 ` [PATCH v2 2/5] y2038: Introduce struct __timeval64 - new internal glibc type Lukasz Majewski
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Lukasz Majewski @ 2020-01-26 14:53 UTC (permalink / raw)
  To: Joseph Myers, Paul Eggert, Adhemerval Zanella
  Cc: Alistair Francis, Alistair Francis, GNU C Library,
	Siddhesh Poyarekar, Florian Weimer, Florian Weimer,
	Zack Weinberg, Carlos O'Donell, Andreas Schwab,
	Lukasz Majewski

The __suseconds64_t type is supposed to be the 64 bit type across all
architectures.

It would be mostly used internally in the glibc - however, when passed to
Linux kernel (very unlikely), if necessary, it shall be converted to 32
bit type (i.e. __suseconds_t)

---
Changes for v2:
- New patch
---
 bits/typesizes.h                                 | 1 +
 posix/bits/types.h                               | 1 +
 sysdeps/mach/hurd/bits/typesizes.h               | 1 +
 sysdeps/unix/sysv/linux/alpha/bits/typesizes.h   | 1 +
 sysdeps/unix/sysv/linux/generic/bits/typesizes.h | 1 +
 sysdeps/unix/sysv/linux/s390/bits/typesizes.h    | 1 +
 sysdeps/unix/sysv/linux/sparc/bits/typesizes.h   | 1 +
 sysdeps/unix/sysv/linux/x86/bits/typesizes.h     | 1 +
 8 files changed, 8 insertions(+)

diff --git a/bits/typesizes.h b/bits/typesizes.h
index 014c9aab21..599408973e 100644
--- a/bits/typesizes.h
+++ b/bits/typesizes.h
@@ -50,6 +50,7 @@
 #define __TIME_T_TYPE		__SLONGWORD_TYPE
 #define __USECONDS_T_TYPE	__U32_TYPE
 #define __SUSECONDS_T_TYPE	__SLONGWORD_TYPE
+#define __SUSECONDS64_T_TYPE	__SQUAD_TYPE
 #define __DADDR_T_TYPE		__S32_TYPE
 #define __KEY_T_TYPE		__S32_TYPE
 #define __CLOCKID_T_TYPE	__S32_TYPE
diff --git a/posix/bits/types.h b/posix/bits/types.h
index adba926b45..a26cd383e4 100644
--- a/posix/bits/types.h
+++ b/posix/bits/types.h
@@ -160,6 +160,7 @@ __STD_TYPE __ID_T_TYPE __id_t;		/* General type for IDs.  */
 __STD_TYPE __TIME_T_TYPE __time_t;	/* Seconds since the Epoch.  */
 __STD_TYPE __USECONDS_T_TYPE __useconds_t; /* Count of microseconds.  */
 __STD_TYPE __SUSECONDS_T_TYPE __suseconds_t; /* Signed count of microseconds.  */
+__STD_TYPE __SUSECONDS64_T_TYPE __suseconds64_t;
 
 __STD_TYPE __DADDR_T_TYPE __daddr_t;	/* The type of a disk address.  */
 __STD_TYPE __KEY_T_TYPE __key_t;	/* Type of an IPC key.  */
diff --git a/sysdeps/mach/hurd/bits/typesizes.h b/sysdeps/mach/hurd/bits/typesizes.h
index b429379d7d..0cc48598d1 100644
--- a/sysdeps/mach/hurd/bits/typesizes.h
+++ b/sysdeps/mach/hurd/bits/typesizes.h
@@ -50,6 +50,7 @@
 #define __TIME_T_TYPE		__SLONGWORD_TYPE
 #define __USECONDS_T_TYPE	__U32_TYPE
 #define __SUSECONDS_T_TYPE	__SLONGWORD_TYPE
+#define __SUSECONDS64_T_TYPE    __SQUAD_TYPE
 #define __DADDR_T_TYPE		__S32_TYPE
 #define __KEY_T_TYPE		__S32_TYPE
 #define __CLOCKID_T_TYPE	__S32_TYPE
diff --git a/sysdeps/unix/sysv/linux/alpha/bits/typesizes.h b/sysdeps/unix/sysv/linux/alpha/bits/typesizes.h
index 30356ba6d6..484a323d4d 100644
--- a/sysdeps/unix/sysv/linux/alpha/bits/typesizes.h
+++ b/sysdeps/unix/sysv/linux/alpha/bits/typesizes.h
@@ -49,6 +49,7 @@
 #define __TIME_T_TYPE		__SLONGWORD_TYPE
 #define __USECONDS_T_TYPE	__U32_TYPE
 #define __SUSECONDS_T_TYPE	__S64_TYPE
+#define __SUSECONDS64_T_TYPE    __SQUAD_TYPE
 #define __DADDR_T_TYPE		__S32_TYPE
 #define __KEY_T_TYPE		__S32_TYPE
 #define __CLOCKID_T_TYPE	__S32_TYPE
diff --git a/sysdeps/unix/sysv/linux/generic/bits/typesizes.h b/sysdeps/unix/sysv/linux/generic/bits/typesizes.h
index a916dea047..03990f2305 100644
--- a/sysdeps/unix/sysv/linux/generic/bits/typesizes.h
+++ b/sysdeps/unix/sysv/linux/generic/bits/typesizes.h
@@ -51,6 +51,7 @@
 #define __TIME_T_TYPE		__SLONGWORD_TYPE
 #define __USECONDS_T_TYPE	__U32_TYPE
 #define __SUSECONDS_T_TYPE	__SLONGWORD_TYPE
+#define __SUSECONDS64_T_TYPE    __SQUAD_TYPE
 #define __DADDR_T_TYPE		__S32_TYPE
 #define __KEY_T_TYPE		__S32_TYPE
 #define __CLOCKID_T_TYPE	__S32_TYPE
diff --git a/sysdeps/unix/sysv/linux/s390/bits/typesizes.h b/sysdeps/unix/sysv/linux/s390/bits/typesizes.h
index 45f70184ea..29728585ad 100644
--- a/sysdeps/unix/sysv/linux/s390/bits/typesizes.h
+++ b/sysdeps/unix/sysv/linux/s390/bits/typesizes.h
@@ -50,6 +50,7 @@
 #define __TIME_T_TYPE		__SLONGWORD_TYPE
 #define __USECONDS_T_TYPE	__U32_TYPE
 #define __SUSECONDS_T_TYPE	__SLONGWORD_TYPE
+#define __SUSECONDS64_T_TYPE    __SQUAD_TYPE
 #define __DADDR_T_TYPE		__S32_TYPE
 #define __KEY_T_TYPE		__S32_TYPE
 #define __CLOCKID_T_TYPE	__S32_TYPE
diff --git a/sysdeps/unix/sysv/linux/sparc/bits/typesizes.h b/sysdeps/unix/sysv/linux/sparc/bits/typesizes.h
index 1f3bbc8002..eb2c63d523 100644
--- a/sysdeps/unix/sysv/linux/sparc/bits/typesizes.h
+++ b/sysdeps/unix/sysv/linux/sparc/bits/typesizes.h
@@ -50,6 +50,7 @@
 #define __TIME_T_TYPE		__SLONGWORD_TYPE
 #define __USECONDS_T_TYPE	__U32_TYPE
 #define __SUSECONDS_T_TYPE	__S32_TYPE
+#define __SUSECONDS64_T_TYPE    __SQUAD_TYPE
 #define __DADDR_T_TYPE		__S32_TYPE
 #define __KEY_T_TYPE		__S32_TYPE
 #define __CLOCKID_T_TYPE	__S32_TYPE
diff --git a/sysdeps/unix/sysv/linux/x86/bits/typesizes.h b/sysdeps/unix/sysv/linux/x86/bits/typesizes.h
index d084145597..f436f6c56f 100644
--- a/sysdeps/unix/sysv/linux/x86/bits/typesizes.h
+++ b/sysdeps/unix/sysv/linux/x86/bits/typesizes.h
@@ -64,6 +64,7 @@
 #define __TIME_T_TYPE		__SYSCALL_SLONG_TYPE
 #define __USECONDS_T_TYPE	__U32_TYPE
 #define __SUSECONDS_T_TYPE	__SYSCALL_SLONG_TYPE
+#define __SUSECONDS64_T_TYPE    __SQUAD_TYPE
 #define __DADDR_T_TYPE		__S32_TYPE
 #define __KEY_T_TYPE		__S32_TYPE
 #define __CLOCKID_T_TYPE	__S32_TYPE
-- 
2.20.1

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

* [PATCH v2 5/5] y2038: linux: Provide __settimeofday64 implementation
  2020-01-26 14:53 [PATCH v2 1/5] y2038: Define __suseconds64_t type to be used with struct __timeval64 Lukasz Majewski
                   ` (2 preceding siblings ...)
  2020-01-26 14:53 ` [PATCH v2 3/5] y2038: alpha: Rename valid_timeval_to_timeval64 to valid_timeval32_to_timeval Lukasz Majewski
@ 2020-01-27  8:39 ` Lukasz Majewski
  2020-01-27 10:03 ` [PATCH v2 1/5] y2038: Define __suseconds64_t type to be used with struct __timeval64 Andreas Schwab
  4 siblings, 0 replies; 11+ messages in thread
From: Lukasz Majewski @ 2020-01-27  8:39 UTC (permalink / raw)
  To: Joseph Myers, Paul Eggert, Adhemerval Zanella
  Cc: Alistair Francis, Alistair Francis, GNU C Library,
	Siddhesh Poyarekar, Florian Weimer, Florian Weimer,
	Zack Weinberg, Carlos O'Donell, Andreas Schwab,
	Lukasz Majewski

This patch provides new __settimeofday64 explicit 64 bit function for setting
64 bit time in the kernel (by internally calling __clock_settime64).
Moreover, a 32 bit version - __settimeofday has been refactored to internally
use __settimeofday64.

The __settimeofday is now supposed to be used on systems still supporting 32
bit time (__TIMESIZE != 64) - hence the necessary conversion of struct
timeval to 64 bit struct __timespec64.

Internally the settimeofday uses __settimeofday64. This patch is necessary
for having architectures with __WORDSIZE == 32 Y2038 safe.

Build tests:
./src/scripts/build-many-glibcs.py glibcs

Run-time tests:
- Run specific tests on ARM/x86 32bit systems (qemu):
  https://github.com/lmajewski/meta-y2038 and run tests:
  https://github.com/lmajewski/y2038-tests/commits/master

Above tests were performed with Y2038 redirection applied as well as without
to test proper usage of both __settimeofday64 and __settimeofday.

---
Changes for v2:
- The conversion to support 64 bit time for settimeofday() has been moved
  from ./time/settimeofday.c to sysdeps/unix/sysv/linux/settimeofday.c
  (as suggested by Adhemerval) to avoid the need to create __clock_settime64()
  method for HURD (as 64 bit time support for machines with __WORDSIZE=32
  and __TIMESIZE=32 is now developed solely for Linux).
---
 include/time.h                         |  9 +++++
 sysdeps/unix/sysv/linux/settimeofday.c | 53 ++++++++++++++++++++++++++
 2 files changed, 62 insertions(+)
 create mode 100644 sysdeps/unix/sysv/linux/settimeofday.c

diff --git a/include/time.h b/include/time.h
index 9166354150..42b393003b 100644
--- a/include/time.h
+++ b/include/time.h
@@ -8,6 +8,7 @@
 # include <time/mktime-internal.h>
 # include <endian.h>
 # include <time-clockid.h>
+# include <sys/time.h>
 
 extern __typeof (strftime_l) __strftime_l;
 libc_hidden_proto (__strftime_l)
@@ -224,6 +225,14 @@ extern int __sched_rr_get_interval64 (pid_t pid, struct __timespec64 *tp);
 libc_hidden_proto (__sched_rr_get_interval64);
 #endif
 
+#if __TIMESIZE == 64
+# define __settimeofday64 __settimeofday
+#else
+extern int __settimeofday64 (const struct __timeval64 *tv,
+                             const struct timezone *tz);
+libc_hidden_proto (__settimeofday64)
+#endif
+
 /* 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/sysdeps/unix/sysv/linux/settimeofday.c b/sysdeps/unix/sysv/linux/settimeofday.c
new file mode 100644
index 0000000000..ea45f1d7cb
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/settimeofday.c
@@ -0,0 +1,53 @@
+/* settimeofday -- set system time - Linux version supporting 64 bit time.
+   Copyright (C) 2020 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
+   <https://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <time.h>
+#include <sys/time.h>
+
+/* Set the current time of day and timezone information.
+   This call is restricted to the super-user.  */
+int
+__settimeofday64 (const struct __timeval64 *tv, const struct timezone *tz)
+{
+  if (__glibc_unlikely (tz != 0))
+    {
+      if (tv != 0)
+	{
+	  __set_errno (EINVAL);
+	  return -1;
+	}
+      return __settimezone (tz);
+    }
+
+  struct __timespec64 ts = timeval64_to_timespec64 (*tv);
+  return __clock_settime64 (CLOCK_REALTIME, &ts);
+}
+
+#if __TIMESIZE != 64
+libc_hidden_def (__settimeofday64)
+
+int
+__settimeofday (const struct timeval *tv, const struct timezone *tz)
+{
+  struct __timeval64 tv64 = valid_timeval_to_timeval64 (*tv);
+
+  return __settimeofday64 (&tv64, tz);
+}
+#endif
+weak_alias (__settimeofday, settimeofday);
-- 
2.20.1

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

* Re: [PATCH v2 1/5] y2038: Define __suseconds64_t type to be used with struct __timeval64
  2020-01-26 14:53 [PATCH v2 1/5] y2038: Define __suseconds64_t type to be used with struct __timeval64 Lukasz Majewski
                   ` (3 preceding siblings ...)
  2020-01-27  8:39 ` [PATCH v2 5/5] y2038: linux: Provide __settimeofday64 implementation Lukasz Majewski
@ 2020-01-27 10:03 ` Andreas Schwab
  4 siblings, 0 replies; 11+ messages in thread
From: Andreas Schwab @ 2020-01-27 10:03 UTC (permalink / raw)
  To: Lukasz Majewski
  Cc: Joseph Myers, Paul Eggert, Adhemerval Zanella, Alistair Francis,
	Alistair Francis, GNU C Library, Siddhesh Poyarekar,
	Florian Weimer, Florian Weimer, Zack Weinberg,
	Carlos O'Donell

On Jan 26 2020, Lukasz Majewski wrote:

> diff --git a/sysdeps/mach/hurd/bits/typesizes.h b/sysdeps/mach/hurd/bits/typesizes.h
> index b429379d7d..0cc48598d1 100644
> --- a/sysdeps/mach/hurd/bits/typesizes.h
> +++ b/sysdeps/mach/hurd/bits/typesizes.h
> @@ -50,6 +50,7 @@
>  #define __TIME_T_TYPE		__SLONGWORD_TYPE
>  #define __USECONDS_T_TYPE	__U32_TYPE
>  #define __SUSECONDS_T_TYPE	__SLONGWORD_TYPE
> +#define __SUSECONDS64_T_TYPE    __SQUAD_TYPE
>  #define __DADDR_T_TYPE		__S32_TYPE
>  #define __KEY_T_TYPE		__S32_TYPE
>  #define __CLOCKID_T_TYPE	__S32_TYPE

Please use consistent spacing (tab instead of spaces).

Andreas.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."

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

* Re: [PATCH v2 2/5] y2038: Introduce struct __timeval64 - new internal glibc type
  2020-01-26 14:53 ` [PATCH v2 2/5] y2038: Introduce struct __timeval64 - new internal glibc type Lukasz Majewski
@ 2020-01-28  0:47   ` Alistair Francis
  2020-01-28  1:32     ` Joseph Myers
  0 siblings, 1 reply; 11+ messages in thread
From: Alistair Francis @ 2020-01-28  0:47 UTC (permalink / raw)
  To: Lukasz Majewski
  Cc: Joseph Myers, Paul Eggert, Adhemerval Zanella, Alistair Francis,
	GNU C Library, Siddhesh Poyarekar, Florian Weimer,
	Florian Weimer, Zack Weinberg, Carlos O'Donell,
	Andreas Schwab

On Mon, Jan 27, 2020 at 12:53 AM Lukasz Majewski <lukma@denx.de> wrote:
>
> This type is a glibc's "internal" type similar to struct timeval but
> whose tv_sec field is a __time64_t rather than a time_t, which makes it
> Y2038-proof. This struct is NOT supposed to be passed to the kernel -
> instead it shall be converted to struct __timespec64 and clock_[sg]ettime
> syscalls shall be used (which are now Y2038 safe).
>
> Build tests:
> ./src/scripts/build-many-glibcs.py glibcs
>
> ---
> Changes for v2:
> - Replace __suseconds_t with __suseconds64_t
> ---
>  include/time.h | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
>
> diff --git a/include/time.h b/include/time.h
> index 047f431a1a..99492a1577 100644
> --- a/include/time.h
> +++ b/include/time.h
> @@ -93,6 +93,20 @@ struct __itimerspec64
>  };
>  #endif
>
> +#if __TIMESIZE == 64
> +# define __timeval64 timeval
> +#else
> +/* The glibc Y2038-proof struct __timeval64 structure for a time value.
> +   This structure is NOT supposed to be passed to the Linux kernel.
> +   Instead, it shall be converted to struct __timespec64 and time shall
> +   be [sg]et via clock_[sg]ettime (which are now Y2038 safe).  */
> +struct __timeval64
> +{
> +  __time64_t tv_sec;         /* Seconds */
> +  __suseconds64_t tv_usec;       /* Microseconds */
> +};
> +#endif

Can this be moved to time/bits/types/struct_timeval.h?

The reason is that we need it in include/bits/types/struct_rusage.h
and including time.h results in exposed symbols (from memory I see
glibc test failures when trying to do this).

The other problem is that we need __timeval64 in time/sys/time.h for
__getitimer64() and __setitimer64() and include/time.h isn't included
in there.

Alistair

> +
>  #if __TIMESIZE == 64
>  # define __ctime64 ctime
>  #else
> --
> 2.20.1
>

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

* Re: [PATCH v2 2/5] y2038: Introduce struct __timeval64 - new internal glibc type
  2020-01-28  0:47   ` Alistair Francis
@ 2020-01-28  1:32     ` Joseph Myers
  2020-01-28  1:42       ` Alistair Francis
  0 siblings, 1 reply; 11+ messages in thread
From: Joseph Myers @ 2020-01-28  1:32 UTC (permalink / raw)
  To: Alistair Francis
  Cc: Lukasz Majewski, Paul Eggert, Adhemerval Zanella,
	Alistair Francis, GNU C Library, Siddhesh Poyarekar,
	Florian Weimer, Florian Weimer, Zack Weinberg,
	Carlos O'Donell, Andreas Schwab

On Tue, 28 Jan 2020, Alistair Francis wrote:

> Can this be moved to time/bits/types/struct_timeval.h?

That's an installed header.  Internal types don't belong in installed 
headers unless unavoidable.  Note that the __USE_TIME_BITS64 conditionals 
we eventually get in installed headers will (for example) change the 
contents of "struct timeval" depending on __USE_TIME_BITS64, rather than 
adding a new type with an internal name.

> The reason is that we need it in include/bits/types/struct_rusage.h
> and including time.h results in exposed symbols (from memory I see
> glibc test failures when trying to do this).

include/bits/types/struct_rusage.h is a *wrapper* round an installed 
header.  Although such wrappers can contain internal declarations under a 
!_ISOMAC condition, it's best not to in this case because of the rule that 
including <bits/types/foo.h> should always get a definition of the type 
foo and nothing else beyond foo's dependencies, and breaking that rule 
would be confusing.

> The other problem is that we need __timeval64 in time/sys/time.h for
> __getitimer64() and __setitimer64() and include/time.h isn't included
> in there.

But time/sys/time.h is an installed header.  So it shouldn't get internal 
types either.  __getitimer64 and __setitimer64 are not public interfaces 
(nor, as APIs, should they ever be, though eventually __USE_TIME_BITS64 
may cause redirection to such names as ABIs).

The installed header changes for _TIME_BITS=64 support aren't until all 
the internal pieces are ready.  Until then, to a first approximation, you 
should only be changing *internal, non-installed* headers and 
implementation files, not installed headers.

-- 
Joseph S. Myers
joseph@codesourcery.com

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

* Re: [PATCH v2 2/5] y2038: Introduce struct __timeval64 - new internal glibc type
  2020-01-28  1:32     ` Joseph Myers
@ 2020-01-28  1:42       ` Alistair Francis
  2020-01-28 10:47         ` Joseph Myers
  0 siblings, 1 reply; 11+ messages in thread
From: Alistair Francis @ 2020-01-28  1:42 UTC (permalink / raw)
  To: Joseph Myers
  Cc: Lukasz Majewski, Paul Eggert, Adhemerval Zanella,
	Alistair Francis, GNU C Library, Siddhesh Poyarekar,
	Florian Weimer, Florian Weimer, Zack Weinberg,
	Carlos O'Donell, Andreas Schwab

On Mon, Jan 27, 2020 at 4:47 PM Joseph Myers <joseph@codesourcery.com> wrote:
>
> On Tue, 28 Jan 2020, Alistair Francis wrote:
>
> > Can this be moved to time/bits/types/struct_timeval.h?
>
> That's an installed header.  Internal types don't belong in installed
> headers unless unavoidable.  Note that the __USE_TIME_BITS64 conditionals
> we eventually get in installed headers will (for example) change the
> contents of "struct timeval" depending on __USE_TIME_BITS64, rather than
> adding a new type with an internal name.
>
> > The reason is that we need it in include/bits/types/struct_rusage.h
> > and including time.h results in exposed symbols (from memory I see
> > glibc test failures when trying to do this).
>
> include/bits/types/struct_rusage.h is a *wrapper* round an installed
> header.  Although such wrappers can contain internal declarations under a
> !_ISOMAC condition, it's best not to in this case because of the rule that
> including <bits/types/foo.h> should always get a definition of the type
> foo and nothing else beyond foo's dependencies, and breaking that rule
> would be confusing.

How should I add a __rusage64 type then? Right now I have modified
include/bits/types/struct_rusage.h to include the header twice with
different definitions based on macros.

>
> > The other problem is that we need __timeval64 in time/sys/time.h for
> > __getitimer64() and __setitimer64() and include/time.h isn't included
> > in there.
>
> But time/sys/time.h is an installed header.  So it shouldn't get internal
> types either.  __getitimer64 and __setitimer64 are not public interfaces
> (nor, as APIs, should they ever be, though eventually __USE_TIME_BITS64
> may cause redirection to such names as ABIs).

From memory I was seeing compiler failures, as something doesn't
include time.h. I can look into this more though.

Alistair

>
> The installed header changes for _TIME_BITS=64 support aren't until all
> the internal pieces are ready.  Until then, to a first approximation, you
> should only be changing *internal, non-installed* headers and
> implementation files, not installed headers.
>
> --
> Joseph S. Myers
> joseph@codesourcery.com

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

* Re: [PATCH v2 2/5] y2038: Introduce struct __timeval64 - new internal glibc type
  2020-01-28  1:42       ` Alistair Francis
@ 2020-01-28 10:47         ` Joseph Myers
  2020-01-29  4:44           ` Alistair Francis
  0 siblings, 1 reply; 11+ messages in thread
From: Joseph Myers @ 2020-01-28 10:47 UTC (permalink / raw)
  To: Alistair Francis
  Cc: Lukasz Majewski, Paul Eggert, Adhemerval Zanella,
	Alistair Francis, GNU C Library, Siddhesh Poyarekar,
	Florian Weimer, Florian Weimer, Zack Weinberg,
	Carlos O'Donell, Andreas Schwab

On Tue, 28 Jan 2020, Alistair Francis wrote:

> How should I add a __rusage64 type then? Right now I have modified

Define it in an *internal, non-installed* header, just like __timespec64 
is defined in include/time.h (the internal wrapper for the installed 
header).  For example, inside the "#ifndef _ISOMAC" section of 
include/sys/resource.h (if using a wrapper header like that, such internal 
definitions must be inside #ifndef _ISOMAC and the include of the public 
header outside that conditional).

-- 
Joseph S. Myers
joseph@codesourcery.com

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

* Re: [PATCH v2 2/5] y2038: Introduce struct __timeval64 - new internal glibc type
  2020-01-28 10:47         ` Joseph Myers
@ 2020-01-29  4:44           ` Alistair Francis
  0 siblings, 0 replies; 11+ messages in thread
From: Alistair Francis @ 2020-01-29  4:44 UTC (permalink / raw)
  To: Joseph Myers
  Cc: Lukasz Majewski, Paul Eggert, Adhemerval Zanella,
	Alistair Francis, GNU C Library, Siddhesh Poyarekar,
	Florian Weimer, Florian Weimer, Zack Weinberg,
	Carlos O'Donell, Andreas Schwab

On Mon, Jan 27, 2020 at 5:42 PM Joseph Myers <joseph@codesourcery.com> wrote:
>
> On Tue, 28 Jan 2020, Alistair Francis wrote:
>
> > How should I add a __rusage64 type then? Right now I have modified
>
> Define it in an *internal, non-installed* header, just like __timespec64
> is defined in include/time.h (the internal wrapper for the installed
> header).  For example, inside the "#ifndef _ISOMAC" section of
> include/sys/resource.h (if using a wrapper header like that, such internal
> definitions must be inside #ifndef _ISOMAC and the include of the public
> header outside that conditional).

Thanks for the help Joseph. I think I have changed it all around so
it's in non-installed headers.

Alistair

>
> --
> Joseph S. Myers
> joseph@codesourcery.com

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

end of thread, other threads:[~2020-01-28 23:18 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-26 14:53 [PATCH v2 1/5] y2038: Define __suseconds64_t type to be used with struct __timeval64 Lukasz Majewski
2020-01-26 14:53 ` [PATCH v2 2/5] y2038: Introduce struct __timeval64 - new internal glibc type Lukasz Majewski
2020-01-28  0:47   ` Alistair Francis
2020-01-28  1:32     ` Joseph Myers
2020-01-28  1:42       ` Alistair Francis
2020-01-28 10:47         ` Joseph Myers
2020-01-29  4:44           ` Alistair Francis
2020-01-26 14:53 ` [PATCH v2 4/5] y2038: Provide conversion helpers for struct __timeval64 Lukasz Majewski
2020-01-26 14:53 ` [PATCH v2 3/5] y2038: alpha: Rename valid_timeval_to_timeval64 to valid_timeval32_to_timeval Lukasz Majewski
2020-01-27  8:39 ` [PATCH v2 5/5] y2038: linux: Provide __settimeofday64 implementation Lukasz Majewski
2020-01-27 10:03 ` [PATCH v2 1/5] y2038: Define __suseconds64_t type to be used with struct __timeval64 Andreas Schwab

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).