[RFC,05/10] y2038: Convert pthread_* functions to support 64 bit time

Message ID 20200707150827.20899-6-lukma@denx.de
State New
Headers show
Series
  • y2038: nptl: futex: Provide support for futex_time64
Related show

Commit Message

Lukasz Majewski July 7, 2020, 3:08 p.m.
Following function are converted to support 64 bit abstime parameter on
archs with __TIMESIZE != 64 and __WORDSIZE == 32:

pthread_cond_timedwait
pthread_cond_clockwait
pthread_mutex_clocklock
pthread_mutex_timedlock
pthread_clockjoin_np
pthread_timedjoin_np
pthread_rwlock_clockrdlock
pthread_rwlock_clockwrlock
pthread_rwlock_timedrdlock
pthread_rwlock_timedwrlock
---
 nptl/pthreadP.h                   | 53 ++++++++++++++++++++++++++++++-
 nptl/pthread_clockjoin.c          | 22 +++++++++++--
 nptl/pthread_cond_wait.c          | 46 +++++++++++++++++++++++----
 nptl/pthread_join_common.c        | 11 ++++---
 nptl/pthread_mutex_timedlock.c    | 39 ++++++++++++++++++-----
 nptl/pthread_rwlock_clockrdlock.c | 21 ++++++++++--
 nptl/pthread_rwlock_clockwrlock.c | 21 ++++++++++--
 nptl/pthread_rwlock_common.c      |  4 +--
 nptl/pthread_rwlock_timedrdlock.c | 21 ++++++++++--
 nptl/pthread_rwlock_timedwrlock.c | 21 ++++++++++--
 nptl/pthread_timedjoin.c          | 20 ++++++++++--
 11 files changed, 245 insertions(+), 34 deletions(-)

-- 
2.20.1

Patch

diff --git a/nptl/pthreadP.h b/nptl/pthreadP.h
index 6f94d6be31..cab4adf4a1 100644
--- a/nptl/pthreadP.h
+++ b/nptl/pthreadP.h
@@ -458,6 +458,57 @@  extern int __pthread_cond_init (pthread_cond_t *cond,
 libc_hidden_proto (__pthread_cond_init)
 extern int __pthread_cond_signal (pthread_cond_t *cond);
 extern int __pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex);
+
+#if __TIMESIZE == 64
+# define __pthread_cond_timedwait64 __pthread_cond_timedwait
+# define __pthread_cond_clockwait64 __pthread_cond_clockwait
+# define __pthread_mutex_clocklock64 __pthread_mutex_clocklock
+# define __pthread_mutex_timedlock64 __pthread_mutex_timedlock
+# define __pthread_clockjoin_np64 __pthread_clockjoin_np
+# define __pthread_timedjoin_np64 __pthread_timedjoin_np
+# define __pthread_rwlock_clockrdlock64 __pthread_rwlock_clockrdlock
+# define __pthread_rwlock_clockwrlock64 __pthread_rwlock_clockwrlock
+# define __pthread_rwlock_timedrdlock64 __pthread_rwlock_timedrdlock
+# define __pthread_rwlock_timedwrlock64 __pthread_rwlock_timedwrlock
+#else
+extern int __pthread_cond_timedwait64 (pthread_cond_t *cond,
+				       pthread_mutex_t *mutex,
+				       const struct __timespec64 *abstime);
+libc_hidden_proto (__pthread_cond_timedwait64)
+extern int __pthread_cond_clockwait64 (pthread_cond_t *cond,
+				       pthread_mutex_t *mutex,
+				       clockid_t clockid,
+				       const struct __timespec64 *abstime);
+libc_hidden_proto (__pthread_cond_clockwait64)
+extern int __pthread_mutex_clocklock64 (pthread_mutex_t *mutex,
+					clockid_t clockid,
+					const struct __timespec64 *abstime);
+libc_hidden_proto (__pthread_mutex_clocklock64)
+extern int __pthread_mutex_timedlock64 (pthread_mutex_t *mutex,
+					const struct __timespec64 *abstime);
+libc_hidden_proto (__pthread_mutex_timedlock64)
+extern int __pthread_clockjoin_np64 (pthread_t threadid, void **thread_return,
+				     clockid_t clockid,
+				     const struct __timespec64 *abstime);
+libc_hidden_proto (__pthread_clockjoin_np64)
+extern int __pthread_timedjoin_np64 (pthread_t threadid, void **thread_return,
+				     const struct __timespec64 *abstime);
+libc_hidden_proto (__pthread_timedjoin_np64)
+extern int __pthread_rwlock_clockrdlock64 (pthread_rwlock_t *rwlock,
+					   clockid_t clockid,
+					   const struct __timespec64 *abstime);
+libc_hidden_proto (__pthread_rwlock_clockrdlock64)
+extern int __pthread_rwlock_clockwrlock64 (pthread_rwlock_t *rwlock,
+					   clockid_t clockid,
+					   const struct __timespec64 *abstime);
+libc_hidden_proto (__pthread_rwlock_clockwrlock64)
+extern int __pthread_rwlock_timedrdlock64 (pthread_rwlock_t *rwlock,
+					   const struct __timespec64 *abstime);
+libc_hidden_proto (__pthread_rwlock_timedrdlock64)
+extern int __pthread_rwlock_timedwrlock64 (pthread_rwlock_t *rwlock,
+					   const struct __timespec64 *abstime);
+libc_hidden_proto (__pthread_rwlock_timedwrlock64)
+#endif
 extern int __pthread_cond_timedwait (pthread_cond_t *cond,
 				     pthread_mutex_t *mutex,
 				     const struct timespec *abstime);
