unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v4 0/8] Always use 32-bit time_t for certain syscalls
@ 2020-02-19 18:10 Alistair Francis
  2020-02-19 18:10 ` [PATCH v4 1/8] sysv/linux: Rename alpha functions to be alpha specific Alistair Francis
                   ` (7 more replies)
  0 siblings, 8 replies; 15+ messages in thread
From: Alistair Francis @ 2020-02-19 18:10 UTC (permalink / raw)
  To: libc-alpha; +Cc: alistair23, Alistair Francis

On y2038 safe 32-bit systems the Linux kernel expects itimerval
and rusage to use a 32-bit time_t, even though the other time_t's
are 64-bit.

This series converts getitimer, setitimer, getrusage and wait4 to be
both y2038 safe and pass a 32-bit time_t based on the
__KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64 macro. On 32-bit systems
we will pass a 32-bit time to the kernel (no matter the time_t size). This is
no change for most 64-bit architectures or 32-bit architectures with a 32-bit time_t.

We can also remove the old Alpha functions as this is now handled genericly.

This follows the standard y2038 conversion so that we don't break
backwards compatibility but we expose a 64-bit version for y2038 safe
architectrures (like RV32).

This series was tested by running:
  ./scripts/build-many-glibcs.py ... compilers
  ./scripts/build-many-glibcs.py ... glibcs
on my x86_64 machine.

I also ran make check on RV32 and I only see a total of 10 test failures.

I don't have a way to test this on Alpha, would someone mind testing it for me?

Alistair Francis (8):
  sysv/linux: Rename alpha functions to be alpha specific
  time: Add a timeval with a 32-bit tv_sec and tv_usec
  time: Add a __itimerval64 struct
  sysv: Define __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64
  linux: Use long time_t __getitimer/__setitimer
  resource: Add a __rusage64 struct
  linux: Use long time_t for wait4/getrusage
  sysv/alpha: Use generic __timeval32 and helpers

 bits/typesizes.h                              |   6 +
 include/sys/resource.h                        | 121 ++++++++++++++++++
 include/time.h                                |  71 ++++++++++
 sysdeps/unix/syscalls.list                    |   3 -
 .../unix/sysv/linux/alpha/bits/typesizes.h    |   3 +
 sysdeps/unix/sysv/linux/alpha/osf_adjtime.c   |   7 +-
 sysdeps/unix/sysv/linux/alpha/osf_getitimer.c |   3 +-
 sysdeps/unix/sysv/linux/alpha/osf_getrusage.c |   8 +-
 .../unix/sysv/linux/alpha/osf_gettimeofday.c  |   4 +-
 sysdeps/unix/sysv/linux/alpha/osf_setitimer.c |   5 +-
 .../unix/sysv/linux/alpha/osf_settimeofday.c  |   4 +-
 sysdeps/unix/sysv/linux/alpha/osf_utimes.c    |   4 +-
 sysdeps/unix/sysv/linux/alpha/osf_wait4.c     |   8 +-
 .../unix/sysv/linux/generic/bits/typesizes.h  |   6 +
 sysdeps/unix/sysv/linux/getitimer.c           |  59 +++++++++
 sysdeps/unix/sysv/linux/getrusage.c           |  58 +++++++++
 sysdeps/unix/sysv/linux/s390/bits/typesizes.h |   6 +
 sysdeps/unix/sysv/linux/setitimer.c           |  95 ++++++++++++++
 .../unix/sysv/linux/sparc/bits/typesizes.h    |   6 +
 .../unix/sysv/linux/{alpha => }/tv32-compat.h |  90 +++++--------
 sysdeps/unix/sysv/linux/wait4.c               |  50 +++++++-
 sysdeps/unix/sysv/linux/x86/bits/typesizes.h  |   3 +
 22 files changed, 540 insertions(+), 80 deletions(-)
 create mode 100644 sysdeps/unix/sysv/linux/getitimer.c
 create mode 100644 sysdeps/unix/sysv/linux/getrusage.c
 create mode 100644 sysdeps/unix/sysv/linux/setitimer.c
 rename sysdeps/unix/sysv/linux/{alpha => }/tv32-compat.h (56%)

-- 
2.25.0


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

* [PATCH v4 1/8] sysv/linux: Rename alpha functions to be alpha specific
  2020-02-19 18:10 [PATCH v4 0/8] Always use 32-bit time_t for certain syscalls Alistair Francis
@ 2020-02-19 18:10 ` Alistair Francis
  2020-02-28 17:30   ` Adhemerval Zanella
  2020-02-19 18:10 ` [PATCH v4 2/8] time: Add a timeval with a 32-bit tv_sec and tv_usec Alistair Francis
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 15+ messages in thread
From: Alistair Francis @ 2020-02-19 18:10 UTC (permalink / raw)
  To: libc-alpha; +Cc: alistair23, Alistair Francis, Lukasz Majewski

These functions are alpha specifc, rename them to be clear.

Let's also rename the header file from tv32-compat.h to
alpha-tv32-compat.h. This is to avoid conflicts with the one we will
introduce later.

Reviewed-by: Lukasz Majewski <lukma@denx.de>
---
 .../alpha/{tv32-compat.h => alpha-tv32-compat.h} | 16 ++++++++--------
 sysdeps/unix/sysv/linux/alpha/osf_adjtime.c      | 10 +++++-----
 sysdeps/unix/sysv/linux/alpha/osf_getitimer.c    |  6 +++---
 sysdeps/unix/sysv/linux/alpha/osf_getrusage.c    |  4 ++--
 sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c |  4 ++--
 sysdeps/unix/sysv/linux/alpha/osf_setitimer.c    | 10 +++++-----
 sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c |  4 ++--
 sysdeps/unix/sysv/linux/alpha/osf_utimes.c       |  6 +++---
 sysdeps/unix/sysv/linux/alpha/osf_wait4.c        |  4 ++--
 9 files changed, 32 insertions(+), 32 deletions(-)
 rename sysdeps/unix/sysv/linux/alpha/{tv32-compat.h => alpha-tv32-compat.h} (88%)

diff --git a/sysdeps/unix/sysv/linux/alpha/tv32-compat.h b/sysdeps/unix/sysv/linux/alpha/alpha-tv32-compat.h
similarity index 88%
rename from sysdeps/unix/sysv/linux/alpha/tv32-compat.h
rename to sysdeps/unix/sysv/linux/alpha/alpha-tv32-compat.h
index 8e34ed1c1b..3073005c65 100644
--- a/sysdeps/unix/sysv/linux/alpha/tv32-compat.h
+++ b/sysdeps/unix/sysv/linux/alpha/alpha-tv32-compat.h
@@ -70,13 +70,13 @@ struct rusage32
    overflow, they write { INT32_MAX, TV_USEC_MAX } to the output.  */
 
 static inline struct timeval
-valid_timeval32_to_timeval (const struct timeval32 tv)
+alpha_valid_timeval32_to_timeval (const struct timeval32 tv)
 {
   return (struct timeval) { tv.tv_sec, tv.tv_usec };
 }
 
 static inline struct timeval32
-valid_timeval_to_timeval32 (const struct timeval tv64)
+alpha_valid_timeval_to_timeval32 (const struct timeval tv64)
 {
   if (__glibc_unlikely (tv64.tv_sec > (time_t) INT32_MAX))
     return (struct timeval32) { INT32_MAX, TV_USEC_MAX};
@@ -84,27 +84,27 @@ valid_timeval_to_timeval32 (const struct timeval tv64)
 }
 
 static inline struct timespec
-valid_timeval32_to_timespec (const struct timeval32 tv)
+alpha_valid_timeval32_to_timespec (const struct timeval32 tv)
 {
   return (struct timespec) { tv.tv_sec, tv.tv_usec * 1000 };
 }
 
 static inline struct timeval32
-valid_timespec_to_timeval32 (const struct timespec ts)
+alpha_valid_timespec_to_timeval32 (const struct timespec ts)
 {
   return (struct timeval32) { (time_t) ts.tv_sec, ts.tv_nsec / 1000 };
 }
 
 static inline void
-rusage64_to_rusage32 (struct rusage32 *restrict r32,
+alpha_rusage64_to_rusage32 (struct rusage32 *restrict r32,
                       const struct rusage *restrict r64)
 {
   /* Make sure the entire output structure is cleared, including
      padding and reserved fields.  */
   memset (r32, 0, sizeof *r32);
 
-  r32->ru_utime    = valid_timeval_to_timeval32 (r64->ru_utime);
-  r32->ru_stime    = valid_timeval_to_timeval32 (r64->ru_stime);
+  r32->ru_utime    = alpha_valid_timeval_to_timeval32 (r64->ru_utime);
+  r32->ru_stime    = alpha_valid_timeval_to_timeval32 (r64->ru_stime);
   r32->ru_maxrss   = r64->ru_maxrss;
   r32->ru_ixrss    = r64->ru_ixrss;
   r32->ru_idrss    = r64->ru_idrss;
@@ -121,4 +121,4 @@ rusage64_to_rusage32 (struct rusage32 *restrict r32,
   r32->ru_nivcsw   = r64->ru_nivcsw;
 }
 
-#endif /* tv32-compat.h */
+#endif /* alpha-tv32-compat.h */
diff --git a/sysdeps/unix/sysv/linux/alpha/osf_adjtime.c b/sysdeps/unix/sysv/linux/alpha/osf_adjtime.c
index 9825a4734d..f0a1123639 100644
--- a/sysdeps/unix/sysv/linux/alpha/osf_adjtime.c
+++ b/sysdeps/unix/sysv/linux/alpha/osf_adjtime.c
@@ -22,7 +22,7 @@
 
 #include <sys/time.h>
 #include <sys/timex.h>
-#include <tv32-compat.h>
+#include <alpha-tv32-compat.h>
 
 struct timex32 {
 	unsigned int modes;	/* mode selector */
@@ -57,13 +57,13 @@ int
 attribute_compat_text_section
 __adjtime_tv32 (const struct timeval32 *itv, struct timeval32 *otv)
 {
-  struct timeval itv64 = valid_timeval32_to_timeval (*itv);
+  struct timeval itv64 = alpha_valid_timeval32_to_timeval (*itv);
   struct timeval otv64;
 
   if (__adjtime (&itv64, &otv64) == -1)
     return -1;
 
-  *otv = valid_timeval_to_timeval32 (otv64);
+  *otv = alpha_valid_timeval_to_timeval32 (otv64);
   return 0;
 }
 
@@ -91,7 +91,7 @@ __adjtimex_tv32 (struct timex32 *tx)
   tx64.calcnt    = tx->calcnt;
   tx64.errcnt    = tx->errcnt;
   tx64.stbcnt    = tx->stbcnt;
-  tx64.time      = valid_timeval32_to_timeval (tx->time);
+  tx64.time      = alpha_valid_timeval32_to_timeval (tx->time);
 
   int status = __adjtimex (&tx64);
   if (status < 0)
@@ -116,7 +116,7 @@ __adjtimex_tv32 (struct timex32 *tx)
   tx->calcnt    = tx64.calcnt;
   tx->errcnt    = tx64.errcnt;
   tx->stbcnt    = tx64.stbcnt;
-  tx->time      = valid_timeval_to_timeval32 (tx64.time);
+  tx->time      = alpha_valid_timeval_to_timeval32 (tx64.time);
 
   return status;
 }
diff --git a/sysdeps/unix/sysv/linux/alpha/osf_getitimer.c b/sysdeps/unix/sysv/linux/alpha/osf_getitimer.c
index e9de2b287b..204d4ba796 100644
--- a/sysdeps/unix/sysv/linux/alpha/osf_getitimer.c
+++ b/sysdeps/unix/sysv/linux/alpha/osf_getitimer.c
@@ -21,7 +21,7 @@
 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
 
 #include <sys/time.h>
-#include <tv32-compat.h>
+#include <alpha-tv32-compat.h>
 
 int
 attribute_compat_text_section
@@ -33,9 +33,9 @@ __getitimer_tv32 (int which, struct itimerval32 *curr_value)
 
   /* Write all fields of 'curr_value' regardless of overflow.  */
   curr_value->it_interval
-    = valid_timeval_to_timeval32 (curr_value_64.it_interval);
+    = alpha_valid_timeval_to_timeval32 (curr_value_64.it_interval);
   curr_value->it_value
-    = valid_timeval_to_timeval32 (curr_value_64.it_value);
+    = alpha_valid_timeval_to_timeval32 (curr_value_64.it_value);
   return 0;
 }
 
diff --git a/sysdeps/unix/sysv/linux/alpha/osf_getrusage.c b/sysdeps/unix/sysv/linux/alpha/osf_getrusage.c
index 74c6fb49aa..be81994654 100644
--- a/sysdeps/unix/sysv/linux/alpha/osf_getrusage.c
+++ b/sysdeps/unix/sysv/linux/alpha/osf_getrusage.c
@@ -22,7 +22,7 @@
 
 #include <sys/time.h>
 #include <sys/resource.h>
-#include <tv32-compat.h>
+#include <alpha-tv32-compat.h>
 
 int
 __getrusage_tv32 (int who, struct rusage32 *usage32)
@@ -31,7 +31,7 @@ __getrusage_tv32 (int who, struct rusage32 *usage32)
   if (__getrusage (who, &usage64) == -1)
     return -1;
 
-  rusage64_to_rusage32 (usage32, &usage64);
+  alpha_rusage64_to_rusage32 (usage32, &usage64);
   return 0;
 }
 
diff --git a/sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c b/sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c
index df7f06765b..9ffda2fde3 100644
--- a/sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c
+++ b/sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c
@@ -23,7 +23,7 @@
 #include <string.h>
 #include <time.h>
 #include <sys/time.h>
-#include <tv32-compat.h>
+#include <alpha-tv32-compat.h>
 
 /* Get the current time of day and timezone information putting it
    into *TV and *TZ.  */
@@ -38,7 +38,7 @@ __gettimeofday_tv32 (struct timeval32 *restrict tv32, void *restrict tz)
   struct timespec ts;
   __clock_gettime (CLOCK_REALTIME, &ts);
 
-  *tv32 = valid_timespec_to_timeval32 (ts);
+  *tv32 = alpha_valid_timespec_to_timeval32 (ts);
   return 0;
 }
 
diff --git a/sysdeps/unix/sysv/linux/alpha/osf_setitimer.c b/sysdeps/unix/sysv/linux/alpha/osf_setitimer.c
index 7df2d1b71c..726dfc8b0e 100644
--- a/sysdeps/unix/sysv/linux/alpha/osf_setitimer.c
+++ b/sysdeps/unix/sysv/linux/alpha/osf_setitimer.c
@@ -21,7 +21,7 @@
 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
 
 #include <sys/time.h>
-#include <tv32-compat.h>
+#include <alpha-tv32-compat.h>
 
 int
 attribute_compat_text_section
@@ -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_timeval32_to_timeval (new_value->it_interval);
+    = alpha_valid_timeval32_to_timeval (new_value->it_interval);
   new_value_64.it_value
-    = valid_timeval32_to_timeval (new_value->it_value);
+    = alpha_valid_timeval32_to_timeval (new_value->it_value);
 
   if (old_value == NULL)
     return __setitimer (which, &new_value_64, NULL);
@@ -43,9 +43,9 @@ __setitimer_tv32 (int which, const struct itimerval32 *restrict new_value,
 
   /* Write all fields of 'old_value' regardless of overflow.  */
   old_value->it_interval
-     = valid_timeval_to_timeval32 (old_value_64.it_interval);
+     = alpha_valid_timeval_to_timeval32 (old_value_64.it_interval);
   old_value->it_value
-     = valid_timeval_to_timeval32 (old_value_64.it_value);
+     = alpha_valid_timeval_to_timeval32 (old_value_64.it_value);
   return 0;
 }
 
diff --git a/sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c b/sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c
index 6e17a95a47..044363e079 100644
--- a/sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c
+++ b/sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c
@@ -23,7 +23,7 @@
 #include <sys/time.h>
 #include <time.h>
 #include <errno.h>
-#include <tv32-compat.h>
+#include <alpha-tv32-compat.h>
 
 /* Set the current time of day and timezone information.
    This call is restricted to the super-user.  */
@@ -42,7 +42,7 @@ __settimeofday_tv32 (const struct timeval32 *tv32,
       return __settimezone (tz);
     }
 
-  struct timespec ts = valid_timeval32_to_timespec (*tv32);
+  struct timespec ts = alpha_valid_timeval32_to_timespec (*tv32);
   return __clock_settime (CLOCK_REALTIME, &ts);
 }
 
diff --git a/sysdeps/unix/sysv/linux/alpha/osf_utimes.c b/sysdeps/unix/sysv/linux/alpha/osf_utimes.c
index 6c3fad0132..8ad9fb567c 100644
--- a/sysdeps/unix/sysv/linux/alpha/osf_utimes.c
+++ b/sysdeps/unix/sysv/linux/alpha/osf_utimes.c
@@ -21,15 +21,15 @@
 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
 
 #include <sys/time.h>
-#include <tv32-compat.h>
+#include <alpha-tv32-compat.h>
 
 int
 attribute_compat_text_section
 __utimes_tv32 (const char *filename, const struct timeval32 times32[2])
 {
   struct timeval times[2];
-  times[0] = valid_timeval32_to_timeval (times32[0]);
-  times[1] = valid_timeval32_to_timeval (times32[1]);
+  times[0] = alpha_valid_timeval32_to_timeval (times32[0]);
+  times[1] = alpha_valid_timeval32_to_timeval (times32[1]);
   return __utimes (filename, times);
 }
 
diff --git a/sysdeps/unix/sysv/linux/alpha/osf_wait4.c b/sysdeps/unix/sysv/linux/alpha/osf_wait4.c
index 6af8347871..c664e8e93f 100644
--- a/sysdeps/unix/sysv/linux/alpha/osf_wait4.c
+++ b/sysdeps/unix/sysv/linux/alpha/osf_wait4.c
@@ -23,7 +23,7 @@
 #include <sys/time.h>
 #include <sys/resource.h>
 #include <sys/wait.h>
-#include <tv32-compat.h>
+#include <alpha-tv32-compat.h>
 
 pid_t
 attribute_compat_text_section
@@ -33,7 +33,7 @@ __wait4_tv32 (pid_t pid, int *status, int options, struct rusage32 *usage32)
   pid_t child = __wait4 (pid, status, options, &usage64);
 
   if (child >= 0 && usage32 != NULL)
-    rusage64_to_rusage32 (usage32, &usage64);
+    alpha_rusage64_to_rusage32 (usage32, &usage64);
   return child;
 }
 
-- 
2.25.0


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

* [PATCH v4 2/8] time: Add a timeval with a 32-bit tv_sec and tv_usec
  2020-02-19 18:10 [PATCH v4 0/8] Always use 32-bit time_t for certain syscalls Alistair Francis
  2020-02-19 18:10 ` [PATCH v4 1/8] sysv/linux: Rename alpha functions to be alpha specific Alistair Francis
