[RFC,06/10] y2038: Convert sem_{timed|clock}wait to support 64 bit timeout

Message ID 20200707150827.20899-7-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.
The conversion was to:
- Replace struct timespec with struct __timespec64
- Provide aliases to __sem_* functions
- Introduce Y2038 safe versions of __sem_timedwait64 and __sem_clockwait64
---
 nptl/sem_clockwait.c  | 21 +++++++++++++++++++--
 nptl/sem_timedwait.c  | 18 +++++++++++++++++-
 nptl/sem_waitcommon.c |  4 ++--
 nptl/semaphoreP.h     | 12 ++++++++++++
 4 files changed, 50 insertions(+), 5 deletions(-)

-- 
2.20.1

Patch

diff --git a/nptl/sem_clockwait.c b/nptl/sem_clockwait.c
index b9bae75183..86ce18ee2b 100644
--- a/nptl/sem_clockwait.c
+++ b/nptl/sem_clockwait.c
@@ -20,10 +20,11 @@ 
 
 #include <time.h>
 #include "sem_waitcommon.c"
+#include "semaphoreP.h"
 
 int
-sem_clockwait (sem_t *sem, clockid_t clockid,
-	       const struct timespec *abstime)
+__sem_clockwait64 (sem_t *sem, clockid_t clockid,
+		   const struct __timespec64 *abstime)
 {
   /* Check that supplied clockid is one we support, even if we don't end up
      waiting.  */
@@ -44,3 +45,19 @@  sem_clockwait (sem_t *sem, clockid_t clockid,
   else
     return __new_sem_wait_slow ((struct new_sem *) sem, clockid, abstime);
 }
+
+#if __TIMESIZE != 64
+libc_hidden_def (__sem_timedwait64)
+
+int
+__sem_clockwait (sem_t *sem, clockid_t clockid,
+		 const struct timespec *abstime)
+{
+  struct __timespec64 ts64;
+  if (abstime != NULL)
+    ts64 = valid_timespec_to_timespec64 (*abstime);
+
+  return __sem_clockwait64 (sem, clockid, abstime != NULL ? &ts64 : NULL);
+}
+#endif
+weak_alias (__sem_clockwait, sem_clockwait)
diff --git a/nptl/sem_timedwait.c b/nptl/sem_timedwait.c
index 99c11bf20e..0ffb56ec67 100644
--- a/nptl/sem_timedwait.c
+++ b/nptl/sem_timedwait.c
@@ -19,11 +19,12 @@ 
 
 #include <time.h>
 #include "sem_waitcommon.c"
+#include "semaphoreP.h"
 
 /* This is in a separate file because because sem_timedwait is only provided
    if __USE_XOPEN2K is defined.  */
 int
-sem_timedwait (sem_t *sem, const struct timespec *abstime)
+__sem_timedwait64 (sem_t *sem, const struct __timespec64 *abstime)
 {
   if (! valid_nanoseconds (abstime->tv_nsec))
     {
@@ -40,3 +41,18 @@  sem_timedwait (sem_t *sem, const struct timespec *abstime)
     return __new_sem_wait_slow ((struct new_sem *) sem,
 				CLOCK_REALTIME, abstime);
 }
+
+#if __TIMESIZE != 64
+libc_hidden_def (__sem_timedwait64)
+
+int
+__sem_timedwait (sem_t *sem, const struct timespec *abstime)
+{
+  struct __timespec64 ts64;
+  if (abstime != NULL)
+    ts64 = valid_timespec_to_timespec64 (*abstime);
+
+  return __sem_timedwait64 (sem, abstime != NULL ? &ts64 : NULL);
+}
+#endif
+weak_alias (__sem_timedwait, sem_timedwait)
diff --git a/nptl/sem_waitcommon.c b/nptl/sem_waitcommon.c
index 5a6d2643ee..7fdc084d53 100644
--- a/nptl/sem_waitcommon.c
+++ b/nptl/sem_waitcommon.c
@@ -104,7 +104,7 @@  __sem_wait_cleanup (void *arg)
 static int
 __attribute__ ((noinline))
 do_futex_wait (struct new_sem *sem, clockid_t clockid,
-	       const struct timespec *abstime)
+	       const struct __timespec64 *abstime)
 {
   int err;
 
@@ -163,7 +163,7 @@  __new_sem_wait_fast (struct new_sem *sem, int definitive_result)
 static int
 __attribute__ ((noinline))
 __new_sem_wait_slow (struct new_sem *sem, clockid_t clockid,
-		     const struct timespec *abstime)
+		     const struct __timespec64 *abstime)
 {
   int err = 0;
 
diff --git a/nptl/semaphoreP.h b/nptl/semaphoreP.h
index e7e1c9763f..9023ea5573 100644
--- a/nptl/semaphoreP.h
+++ b/nptl/semaphoreP.h
@@ -17,6 +17,7 @@ 
    <https://www.gnu.org/licenses/>.  */
 
 #include <semaphore.h>
+#include <struct___timespec64.h>
 #include "pthreadP.h"
 
 #define SEM_SHM_PREFIX  "sem."
@@ -52,3 +53,14 @@  extern int __new_sem_wait (sem_t *sem);
 extern int __old_sem_wait (sem_t *sem);
 extern int __new_sem_trywait (sem_t *sem);
 extern int __new_sem_getvalue (sem_t *sem, int *sval);
+
+#if __TIMESIZE == 64
+# define __sem_timedwait64 __sem_timedwait
+# define __sem_clockwait64 __sem_clockwait
+#else
+extern int __sem_timedwait64 (sem_t *sem, const struct __timespec64 *abstime);
+libc_hidden_proto (__sem_timedwait64)
+extern int __sem_clockwait64 (sem_t *sem, clockid_t clockid,
+			      const struct __timespec64 *abstime);
+libc_hidden_proto (__sem_clockwait64)
+#endif