@@ -488,7 +539,7 @@  extern int __pthread_enable_asynccancel (void) attribute_hidden;
 extern void __pthread_disable_asynccancel (int oldtype) attribute_hidden;
 extern void __pthread_testcancel (void);
 extern int __pthread_clockjoin_ex (pthread_t, void **, clockid_t,
-				   const struct timespec *, bool)
+				   const struct __timespec64 *, bool)
   attribute_hidden;
 extern int __pthread_sigmask (int, const sigset_t *, sigset_t *);
 libc_hidden_proto (__pthread_sigmask);
diff --git a/nptl/pthread_clockjoin.c b/nptl/pthread_clockjoin.c
index a3e7f37e3b..c3a92e5e0b 100644
--- a/nptl/pthread_clockjoin.c
+++ b/nptl/pthread_clockjoin.c
@@ -16,14 +16,32 @@ 
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#include <time.h>
 #include "pthreadP.h"
 
+int
+__pthread_clockjoin_np64 (pthread_t threadid, void **thread_return,
+			  clockid_t clockid,
+			  const struct __timespec64 *abstime)
+{
+  return __pthread_clockjoin_ex (threadid, thread_return,
+				 clockid, abstime, true);
+}
+
+#if __TIMESIZE != 64
+libc_hidden_def (__pthread_clockjoin_np64)
+
 int
 __pthread_clockjoin_np (pthread_t threadid, void **thread_return,
 			clockid_t clockid,
 			const struct timespec *abstime)
 {
-  return __pthread_clockjoin_ex (threadid, thread_return,
-                                 clockid, abstime, true);
+  struct __timespec64 ts64;
+  if (abstime != NULL)
+    ts64 = valid_timespec_to_timespec64 (*abstime);
+
+  return __pthread_clockjoin_np64 (threadid, thread_return,
+                                   clockid, abstime != NULL ? &ts64 : NULL);
 }
+#endif
 weak_alias (__pthread_clockjoin_np, pthread_clockjoin_np)
diff --git a/nptl/pthread_cond_wait.c b/nptl/pthread_cond_wait.c
index 85ddbc1011..69b18b1316 100644
--- a/nptl/pthread_cond_wait.c
+++ b/nptl/pthread_cond_wait.c
@@ -379,7 +379,7 @@  __condvar_cleanup_waiting (void *arg)
 static __always_inline int
 __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex,
     clockid_t clockid,
-    const struct timespec *abstime)
+    const struct __timespec64 *abstime)
 {
   const int maxspin = 0;
   int err;
@@ -640,8 +640,8 @@  __pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex)
 
 /* See __pthread_cond_wait_common.  */
 int