@ 2020-02-19 18:10 ` Alistair Francis
  2020-02-19 18:10 ` [PATCH v4 3/8] time: Add a __itimerval64 struct Alistair Francis
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 15+ messages in thread
From: Alistair Francis @ 2020-02-19 18:10 UTC (permalink / raw)
  To: libc-alpha; +Cc: alistair23, Alistair Francis, Lukasz Majewski

On y2038 safe 32-bit systems the Linux kernel expects itimerval to
use a 32-bit time_t, even though the other time_t's are 64-bit. To
address this let's add a __timeval32 struct to be used internally.

Reviewed-by: Lukasz Majewski <lukma@denx.de>
---
 include/time.h | 45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/include/time.h b/include/time.h
index 61806658e7..945650af5e 100644
--- a/include/time.h
+++ b/include/time.h
@@ -404,6 +404,51 @@ timespec64_to_timeval64 (const struct __timespec64 ts64)
   return tv64;
 }
 
+/* A version of 'struct timeval' with 32-bit time_t
+   and suseconds_t.  */
+struct __timeval32
+{
+  __int32_t tv_sec;         /* Seconds.  */
+  __int32_t tv_usec;        /* Microseconds.  */
+};
+
+/* Conversion functions for converting to/from __timeval32  */
+static inline struct __timeval64
+valid_timeval32_to_timeval64 (const struct __timeval32 tv)
+{
+  return (struct __timeval64) { tv.tv_sec, tv.tv_usec };
+}
+
+static inline struct __timeval32
+valid_timeval64_to_timeval32 (const struct __timeval64 tv64)
+{
+  return (struct __timeval32) { tv64.tv_sec, tv64.tv_usec };
+}
+
+static inline struct timeval
+valid_timeval32_to_timeval (const struct __timeval32 tv)
+{
+  return (struct timeval) { tv.tv_sec, tv.tv_usec };
+}
+
+static inline struct __timeval32
+valid_timeval_to_timeval32 (const struct timeval tv)
+{
+  return (struct __timeval32) { tv.tv_sec, tv.tv_usec };
+}
+
+static inline struct timespec
+valid_timeval32_to_timespec (const struct __timeval32 tv)
+{
+  return (struct timespec) { tv.tv_sec, tv.tv_usec * 1000 };
+}
+
+static inline struct __timeval32
+valid_timespec_to_timeval32 (const struct timespec ts)
+{
+  return (struct __timeval32) { (time_t) ts.tv_sec, ts.tv_nsec / 1000 };
+}
+
 /* Check if a value is in the valid nanoseconds range. Return true if
    it is, false otherwise.  */
 static inline bool
-- 
2.25.0


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

* [PATCH v4 3/8] time: Add a __itimerval64 struct
  2020-02-19 18:10 [PATCH v4 0/8] Always use 32-bit time_t for certain syscalls Alistair Francis
  2020-02-19 18:10 ` [PATCH v4 1/8] sysv/linux: Rename alpha functions to be alpha specific Alistair Francis
  2020-02-19 18:10 ` [PATCH v4 2/8] time: Add a timeval with a 32-bit tv_sec and tv_usec Alistair Francis
@ 2020-02-19 18:10 ` Alistair Francis
  2020-02-19 18:10 ` [PATCH v4 4/8] sysv: Define __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64 Alistair Francis
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 15+ messages in thread
From: Alistair Francis @ 2020-02-19 18:10 UTC (permalink / raw)
  To: libc-alpha; +Cc: alistair23, Alistair Francis, Lukasz Majewski

Add a __itimerval64 which always uses a 64-bit time_t.

Reviewed-by: Lukasz Majewski <lukma@denx.de>
---
 include/time.h | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/include/time.h b/include/time.h
index 945650af5e..8a4abb159f 100644
--- a/include/time.h
+++ b/include/time.h
@@ -108,6 +108,17 @@ struct __timeval64
 };
 #endif
 
+#if __TIMESIZE == 64
+# define __itimerval64 itimerval
+#else
+/* The glibc's internal representation of the struct itimerval.  */
+struct __itimerval64
+{
+  struct __timeval64 it_interval;
+  struct __timeval64 it_value;
+};
+#endif
+
 #if __TIMESIZE == 64
 # define __ctime64 ctime
 #else
-- 
2.25.0


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

* [PATCH v4 4/8] sysv: Define __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64
  2020-02-19 18:10 [PATCH v4 0/8] Always use 32-bit time_t for certain syscalls Alistair Francis
                   ` (2 preceding siblings ...)
  2020-02-19 18:10 ` [PATCH v4 3/8] time: Add a __itimerval64 struct Alistair Francis
@ 2020-02-19 18:10 ` Alistair Francis
  2020-02-19 18:10 ` [PATCH v4 5/8] linux: Use long time_t __getitimer/__setitimer Alistair Francis
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 15+ messages in thread
From: Alistair Francis @ 2020-02-19 18:10 UTC (permalink / raw)
  To: libc-alpha; +Cc: alistair23, Alistair Francis, Lukasz Majewski

On y2038 safe 32-bit systems the Linux kernel expects itimerval
and rusage to use a 32-bit time_t, even though the other time_t's
are 64-bit.

There are also other occurances where the time passed to the kernel via
timeval doesn't match the wordsize.

To handle these cases let's define a new macro
__KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64. This macro specifies if the
kernel's old_timeval matches the new timeval64. This should be true for
64-bit architectures (expect for Alpha) and x32.

Reviewed-by: Lukasz Majewski <lukma@denx.de>
---
 bits/typesizes.h                                 | 6 ++++++
 sysdeps/unix/sysv/linux/alpha/bits/typesizes.h   | 3 +++
 sysdeps/unix/sysv/linux/generic/bits/typesizes.h | 6 ++++++
 sysdeps/unix/sysv/linux/s390/bits/typesizes.h    | 6 ++++++
 sysdeps/unix/sysv/linux/sparc/bits/typesizes.h   | 6 ++++++
 sysdeps/unix/sysv/linux/x86/bits/typesizes.h     | 3 +++
 6 files changed, 30 insertions(+)

diff --git a/bits/typesizes.h b/bits/typesizes.h
index 599408973e..8f16903a21 100644
--- a/bits/typesizes.h
+++ b/bits/typesizes.h
@@ -76,10 +76,16 @@
 
 /* And for fsblkcnt_t, fsblkcnt64_t, fsfilcnt_t and fsfilcnt64_t.  */
 # define __STATFS_MATCHES_STATFS64  1
+
+/* And for getitimer, setitimer and rusage  */
+# define __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64 1
 #else
 # define __RLIM_T_MATCHES_RLIM64_T	0
 
 # define __STATFS_MATCHES_STATFS64  0
+
+/* And for getitimer, setitimer and rusage  */
+# define __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64 0
 #endif
 
 /* Number of descriptors that can fit in an `fd_set'.  */
diff --git a/sysdeps/unix/sysv/linux/alpha/bits/typesizes.h b/sysdeps/unix/sysv/linux/alpha/bits/typesizes.h
index 28ee3e5920..e5d7774468 100644
--- a/sysdeps/unix/sysv/linux/alpha/bits/typesizes.h
+++ b/sysdeps/unix/sysv/linux/alpha/bits/typesizes.h
@@ -73,6 +73,9 @@
 /* Not for fsblkcnt_t, fsblkcnt64_t, fsfilcnt_t and fsfilcnt64_t.  */
 # define __STATFS_MATCHES_STATFS64  0
 
+/* And for getitimer, setitimer and rusage  */
+#define __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64 0
+
 /* Number of descriptors that can fit in an `fd_set'.  */
 #define	__FD_SETSIZE		1024
 
diff --git a/sysdeps/unix/sysv/linux/generic/bits/typesizes.h b/sysdeps/unix/sysv/linux/generic/bits/typesizes.h
index 7c963e523e..4fb246ac74 100644
--- a/sysdeps/unix/sysv/linux/generic/bits/typesizes.h
+++ b/sysdeps/unix/sysv/linux/generic/bits/typesizes.h
@@ -77,11 +77,17 @@
 
 /* And for fsblkcnt_t, fsblkcnt64_t, fsfilcnt_t and fsfilcnt64_t.  */
 # define __STATFS_MATCHES_STATFS64  1
+
+/* And for getitimer, setitimer and rusage  */
+# define __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64 1
 #else
 # define __RLIM_T_MATCHES_RLIM64_T	0
 
 # define __STATFS_MATCHES_STATFS64  0
+
+# define __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64 0
 #endif
+
 /* Number of descriptors that can fit in an `fd_set'.  */
 #define	__FD_SETSIZE		1024
 
diff --git a/sysdeps/unix/sysv/linux/s390/bits/typesizes.h b/sysdeps/unix/sysv/linux/s390/bits/typesizes.h
index e775e460bb..2bc87c1079 100644
--- a/sysdeps/unix/sysv/linux/s390/bits/typesizes.h
+++ b/sysdeps/unix/sysv/linux/s390/bits/typesizes.h
@@ -82,10 +82,16 @@
 
 /* And for fsblkcnt_t, fsblkcnt64_t, fsfilcnt_t and fsfilcnt64_t.  */
 # define __STATFS_MATCHES_STATFS64  1
+
+/* And for getitimer, setitimer and rusage  */
+# define __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64 1
 #else
 # define __RLIM_T_MATCHES_RLIM64_T	0
 
 # define __STATFS_MATCHES_STATFS64  0
+
+/* And for getitimer, setitimer and rusage  */
+# define __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64 0
 #endif
 
 /* Number of descriptors that can fit in an `fd_set'.  */
diff --git a/sysdeps/unix/sysv/linux/sparc/bits/typesizes.h b/sysdeps/unix/sysv/linux/sparc/bits/typesizes.h
index ac48c23e37..288a902b5f 100644
--- a/sysdeps/unix/sysv/linux/sparc/bits/typesizes.h
+++ b/sysdeps/unix/sysv/linux/sparc/bits/typesizes.h
@@ -76,10 +76,16 @@
 
 /* And for fsblkcnt_t, fsblkcnt64_t, fsfilcnt_t and fsfilcnt64_t.  */
 # define __STATFS_MATCHES_STATFS64  1
+
+/* And for getitimer, setitimer and rusage  */
+# define __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64 1
 #else
 # define __RLIM_T_MATCHES_RLIM64_T	0
 
 # define __STATFS_MATCHES_STATFS64  0
+
+/* And for getitimer, setitimer and rusage  */
+# define __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64 0
 #endif
 
 /* Number of descriptors that can fit in an `fd_set'.  */
diff --git a/sysdeps/unix/sysv/linux/x86/bits/typesizes.h b/sysdeps/unix/sysv/linux/x86/bits/typesizes.h
index 87c50a4f32..f68dfecc90 100644
--- a/sysdeps/unix/sysv/linux/x86/bits/typesizes.h
+++ b/sysdeps/unix/sysv/linux/x86/bits/typesizes.h
@@ -94,6 +94,9 @@
 # define __STATFS_MATCHES_STATFS64  0
 #endif
 
+/* And for getitimer, setitimer and rusage  */
+#define __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64 1
+
 /* Number of descriptors that can fit in an `fd_set'.  */
 #define __FD_SETSIZE		1024
 
-- 
2.25.0


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

* [PATCH v4 5/8] linux: Use long time_t __getitimer/__setitimer
  2020-02-19 18:10 [PATCH v4 0/8] Always use 32-bit time_t for certain syscalls Alistair Francis
                   ` (3 preceding siblings ...)
  2020-02-19 18:10 ` [PATCH v4 4/8] sysv: Define __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64 Alistair Francis
@ 2020-02-19 18:10 ` Alistair Francis
  2020-02-21 10:03   ` Lukasz Majewski
  2020-02-19 18:10 ` [PATCH v4 6/8] resource: Add a __rusage64 struct Alistair Francis
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 15+ messages in thread
From: Alistair Francis @ 2020-02-19 18:10 UTC (permalink / raw)
  To: libc-alpha; +Cc: alistair23, Alistair Francis

The Linux kernel expects itimerval to use a 32-bit time_t, even on archs
with a 64-bit time_t (like RV32). To address this let's convert
itimerval to/from 32-bit and 64-bit to ensure the kernel always gets
a 32-bit time_t.

While we are converting these functions let's also convert them to be
the y2038 safe versions. This means there is a *64 function that is
called by a backwards compatible wrapper.
---
 include/time.h                        | 15 +++++
 sysdeps/unix/syscalls.list            |  2 -
 sysdeps/unix/sysv/linux/getitimer.c   | 59 +++++++++++++++++
 sysdeps/unix/sysv/linux/setitimer.c   | 95 +++++++++++++++++++++++++++
 sysdeps/unix/sysv/linux/tv32-compat.h | 31 +++++++++
 5 files changed, 200 insertions(+), 2 deletions(-)
 create mode 100644 sysdeps/unix/sysv/linux/getitimer.c
 create mode 100644 sysdeps/unix/sysv/linux/setitimer.c
 create mode 100644 sysdeps/unix/sysv/linux/tv32-compat.h

diff --git a/include/time.h b/include/time.h
index 8a4abb159f..eaa536d5c0 100644
--- a/include/time.h
+++ b/include/time.h
@@ -6,6 +6,7 @@
 # include <bits/types/locale_t.h>
 # include <stdbool.h>
 # include <time/mktime-internal.h>
+# include <sys/time.h>
 # include <endian.h>
 # include <time-clockid.h>
 # include <sys/time.h>
@@ -119,6 +120,20 @@ struct __itimerval64
 };
 #endif
 
+#if __TIMESIZE == 64
+# define __getitimer64 __getitimer
+# define __setitimer64 __setitimer
+#else
+extern int __getitimer64 (enum __itimer_which __which,
+                          struct __itimerval64 *__value);
+
+libc_hidden_proto (__getitimer64)
+extern int __setitimer64 (enum __itimer_which __which,
+                          const struct __itimerval64 *__restrict __new,
+                          struct __itimerval64 *__restrict __old);
+libc_hidden_proto (__setitimer64)
+#endif
+
 #if __TIMESIZE == 64
 # define __ctime64 ctime
 #else
diff --git a/sysdeps/unix/syscalls.list b/sysdeps/unix/syscalls.list
index e28e801c7a..d249049d6e 100644
--- a/sysdeps/unix/syscalls.list
+++ b/sysdeps/unix/syscalls.list
@@ -25,7 +25,6 @@ getgid		-	getgid		Ei:	__getgid	getgid
 getgroups	-	getgroups	i:ip	__getgroups	getgroups
 gethostid	-	gethostid	i:	gethostid
 gethostname	-	gethostname	i:bn	__gethostname	gethostname
-getitimer	-	getitimer	i:ip	__getitimer	getitimer
 getpeername	-	getpeername	i:ibN	__getpeername	getpeername
 getpid		-	getpid		Ei:	__getpid	getpid
 getpriority	-	getpriority	i:ii	__getpriority	getpriority
@@ -67,7 +66,6 @@ setgid		-	setgid		i:i	__setgid	setgid
 setgroups	-	setgroups	i:ip	setgroups
 sethostid	-	sethostid	i:i	sethostid
 sethostname	-	sethostname	i:pi	sethostname
-setitimer	-	setitimer	i:ipp	__setitimer	setitimer
 setpgid		-	setpgrp		i:ii	__setpgid	setpgid
 setpriority	-	setpriority	i:iii	__setpriority	setpriority
 setregid	-	setregid	i:ii	__setregid	setregid
diff --git a/sysdeps/unix/sysv/linux/getitimer.c b/sysdeps/unix/sysv/linux/getitimer.c
new file mode 100644
index 0000000000..12f7963949
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/getitimer.c
@@ -0,0 +1,59 @@
+/* getitimer -- Get the state of an interval timer.  Linux/tv32 version.
+   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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <time.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sysdep.h>
+#include <tv32-compat.h>
+
+int
+__getitimer64 (__itimer_which_t which, struct __itimerval64 *curr_value)
+{
+#if __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64
+  return INLINE_SYSCALL_CALL (getitimer, which, curr_value);
+#else
+  struct __itimerval32 curr_value_32;
+  if (INLINE_SYSCALL_CALL (getitimer, which, &curr_value_32) == -1)
+    return -1;
+
+  /* Write all fields of 'curr_value' regardless of overflow.  */
+  curr_value->it_interval
+    = valid_timeval32_to_timeval64 (curr_value_32.it_interval);
+  curr_value->it_value
+    = valid_timeval32_to_timeval64 (curr_value_32.it_value);
+  return 0;
+#endif
+}
+
+#if __TIMESIZE != 64
+libc_hidden_def (__getitimer64)
+int
+__getitimer (__itimer_which_t which, struct itimerval *curr_value)
+{
+  struct __itimerval64 val64;
+
+  val64.it_interval
+    = valid_timeval_to_timeval64 (curr_value->it_interval);
+  val64.it_value
+    = valid_timeval_to_timeval64 (curr_value->it_value);
+
+  return __getitimer64 (which, &val64);
+}
+#endif
+weak_alias (__getitimer, getitimer)
diff --git a/sysdeps/unix/sysv/linux/setitimer.c b/sysdeps/unix/sysv/linux/setitimer.c
new file mode 100644
index 0000000000..238853dd33
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/setitimer.c
@@ -0,0 +1,95 @@
+/* setitimer -- Set the state of an interval timer.  Linux/tv32 version.
+   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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <time.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sysdep.h>
+#include <tv32-compat.h>
+
+int
+__setitimer64 (__itimer_which_t which,
+               const struct __itimerval64 *restrict new_value,
+               struct __itimerval64 *restrict old_value)
+{
+#if __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64
+  return INLINE_SYSCALL_CALL (setitimer, which, new_value, old_value);
+#else
+  struct __itimerval32 new_value_32;
+
+  if (! in_time_t_range (new_value->it_interval.tv_sec))
+  {
+    __set_errno (EOVERFLOW);
+    return -1;
+  }
+  new_value_32.it_interval
+    = valid_timeval64_to_timeval32 (new_value->it_interval);
+
+  if (! in_time_t_range (new_value->it_value.tv_sec))
+  {
+    __set_errno (EOVERFLOW);
+    return -1;
+  }
+  new_value_32.it_value
+    = valid_timeval64_to_timeval32 (new_value->it_value);
+
+  if (old_value == NULL)
+    return INLINE_SYSCALL_CALL (setitimer, which, &new_value_32, NULL);
+
+  struct __itimerval32 old_value_32;
+  if (INLINE_SYSCALL_CALL (setitimer, which, &new_value_32, &old_value_32) == -1)
+    return -1;
+
+  /* Write all fields of 'old_value' regardless of overflow.  */
+  old_value->it_interval
+     = valid_timeval32_to_timeval64 (old_value_32.it_interval);
+  old_value->it_value
+     = valid_timeval32_to_timeval64 (old_value_32.it_value);
+  return 0;
+#endif
+}
+
+#if __TIMESIZE != 64
+libc_hidden_def (__setitimer64)
+int
+__setitimer (__itimer_which_t which,
+             const struct itimerval *restrict new_value,
+             struct itimerval *restrict old_value)
+{
+  int ret;
+  struct __itimerval64 new64, old64;
+
+  new64.it_interval
+    = valid_timeval_to_timeval64 (new_value->it_interval);
+  new64.it_value
+    = valid_timeval_to_timeval64 (new_value->it_value);
+
+  ret = __setitimer64 (which, &new64, old_value ? &old64 : NULL);
+
+  if (ret == 0 && old_value)
+    {
+      old_value->it_interval
+        = valid_timeval64_to_timeval (old64.it_interval);
+      old_value->it_value
+        = valid_timeval64_to_timeval (old64.it_value);
+    }
+
+  return ret;
+}
+#endif
+weak_alias (__setitimer, setitimer)
diff --git a/sysdeps/unix/sysv/linux/tv32-compat.h b/sysdeps/unix/sysv/linux/tv32-compat.h
new file mode 100644
index 0000000000..b8791b1db8
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/tv32-compat.h
@@ -0,0 +1,31 @@
+/* Compatibility definitions for `struct timeval' with 32-bit time_t.
+   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
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _TV32_COMPAT_H
+#define _TV32_COMPAT_H 1
+
+#include <bits/types/time_t.h>
+
+/* Structures containing 'struct timeval' with 32-bit time_t.  */
+struct __itimerval32
+{
+  struct __timeval32 it_interval;
+  struct __timeval32 it_value;
+};
+
+#endif /* tv32-compat.h */
-- 
2.25.0


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