-__pthread_cond_timedwait (pthread_cond_t *cond, pthread_mutex_t *mutex,
-    const struct timespec *abstime)
+__pthread_cond_timedwait64 (pthread_cond_t *cond, pthread_mutex_t *mutex,
+			    const struct __timespec64 *abstime)
 {
   /* Check parameter validity.  This should also tell the compiler that
      it can assume that abstime is not NULL.  */
@@ -655,6 +655,23 @@  __pthread_cond_timedwait (pthread_cond_t *cond, pthread_mutex_t *mutex,
                     ? CLOCK_MONOTONIC : CLOCK_REALTIME;
   return __pthread_cond_wait_common (cond, mutex, clockid, abstime);
 }
+
+#if __TIMESIZE != 64
+libc_hidden_def (__pthread_cond_timedwait64)
+
+int
+__pthread_cond_timedwait (pthread_cond_t *cond, pthread_mutex_t *mutex,
+                          const struct timespec *abstime)
+{
+  struct __timespec64 ts64;
+  if (abstime != NULL)
+    ts64 = valid_timespec_to_timespec64 (*abstime);
+
+  return __pthread_cond_timedwait64 (cond, mutex,
+                                     abstime != NULL ? &ts64 : NULL);
+}
+#endif
+
 versioned_symbol (libpthread, __pthread_cond_wait, pthread_cond_wait,
 		  GLIBC_2_3_2);
 versioned_symbol (libpthread, __pthread_cond_timedwait, pthread_cond_timedwait,
@@ -662,9 +679,9 @@  versioned_symbol (libpthread, __pthread_cond_timedwait, pthread_cond_timedwait,
 
 /* See __pthread_cond_wait_common.  */
 int
-__pthread_cond_clockwait (pthread_cond_t *cond, pthread_mutex_t *mutex,
-			  clockid_t clockid,
-			  const struct timespec *abstime)
+__pthread_cond_clockwait64 (pthread_cond_t *cond, pthread_mutex_t *mutex,
+                            clockid_t clockid,
+                            const struct __timespec64 *abstime)
 {
   /* Check parameter validity.  This should also tell the compiler that
      it can assume that abstime is not NULL.  */
@@ -676,4 +693,21 @@  __pthread_cond_clockwait (pthread_cond_t *cond, pthread_mutex_t *mutex,
 
   return __pthread_cond_wait_common (cond, mutex, clockid, abstime);
 }
+
+#if __TIMESIZE != 64
+libc_hidden_def (__pthread_cond_clockwait64)
+
+int
+__pthread_cond_clockwait (pthread_cond_t *cond, pthread_mutex_t *mutex,
+                          clockid_t clockid,
+                          const struct timespec *abstime)
+{
+  struct __timespec64 ts64;
+  if (abstime != NULL)
+    ts64 = valid_timespec_to_timespec64 (*abstime);
+
+  return __pthread_cond_clockwait64(cond, mutex, clockid,
+				    abstime != NULL ? &ts64 : NULL);
+}
+#endif
 weak_alias (__pthread_cond_clockwait, pthread_cond_clockwait);
diff --git a/nptl/pthread_join_common.c b/nptl/pthread_join_common.c
index a96ceafde4..38a078fd23 100644
--- a/nptl/pthread_join_common.c
+++ b/nptl/pthread_join_common.c
@@ -37,7 +37,8 @@  cleanup (void *arg)
    afterwards.  The kernel up to version 3.16.3 does not use the private futex
    operations for futex wake-up when the clone terminates.  */
 static int
-clockwait_tid (pid_t *tidp, clockid_t clockid, const struct timespec *abstime)
+clockwait_tid (pid_t *tidp, clockid_t clockid,
+               const struct __timespec64 *abstime)
 {
   pid_t tid;
 
@@ -47,11 +48,11 @@  clockwait_tid (pid_t *tidp, clockid_t clockid, const struct timespec *abstime)
   /* Repeat until thread terminated.  */
   while ((tid = *tidp) != 0)
     {
-      struct timespec rt;
+      struct __timespec64 rt;
 
       /* Get the current time. This can only fail if clockid is
          invalid. */
-      if (__glibc_unlikely (__clock_gettime (clockid, &rt)))
+      if (__glibc_unlikely (__clock_gettime64 (clockid, &rt)))
         return EINVAL;
 
       /* Compute relative timeout.  */
@@ -80,8 +81,8 @@  clockwait_tid (pid_t *tidp, clockid_t clockid, const struct timespec *abstime)
 
 int
 __pthread_clockjoin_ex (pthread_t threadid, void **thread_return,
-			clockid_t clockid,
-			const struct timespec *abstime, bool block)
+                        clockid_t clockid,
+                        const struct __timespec64 *abstime, bool block)
 {
   struct pthread *pd = (struct pthread *) threadid;
 
diff --git a/nptl/pthread_mutex_timedlock.c b/nptl/pthread_mutex_timedlock.c
index 8ae814b984..2438c61aa4 100644
--- a/nptl/pthread_mutex_timedlock.c
+++ b/nptl/pthread_mutex_timedlock.c
@@ -45,7 +45,7 @@ 
 int
 __pthread_mutex_clocklock_common (pthread_mutex_t *mutex,
 				  clockid_t clockid,
-				  const struct timespec *abstime)
+				  const struct __timespec64 *abstime)
 {
   int oldval;
   pid_t id = THREAD_GETMEM (THREAD_SELF, tid);
@@ -543,10 +543,10 @@  __pthread_mutex_clocklock_common (pthread_mutex_t *mutex,
 			goto failpp;
 		      }
 
-		    struct timespec rt;
+		    struct __timespec64 rt;
 
 		    /* Get the current time.  */
-		    __clock_gettime (CLOCK_REALTIME, &rt);
+		    __clock_gettime64 (CLOCK_REALTIME, &rt);
 
 		    /* Compute relative timeout.  */
 		    rt.tv_sec = abstime->tv_sec - rt.tv_sec;
@@ -599,9 +599,9 @@  __pthread_mutex_clocklock_common (pthread_mutex_t *mutex,
 }
 
 int
-__pthread_mutex_clocklock (pthread_mutex_t *mutex,
-			   clockid_t clockid,
-			   const struct timespec *abstime)
+__pthread_mutex_clocklock64 (pthread_mutex_t *mutex,
+                             clockid_t clockid,
+                             const struct __timespec64 *abstime)
 {
   if (__glibc_unlikely (!lll_futex_supported_clockid (clockid)))
     return EINVAL;
@@ -609,13 +609,36 @@  __pthread_mutex_clocklock (pthread_mutex_t *mutex,
   LIBC_PROBE (mutex_clocklock_entry, 3, mutex, clockid, abstime);
   return __pthread_mutex_clocklock_common (mutex, clockid, abstime);
 }
+
+#if __TIMESIZE != 64
+libc_hidden_def (__pthread_mutex_clocklock64)
+int
+__pthread_mutex_clocklock (pthread_mutex_t *mutex,
+                           clockid_t clockid,
+                           const struct timespec *abstime)
+{
+  struct __timespec64 ts64 = valid_timespec_to_timespec64 (*abstime);
+  return __pthread_mutex_clocklock64 (mutex, clockid, &ts64);
+}
+#endif
 weak_alias (__pthread_mutex_clocklock, pthread_mutex_clocklock)
 
 int
-__pthread_mutex_timedlock (pthread_mutex_t *mutex,
-			   const struct timespec *abstime)
+__pthread_mutex_timedlock64 (pthread_mutex_t *mutex,
+                             const struct __timespec64 *abstime)
 {
   LIBC_PROBE (mutex_timedlock_entry, 2, mutex, abstime);
   return __pthread_mutex_clocklock_common (mutex, CLOCK_REALTIME, abstime);
 }
+
+#if __TIMESIZE != 64
+libc_hidden_def (__pthread_mutex_timedlock64)
+int
+__pthread_mutex_timedlock (pthread_mutex_t *mutex,
+                           const struct timespec *abstime)
+{
+  struct __timespec64 ts64 = valid_timespec_to_timespec64 (*abstime);
+  return __pthread_mutex_timedlock64 (mutex, &ts64);
+}
+#endif
 weak_alias (__pthread_mutex_timedlock, pthread_mutex_timedlock)
diff --git a/nptl/pthread_rwlock_clockrdlock.c b/nptl/pthread_rwlock_clockrdlock.c
index 4cedfd1dcd..bb0a0b0d16 100644
--- a/nptl/pthread_rwlock_clockrdlock.c
+++ b/nptl/pthread_rwlock_clockrdlock.c
@@ -21,8 +21,25 @@ 
 
 /* See pthread_rwlock_common.c.  */
 int
-pthread_rwlock_clockrdlock (pthread_rwlock_t *rwlock, clockid_t clockid,
-			    const struct timespec *abstime)
+__pthread_rwlock_clockrdlock64 (pthread_rwlock_t *rwlock, clockid_t clockid,
+                                const struct __timespec64 *abstime)
 {
   return __pthread_rwlock_rdlock_full (rwlock, clockid, abstime);
 }
+
+#if __TIMESIZE != 64
+libc_hidden_def (__pthread_rwlock_clockrdlock64)
+
+int
+__pthread_rwlock_clockrdlock (pthread_rwlock_t *rwlock, clockid_t clockid,
+                              const struct timespec *abstime)
+{
+  struct __timespec64 ts64;
+  if (abstime != NULL)
+    ts64 = valid_timespec_to_timespec64 (*abstime);
+
+  return __pthread_rwlock_clockrdlock64 (rwlock, clockid,
+                                         abstime != NULL ? &ts64 : NULL);
+}
+#endif
+weak_alias (__pthread_rwlock_clockrdlock, pthread_rwlock_clockrdlock)
diff --git a/nptl/pthread_rwlock_clockwrlock.c b/nptl/pthread_rwlock_clockwrlock.c
index 7a954cf529..742fa04dbc 100644
--- a/nptl/pthread_rwlock_clockwrlock.c
+++ b/nptl/pthread_rwlock_clockwrlock.c
@@ -21,8 +21,25 @@ 
 
 /* See pthread_rwlock_common.c.  */
 int
-pthread_rwlock_clockwrlock (pthread_rwlock_t *rwlock, clockid_t clockid,
-			    const struct timespec *abstime)
+__pthread_rwlock_clockwrlock64 (pthread_rwlock_t *rwlock, clockid_t clockid,
+                                const struct __timespec64 *abstime)
 {
   return __pthread_rwlock_wrlock_full (rwlock, clockid, abstime);
 }
+
+#if __TIMESIZE != 64
+libc_hidden_def (__pthread_rwlock_clockwrlock64)
+
+int
+__pthread_rwlock_clockwrlock (pthread_rwlock_t *rwlock, clockid_t clockid,
+                              const struct timespec *abstime)
+{
+  struct __timespec64 ts64;
+  if (abstime != NULL)
+    ts64 = valid_timespec_to_timespec64 (*abstime);
+
+  return __pthread_rwlock_clockwrlock64 (rwlock, clockid,
+                                         abstime != NULL ? &ts64 : NULL);
+}
+#endif
+weak_alias (__pthread_rwlock_clockwrlock, pthread_rwlock_clockwrlock)
diff --git a/nptl/pthread_rwlock_common.c b/nptl/pthread_rwlock_common.c
index 3fbc66ded2..438cf2f74c 100644
--- a/nptl/pthread_rwlock_common.c
+++ b/nptl/pthread_rwlock_common.c
@@ -280,7 +280,7 @@  __pthread_rwlock_rdunlock (pthread_rwlock_t *rwlock)
 static __always_inline int
 __pthread_rwlock_rdlock_full (pthread_rwlock_t *rwlock,
     clockid_t clockid,
-    const struct timespec *abstime)
+    const struct __timespec64 *abstime)
 {
   unsigned int r;
 
@@ -587,7 +587,7 @@  __pthread_rwlock_wrunlock (pthread_rwlock_t *rwlock)
 static __always_inline int
 __pthread_rwlock_wrlock_full (pthread_rwlock_t *rwlock,
     clockid_t clockid,
-    const struct timespec *abstime)
+    const struct __timespec64 *abstime)
 {
   /* Make sure any passed in clockid and timeout value are valid.  Note that
      the previous implementation assumed that this check *must* not be
diff --git a/nptl/pthread_rwlock_timedrdlock.c b/nptl/pthread_rwlock_timedrdlock.c
index c5d8aee909..7e808439a6 100644
--- a/nptl/pthread_rwlock_timedrdlock.c
+++ b/nptl/pthread_rwlock_timedrdlock.c
@@ -20,8 +20,25 @@ 
 
 /* See pthread_rwlock_common.c.  */
 int
-pthread_rwlock_timedrdlock (pthread_rwlock_t *rwlock,
-    const struct timespec *abstime)
+__pthread_rwlock_timedrdlock64 (pthread_rwlock_t *rwlock,
+                                const struct __timespec64 *abstime)
 {
   return __pthread_rwlock_rdlock_full (rwlock, CLOCK_REALTIME, abstime);
 }
+
+#if __TIMESIZE != 64
+libc_hidden_def (__pthread_rwlock_timedrdlock64)
+
+int
+__pthread_rwlock_timedrdlock (pthread_rwlock_t *rwlock,
+                              const struct timespec *abstime)
+{
+  struct __timespec64 ts64;
+  if (abstime != NULL)
+    ts64 = valid_timespec_to_timespec64 (*abstime);
+
+  return  __pthread_rwlock_timedrdlock64 (rwlock,
+                                          abstime != NULL ? &ts64 : NULL);
+}
+#endif
+weak_alias (__pthread_rwlock_timedrdlock, pthread_rwlock_timedrdlock)
diff --git a/nptl/pthread_rwlock_timedwrlock.c b/nptl/pthread_rwlock_timedwrlock.c
index ccee8b77d9..8160c18819 100644
--- a/nptl/pthread_rwlock_timedwrlock.c
+++ b/nptl/pthread_rwlock_timedwrlock.c
@@ -20,8 +20,25 @@ 
 
 /* See pthread_rwlock_common.c.  */
 int
-pthread_rwlock_timedwrlock (pthread_rwlock_t *rwlock,
-    const struct timespec *abstime)
+__pthread_rwlock_timedwrlock64 (pthread_rwlock_t *rwlock,
+                                const struct __timespec64 *abstime)
 {
   return __pthread_rwlock_wrlock_full (rwlock, CLOCK_REALTIME, abstime);
 }
+
+#if __TIMESIZE != 64
+libc_hidden_def (__pthread_rwlock_timedwrlock64)
+
+int
+__pthread_rwlock_timedwrlock (pthread_rwlock_t *rwlock,
+                              const struct timespec *abstime)
+{
+  struct __timespec64 ts64;
+  if (abstime != NULL)
+    ts64 = valid_timespec_to_timespec64 (*abstime);
+
+  return __pthread_rwlock_timedwrlock64 (rwlock,
+                                         abstime != NULL ? &ts64 : NULL);
+}
+#endif
+weak_alias (__pthread_rwlock_timedwrlock, pthread_rwlock_timedwrlock)
diff --git a/nptl/pthread_timedjoin.c b/nptl/pthread_timedjoin.c
index dd7038dcf7..a6c2bbae53 100644
--- a/nptl/pthread_timedjoin.c
+++ b/nptl/pthread_timedjoin.c
@@ -19,10 +19,26 @@ 
 #include "pthreadP.h"
 
 int
-__pthread_timedjoin_np (pthread_t threadid, void **thread_return,
-			const struct timespec *abstime)
+__pthread_timedjoin_np64 (pthread_t threadid, void **thread_return,
+                          const struct __timespec64 *abstime)
 {
   return __pthread_clockjoin_ex (threadid, thread_return,
                                  CLOCK_REALTIME, abstime, true);
 }
+
+#if __TIMESIZE != 64
+libc_hidden_def (__pthread_timedjoin_np64)
+
+int
+__pthread_timedjoin_np (pthread_t threadid, void **thread_return,
+                        const struct timespec *abstime)
+{
+  struct __timespec64 ts64;
+  if (abstime != NULL)
+    ts64 = valid_timespec_to_timespec64 (*abstime);
+
+  return __pthread_timedjoin_np64 (threadid, thread_return,
+                                   abstime != NULL ? &ts64 : NULL);
+}
+#endif
 weak_alias (__pthread_timedjoin_np, pthread_timedjoin_np)