* [PATCH v4 6/8] resource: Add a __rusage64 struct
  2020-02-19 18:10 [PATCH v4 0/8] Always use 32-bit time_t for certain syscalls Alistair Francis
                   ` (4 preceding siblings ...)
  2020-02-19 18:10 ` [PATCH v4 5/8] linux: Use long time_t __getitimer/__setitimer Alistair Francis
@ 2020-02-19 18:10 ` Alistair Francis
  2020-02-19 18:10 ` [PATCH v4 7/8] linux: Use long time_t for wait4/getrusage Alistair Francis
  2020-02-19 18:10 ` [PATCH v4 8/8] sysv/alpha: Use generic __timeval32 and helpers Alistair Francis
  7 siblings, 0 replies; 15+ messages in thread
From: Alistair Francis @ 2020-02-19 18:10 UTC (permalink / raw)
  To: libc-alpha; +Cc: alistair23, Alistair Francis, Lukasz Majewski

Add a __rusage64 struct which always uses a 64-bit time_t.

Reviewed-by: Lukasz Majewski <lukma@denx.de>
---
 include/sys/resource.h | 110 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 110 insertions(+)

diff --git a/include/sys/resource.h b/include/sys/resource.h
index c55d4e63bd..9d604dfe3e 100644
--- a/include/sys/resource.h
+++ b/include/sys/resource.h
@@ -2,6 +2,116 @@
 #include <resource/sys/resource.h>
 
 #ifndef _ISOMAC
+# include <time.h>
+# include <string.h>
+
+/* Internal version of rusage with a 64-bit time_t. */
+#if __TIMESIZE == 64
+# define __rusage64 rusage
+#else
+struct __rusage64
+  {
+    struct __timeval64 ru_utime;
+    struct __timeval64 ru_stime;
+    __extension__ union
+      {
+	long int ru_maxrss;
+	__syscall_slong_t __ru_maxrss_word;
+      };
+    __extension__ union
+      {
+	long int ru_ixrss;
+	__syscall_slong_t __ru_ixrss_word;
+      };
+    __extension__ union
+      {
+	long int ru_idrss;
+	__syscall_slong_t __ru_idrss_word;
+      };
+    __extension__ union
+      {
+	long int ru_isrss;
+	 __syscall_slong_t __ru_isrss_word;
+      };
+    __extension__ union
+      {
+	long int ru_minflt;
+	__syscall_slong_t __ru_minflt_word;
+      };
+    __extension__ union
+      {
+	long int ru_majflt;
+	__syscall_slong_t __ru_majflt_word;
+      };
+    __extension__ union
+      {
+	long int ru_nswap;
+	__syscall_slong_t __ru_nswap_word;
+      };
+    __extension__ union
+      {
+	long int ru_inblock;
+	__syscall_slong_t __ru_inblock_word;
+      };
+    __extension__ union
+      {
+	long int ru_oublock;
+	__syscall_slong_t __ru_oublock_word;
+      };
+    __extension__ union
+      {
+	long int ru_msgsnd;
+	__syscall_slong_t __ru_msgsnd_word;
+      };
+    __extension__ union
+      {
+	long int ru_msgrcv;
+	__syscall_slong_t __ru_msgrcv_word;
+      };
+    __extension__ union
+      {
+	long int ru_nsignals;
+	__syscall_slong_t __ru_nsignals_word;
+      };
+    __extension__ union
+      {
+	long int ru_nvcsw;
+	__syscall_slong_t __ru_nvcsw_word;
+      };
+    __extension__ union
+      {
+	long int ru_nivcsw;
+	__syscall_slong_t __ru_nivcsw_word;
+      };
+  };
+#endif
+
+static inline void
+rusage64_to_rusage (const struct __rusage64 *restrict r64,
+                    struct rusage *restrict r)
+{
+  /* Make sure the entire output structure is cleared, including
+     padding and reserved fields.  */
+  memset (r, 0, sizeof *r);
+
+  r->ru_utime    = valid_timeval64_to_timeval (r64->ru_utime);
+  r->ru_stime    = valid_timeval64_to_timeval (r64->ru_stime);
+  r->ru_maxrss   = r64->ru_maxrss;
+  r->ru_ixrss    = r64->ru_ixrss;
+  r->ru_idrss    = r64->ru_idrss;
+  r->ru_isrss    = r64->ru_isrss;
+  r->ru_minflt   = r64->ru_minflt;
+  r->ru_majflt   = r64->ru_majflt;
+  r->ru_nswap    = r64->ru_nswap;
+  r->ru_inblock  = r64->ru_inblock;
+  r->ru_oublock  = r64->ru_oublock;
+  r->ru_msgsnd   = r64->ru_msgsnd;
+  r->ru_msgrcv   = r64->ru_msgrcv;
+  r->ru_nsignals = r64->ru_nsignals;
+  r->ru_nvcsw    = r64->ru_nvcsw;
+  r->ru_nivcsw   = r64->ru_nivcsw;
+}
+
 /* Prototypes repeated instead of using __typeof because
    sys/resource.h is included in C++ tests, and declaring functions
    with __typeof and __THROW doesn't work for C++.  */
-- 
2.25.0


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

* [PATCH v4 7/8] linux: Use long time_t for wait4/getrusage
  2020-02-19 18:10 [PATCH v4 0/8] Always use 32-bit time_t for certain syscalls Alistair Francis
                   ` (5 preceding siblings ...)
  2020-02-19 18:10 ` [PATCH v4 6/8] resource: Add a __rusage64 struct Alistair Francis
@ 2020-02-19 18:10 ` Alistair Francis
  2020-02-21 10:08   ` Lukasz Majewski
  2020-02-19 18:10 ` [PATCH v4 8/8] sysv/alpha: Use generic __timeval32 and helpers Alistair Francis
  7 siblings, 1 reply; 15+ messages in thread
From: Alistair Francis @ 2020-02-19 18:10 UTC (permalink / raw)
  To: libc-alpha; +Cc: alistair23, Alistair Francis

The Linux kernel expects rusage to use a 32-bit time_t, even on archs
with a 64-bit time_t (like RV32). To address this let's convert
rusage to/from 32-bit and 64-bit to ensure the kernel always gets
a 32-bit time_t.

While we are converting these functions let's also convert them to be
the y2038 safe versions. This means there is a *64 function that is
called by a backwards compatible wrapper.
---
 include/sys/resource.h                | 11 +++++
 sysdeps/unix/syscalls.list            |  1 -
 sysdeps/unix/sysv/linux/getrusage.c   | 58 +++++++++++++++++++++++++++
 sysdeps/unix/sysv/linux/tv32-compat.h | 47 ++++++++++++++++++++++
 sysdeps/unix/sysv/linux/wait4.c       | 50 ++++++++++++++++++++++-
 5 files changed, 164 insertions(+), 3 deletions(-)
 create mode 100644 sysdeps/unix/sysv/linux/getrusage.c

diff --git a/include/sys/resource.h b/include/sys/resource.h
index 9d604dfe3e..64925f257c 100644
--- a/include/sys/resource.h
+++ b/include/sys/resource.h
@@ -134,5 +134,16 @@ extern int __getrusage (enum __rusage_who __who, struct rusage *__usage)
 extern int __setrlimit (enum __rlimit_resource __resource,
 			const struct rlimit *__rlimits);
 libc_hidden_proto (__setrlimit);
+
+#if __TIMESIZE == 64
+# define __getrusage64 __getrusage
+# define __wait4_time64 __wait4
+#else
+extern int __getrusage64 (enum __rusage_who who, struct __rusage64 *usage);
+libc_hidden_proto (__getrusage64)
+extern pid_t __wait4_time64 (pid_t pid, int *stat_loc, int options,
+                             struct __rusage64 *usage);
+libc_hidden_proto (__wait4_time64)
+#endif
 #endif
 #endif
diff --git a/sysdeps/unix/syscalls.list b/sysdeps/unix/syscalls.list
index d249049d6e..01c4a0e6b1 100644
--- a/sysdeps/unix/syscalls.list
+++ b/sysdeps/unix/syscalls.list
@@ -29,7 +29,6 @@ getpeername	-	getpeername	i:ibN	__getpeername	getpeername
 getpid		-	getpid		Ei:	__getpid	getpid
 getpriority	-	getpriority	i:ii	__getpriority	getpriority
 getrlimit	-	getrlimit	i:ip	__getrlimit	getrlimit
-getrusage	-	getrusage	i:ip	__getrusage	getrusage
 getsockname	-	getsockname	i:ibN	__getsockname	getsockname
 getsockopt	-	getsockopt	i:iiiBN	getsockopt
 getuid		-	getuid		Ei:	__getuid	getuid
diff --git a/sysdeps/unix/sysv/linux/getrusage.c b/sysdeps/unix/sysv/linux/getrusage.c
new file mode 100644
index 0000000000..a4e382ed53
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/getrusage.c
@@ -0,0 +1,58 @@
+/* getrusage -- get the rusage struct.  Linux version.
+   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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <sys/types.h>
+#include <sysdep.h>
+#include <tv32-compat.h>
+
+int
+__getrusage64 (enum __rusage_who who, struct __rusage64 *usage)
+{
+#if __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64
+  return INLINE_SYSCALL_CALL (getrusage, who, usage);
+#else
+  struct __rusage32 usage32;
+  if (INLINE_SYSCALL_CALL (getrusage, who, &usage32) == -1)
+    return -1;
+
+  rusage32_to_rusage64 (&usage32, usage);
+  return 0;
+#endif
+}
+
+#if __TIMESIZE != 64
+libc_hidden_def (__getrusage64)
+int
+__getrusage (enum __rusage_who who, struct rusage *usage)
+{
+  int ret ;
+  struct __rusage64 usage64;
+
+  ret = __getrusage64 (who, &usage64);
+
+  if (ret != 0)
+    return ret;
+
+  rusage64_to_rusage (&usage64, usage);
+
+  return ret;
+}
+#endif
+weak_alias (__getrusage, getrusage)
diff --git a/sysdeps/unix/sysv/linux/tv32-compat.h b/sysdeps/unix/sysv/linux/tv32-compat.h
index b8791b1db8..1ada1f729c 100644
--- a/sysdeps/unix/sysv/linux/tv32-compat.h
+++ b/sysdeps/unix/sysv/linux/tv32-compat.h
@@ -20,6 +20,7 @@
 #define _TV32_COMPAT_H 1
 
 #include <bits/types/time_t.h>
+#include <sys/resource.h>
 
 /* Structures containing 'struct timeval' with 32-bit time_t.  */
 struct __itimerval32
@@ -28,4 +29,50 @@ struct __itimerval32
   struct __timeval32 it_value;
 };
 
+struct __rusage32
+{
+  struct __timeval32 ru_utime;	/* user time used */
+  struct __timeval32 ru_stime;	/* system time used */
+  long ru_maxrss;		/* maximum resident set size */
+  long ru_ixrss;		/* integral shared memory size */
+  long ru_idrss;		/* integral unshared data size */
+  long ru_isrss;		/* integral unshared stack size */
+  long ru_minflt;		/* page reclaims */
+  long ru_majflt;		/* page faults */
+  long ru_nswap;		/* swaps */
+  long ru_inblock;		/* block input operations */
+  long ru_oublock;		/* block output operations */
+  long ru_msgsnd;		/* messages sent */
+  long ru_msgrcv;		/* messages received */
+  long ru_nsignals;		/* signals received */
+  long ru_nvcsw;		/* voluntary context switches */
+  long ru_nivcsw;		/* involuntary " */
+};
+
+static inline void
+rusage32_to_rusage64 (const struct __rusage32 *restrict r32,
+                    struct __rusage64 *restrict r64)
+{
+  /* Make sure the entire output structure is cleared, including
+     padding and reserved fields.  */
+  memset (r64, 0, sizeof *r64);
+
+  r64->ru_utime    = valid_timeval32_to_timeval64 (r32->ru_utime);
+  r64->ru_stime    = valid_timeval32_to_timeval64 (r32->ru_stime);
+  r64->ru_maxrss   = r32->ru_maxrss;
+  r64->ru_ixrss    = r32->ru_ixrss;
+  r64->ru_idrss    = r32->ru_idrss;
+  r64->ru_isrss    = r32->ru_isrss;
+  r64->ru_minflt   = r32->ru_minflt;
+  r64->ru_majflt   = r32->ru_majflt;
+  r64->ru_nswap    = r32->ru_nswap;
+  r64->ru_inblock  = r32->ru_inblock;
+  r64->ru_oublock  = r32->ru_oublock;
+  r64->ru_msgsnd   = r32->ru_msgsnd;
+  r64->ru_msgrcv   = r32->ru_msgrcv;
+  r64->ru_nsignals = r32->ru_nsignals;
+  r64->ru_nvcsw    = r32->ru_nvcsw;
+  r64->ru_nivcsw   = r32->ru_nivcsw;
+}
+
 #endif /* tv32-compat.h */
diff --git a/sysdeps/unix/sysv/linux/wait4.c b/sysdeps/unix/sysv/linux/wait4.c
index 3a8bed1169..da591da4d4 100644
--- a/sysdeps/unix/sysv/linux/wait4.c
+++ b/sysdeps/unix/sysv/linux/wait4.c
@@ -18,14 +18,30 @@
 
 #include <sys/wait.h>
 #include <sys/resource.h>
+#include <sys/types.h>
 #include <sysdep-cancel.h>
+#include <tv32-compat.h>
 
 pid_t
-__wait4 (pid_t pid, int *stat_loc, int options, struct rusage *usage)
+__wait4_time64 (pid_t pid, int *stat_loc, int options, struct __rusage64 *usage)
 {
 #ifdef __NR_wait4
+# if __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64
   return SYSCALL_CANCEL (wait4, pid, stat_loc, options, usage);
+# else
+  struct __rusage32 usage32;
+  pid_t ret = SYSCALL_CANCEL (wait4, pid, stat_loc, options, &usage32);
+
+  if (ret != 0)
+    return ret;
+
+  if (usage != NULL)
+      rusage32_to_rusage64 (&usage32, usage);
+
+  return ret;
+# endif
 #elif defined (__ASSUME_WAITID_PID0_P_PGID)
+  struct __rusage32 usage32;
   idtype_t idtype = P_PID;
 
   if (pid < -1)
@@ -41,7 +57,12 @@ __wait4 (pid_t pid, int *stat_loc, int options, struct rusage *usage)
   options |= WEXITED;
 
   siginfo_t infop;
+
+# if __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64
   if (SYSCALL_CANCEL (waitid, idtype, pid, &infop, options, usage) < 0)
+# else
+  if (SYSCALL_CANCEL (waitid, idtype, pid, &infop, options, &usage32) < 0)
+# endif
     return -1;
 
   if (stat_loc)
@@ -70,8 +91,13 @@ __wait4 (pid_t pid, int *stat_loc, int options, struct rusage *usage)
         }
     }
 
+# if __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64 == 0
+  if (usage != NULL)
+      rusage32_to_rusage64 (&usage32, usage);
+# endif
+
   return infop.si_pid;
-# else
+#else
 /* Linux waitid prior kernel 5.4 does not support waiting for the current
    process.  It is possible to emulate wait4 it by calling getpgid for
    PID 0, however, it would require an additional syscall and it is inherent
@@ -81,5 +107,25 @@ __wait4 (pid_t pid, int *stat_loc, int options, struct rusage *usage)
 # error "The kernel ABI does not provide a way to implement wait4"
 #endif
 }
+
+#if __TIMESIZE != 64
+libc_hidden_def (__wait4_time64)
+
+pid_t
+__wait4 (pid_t pid, int *stat_loc, int options, struct rusage *usage)
+{
+  pid_t ret ;
+  struct __rusage64 usage64;
+
+  ret = __wait4_time64 (pid, stat_loc, options, &usage64);
+
+  if (ret != 0)
+    return ret;
+
+  rusage64_to_rusage (&usage64, usage);
+
+  return ret;
+}
+#endif
 libc_hidden_def (__wait4);
 weak_alias (__wait4, wait4)
-- 
2.25.0


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

* [PATCH v4 8/8] sysv/alpha: Use generic __timeval32 and helpers
  2020-02-19 18:10 [PATCH v4 0/8] Always use 32-bit time_t for certain syscalls Alistair Francis
                   ` (6 preceding siblings ...)
  2020-02-19 18:10 ` [PATCH v4 7/8] linux: Use long time_t for wait4/getrusage Alistair Francis
@ 2020-02-19 18:10 ` Alistair Francis
  2020-02-21  9:52   ` Lukasz Majewski
  7 siblings, 1 reply; 15+ messages in thread
From: Alistair Francis @ 2020-02-19 18:10 UTC (permalink / raw)
  To: libc-alpha; +Cc: alistair23, Alistair Francis

Now there is a generic __timeval32 and helpers we can use them for Alpha
instead of the Alpha specific ones.
---
 .../unix/sysv/linux/alpha/alpha-tv32-compat.h | 124 ------------------
 sysdeps/unix/sysv/linux/alpha/osf_adjtime.c   |  15 ++-
 sysdeps/unix/sysv/linux/alpha/osf_getitimer.c |   9 +-
 sysdeps/unix/sysv/linux/alpha/osf_getrusage.c |  10 +-
 .../unix/sysv/linux/alpha/osf_gettimeofday.c  |   6 +-
 sysdeps/unix/sysv/linux/alpha/osf_setitimer.c |  15 ++-
 .../unix/sysv/linux/alpha/osf_settimeofday.c  |   6 +-
 sysdeps/unix/sysv/linux/alpha/osf_utimes.c    |   8 +-
 sysdeps/unix/sysv/linux/alpha/osf_wait4.c     |  10 +-
 sysdeps/unix/sysv/linux/tv32-compat.h         |  26 ++++
 10 files changed, 67 insertions(+), 162 deletions(-)
 delete mode 100644 sysdeps/unix/sysv/linux/alpha/alpha-tv32-compat.h

diff --git a/sysdeps/unix/sysv/linux/alpha/alpha-tv32-compat.h b/sysdeps/unix/sysv/linux/alpha/alpha-tv32-compat.h
deleted file mode 100644
index 3073005c65..0000000000
--- a/sysdeps/unix/sysv/linux/alpha/alpha-tv32-compat.h
+++ /dev/null
@@ -1,124 +0,0 @@
-/* Compatibility definitions for `struct timeval' with 32-bit time_t.
-   Copyright (C) 2019-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
-   <http://www.gnu.org/licenses/>.  */
-
-#ifndef _TV32_COMPAT_H
-#define _TV32_COMPAT_H 1
-
-#include <features.h>
-
-#include <bits/types.h>
-#include <bits/types/time_t.h>
-#include <bits/types/struct_timeval.h>
-#include <bits/types/struct_timespec.h>
-#include <bits/types/struct_rusage.h>
-
-#include <stdint.h> // for INT32_MAX
-#include <string.h> // for memset
-
-#define TV_USEC_MAX 999999 // 10**6 - 1
-
-/* A version of 'struct timeval' with 32-bit time_t.  */
-struct timeval32
-{
-  int32_t tv_sec;
-  int32_t tv_usec;
-};
-
-/* Structures containing 'struct timeval' with 32-bit time_t.  */
-struct itimerval32
-{
-  struct timeval32 it_interval;
-  struct timeval32 it_value;
-};
-
-struct rusage32
-{
-  struct timeval32 ru_utime;	/* user time used */
-  struct timeval32 ru_stime;	/* system time used */
-  long ru_maxrss;		/* maximum resident set size */
-  long ru_ixrss;		/* integral shared memory size */
-  long ru_idrss;		/* integral unshared data size */
-  long ru_isrss;		/* integral unshared stack size */
-  long ru_minflt;		/* page reclaims */
-  long ru_majflt;		/* page faults */
-  long ru_nswap;		/* swaps */
-  long ru_inblock;		/* block input operations */
-  long ru_oublock;		/* block output operations */
-  long ru_msgsnd;		/* messages sent */
-  long ru_msgrcv;		/* messages received */
-  long ru_nsignals;		/* signals received */
-  long ru_nvcsw;		/* voluntary context switches */
-  long ru_nivcsw;		/* involuntary " */
-};
-
-/* Conversion functions.  If the seconds field of a timeval32 would
-   overflow, they write { INT32_MAX, TV_USEC_MAX } to the output.  */
-
-static inline struct timeval
-alpha_valid_timeval32_to_timeval (const struct timeval32 tv)
-{
-  return (struct timeval) { tv.tv_sec, tv.tv_usec };
-}
-
-static inline struct timeval32
-alpha_valid_timeval_to_timeval32 (const struct timeval tv64)
-{
-  if (__glibc_unlikely (tv64.tv_sec > (time_t) INT32_MAX))
-    return (struct timeval32) { INT32_MAX, TV_USEC_MAX};
-  return (struct timeval32) { tv64.tv_sec, tv64.tv_usec };
-}
-
-static inline struct timespec
-alpha_valid_timeval32_to_timespec (const struct timeval32 tv)
-{
-  return (struct timespec) { tv.tv_sec, tv.tv_usec * 1000 };
-}
-
-static inline struct timeval32
-alpha_valid_timespec_to_timeval32 (const struct timespec ts)
-{
-  return (struct timeval32) { (time_t) ts.tv_sec, ts.tv_nsec / 1000 };
-}
-
-static inline void
-alpha_rusage64_to_rusage32 (struct rusage32 *restrict r32,
-                      const struct rusage *restrict r64)
-{
-  /* Make sure the entire output structure is cleared, including
-     padding and reserved fields.  */
-  memset (r32, 0, sizeof *r32);
-
-  r32->ru_utime    = alpha_valid_timeval_to_timeval32 (r64->ru_utime);
-  r32->ru_stime    = alpha_valid_timeval_to_timeval32 (r64->ru_stime);
-  r32->ru_maxrss   = r64->ru_maxrss;
-  r32->ru_ixrss    = r64->ru_ixrss;
-  r32->ru_idrss    = r64->ru_idrss;
-  r32->ru_isrss    = r64->ru_isrss;
-  r32->ru_minflt   = r64->ru_minflt;
-  r32->ru_majflt   = r64->ru_majflt;
-  r32->ru_nswap    = r64->ru_nswap;
-  r32->ru_inblock  = r64->ru_inblock;
-  r32->ru_oublock  = r64->ru_oublock;
-  r32->ru_msgsnd   = r64->ru_msgsnd;
-  r32->ru_msgrcv   = r64->ru_msgrcv;
-  r32->ru_nsignals = r64->ru_nsignals;
-  r32->ru_nvcsw    = r64->ru_nvcsw;
-  r32->ru_nivcsw   = r64->ru_nivcsw;
-}
-
-#endif /* alpha-tv32-compat.h */
diff --git a/sysdeps/unix/sysv/linux/alpha/osf_adjtime.c b/sysdeps/unix/sysv/linux/alpha/osf_adjtime.c
index f0a1123639..95d646452e 100644
--- a/sysdeps/unix/sysv/linux/alpha/osf_adjtime.c
+++ b/sysdeps/unix/sysv/linux/alpha/osf_adjtime.c
@@ -20,9 +20,10 @@
 
 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
 
+#include <time.h>
 #include <sys/time.h>
 #include <sys/timex.h>
-#include <alpha-tv32-compat.h>
+#include <string.h>
 
 struct timex32 {
 	unsigned int modes;	/* mode selector */
@@ -36,7 +37,7 @@ struct timex32 {
 	long tolerance;		/* clock frequency tolerance (ppm)
 				 * (read only)
 				 */
-	struct timeval32 time;	/* (read only) */
+	struct __timeval32 time;	/* (read only) */
 	long tick;		/* (modified) usecs between clock ticks */
 
 	long ppsfreq;           /* pps frequency (scaled ppm) (ro) */
@@ -55,15 +56,15 @@ struct timex32 {
 
 int
 attribute_compat_text_section
-__adjtime_tv32 (const struct timeval32 *itv, struct timeval32 *otv)
+__adjtime_tv32 (const struct __timeval32 *itv, struct __timeval32 *otv)
 {
-  struct timeval itv64 = alpha_valid_timeval32_to_timeval (*itv);
+  struct timeval itv64 = valid_timeval32_to_timeval (*itv);
   struct timeval otv64;
 
   if (__adjtime (&itv64, &otv64) == -1)
     return -1;
 
-  *otv = alpha_valid_timeval_to_timeval32 (otv64);
+  *otv = valid_timeval_to_timeval32 (otv64);
   return 0;
 }
 
@@ -91,7 +92,7 @@ __adjtimex_tv32 (struct timex32 *tx)
   tx64.calcnt    = tx->calcnt;
   tx64.errcnt    = tx->errcnt;
   tx64.stbcnt    = tx->stbcnt;
-  tx64.time      = alpha_valid_timeval32_to_timeval (tx->time);
+  tx64.time      = valid_timeval32_to_timeval (tx->time);
 
   int status = __adjtimex (&tx64);
   if (status < 0)
@@ -116,7 +117,7 @@ __adjtimex_tv32 (struct timex32 *tx)
   tx->calcnt    = tx64.calcnt;
   tx->errcnt    = tx64.errcnt;
   tx->stbcnt    = tx64.stbcnt;
-  tx->time      = alpha_valid_timeval_to_timeval32 (tx64.time);
+  tx->time      = valid_timeval_to_timeval32 (tx64.time);
 
   return status;
 }
diff --git a/sysdeps/unix/sysv/linux/alpha/osf_getitimer.c b/sysdeps/unix/sysv/linux/alpha/osf_getitimer.c
index 204d4ba796..4d25060e96 100644
--- a/sysdeps/unix/sysv/linux/alpha/osf_getitimer.c
+++ b/sysdeps/unix/sysv/linux/alpha/osf_getitimer.c
@@ -20,12 +20,13 @@
 
 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
 
+#include <time.h>
 #include <sys/time.h>
-#include <alpha-tv32-compat.h>
+#include <tv32-compat.h>
 
 int
 attribute_compat_text_section
-__getitimer_tv32 (int which, struct itimerval32 *curr_value)
+__getitimer_tv32 (int which, struct __itimerval32 *curr_value)
 {
   struct itimerval curr_value_64;
   if (__getitimer (which, &curr_value_64) == -1)
@@ -33,9 +34,9 @@ __getitimer_tv32 (int which, struct itimerval32 *curr_value)
 
   /* Write all fields of 'curr_value' regardless of overflow.  */
   curr_value->it_interval
-    = alpha_valid_timeval_to_timeval32 (curr_value_64.it_interval);
+    = valid_timeval_to_timeval32 (curr_value_64.it_interval);
   curr_value->it_value
-    = alpha_valid_timeval_to_timeval32 (curr_value_64.it_value);
+    = valid_timeval_to_timeval32 (curr_value_64.it_value);
   return 0;
 }
 
diff --git a/sysdeps/unix/sysv/linux/alpha/osf_getrusage.c b/sysdeps/unix/sysv/linux/alpha/osf_getrusage.c
index be81994654..95cedb0cf6 100644
--- a/sysdeps/unix/sysv/linux/alpha/osf_getrusage.c
+++ b/sysdeps/unix/sysv/linux/alpha/osf_getrusage.c
@@ -22,16 +22,16 @@
 
 #include <sys/time.h>
 #include <sys/resource.h>
-#include <alpha-tv32-compat.h>
+#include <tv32-compat.h>
 
 int
-__getrusage_tv32 (int who, struct rusage32 *usage32)
+__getrusage_tv32 (int who, struct __rusage32 *usage32)
 {
-  struct rusage usage64;
-  if (__getrusage (who, &usage64) == -1)
+  struct rusage usage;
+  if (__getrusage (who, &usage) == -1)
     return -1;
 
-  alpha_rusage64_to_rusage32 (usage32, &usage64);
+  rusage64_to_rusage32 (&usage, usage32);
   return 0;
 }
 
diff --git a/sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c b/sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c
index 9ffda2fde3..8cf5d303f9 100644
--- a/sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c
+++ b/sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c
@@ -20,17 +20,17 @@
 
 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
 
+#include <time.h>
 #include <string.h>
 #include <time.h>
 #include <sys/time.h>
-#include <alpha-tv32-compat.h>
 
 /* Get the current time of day and timezone information putting it
    into *TV and *TZ.  */
 
 int
 attribute_compat_text_section
-__gettimeofday_tv32 (struct timeval32 *restrict tv32, void *restrict tz)
+__gettimeofday_tv32 (struct __timeval32 *restrict tv32, void *restrict tz)
 {
   if (__glibc_unlikely (tz != 0))
     memset (tz, 0, sizeof (struct timezone));
@@ -38,7 +38,7 @@ __gettimeofday_tv32 (struct timeval32 *restrict tv32, void *restrict tz)
   struct timespec ts;
   __clock_gettime (CLOCK_REALTIME, &ts);
 
-  *tv32 = alpha_valid_timespec_to_timeval32 (ts);
+  *tv32 = valid_timespec_to_timeval32 (ts);
   return 0;
 }
 
diff --git a/sysdeps/unix/sysv/linux/alpha/osf_setitimer.c b/sysdeps/unix/sysv/linux/alpha/osf_setitimer.c
index 726dfc8b0e..842ab5f64e 100644
--- a/sysdeps/unix/sysv/linux/alpha/osf_setitimer.c
+++ b/sysdeps/unix/sysv/linux/alpha/osf_setitimer.c
@@ -20,19 +20,20 @@
 
 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
 
+#include <time.h>
 #include <sys/time.h>
-#include <alpha-tv32-compat.h>
+#include <tv32-compat.h>
 
 int
 attribute_compat_text_section
-__setitimer_tv32 (int which, const struct itimerval32 *restrict new_value,
-		  struct itimerval32 *restrict old_value)
+__setitimer_tv32 (int which, const struct __itimerval32 *restrict new_value,
+		  struct __itimerval32 *restrict old_value)
 {
   struct itimerval new_value_64;
   new_value_64.it_interval
-    = alpha_valid_timeval32_to_timeval (new_value->it_interval);
+    = valid_timeval32_to_timeval (new_value->it_interval);
   new_value_64.it_value
-    = alpha_valid_timeval32_to_timeval (new_value->it_value);
+    = valid_timeval32_to_timeval (new_value->it_value);
 
   if (old_value == NULL)
     return __setitimer (which, &new_value_64, NULL);
@@ -43,9 +44,9 @@ __setitimer_tv32 (int which, const struct itimerval32 *restrict new_value,
 
   /* Write all fields of 'old_value' regardless of overflow.  */
   old_value->it_interval
-     = alpha_valid_timeval_to_timeval32 (old_value_64.it_interval);
+     = valid_timeval_to_timeval32 (old_value_64.it_interval);
   old_value->it_value
-     = alpha_valid_timeval_to_timeval32 (old_value_64.it_value);
+     = valid_timeval_to_timeval32 (old_value_64.it_value);
   return 0;
 }
 
diff --git a/sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c b/sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c
index 044363e079..5ea0a5afb7 100644
--- a/sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c
+++ b/sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c
@@ -20,16 +20,16 @@
 
 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
 
+#include <time.h>
 #include <sys/time.h>
 #include <time.h>
 #include <errno.h>
-#include <alpha-tv32-compat.h>
 
 /* Set the current time of day and timezone information.
    This call is restricted to the super-user.  */
 int
 attribute_compat_text_section
-__settimeofday_tv32 (const struct timeval32 *tv32,
+__settimeofday_tv32 (const struct __timeval32 *tv32,
                      const struct timezone *tz)
 {
   if (__glibc_unlikely (tz != 0))
@@ -42,7 +42,7 @@ __settimeofday_tv32 (const struct timeval32 *tv32,
       return __settimezone (tz);
     }
 
-  struct timespec ts = alpha_valid_timeval32_to_timespec (*tv32);
+  struct timespec ts = valid_timeval32_to_timespec (*tv32);
   return __clock_settime (CLOCK_REALTIME, &ts);
 }
 
diff --git a/sysdeps/unix/sysv/linux/alpha/osf_utimes.c b/sysdeps/unix/sysv/linux/alpha/osf_utimes.c
index 8ad9fb567c..8afbf12185 100644
--- a/sysdeps/unix/sysv/linux/alpha/osf_utimes.c
+++ b/sysdeps/unix/sysv/linux/alpha/osf_utimes.c
@@ -20,16 +20,16 @@
 
 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
 
+#include <time.h>
 #include <sys/time.h>
-#include <alpha-tv32-compat.h>
 
 int
 attribute_compat_text_section
-__utimes_tv32 (const char *filename, const struct timeval32 times32[2])
+__utimes_tv32 (const char *filename, const struct __timeval32 times32[2])
 {
   struct timeval times[2];
-  times[0] = alpha_valid_timeval32_to_timeval (times32[0]);
-  times[1] = alpha_valid_timeval32_to_timeval (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/osf_wait4.c b/sysdeps/unix/sysv/linux/alpha/osf_wait4.c
index c664e8e93f..4242d5227f 100644
--- a/sysdeps/unix/sysv/linux/alpha/osf_wait4.c
+++ b/sysdeps/unix/sysv/linux/alpha/osf_wait4.c
@@ -23,17 +23,17 @@
 #include <sys/time.h>
 #include <sys/resource.h>
 #include <sys/wait.h>
-#include <alpha-tv32-compat.h>
+#include <tv32-compat.h>
 
 pid_t
 attribute_compat_text_section
-__wait4_tv32 (pid_t pid, int *status, int options, struct rusage32 *usage32)
+__wait4_tv32 (pid_t pid, int *status, int options, struct __rusage32 *usage32)
 {
-  struct rusage usage64;
-  pid_t child = __wait4 (pid, status, options, &usage64);
+  struct rusage usage;
+  pid_t child = __wait4 (pid, status, options, &usage);
 
   if (child >= 0 && usage32 != NULL)
-    alpha_rusage64_to_rusage32 (usage32, &usage64);
+    rusage64_to_rusage32 (&usage, usage32);
   return child;
 }
 
diff --git a/sysdeps/unix/sysv/linux/tv32-compat.h b/sysdeps/unix/sysv/linux/tv32-compat.h
index 1ada1f729c..f906f6acf5 100644
--- a/sysdeps/unix/sysv/linux/tv32-compat.h
+++ b/sysdeps/unix/sysv/linux/tv32-compat.h
@@ -75,4 +75,30 @@ rusage32_to_rusage64 (const struct __rusage32 *restrict r32,
   r64->ru_nivcsw   = r32->ru_nivcsw;
 }
 
+static inline void
+rusage64_to_rusage32 (const struct __rusage64 *restrict r64,
+                    struct __rusage32 *restrict r32)
+{
+  /* Make sure the entire output structure is cleared, including
+     padding and reserved fields.  */
+  memset (r32, 0, sizeof *r32);
+
+  r32->ru_utime    = valid_timeval64_to_timeval32 (r64->ru_utime);
+  r32->ru_stime    = valid_timeval64_to_timeval32 (r64->ru_stime);
+  r32->ru_maxrss   = r64->ru_maxrss;
+  r32->ru_ixrss    = r64->ru_ixrss;
+  r32->ru_idrss    = r64->ru_idrss;
+  r32->ru_isrss    = r64->ru_isrss;
+  r32->ru_minflt   = r64->ru_minflt;
+  r32->ru_majflt   = r64->ru_majflt;
+  r32->ru_nswap    = r64->ru_nswap;
+  r32->ru_inblock  = r64->ru_inblock;
+  r32->ru_oublock  = r64->ru_oublock;
+  r32->ru_msgsnd   = r64->ru_msgsnd;
+  r32->ru_msgrcv   = r64->ru_msgrcv;
+  r32->ru_nsignals = r64->ru_nsignals;
+  r32->ru_nvcsw    = r64->ru_nvcsw;
+  r32->ru_nivcsw   = r64->ru_nivcsw;
+}
+
 #endif /* tv32-compat.h */
-- 
2.25.0


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

* Re: [PATCH v4 8/8] sysv/alpha: Use generic __timeval32 and helpers
  2020-02-19 18:10 ` [PATCH v4 8/8] sysv/alpha: Use generic __timeval32 and helpers Alistair Francis
@ 2020-02-21  9:52   ` Lukasz Majewski
  0 siblings, 0 replies; 15+ messages in thread
From: Lukasz Majewski @ 2020-02-21  9:52 UTC (permalink / raw)
  To: Alistair Francis; +Cc: libc-alpha, alistair23

[-- Attachment #1: Type: text/plain, Size: 17844 bytes --]

On Wed, 19 Feb 2020 10:10:57 -0800
Alistair Francis <alistair.francis@wdc.com> wrote:

> Now there is a generic __timeval32 and helpers we can use them for
> Alpha instead of the Alpha specific ones.
> ---
>  .../unix/sysv/linux/alpha/alpha-tv32-compat.h | 124
> ------------------ sysdeps/unix/sysv/linux/alpha/osf_adjtime.c   |
> 15 ++- sysdeps/unix/sysv/linux/alpha/osf_getitimer.c |   9 +-
>  sysdeps/unix/sysv/linux/alpha/osf_getrusage.c |  10 +-
>  .../unix/sysv/linux/alpha/osf_gettimeofday.c  |   6 +-
>  sysdeps/unix/sysv/linux/alpha/osf_setitimer.c |  15 ++-
>  .../unix/sysv/linux/alpha/osf_settimeofday.c  |   6 +-
>  sysdeps/unix/sysv/linux/alpha/osf_utimes.c    |   8 +-
>  sysdeps/unix/sysv/linux/alpha/osf_wait4.c     |  10 +-
>  sysdeps/unix/sysv/linux/tv32-compat.h         |  26 ++++
>  10 files changed, 67 insertions(+), 162 deletions(-)
>  delete mode 100644 sysdeps/unix/sysv/linux/alpha/alpha-tv32-compat.h
> 
> diff --git a/sysdeps/unix/sysv/linux/alpha/alpha-tv32-compat.h
> b/sysdeps/unix/sysv/linux/alpha/alpha-tv32-compat.h deleted file mode
> 100644 index 3073005c65..0000000000
> --- a/sysdeps/unix/sysv/linux/alpha/alpha-tv32-compat.h
> +++ /dev/null
> @@ -1,124 +0,0 @@
> -/* Compatibility definitions for `struct timeval' with 32-bit time_t.
> -   Copyright (C) 2019-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
> -   <http://www.gnu.org/licenses/>.  */
> -
> -#ifndef _TV32_COMPAT_H
> -#define _TV32_COMPAT_H 1
> -
> -#include <features.h>
> -
> -#include <bits/types.h>
> -#include <bits/types/time_t.h>
> -#include <bits/types/struct_timeval.h>
> -#include <bits/types/struct_timespec.h>
> -#include <bits/types/struct_rusage.h>
> -
> -#include <stdint.h> // for INT32_MAX
> -#include <string.h> // for memset
> -
> -#define TV_USEC_MAX 999999 // 10**6 - 1
> -
> -/* A version of 'struct timeval' with 32-bit time_t.  */
> -struct timeval32
> -{
> -  int32_t tv_sec;
> -  int32_t tv_usec;
> -};
> -
> -/* Structures containing 'struct timeval' with 32-bit time_t.  */
> -struct itimerval32
> -{
> -  struct timeval32 it_interval;
> -  struct timeval32 it_value;
> -};
> -
> -struct rusage32
> -{
> -  struct timeval32 ru_utime;	/* user time used */
> -  struct timeval32 ru_stime;	/* system time used */
> -  long ru_maxrss;		/* maximum resident set size */
> -  long ru_ixrss;		/* integral shared memory size */
> -  long ru_idrss;		/* integral unshared data size */
> -  long ru_isrss;		/* integral unshared stack size */
> -  long ru_minflt;		/* page reclaims */
> -  long ru_majflt;		/* page faults */
> -  long ru_nswap;		/* swaps */
> -  long ru_inblock;		/* block input operations */
> -  long ru_oublock;		/* block output operations */
> -  long ru_msgsnd;		/* messages sent */
> -  long ru_msgrcv;		/* messages received */
> -  long ru_nsignals;		/* signals received */
> -  long ru_nvcsw;		/* voluntary context switches */
> -  long ru_nivcsw;		/* involuntary " */
> -};
> -
> -/* Conversion functions.  If the seconds field of a timeval32 would
> -   overflow, they write { INT32_MAX, TV_USEC_MAX } to the output.  */
> -
> -static inline struct timeval
> -alpha_valid_timeval32_to_timeval (const struct timeval32 tv)
> -{
> -  return (struct timeval) { tv.tv_sec, tv.tv_usec };
> -}
> -
> -static inline struct timeval32
> -alpha_valid_timeval_to_timeval32 (const struct timeval tv64)
> -{
> -  if (__glibc_unlikely (tv64.tv_sec > (time_t) INT32_MAX))
> -    return (struct timeval32) { INT32_MAX, TV_USEC_MAX};
> -  return (struct timeval32) { tv64.tv_sec, tv64.tv_usec };
> -}
> -
> -static inline struct timespec
> -alpha_valid_timeval32_to_timespec (const struct timeval32 tv)
> -{
> -  return (struct timespec) { tv.tv_sec, tv.tv_usec * 1000 };
> -}
> -
> -static inline struct timeval32
> -alpha_valid_timespec_to_timeval32 (const struct timespec ts)
> -{
> -  return (struct timeval32) { (time_t) ts.tv_sec, ts.tv_nsec / 1000
> }; -}
> -
> -static inline void
> -alpha_rusage64_to_rusage32 (struct rusage32 *restrict r32,
> -                      const struct rusage *restrict r64)
> -{
> -  /* Make sure the entire output structure is cleared, including
> -     padding and reserved fields.  */
> -  memset (r32, 0, sizeof *r32);
> -
> -  r32->ru_utime    = alpha_valid_timeval_to_timeval32
> (r64->ru_utime);
> -  r32->ru_stime    = alpha_valid_timeval_to_timeval32
> (r64->ru_stime);
> -  r32->ru_maxrss   = r64->ru_maxrss;
> -  r32->ru_ixrss    = r64->ru_ixrss;
> -  r32->ru_idrss    = r64->ru_idrss;
> -  r32->ru_isrss    = r64->ru_isrss;
> -  r32->ru_minflt   = r64->ru_minflt;
> -  r32->ru_majflt   = r64->ru_majflt;
> -  r32->ru_nswap    = r64->ru_nswap;
> -  r32->ru_inblock  = r64->ru_inblock;
> -  r32->ru_oublock  = r64->ru_oublock;
> -  r32->ru_msgsnd   = r64->ru_msgsnd;
> -  r32->ru_msgrcv   = r64->ru_msgrcv;
> -  r32->ru_nsignals = r64->ru_nsignals;
> -  r32->ru_nvcsw    = r64->ru_nvcsw;
> -  r32->ru_nivcsw   = r64->ru_nivcsw;
> -}
> -
> -#endif /* alpha-tv32-compat.h */
> diff --git a/sysdeps/unix/sysv/linux/alpha/osf_adjtime.c
> b/sysdeps/unix/sysv/linux/alpha/osf_adjtime.c index
> f0a1123639..95d646452e 100644 ---
> a/sysdeps/unix/sysv/linux/alpha/osf_adjtime.c +++
> b/sysdeps/unix/sysv/linux/alpha/osf_adjtime.c @@ -20,9 +20,10 @@
>  
>  #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
>  
> +#include <time.h>
>  #include <sys/time.h>
>  #include <sys/timex.h>
> -#include <alpha-tv32-compat.h>
> +#include <string.h>
>  
>  struct timex32 {
>  	unsigned int modes;	/* mode selector */
> @@ -36,7 +37,7 @@ struct timex32 {
>  	long tolerance;		/* clock frequency tolerance
> (ppm)
>  				 * (read only)
>  				 */
> -	struct timeval32 time;	/* (read only) */
> +	struct __timeval32 time;	/* (read only) */
>  	long tick;		/* (modified) usecs between clock
> ticks */ 
>  	long ppsfreq;           /* pps frequency (scaled ppm) (ro) */
> @@ -55,15 +56,15 @@ struct timex32 {
>  
>  int
>  attribute_compat_text_section
> -__adjtime_tv32 (const struct timeval32 *itv, struct timeval32 *otv)
> +__adjtime_tv32 (const struct __timeval32 *itv, struct __timeval32
> *otv) {
> -  struct timeval itv64 = alpha_valid_timeval32_to_timeval (*itv);
> +  struct timeval itv64 = valid_timeval32_to_timeval (*itv);
>    struct timeval otv64;
>  
>    if (__adjtime (&itv64, &otv64) == -1)
>      return -1;
>  
> -  *otv = alpha_valid_timeval_to_timeval32 (otv64);
> +  *otv = valid_timeval_to_timeval32 (otv64);
>    return 0;
>  }
>  
> @@ -91,7 +92,7 @@ __adjtimex_tv32 (struct timex32 *tx)
>    tx64.calcnt    = tx->calcnt;
>    tx64.errcnt    = tx->errcnt;
>    tx64.stbcnt    = tx->stbcnt;
> -  tx64.time      = alpha_valid_timeval32_to_timeval (tx->time);
> +  tx64.time      = valid_timeval32_to_timeval (tx->time);
>  
>    int status = __adjtimex (&tx64);
>    if (status < 0)
> @@ -116,7 +117,7 @@ __adjtimex_tv32 (struct timex32 *tx)
>    tx->calcnt    = tx64.calcnt;
>    tx->errcnt    = tx64.errcnt;
>    tx->stbcnt    = tx64.stbcnt;
> -  tx->time      = alpha_valid_timeval_to_timeval32 (tx64.time);
> +  tx->time      = valid_timeval_to_timeval32 (tx64.time);
>  
>    return status;
>  }
> diff --git a/sysdeps/unix/sysv/linux/alpha/osf_getitimer.c
> b/sysdeps/unix/sysv/linux/alpha/osf_getitimer.c index
> 204d4ba796..4d25060e96 100644 ---
> a/sysdeps/unix/sysv/linux/alpha/osf_getitimer.c +++
> b/sysdeps/unix/sysv/linux/alpha/osf_getitimer.c @@ -20,12 +20,13 @@
>  
>  #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
>  
> +#include <time.h>
>  #include <sys/time.h>
> -#include <alpha-tv32-compat.h>
> +#include <tv32-compat.h>
>  
>  int
>  attribute_compat_text_section
> -__getitimer_tv32 (int which, struct itimerval32 *curr_value)
> +__getitimer_tv32 (int which, struct __itimerval32 *curr_value)
>  {
>    struct itimerval curr_value_64;
>    if (__getitimer (which, &curr_value_64) == -1)
> @@ -33,9 +34,9 @@ __getitimer_tv32 (int which, struct itimerval32
> *curr_value) 
>    /* Write all fields of 'curr_value' regardless of overflow.  */
>    curr_value->it_interval
> -    = alpha_valid_timeval_to_timeval32 (curr_value_64.it_interval);
> +    = valid_timeval_to_timeval32 (curr_value_64.it_interval);
>    curr_value->it_value
> -    = alpha_valid_timeval_to_timeval32 (curr_value_64.it_value);
> +    = valid_timeval_to_timeval32 (curr_value_64.it_value);
>    return 0;
>  }
>  
> diff --git a/sysdeps/unix/sysv/linux/alpha/osf_getrusage.c
> b/sysdeps/unix/sysv/linux/alpha/osf_getrusage.c index
> be81994654..95cedb0cf6 100644 ---
> a/sysdeps/unix/sysv/linux/alpha/osf_getrusage.c +++
> b/sysdeps/unix/sysv/linux/alpha/osf_getrusage.c @@ -22,16 +22,16 @@
>  
>  #include <sys/time.h>
>  #include <sys/resource.h>
> -#include <alpha-tv32-compat.h>
> +#include <tv32-compat.h>
>  
>  int
> -__getrusage_tv32 (int who, struct rusage32 *usage32)
> +__getrusage_tv32 (int who, struct __rusage32 *usage32)
>  {
> -  struct rusage usage64;
> -  if (__getrusage (who, &usage64) == -1)
> +  struct rusage usage;
> +  if (__getrusage (who, &usage) == -1)
>      return -1;
>  
> -  alpha_rusage64_to_rusage32 (usage32, &usage64);
> +  rusage64_to_rusage32 (&usage, usage32);
>    return 0;
>  }
>  
> diff --git a/sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c
> b/sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c index
> 9ffda2fde3..8cf5d303f9 100644 ---
> a/sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c +++
> b/sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c @@ -20,17 +20,17 @@
>  
>  #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
>  
> +#include <time.h>
>  #include <string.h>
>  #include <time.h>
>  #include <sys/time.h>
> -#include <alpha-tv32-compat.h>
>  
>  /* Get the current time of day and timezone information putting it
>     into *TV and *TZ.  */
>  
>  int
>  attribute_compat_text_section
> -__gettimeofday_tv32 (struct timeval32 *restrict tv32, void *restrict
> tz) +__gettimeofday_tv32 (struct __timeval32 *restrict tv32, void
> *restrict tz) {
>    if (__glibc_unlikely (tz != 0))
>      memset (tz, 0, sizeof (struct timezone));
> @@ -38,7 +38,7 @@ __gettimeofday_tv32 (struct timeval32 *restrict
> tv32, void *restrict tz) struct timespec ts;
>    __clock_gettime (CLOCK_REALTIME, &ts);
>  
> -  *tv32 = alpha_valid_timespec_to_timeval32 (ts);
> +  *tv32 = valid_timespec_to_timeval32 (ts);
>    return 0;
>  }
>  
> diff --git a/sysdeps/unix/sysv/linux/alpha/osf_setitimer.c
> b/sysdeps/unix/sysv/linux/alpha/osf_setitimer.c index
> 726dfc8b0e..842ab5f64e 100644 ---
> a/sysdeps/unix/sysv/linux/alpha/osf_setitimer.c +++
> b/sysdeps/unix/sysv/linux/alpha/osf_setitimer.c @@ -20,19 +20,20 @@
>  
>  #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
>  
> +#include <time.h>
>  #include <sys/time.h>
> -#include <alpha-tv32-compat.h>
> +#include <tv32-compat.h>
>  
>  int
>  attribute_compat_text_section
> -__setitimer_tv32 (int which, const struct itimerval32 *restrict
> new_value,
> -		  struct itimerval32 *restrict old_value)
> +__setitimer_tv32 (int which, const struct __itimerval32 *restrict
> new_value,
> +		  struct __itimerval32 *restrict old_value)
>  {
>    struct itimerval new_value_64;
>    new_value_64.it_interval
> -    = alpha_valid_timeval32_to_timeval (new_value->it_interval);
> +    = valid_timeval32_to_timeval (new_value->it_interval);
>    new_value_64.it_value
> -    = alpha_valid_timeval32_to_timeval (new_value->it_value);
> +    = valid_timeval32_to_timeval (new_value->it_value);
>  
>    if (old_value == NULL)
>      return __setitimer (which, &new_value_64, NULL);
> @@ -43,9 +44,9 @@ __setitimer_tv32 (int which, const struct
> itimerval32 *restrict new_value, 
>    /* Write all fields of 'old_value' regardless of overflow.  */
>    old_value->it_interval
> -     = alpha_valid_timeval_to_timeval32 (old_value_64.it_interval);
> +     = valid_timeval_to_timeval32 (old_value_64.it_interval);
>    old_value->it_value
> -     = alpha_valid_timeval_to_timeval32 (old_value_64.it_value);
> +     = valid_timeval_to_timeval32 (old_value_64.it_value);
>    return 0;
>  }
>  
> diff --git a/sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c
> b/sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c index
> 044363e079..5ea0a5afb7 100644 ---
> a/sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c +++
> b/sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c @@ -20,16 +20,16 @@
>  
>  #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
>  
> +#include <time.h>
>  #include <sys/time.h>
>  #include <time.h>
>  #include <errno.h>
> -#include <alpha-tv32-compat.h>
>  
>  /* Set the current time of day and timezone information.
>     This call is restricted to the super-user.  */
>  int
>  attribute_compat_text_section
> -__settimeofday_tv32 (const struct timeval32 *tv32,
> +__settimeofday_tv32 (const struct __timeval32 *tv32,
>                       const struct timezone *tz)
>  {
>    if (__glibc_unlikely (tz != 0))
> @@ -42,7 +42,7 @@ __settimeofday_tv32 (const struct timeval32 *tv32,
>        return __settimezone (tz);
>      }
>  
> -  struct timespec ts = alpha_valid_timeval32_to_timespec (*tv32);
> +  struct timespec ts = valid_timeval32_to_timespec (*tv32);
>    return __clock_settime (CLOCK_REALTIME, &ts);
>  }
>  
> diff --git a/sysdeps/unix/sysv/linux/alpha/osf_utimes.c
> b/sysdeps/unix/sysv/linux/alpha/osf_utimes.c index
> 8ad9fb567c..8afbf12185 100644 ---
> a/sysdeps/unix/sysv/linux/alpha/osf_utimes.c +++
> b/sysdeps/unix/sysv/linux/alpha/osf_utimes.c @@ -20,16 +20,16 @@
>  
>  #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
>  
> +#include <time.h>
>  #include <sys/time.h>
> -#include <alpha-tv32-compat.h>
>  
>  int
>  attribute_compat_text_section
> -__utimes_tv32 (const char *filename, const struct timeval32
> times32[2]) +__utimes_tv32 (const char *filename, const struct
> __timeval32 times32[2]) {
>    struct timeval times[2];
> -  times[0] = alpha_valid_timeval32_to_timeval (times32[0]);
> -  times[1] = alpha_valid_timeval32_to_timeval (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/osf_wait4.c
> b/sysdeps/unix/sysv/linux/alpha/osf_wait4.c index
> c664e8e93f..4242d5227f 100644 ---
> a/sysdeps/unix/sysv/linux/alpha/osf_wait4.c +++
> b/sysdeps/unix/sysv/linux/alpha/osf_wait4.c @@ -23,17 +23,17 @@
>  #include <sys/time.h>
>  #include <sys/resource.h>
>  #include <sys/wait.h>
> -#include <alpha-tv32-compat.h>
> +#include <tv32-compat.h>
>  
>  pid_t
>  attribute_compat_text_section
> -__wait4_tv32 (pid_t pid, int *status, int options, struct rusage32
> *usage32) +__wait4_tv32 (pid_t pid, int *status, int options, struct
> __rusage32 *usage32) {
> -  struct rusage usage64;
> -  pid_t child = __wait4 (pid, status, options, &usage64);
> +  struct rusage usage;
> +  pid_t child = __wait4 (pid, status, options, &usage);
>  
>    if (child >= 0 && usage32 != NULL)
> -    alpha_rusage64_to_rusage32 (usage32, &usage64);
> +    rusage64_to_rusage32 (&usage, usage32);
>    return child;
>  }
>  
> diff --git a/sysdeps/unix/sysv/linux/tv32-compat.h
> b/sysdeps/unix/sysv/linux/tv32-compat.h index 1ada1f729c..f906f6acf5
> 100644 --- a/sysdeps/unix/sysv/linux/tv32-compat.h
> +++ b/sysdeps/unix/sysv/linux/tv32-compat.h
> @@ -75,4 +75,30 @@ rusage32_to_rusage64 (const struct __rusage32
> *restrict r32, r64->ru_nivcsw   = r32->ru_nivcsw;
>  }
>  
> +static inline void
> +rusage64_to_rusage32 (const struct __rusage64 *restrict r64,
> +                    struct __rusage32 *restrict r32)
> +{
> +  /* Make sure the entire output structure is cleared, including
> +     padding and reserved fields.  */
> +  memset (r32, 0, sizeof *r32);
> +
> +  r32->ru_utime    = valid_timeval64_to_timeval32 (r64->ru_utime);
> +  r32->ru_stime    = valid_timeval64_to_timeval32 (r64->ru_stime);
> +  r32->ru_maxrss   = r64->ru_maxrss;
> +  r32->ru_ixrss    = r64->ru_ixrss;
> +  r32->ru_idrss    = r64->ru_idrss;
> +  r32->ru_isrss    = r64->ru_isrss;
> +  r32->ru_minflt   = r64->ru_minflt;
> +  r32->ru_majflt   = r64->ru_majflt;
> +  r32->ru_nswap    = r64->ru_nswap;
> +  r32->ru_inblock  = r64->ru_inblock;
> +  r32->ru_oublock  = r64->ru_oublock;
> +  r32->ru_msgsnd   = r64->ru_msgsnd;
> +  r32->ru_msgrcv   = r64->ru_msgrcv;
> +  r32->ru_nsignals = r64->ru_nsignals;
> +  r32->ru_nvcsw    = r64->ru_nvcsw;
> +  r32->ru_nivcsw   = r64->ru_nivcsw;
> +}
> +
>  #endif /* tv32-compat.h */

Reviewed-by: Lukasz Majewski <lukma@denx.de>


Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma@denx.de

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v4 5/8] linux: Use long time_t __getitimer/__setitimer
  2020-02-19 18:10 ` [PATCH v4 5/8] linux: Use long time_t __getitimer/__setitimer Alistair Francis
@ 2020-02-21 10:03   ` Lukasz Majewski
  2020-02-28 16:56     ` Lukasz Majewski
  0 siblings, 1 reply; 15+ messages in thread
From: Lukasz Majewski @ 2020-02-21 10:03 UTC (permalink / raw)
  To: Alistair Francis; +Cc: libc-alpha, alistair23

[-- Attachment #1: Type: text/plain, Size: 10842 bytes --]

Hi Alistair,

> The Linux kernel expects itimerval to use a 32-bit time_t, even on
> archs with a 64-bit time_t (like RV32). To address this let's convert
> itimerval to/from 32-bit and 64-bit to ensure the kernel always gets
> a 32-bit time_t.
> 
> While we are converting these functions let's also convert them to be
> the y2038 safe versions. This means there is a *64 function that is
> called by a backwards compatible wrapper.
> ---
>  include/time.h                        | 15 +++++
>  sysdeps/unix/syscalls.list            |  2 -
>  sysdeps/unix/sysv/linux/getitimer.c   | 59 +++++++++++++++++
>  sysdeps/unix/sysv/linux/setitimer.c   | 95
> +++++++++++++++++++++++++++ sysdeps/unix/sysv/linux/tv32-compat.h |
> 31 +++++++++ 5 files changed, 200 insertions(+), 2 deletions(-)
>  create mode 100644 sysdeps/unix/sysv/linux/getitimer.c
>  create mode 100644 sysdeps/unix/sysv/linux/setitimer.c
>  create mode 100644 sysdeps/unix/sysv/linux/tv32-compat.h
> 
> diff --git a/include/time.h b/include/time.h
> index 8a4abb159f..eaa536d5c0 100644
> --- a/include/time.h
> +++ b/include/time.h
> @@ -6,6 +6,7 @@
>  # include <bits/types/locale_t.h>
>  # include <stdbool.h>
>  # include <time/mktime-internal.h>
> +# include <sys/time.h>
>  # include <endian.h>
>  # include <time-clockid.h>
>  # include <sys/time.h>
> @@ -119,6 +120,20 @@ struct __itimerval64
>  };
>  #endif
>  
> +#if __TIMESIZE == 64
> +# define __getitimer64 __getitimer
> +# define __setitimer64 __setitimer
> +#else
> +extern int __getitimer64 (enum __itimer_which __which,
> +                          struct __itimerval64 *__value);
> +
> +libc_hidden_proto (__getitimer64)
> +extern int __setitimer64 (enum __itimer_which __which,
> +                          const struct __itimerval64 *__restrict
> __new,
> +                          struct __itimerval64 *__restrict __old);
> +libc_hidden_proto (__setitimer64)
> +#endif
> +
>  #if __TIMESIZE == 64
>  # define __ctime64 ctime
>  #else
> diff --git a/sysdeps/unix/syscalls.list b/sysdeps/unix/syscalls.list
> index e28e801c7a..d249049d6e 100644
> --- a/sysdeps/unix/syscalls.list
> +++ b/sysdeps/unix/syscalls.list
> @@ -25,7 +25,6 @@ getgid		-	getgid
> 	Ei:	__getgid	getgid getgroups	-
> getgroups	i:ip	__getgroups	getgroups
> gethostid	-	gethostid	i:	gethostid
> gethostname	-	gethostname	i:bn
> __gethostname	gethostname -getitimer	-
> getitimer	i:ip	__getitimer	getitimer
> getpeername	-	getpeername	i:ibN
> __getpeername	getpeername getpid		-
> getpid		Ei:	__getpid	getpid
> getpriority	-	getpriority	i:ii
> __getpriority	getpriority @@ -67,7 +66,6 @@ setgid
> 	-	setgid		i:i	__setgid
> setgid setgroups	-	setgroups	i:ip
> setgroups sethostid	-	sethostid	i:i
> sethostid sethostname	-	sethostname	i:pi
> sethostname -setitimer	-	setitimer	i:ipp
> __setitimer	setitimer setpgid		-
> setpgrp		i:ii	__setpgid	setpgid
> setpriority	-	setpriority	i:iii
> __setpriority	setpriority setregid	-
> setregid	i:ii	__setregid	setregid diff --git
> a/sysdeps/unix/sysv/linux/getitimer.c
> b/sysdeps/unix/sysv/linux/getitimer.c new file mode 100644 index
> 0000000000..12f7963949 --- /dev/null +++
> b/sysdeps/unix/sysv/linux/getitimer.c @@ -0,0 +1,59 @@ +/* getitimer
> -- Get the state of an interval timer.  Linux/tv32 version.
> +   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
> +   <http://www.gnu.org/licenses/>.  */
> +
> +#include <time.h>
> +#include <sys/time.h>
> +#include <sys/types.h>
> +#include <sysdep.h>
> +#include <tv32-compat.h>
> +
> +int
> +__getitimer64 (__itimer_which_t which, struct __itimerval64
> *curr_value) +{
> +#if __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64
> +  return INLINE_SYSCALL_CALL (getitimer, which, curr_value);
> +#else
> +  struct __itimerval32 curr_value_32;
> +  if (INLINE_SYSCALL_CALL (getitimer, which, &curr_value_32) == -1)
> +    return -1;
> +
> +  /* Write all fields of 'curr_value' regardless of overflow.  */
> +  curr_value->it_interval
> +    = valid_timeval32_to_timeval64 (curr_value_32.it_interval);
> +  curr_value->it_value
> +    = valid_timeval32_to_timeval64 (curr_value_32.it_value);
> +  return 0;
> +#endif
> +}
> +
> +#if __TIMESIZE != 64
> +libc_hidden_def (__getitimer64)
> +int
> +__getitimer (__itimer_which_t which, struct itimerval *curr_value)
> +{
> +  struct __itimerval64 val64;
> +
> +  val64.it_interval
> +    = valid_timeval_to_timeval64 (curr_value->it_interval);
> +  val64.it_value
> +    = valid_timeval_to_timeval64 (curr_value->it_value);
> +
> +  return __getitimer64 (which, &val64);
> +}
> +#endif
> +weak_alias (__getitimer, getitimer)
> diff --git a/sysdeps/unix/sysv/linux/setitimer.c
> b/sysdeps/unix/sysv/linux/setitimer.c new file mode 100644
> index 0000000000..238853dd33
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/setitimer.c
> @@ -0,0 +1,95 @@
> +/* setitimer -- Set the state of an interval timer.  Linux/tv32
> version.
> +   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
> +   <http://www.gnu.org/licenses/>.  */
> +
> +#include <time.h>
> +#include <sys/time.h>
> +#include <sys/types.h>
> +#include <sysdep.h>
> +#include <tv32-compat.h>
> +
> +int
> +__setitimer64 (__itimer_which_t which,
> +               const struct __itimerval64 *restrict new_value,
> +               struct __itimerval64 *restrict old_value)
> +{
> +#if __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64
> +  return INLINE_SYSCALL_CALL (setitimer, which, new_value,
> old_value); +#else
> +  struct __itimerval32 new_value_32;
> +
> +  if (! in_time_t_range (new_value->it_interval.tv_sec))
> +  {
> +    __set_errno (EOVERFLOW);
> +    return -1;
> +  }
> +  new_value_32.it_interval
> +    = valid_timeval64_to_timeval32 (new_value->it_interval);
> +
> +  if (! in_time_t_range (new_value->it_value.tv_sec))
> +  {
> +    __set_errno (EOVERFLOW);
> +    return -1;
> +  }
> +  new_value_32.it_value
> +    = valid_timeval64_to_timeval32 (new_value->it_value);
> +
> +  if (old_value == NULL)
> +    return INLINE_SYSCALL_CALL (setitimer, which, &new_value_32,
> NULL); +
> +  struct __itimerval32 old_value_32;
> +  if (INLINE_SYSCALL_CALL (setitimer, which, &new_value_32,
> &old_value_32) == -1)
> +    return -1;
> +
> +  /* Write all fields of 'old_value' regardless of overflow.  */
> +  old_value->it_interval
> +     = valid_timeval32_to_timeval64 (old_value_32.it_interval);
> +  old_value->it_value
> +     = valid_timeval32_to_timeval64 (old_value_32.it_value);
> +  return 0;
> +#endif
> +}
> +
> +#if __TIMESIZE != 64
> +libc_hidden_def (__setitimer64)
> +int
> +__setitimer (__itimer_which_t which,
> +             const struct itimerval *restrict new_value,
> +             struct itimerval *restrict old_value)
> +{
> +  int ret;
> +  struct __itimerval64 new64, old64;
> +
> +  new64.it_interval
> +    = valid_timeval_to_timeval64 (new_value->it_interval);
> +  new64.it_value
> +    = valid_timeval_to_timeval64 (new_value->it_value);
> +
> +  ret = __setitimer64 (which, &new64, old_value ? &old64 : NULL);
> +
> +  if (ret == 0 && old_value)
> +    {
> +      old_value->it_interval
> +        = valid_timeval64_to_timeval (old64.it_interval);
> +      old_value->it_value
> +        = valid_timeval64_to_timeval (old64.it_value);
> +    }
> +
> +  return ret;
> +}
> +#endif
> +weak_alias (__setitimer, setitimer)
> diff --git a/sysdeps/unix/sysv/linux/tv32-compat.h
> b/sysdeps/unix/sysv/linux/tv32-compat.h new file mode 100644
> index 0000000000..b8791b1db8
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/tv32-compat.h
> @@ -0,0 +1,31 @@
> +/* Compatibility definitions for `struct timeval' with 32-bit time_t.
> +   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
> +   <http://www.gnu.org/licenses/>.  */
> +
> +#ifndef _TV32_COMPAT_H
> +#define _TV32_COMPAT_H 1
> +
> +#include <bits/types/time_t.h>
> +
> +/* Structures containing 'struct timeval' with 32-bit time_t.  */
> +struct __itimerval32
> +{
> +  struct __timeval32 it_interval;
> +  struct __timeval32 it_value;
> +};
> +
> +#endif /* tv32-compat.h */

Tested-by: Lukasz Majewski <lukma@denx.de>

ARM32 (armv7) with QEMU:
https://github.com/lmajewski/meta-y2038/blob/master/README

Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma@denx.de

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v4 7/8] linux: Use long time_t for wait4/getrusage
  2020-02-19 18:10 ` [PATCH v4 7/8] linux: Use long time_t for wait4/getrusage Alistair Francis
@ 2020-02-21 10:08   ` Lukasz Majewski
  0 siblings, 0 replies; 15+ messages in thread
From: Lukasz Majewski @ 2020-02-21 10:08 UTC (permalink / raw)
  To: Alistair Francis; +Cc: libc-alpha, alistair23

[-- Attachment #1: Type: text/plain, Size: 9960 bytes --]

On Wed, 19 Feb 2020 10:10:56 -0800
Alistair Francis <alistair.francis@wdc.com> wrote:

> The Linux kernel expects rusage to use a 32-bit time_t, even on archs
> with a 64-bit time_t (like RV32). To address this let's convert
> rusage to/from 32-bit and 64-bit to ensure the kernel always gets
> a 32-bit time_t.
> 
> While we are converting these functions let's also convert them to be
> the y2038 safe versions. This means there is a *64 function that is
> called by a backwards compatible wrapper.
> ---
>  include/sys/resource.h                | 11 +++++
>  sysdeps/unix/syscalls.list            |  1 -
>  sysdeps/unix/sysv/linux/getrusage.c   | 58
> +++++++++++++++++++++++++++ sysdeps/unix/sysv/linux/tv32-compat.h |
> 47 ++++++++++++++++++++++ sysdeps/unix/sysv/linux/wait4.c       | 50
> ++++++++++++++++++++++- 5 files changed, 164 insertions(+), 3
> deletions(-) create mode 100644 sysdeps/unix/sysv/linux/getrusage.c
> 
> diff --git a/include/sys/resource.h b/include/sys/resource.h
> index 9d604dfe3e..64925f257c 100644
> --- a/include/sys/resource.h
> +++ b/include/sys/resource.h
> @@ -134,5 +134,16 @@ extern int __getrusage (enum __rusage_who __who,
> struct rusage *__usage) extern int __setrlimit (enum
> __rlimit_resource __resource, const struct rlimit *__rlimits);
>  libc_hidden_proto (__setrlimit);
> +
> +#if __TIMESIZE == 64
> +# define __getrusage64 __getrusage
> +# define __wait4_time64 __wait4
> +#else
> +extern int __getrusage64 (enum __rusage_who who, struct __rusage64
> *usage); +libc_hidden_proto (__getrusage64)
> +extern pid_t __wait4_time64 (pid_t pid, int *stat_loc, int options,
> +                             struct __rusage64 *usage);
> +libc_hidden_proto (__wait4_time64)
> +#endif
>  #endif
>  #endif
> diff --git a/sysdeps/unix/syscalls.list b/sysdeps/unix/syscalls.list
> index d249049d6e..01c4a0e6b1 100644
> --- a/sysdeps/unix/syscalls.list
> +++ b/sysdeps/unix/syscalls.list
> @@ -29,7 +29,6 @@ getpeername	-	getpeername
> i:ibN	__getpeername	getpeername getpid
> -	getpid		Ei:	__getpid	getpid
> getpriority	-	getpriority	i:ii
> __getpriority	getpriority getrlimit	-
> getrlimit	i:ip	__getrlimit	getrlimit
> -getrusage	-	getrusage	i:ip
> __getrusage	getrusage getsockname	-
> getsockname	i:ibN	__getsockname	getsockname
> getsockopt	-	getsockopt	i:iiiBN
> getsockopt getuid		-	getuid
> Ei:	__getuid	getuid diff --git
> a/sysdeps/unix/sysv/linux/getrusage.c
> b/sysdeps/unix/sysv/linux/getrusage.c new file mode 100644 index
> 0000000000..a4e382ed53 --- /dev/null +++
> b/sysdeps/unix/sysv/linux/getrusage.c @@ -0,0 +1,58 @@ +/* getrusage
> -- get the rusage struct.  Linux version.
> +   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
> +   <http://www.gnu.org/licenses/>.  */
> +
> +#include <sys/time.h>
> +#include <sys/resource.h>
> +#include <sys/types.h>
> +#include <sysdep.h>
> +#include <tv32-compat.h>
> +
> +int
> +__getrusage64 (enum __rusage_who who, struct __rusage64 *usage)
> +{
> +#if __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64
> +  return INLINE_SYSCALL_CALL (getrusage, who, usage);
> +#else
> +  struct __rusage32 usage32;
> +  if (INLINE_SYSCALL_CALL (getrusage, who, &usage32) == -1)
> +    return -1;
> +
> +  rusage32_to_rusage64 (&usage32, usage);
> +  return 0;
> +#endif
> +}
> +
> +#if __TIMESIZE != 64
> +libc_hidden_def (__getrusage64)
> +int
> +__getrusage (enum __rusage_who who, struct rusage *usage)
> +{
> +  int ret ;
> +  struct __rusage64 usage64;
> +
> +  ret = __getrusage64 (who, &usage64);
> +
> +  if (ret != 0)
> +    return ret;
> +
> +  rusage64_to_rusage (&usage64, usage);
> +
> +  return ret;
> +}
> +#endif
> +weak_alias (__getrusage, getrusage)
> diff --git a/sysdeps/unix/sysv/linux/tv32-compat.h
> b/sysdeps/unix/sysv/linux/tv32-compat.h index b8791b1db8..1ada1f729c
> 100644 --- a/sysdeps/unix/sysv/linux/tv32-compat.h
> +++ b/sysdeps/unix/sysv/linux/tv32-compat.h
> @@ -20,6 +20,7 @@
>  #define _TV32_COMPAT_H 1
>  
>  #include <bits/types/time_t.h>
> +#include <sys/resource.h>
>  
>  /* Structures containing 'struct timeval' with 32-bit time_t.  */
>  struct __itimerval32
> @@ -28,4 +29,50 @@ struct __itimerval32
>    struct __timeval32 it_value;
>  };
>  
> +struct __rusage32
> +{
> +  struct __timeval32 ru_utime;	/* user time used */
> +  struct __timeval32 ru_stime;	/* system time used */
> +  long ru_maxrss;		/* maximum resident set size */
> +  long ru_ixrss;		/* integral shared memory size */
> +  long ru_idrss;		/* integral unshared data size */
> +  long ru_isrss;		/* integral unshared stack size */
> +  long ru_minflt;		/* page reclaims */
> +  long ru_majflt;		/* page faults */
> +  long ru_nswap;		/* swaps */
> +  long ru_inblock;		/* block input operations */
> +  long ru_oublock;		/* block output operations */
> +  long ru_msgsnd;		/* messages sent */
> +  long ru_msgrcv;		/* messages received */
> +  long ru_nsignals;		/* signals received */
> +  long ru_nvcsw;		/* voluntary context switches */
> +  long ru_nivcsw;		/* involuntary " */
> +};
> +
> +static inline void
> +rusage32_to_rusage64 (const struct __rusage32 *restrict r32,
> +                    struct __rusage64 *restrict r64)
> +{
> +  /* Make sure the entire output structure is cleared, including
> +     padding and reserved fields.  */
> +  memset (r64, 0, sizeof *r64);
> +
> +  r64->ru_utime    = valid_timeval32_to_timeval64 (r32->ru_utime);
> +  r64->ru_stime    = valid_timeval32_to_timeval64 (r32->ru_stime);
> +  r64->ru_maxrss   = r32->ru_maxrss;
> +  r64->ru_ixrss    = r32->ru_ixrss;
> +  r64->ru_idrss    = r32->ru_idrss;
> +  r64->ru_isrss    = r32->ru_isrss;
> +  r64->ru_minflt   = r32->ru_minflt;
> +  r64->ru_majflt   = r32->ru_majflt;
> +  r64->ru_nswap    = r32->ru_nswap;
> +  r64->ru_inblock  = r32->ru_inblock;
> +  r64->ru_oublock  = r32->ru_oublock;
> +  r64->ru_msgsnd   = r32->ru_msgsnd;
> +  r64->ru_msgrcv   = r32->ru_msgrcv;
> +  r64->ru_nsignals = r32->ru_nsignals;
> +  r64->ru_nvcsw    = r32->ru_nvcsw;
> +  r64->ru_nivcsw   = r32->ru_nivcsw;
> +}
> +
>  #endif /* tv32-compat.h */
> diff --git a/sysdeps/unix/sysv/linux/wait4.c
> b/sysdeps/unix/sysv/linux/wait4.c index 3a8bed1169..da591da4d4 100644
> --- a/sysdeps/unix/sysv/linux/wait4.c
> +++ b/sysdeps/unix/sysv/linux/wait4.c
> @@ -18,14 +18,30 @@
>  
>  #include <sys/wait.h>
>  #include <sys/resource.h>
> +#include <sys/types.h>
>  #include <sysdep-cancel.h>
> +#include <tv32-compat.h>
>  
>  pid_t
> -__wait4 (pid_t pid, int *stat_loc, int options, struct rusage *usage)
> +__wait4_time64 (pid_t pid, int *stat_loc, int options, struct
> __rusage64 *usage) {
>  #ifdef __NR_wait4
> +# if __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64
>    return SYSCALL_CANCEL (wait4, pid, stat_loc, options, usage);
> +# else
> +  struct __rusage32 usage32;
> +  pid_t ret = SYSCALL_CANCEL (wait4, pid, stat_loc, options,
> &usage32); +
> +  if (ret != 0)
> +    return ret;
> +
> +  if (usage != NULL)
> +      rusage32_to_rusage64 (&usage32, usage);
> +
> +  return ret;
> +# endif
>  #elif defined (__ASSUME_WAITID_PID0_P_PGID)
> +  struct __rusage32 usage32;
>    idtype_t idtype = P_PID;
>  
>    if (pid < -1)
> @@ -41,7 +57,12 @@ __wait4 (pid_t pid, int *stat_loc, int options,
> struct rusage *usage) options |= WEXITED;
>  
>    siginfo_t infop;
> +
> +# if __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64
>    if (SYSCALL_CANCEL (waitid, idtype, pid, &infop, options, usage) <
> 0) +# else
> +  if (SYSCALL_CANCEL (waitid, idtype, pid, &infop, options,
> &usage32) < 0) +# endif
>      return -1;
>  
>    if (stat_loc)
> @@ -70,8 +91,13 @@ __wait4 (pid_t pid, int *stat_loc, int options,
> struct rusage *usage) }
>      }
>  
> +# if __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64 == 0
> +  if (usage != NULL)
> +      rusage32_to_rusage64 (&usage32, usage);
> +# endif
> +
>    return infop.si_pid;
> -# else
> +#else
>  /* Linux waitid prior kernel 5.4 does not support waiting for the
> current process.  It is possible to emulate wait4 it by calling
> getpgid for PID 0, however, it would require an additional syscall
> and it is inherent @@ -81,5 +107,25 @@ __wait4 (pid_t pid, int
> *stat_loc, int options, struct rusage *usage) # error "The kernel ABI
> does not provide a way to implement wait4" #endif
>  }
> +
> +#if __TIMESIZE != 64
> +libc_hidden_def (__wait4_time64)
> +
> +pid_t
> +__wait4 (pid_t pid, int *stat_loc, int options, struct rusage *usage)
> +{
> +  pid_t ret ;
> +  struct __rusage64 usage64;
> +
> +  ret = __wait4_time64 (pid, stat_loc, options, &usage64);
> +
> +  if (ret != 0)
> +    return ret;
> +
> +  rusage64_to_rusage (&usage64, usage);
> +
> +  return ret;
> +}
> +#endif
>  libc_hidden_def (__wait4);
>  weak_alias (__wait4, wait4)

Reviewed-by: Lukasz Majewski <lukma@denx.de>


Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma@denx.de

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v4 5/8] linux: Use long time_t __getitimer/__setitimer
  2020-02-21 10:03   ` Lukasz Majewski
@ 2020-02-28 16:56     ` Lukasz Majewski
  0 siblings, 0 replies; 15+ messages in thread
From: Lukasz Majewski @ 2020-02-28 16:56 UTC (permalink / raw)
  To: Alistair Francis; +Cc: libc-alpha, alistair23, Adhemerval Zanella, Joseph Myers

[-- Attachment #1: Type: text/plain, Size: 11859 bytes --]

Dear Community,

> Hi Alistair,
> 
> > The Linux kernel expects itimerval to use a 32-bit time_t, even on
> > archs with a 64-bit time_t (like RV32). To address this let's
> > convert itimerval to/from 32-bit and 64-bit to ensure the kernel
> > always gets a 32-bit time_t.
> > 
> > While we are converting these functions let's also convert them to
> > be the y2038 safe versions. This means there is a *64 function that
> > is called by a backwards compatible wrapper.
> > ---
> >  include/time.h                        | 15 +++++
> >  sysdeps/unix/syscalls.list            |  2 -
> >  sysdeps/unix/sysv/linux/getitimer.c   | 59 +++++++++++++++++
> >  sysdeps/unix/sysv/linux/setitimer.c   | 95
> > +++++++++++++++++++++++++++ sysdeps/unix/sysv/linux/tv32-compat.h |
> > 31 +++++++++ 5 files changed, 200 insertions(+), 2 deletions(-)
> >  create mode 100644 sysdeps/unix/sysv/linux/getitimer.c
> >  create mode 100644 sysdeps/unix/sysv/linux/setitimer.c
> >  create mode 100644 sysdeps/unix/sysv/linux/tv32-compat.h
> > 
> > diff --git a/include/time.h b/include/time.h
> > index 8a4abb159f..eaa536d5c0 100644
> > --- a/include/time.h
> > +++ b/include/time.h
> > @@ -6,6 +6,7 @@
> >  # include <bits/types/locale_t.h>
> >  # include <stdbool.h>
> >  # include <time/mktime-internal.h>
> > +# include <sys/time.h>
> >  # include <endian.h>
> >  # include <time-clockid.h>
> >  # include <sys/time.h>
> > @@ -119,6 +120,20 @@ struct __itimerval64
> >  };
> >  #endif
> >  
> > +#if __TIMESIZE == 64
> > +# define __getitimer64 __getitimer
> > +# define __setitimer64 __setitimer
> > +#else
> > +extern int __getitimer64 (enum __itimer_which __which,
> > +                          struct __itimerval64 *__value);
> > +
> > +libc_hidden_proto (__getitimer64)
> > +extern int __setitimer64 (enum __itimer_which __which,
> > +                          const struct __itimerval64 *__restrict
> > __new,
> > +                          struct __itimerval64 *__restrict __old);
> > +libc_hidden_proto (__setitimer64)
> > +#endif
> > +
> >  #if __TIMESIZE == 64
> >  # define __ctime64 ctime
> >  #else
> > diff --git a/sysdeps/unix/syscalls.list b/sysdeps/unix/syscalls.list
> > index e28e801c7a..d249049d6e 100644
> > --- a/sysdeps/unix/syscalls.list
> > +++ b/sysdeps/unix/syscalls.list
> > @@ -25,7 +25,6 @@ getgid		-	getgid
> > 	Ei:	__getgid	getgid getgroups	-
> > getgroups	i:ip	__getgroups	getgroups
> > gethostid	-	gethostid	i:	gethostid
> > gethostname	-	gethostname	i:bn
> > __gethostname	gethostname -getitimer	-
> > getitimer	i:ip	__getitimer	getitimer
> > getpeername	-	getpeername	i:ibN
> > __getpeername	getpeername getpid		-
> > getpid		Ei:	__getpid	getpid
> > getpriority	-	getpriority	i:ii
> > __getpriority	getpriority @@ -67,7 +66,6 @@ setgid
> > 	-	setgid		i:i	__setgid
> > setgid setgroups	-	setgroups	i:ip
> > setgroups sethostid	-	sethostid	i:i
> > sethostid sethostname	-	sethostname	i:pi
> > sethostname -setitimer	-	setitimer	i:ipp
> > __setitimer	setitimer setpgid		-
> > setpgrp		i:ii	__setpgid	setpgid
> > setpriority	-	setpriority	i:iii
> > __setpriority	setpriority setregid	-
> > setregid	i:ii	__setregid	setregid diff --git
> > a/sysdeps/unix/sysv/linux/getitimer.c
> > b/sysdeps/unix/sysv/linux/getitimer.c new file mode 100644 index
> > 0000000000..12f7963949 --- /dev/null +++
> > b/sysdeps/unix/sysv/linux/getitimer.c @@ -0,0 +1,59 @@ +/* getitimer
> > -- Get the state of an interval timer.  Linux/tv32 version.
> > +   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
> > +   <http://www.gnu.org/licenses/>.  */
> > +
> > +#include <time.h>
> > +#include <sys/time.h>
> > +#include <sys/types.h>
> > +#include <sysdep.h>
> > +#include <tv32-compat.h>
> > +
> > +int
> > +__getitimer64 (__itimer_which_t which, struct __itimerval64
> > *curr_value) +{
> > +#if __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64
> > +  return INLINE_SYSCALL_CALL (getitimer, which, curr_value);
> > +#else
> > +  struct __itimerval32 curr_value_32;
> > +  if (INLINE_SYSCALL_CALL (getitimer, which, &curr_value_32) == -1)
> > +    return -1;
> > +
> > +  /* Write all fields of 'curr_value' regardless of overflow.  */
> > +  curr_value->it_interval
> > +    = valid_timeval32_to_timeval64 (curr_value_32.it_interval);
> > +  curr_value->it_value
> > +    = valid_timeval32_to_timeval64 (curr_value_32.it_value);
> > +  return 0;
> > +#endif
> > +}
> > +
> > +#if __TIMESIZE != 64
> > +libc_hidden_def (__getitimer64)
> > +int
> > +__getitimer (__itimer_which_t which, struct itimerval *curr_value)
> > +{
> > +  struct __itimerval64 val64;
> > +
> > +  val64.it_interval
> > +    = valid_timeval_to_timeval64 (curr_value->it_interval);
> > +  val64.it_value
> > +    = valid_timeval_to_timeval64 (curr_value->it_value);
> > +
> > +  return __getitimer64 (which, &val64);
> > +}
> > +#endif
> > +weak_alias (__getitimer, getitimer)
> > diff --git a/sysdeps/unix/sysv/linux/setitimer.c
> > b/sysdeps/unix/sysv/linux/setitimer.c new file mode 100644
> > index 0000000000..238853dd33
> > --- /dev/null
> > +++ b/sysdeps/unix/sysv/linux/setitimer.c
> > @@ -0,0 +1,95 @@
> > +/* setitimer -- Set the state of an interval timer.  Linux/tv32
> > version.
> > +   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
> > +   <http://www.gnu.org/licenses/>.  */
> > +
> > +#include <time.h>
> > +#include <sys/time.h>
> > +#include <sys/types.h>
> > +#include <sysdep.h>
> > +#include <tv32-compat.h>
> > +
> > +int
> > +__setitimer64 (__itimer_which_t which,
> > +               const struct __itimerval64 *restrict new_value,
> > +               struct __itimerval64 *restrict old_value)
> > +{
> > +#if __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64
> > +  return INLINE_SYSCALL_CALL (setitimer, which, new_value,
> > old_value); +#else
> > +  struct __itimerval32 new_value_32;
> > +
> > +  if (! in_time_t_range (new_value->it_interval.tv_sec))
> > +  {
> > +    __set_errno (EOVERFLOW);
> > +    return -1;
> > +  }
> > +  new_value_32.it_interval
> > +    = valid_timeval64_to_timeval32 (new_value->it_interval);
> > +
> > +  if (! in_time_t_range (new_value->it_value.tv_sec))
> > +  {
> > +    __set_errno (EOVERFLOW);
> > +    return -1;
> > +  }
> > +  new_value_32.it_value
> > +    = valid_timeval64_to_timeval32 (new_value->it_value);
> > +
> > +  if (old_value == NULL)
> > +    return INLINE_SYSCALL_CALL (setitimer, which, &new_value_32,
> > NULL); +
> > +  struct __itimerval32 old_value_32;
> > +  if (INLINE_SYSCALL_CALL (setitimer, which, &new_value_32,
> > &old_value_32) == -1)
> > +    return -1;
> > +
> > +  /* Write all fields of 'old_value' regardless of overflow.  */
> > +  old_value->it_interval
> > +     = valid_timeval32_to_timeval64 (old_value_32.it_interval);
> > +  old_value->it_value
> > +     = valid_timeval32_to_timeval64 (old_value_32.it_value);
> > +  return 0;
> > +#endif
> > +}
> > +
> > +#if __TIMESIZE != 64
> > +libc_hidden_def (__setitimer64)
> > +int
> > +__setitimer (__itimer_which_t which,
> > +             const struct itimerval *restrict new_value,
> > +             struct itimerval *restrict old_value)
> > +{
> > +  int ret;
> > +  struct __itimerval64 new64, old64;
> > +
> > +  new64.it_interval
> > +    = valid_timeval_to_timeval64 (new_value->it_interval);
> > +  new64.it_value
> > +    = valid_timeval_to_timeval64 (new_value->it_value);
> > +
> > +  ret = __setitimer64 (which, &new64, old_value ? &old64 : NULL);
> > +
> > +  if (ret == 0 && old_value)
> > +    {
> > +      old_value->it_interval
> > +        = valid_timeval64_to_timeval (old64.it_interval);
> > +      old_value->it_value
> > +        = valid_timeval64_to_timeval (old64.it_value);
> > +    }
> > +
> > +  return ret;
> > +}
> > +#endif
> > +weak_alias (__setitimer, setitimer)
> > diff --git a/sysdeps/unix/sysv/linux/tv32-compat.h
> > b/sysdeps/unix/sysv/linux/tv32-compat.h new file mode 100644
> > index 0000000000..b8791b1db8
> > --- /dev/null
> > +++ b/sysdeps/unix/sysv/linux/tv32-compat.h
> > @@ -0,0 +1,31 @@
> > +/* Compatibility definitions for `struct timeval' with 32-bit
> > time_t.
> > +   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
> > +   <http://www.gnu.org/licenses/>.  */
> > +
> > +#ifndef _TV32_COMPAT_H
> > +#define _TV32_COMPAT_H 1
> > +
> > +#include <bits/types/time_t.h>
> > +
> > +/* Structures containing 'struct timeval' with 32-bit time_t.  */
> > +struct __itimerval32
> > +{
> > +  struct __timeval32 it_interval;
> > +  struct __timeval32 it_value;
> > +};
> > +
> > +#endif /* tv32-compat.h */  
> 
> Tested-by: Lukasz Majewski <lukma@denx.de>
> 
> ARM32 (armv7) with QEMU:
> https://github.com/lmajewski/meta-y2038/blob/master/README
> 

Are there any more comments regarding this patch set? Is it eligible
for pulling?

> Best regards,
> 
> Lukasz Majewski
> 
> --
> 
> DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
> Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email:
> lukma@denx.de




Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma@denx.de

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v4 1/8] sysv/linux: Rename alpha functions to be alpha specific
  2020-02-19 18:10 ` [PATCH v4 1/8] sysv/linux: Rename alpha functions to be alpha specific Alistair Francis
@ 2020-02-28 17:30   ` Adhemerval Zanella
  2020-02-28 17:52     ` Zack Weinberg
  0 siblings, 1 reply; 15+ messages in thread
From: Adhemerval Zanella @ 2020-02-28 17:30 UTC (permalink / raw)
  To: libc-alpha, Zack Weinberg



On 19/02/2020 15:10, Alistair Francis wrote:
> These functions are alpha specifc, rename them to be clear.
> 
> Let's also rename the header file from tv32-compat.h to
> alpha-tv32-compat.h. This is to avoid conflicts with the one we will
> introduce later.
> 
> Reviewed-by: Lukasz Majewski <lukma@denx.de>

My understanding is Zack has raise a strong objetion with this patch.
I would also like to make this patch move forward, so Zack do you
still have objections about this? If so, what do you propose instead?

> ---
>  .../alpha/{tv32-compat.h => alpha-tv32-compat.h} | 16 ++++++++--------
>  sysdeps/unix/sysv/linux/alpha/osf_adjtime.c      | 10 +++++-----
>  sysdeps/unix/sysv/linux/alpha/osf_getitimer.c    |  6 +++---
>  sysdeps/unix/sysv/linux/alpha/osf_getrusage.c    |  4 ++--
>  sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c |  4 ++--
>  sysdeps/unix/sysv/linux/alpha/osf_setitimer.c    | 10 +++++-----
>  sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c |  4 ++--
>  sysdeps/unix/sysv/linux/alpha/osf_utimes.c       |  6 +++---
>  sysdeps/unix/sysv/linux/alpha/osf_wait4.c        |  4 ++--
>  9 files changed, 32 insertions(+), 32 deletions(-)
>  rename sysdeps/unix/sysv/linux/alpha/{tv32-compat.h => alpha-tv32-compat.h} (88%)
> 
> diff --git a/sysdeps/unix/sysv/linux/alpha/tv32-compat.h b/sysdeps/unix/sysv/linux/alpha/alpha-tv32-compat.h
> similarity index 88%
> rename from sysdeps/unix/sysv/linux/alpha/tv32-compat.h
> rename to sysdeps/unix/sysv/linux/alpha/alpha-tv32-compat.h
> index 8e34ed1c1b..3073005c65 100644
> --- a/sysdeps/unix/sysv/linux/alpha/tv32-compat.h
> +++ b/sysdeps/unix/sysv/linux/alpha/alpha-tv32-compat.h
> @@ -70,13 +70,13 @@ struct rusage32
>     overflow, they write { INT32_MAX, TV_USEC_MAX } to the output.  */
>  
>  static inline struct timeval
> -valid_timeval32_to_timeval (const struct timeval32 tv)
> +alpha_valid_timeval32_to_timeval (const struct timeval32 tv)
>  {
>    return (struct timeval) { tv.tv_sec, tv.tv_usec };
>  }
>  
>  static inline struct timeval32
> -valid_timeval_to_timeval32 (const struct timeval tv64)
> +alpha_valid_timeval_to_timeval32 (const struct timeval tv64)
>  {
>    if (__glibc_unlikely (tv64.tv_sec > (time_t) INT32_MAX))
>      return (struct timeval32) { INT32_MAX, TV_USEC_MAX};
> @@ -84,27 +84,27 @@ valid_timeval_to_timeval32 (const struct timeval tv64)
>  }
>  
>  static inline struct timespec
> -valid_timeval32_to_timespec (const struct timeval32 tv)
> +alpha_valid_timeval32_to_timespec (const struct timeval32 tv)
>  {
>    return (struct timespec) { tv.tv_sec, tv.tv_usec * 1000 };
>  }
>  
>  static inline struct timeval32
> -valid_timespec_to_timeval32 (const struct timespec ts)
> +alpha_valid_timespec_to_timeval32 (const struct timespec ts)
>  {
>    return (struct timeval32) { (time_t) ts.tv_sec, ts.tv_nsec / 1000 };
>  }
>  
>  static inline void
> -rusage64_to_rusage32 (struct rusage32 *restrict r32,
> +alpha_rusage64_to_rusage32 (struct rusage32 *restrict r32,
>                        const struct rusage *restrict r64)
>  {
>    /* Make sure the entire output structure is cleared, including
>       padding and reserved fields.  */
>    memset (r32, 0, sizeof *r32);
>  
> -  r32->ru_utime    = valid_timeval_to_timeval32 (r64->ru_utime);
> -  r32->ru_stime    = valid_timeval_to_timeval32 (r64->ru_stime);
> +  r32->ru_utime    = alpha_valid_timeval_to_timeval32 (r64->ru_utime);
> +  r32->ru_stime    = alpha_valid_timeval_to_timeval32 (r64->ru_stime);
>    r32->ru_maxrss   = r64->ru_maxrss;
>    r32->ru_ixrss    = r64->ru_ixrss;
>    r32->ru_idrss    = r64->ru_idrss;
> @@ -121,4 +121,4 @@ rusage64_to_rusage32 (struct rusage32 *restrict r32,
>    r32->ru_nivcsw   = r64->ru_nivcsw;
>  }
>  
> -#endif /* tv32-compat.h */
> +#endif /* alpha-tv32-compat.h */
> diff --git a/sysdeps/unix/sysv/linux/alpha/osf_adjtime.c b/sysdeps/unix/sysv/linux/alpha/osf_adjtime.c
> index 9825a4734d..f0a1123639 100644
> --- a/sysdeps/unix/sysv/linux/alpha/osf_adjtime.c
> +++ b/sysdeps/unix/sysv/linux/alpha/osf_adjtime.c
> @@ -22,7 +22,7 @@
>  
>  #include <sys/time.h>
>  #include <sys/timex.h>
> -#include <tv32-compat.h>
> +#include <alpha-tv32-compat.h>
>  
>  struct timex32 {
>  	unsigned int modes;	/* mode selector */
> @@ -57,13 +57,13 @@ int
>  attribute_compat_text_section
>  __adjtime_tv32 (const struct timeval32 *itv, struct timeval32 *otv)
>  {
> -  struct timeval itv64 = valid_timeval32_to_timeval (*itv);
> +  struct timeval itv64 = alpha_valid_timeval32_to_timeval (*itv);
>    struct timeval otv64;
>  
>    if (__adjtime (&itv64, &otv64) == -1)
>      return -1;
>  
> -  *otv = valid_timeval_to_timeval32 (otv64);
> +  *otv = alpha_valid_timeval_to_timeval32 (otv64);
>    return 0;
>  }
>  
> @@ -91,7 +91,7 @@ __adjtimex_tv32 (struct timex32 *tx)
>    tx64.calcnt    = tx->calcnt;
>    tx64.errcnt    = tx->errcnt;
>    tx64.stbcnt    = tx->stbcnt;
> -  tx64.time      = valid_timeval32_to_timeval (tx->time);
> +  tx64.time      = alpha_valid_timeval32_to_timeval (tx->time);
>  
>    int status = __adjtimex (&tx64);
>    if (status < 0)
> @@ -116,7 +116,7 @@ __adjtimex_tv32 (struct timex32 *tx)
>    tx->calcnt    = tx64.calcnt;
>    tx->errcnt    = tx64.errcnt;
>    tx->stbcnt    = tx64.stbcnt;
> -  tx->time      = valid_timeval_to_timeval32 (tx64.time);
> +  tx->time      = alpha_valid_timeval_to_timeval32 (tx64.time);
>  
>    return status;
>  }
> diff --git a/sysdeps/unix/sysv/linux/alpha/osf_getitimer.c b/sysdeps/unix/sysv/linux/alpha/osf_getitimer.c
> index e9de2b287b..204d4ba796 100644
> --- a/sysdeps/unix/sysv/linux/alpha/osf_getitimer.c
> +++ b/sysdeps/unix/sysv/linux/alpha/osf_getitimer.c
> @@ -21,7 +21,7 @@
>  #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
>  
>  #include <sys/time.h>
> -#include <tv32-compat.h>
> +#include <alpha-tv32-compat.h>
>  
>  int
>  attribute_compat_text_section
> @@ -33,9 +33,9 @@ __getitimer_tv32 (int which, struct itimerval32 *curr_value)
>  
>    /* Write all fields of 'curr_value' regardless of overflow.  */
>    curr_value->it_interval
> -    = valid_timeval_to_timeval32 (curr_value_64.it_interval);
> +    = alpha_valid_timeval_to_timeval32 (curr_value_64.it_interval);
>    curr_value->it_value
> -    = valid_timeval_to_timeval32 (curr_value_64.it_value);
> +    = alpha_valid_timeval_to_timeval32 (curr_value_64.it_value);
>    return 0;
>  }
>  
> diff --git a/sysdeps/unix/sysv/linux/alpha/osf_getrusage.c b/sysdeps/unix/sysv/linux/alpha/osf_getrusage.c
> index 74c6fb49aa..be81994654 100644
> --- a/sysdeps/unix/sysv/linux/alpha/osf_getrusage.c
> +++ b/sysdeps/unix/sysv/linux/alpha/osf_getrusage.c
> @@ -22,7 +22,7 @@
>  
>  #include <sys/time.h>
>  #include <sys/resource.h>
> -#include <tv32-compat.h>
> +#include <alpha-tv32-compat.h>
>  
>  int
>  __getrusage_tv32 (int who, struct rusage32 *usage32)
> @@ -31,7 +31,7 @@ __getrusage_tv32 (int who, struct rusage32 *usage32)
>    if (__getrusage (who, &usage64) == -1)
>      return -1;
>  
> -  rusage64_to_rusage32 (usage32, &usage64);
> +  alpha_rusage64_to_rusage32 (usage32, &usage64);
>    return 0;
>  }
>  
> diff --git a/sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c b/sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c
> index df7f06765b..9ffda2fde3 100644
> --- a/sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c
> +++ b/sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c
> @@ -23,7 +23,7 @@
>  #include <string.h>
>  #include <time.h>
>  #include <sys/time.h>
> -#include <tv32-compat.h>
> +#include <alpha-tv32-compat.h>
>  
>  /* Get the current time of day and timezone information putting it
>     into *TV and *TZ.  */
> @@ -38,7 +38,7 @@ __gettimeofday_tv32 (struct timeval32 *restrict tv32, void *restrict tz)
>    struct timespec ts;
>    __clock_gettime (CLOCK_REALTIME, &ts);
>  
> -  *tv32 = valid_timespec_to_timeval32 (ts);
> +  *tv32 = alpha_valid_timespec_to_timeval32 (ts);
>    return 0;
>  }
>  
> diff --git a/sysdeps/unix/sysv/linux/alpha/osf_setitimer.c b/sysdeps/unix/sysv/linux/alpha/osf_setitimer.c
> index 7df2d1b71c..726dfc8b0e 100644
> --- a/sysdeps/unix/sysv/linux/alpha/osf_setitimer.c
> +++ b/sysdeps/unix/sysv/linux/alpha/osf_setitimer.c
> @@ -21,7 +21,7 @@
>  #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
>  
>  #include <sys/time.h>
> -#include <tv32-compat.h>
> +#include <alpha-tv32-compat.h>
>  
>  int
>  attribute_compat_text_section
> @@ -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_timeval32_to_timeval (new_value->it_interval);
> +    = alpha_valid_timeval32_to_timeval (new_value->it_interval);
>    new_value_64.it_value
> -    = valid_timeval32_to_timeval (new_value->it_value);
> +    = alpha_valid_timeval32_to_timeval (new_value->it_value);
>  
>    if (old_value == NULL)
>      return __setitimer (which, &new_value_64, NULL);
> @@ -43,9 +43,9 @@ __setitimer_tv32 (int which, const struct itimerval32 *restrict new_value,
>  
>    /* Write all fields of 'old_value' regardless of overflow.  */
>    old_value->it_interval
> -     = valid_timeval_to_timeval32 (old_value_64.it_interval);
> +     = alpha_valid_timeval_to_timeval32 (old_value_64.it_interval);
>    old_value->it_value
> -     = valid_timeval_to_timeval32 (old_value_64.it_value);
> +     = alpha_valid_timeval_to_timeval32 (old_value_64.it_value);
>    return 0;
>  }
>  
> diff --git a/sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c b/sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c
> index 6e17a95a47..044363e079 100644
> --- a/sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c
> +++ b/sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c
> @@ -23,7 +23,7 @@
>  #include <sys/time.h>
>  #include <time.h>
>  #include <errno.h>
> -#include <tv32-compat.h>
> +#include <alpha-tv32-compat.h>
>  
>  /* Set the current time of day and timezone information.
>     This call is restricted to the super-user.  */
> @@ -42,7 +42,7 @@ __settimeofday_tv32 (const struct timeval32 *tv32,
>        return __settimezone (tz);
>      }
>  
> -  struct timespec ts = valid_timeval32_to_timespec (*tv32);
> +  struct timespec ts = alpha_valid_timeval32_to_timespec (*tv32);
>    return __clock_settime (CLOCK_REALTIME, &ts);
>  }
>  
> diff --git a/sysdeps/unix/sysv/linux/alpha/osf_utimes.c b/sysdeps/unix/sysv/linux/alpha/osf_utimes.c
> index 6c3fad0132..8ad9fb567c 100644
> --- a/sysdeps/unix/sysv/linux/alpha/osf_utimes.c
> +++ b/sysdeps/unix/sysv/linux/alpha/osf_utimes.c
> @@ -21,15 +21,15 @@
>  #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
>  
>  #include <sys/time.h>
> -#include <tv32-compat.h>
> +#include <alpha-tv32-compat.h>
>  
>  int
>  attribute_compat_text_section
>  __utimes_tv32 (const char *filename, const struct timeval32 times32[2])
>  {
>    struct timeval times[2];
> -  times[0] = valid_timeval32_to_timeval (times32[0]);
> -  times[1] = valid_timeval32_to_timeval (times32[1]);
> +  times[0] = alpha_valid_timeval32_to_timeval (times32[0]);
> +  times[1] = alpha_valid_timeval32_to_timeval (times32[1]);
>    return __utimes (filename, times);
>  }
>  
> diff --git a/sysdeps/unix/sysv/linux/alpha/osf_wait4.c b/sysdeps/unix/sysv/linux/alpha/osf_wait4.c
> index 6af8347871..c664e8e93f 100644
> --- a/sysdeps/unix/sysv/linux/alpha/osf_wait4.c
> +++ b/sysdeps/unix/sysv/linux/alpha/osf_wait4.c
> @@ -23,7 +23,7 @@
>  #include <sys/time.h>
>  #include <sys/resource.h>
>  #include <sys/wait.h>
> -#include <tv32-compat.h>
> +#include <alpha-tv32-compat.h>
>  
>  pid_t
>  attribute_compat_text_section
> @@ -33,7 +33,7 @@ __wait4_tv32 (pid_t pid, int *status, int options, struct rusage32 *usage32)
>    pid_t child = __wait4 (pid, status, options, &usage64);
>  
>    if (child >= 0 && usage32 != NULL)
> -    rusage64_to_rusage32 (usage32, &usage64);
> +    alpha_rusage64_to_rusage32 (usage32, &usage64);
>    return child;
>  }
>  
> 

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

* Re: [PATCH v4 1/8] sysv/linux: Rename alpha functions to be alpha specific
  2020-02-28 17:30   ` Adhemerval Zanella
@ 2020-02-28 17:52     ` Zack Weinberg
  0 siblings, 0 replies; 15+ messages in thread
From: Zack Weinberg @ 2020-02-28 17:52 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: GNU C Library

On Fri, Feb 28, 2020 at 12:30 PM Adhemerval Zanella
<adhemerval.zanella@linaro.org> wrote:
> On 19/02/2020 15:10, Alistair Francis wrote:
> > These functions are alpha specifc, rename them to be clear.
> >
> > Let's also rename the header file from tv32-compat.h to
> > alpha-tv32-compat.h. This is to avoid conflicts with the one we will
> > introduce later.
> >
> > Reviewed-by: Lukasz Majewski <lukma@denx.de>
>
> My understanding is Zack has raise a strong objetion with this patch.
> I would also like to make this patch move forward, so Zack do you
> still have objections about this? If so, what do you propose instead?

I want alpha to use the same tv32-compat.h as all the other
architectures that need these conversions. I thought the previous
round of discussion had come up with a plan to make that happen, so
I'm surprised to see it hasn't.  What happened there?

zw

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

end of thread, other threads:[~2020-02-28 17:53 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-19 18:10 [PATCH v4 0/8] Always use 32-bit time_t for certain syscalls Alistair Francis
2020-02-19 18:10 ` [PATCH v4 1/8] sysv/linux: Rename alpha functions to be alpha specific Alistair Francis
2020-02-28 17:30   ` Adhemerval Zanella
2020-02-28 17:52     ` Zack Weinberg
2020-02-19 18:10 ` [PATCH v4 2/8] time: Add a timeval with a 32-bit tv_sec and tv_usec Alistair Francis
2020-02-19 18:10 ` [PATCH v4 3/8] time: Add a __itimerval64 struct Alistair Francis
2020-02-19 18:10 ` [PATCH v4 4/8] sysv: Define __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64 Alistair Francis
2020-02-19 18:10 ` [PATCH v4 5/8] linux: Use long time_t __getitimer/__setitimer Alistair Francis
2020-02-21 10:03   ` Lukasz Majewski
2020-02-28 16:56     ` Lukasz Majewski
2020-02-19 18:10 ` [PATCH v4 6/8] resource: Add a __rusage64 struct Alistair Francis
2020-02-19 18:10 ` [PATCH v4 7/8] linux: Use long time_t for wait4/getrusage Alistair Francis
2020-02-21 10:08   ` Lukasz Majewski
2020-02-19 18:10 ` [PATCH v4 8/8] sysv/alpha: Use generic __timeval32 and helpers Alistair Francis
2020-02-21  9:52   ` Lukasz Majewski

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