diff mbox series

[RFC,08/10] y2038: Convert aio_suspend to support 64 bit timeout

Message ID 20200707150827.20899-9-lukma@denx.de
State Superseded
Headers show
Series y2038: nptl: futex: Provide support for futex_time64 | expand

Commit Message

Lukasz Majewski July 7, 2020, 3:08 p.m. UTC
This patch converts aio_suspend function to support 64 bit
timeout. This function internally uses futex syscall.
---
 sysdeps/nptl/aio_misc.h       | 11 ++++++++++-
 sysdeps/pthread/aio_suspend.c | 36 ++++++++++++++++++++++++++++-------
 2 files changed, 39 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/sysdeps/nptl/aio_misc.h b/sysdeps/nptl/aio_misc.h
index 3f195f4794..5f0ed58217 100644
--- a/sysdeps/nptl/aio_misc.h
+++ b/sysdeps/nptl/aio_misc.h
@@ -23,6 +23,7 @@ 
 #include <assert.h>
 #include <nptl/pthreadP.h>
 #include <futex-internal.h>
+#include <struct___timespec64.h>
 
 #define DONT_NEED_AIO_MISC_COND	1
 
@@ -49,7 +50,7 @@ 
 		(unsigned int *) futexaddr, oldval, timeout, FUTEX_PRIVATE);  \
 	    else							      \
 	      status = futex_reltimed_wait ((unsigned int *) futexaddr,	      \
-		oldval, timeout, FUTEX_PRIVATE);	      		      \
+		oldval, timeout, FUTEX_PRIVATE);			      \
 	    if (status != EAGAIN)					      \
 	      break;							      \
 									      \
@@ -69,3 +70,11 @@ 
   } while (0)
 
 #include_next <aio_misc.h>
+
+#if __TIMESIZE == 64
+# define __aio_suspend64 __aio_suspend
+#else
+extern int __aio_suspend64 (const struct aiocb *const list[], int nent,
+			    const struct __timespec64 *timeout);
+libc_hidden_proto (__aio_suspend64)
+#endif
diff --git a/sysdeps/pthread/aio_suspend.c b/sysdeps/pthread/aio_suspend.c
index ad03f13558..71e0dbceb1 100644
--- a/sysdeps/pthread/aio_suspend.c
+++ b/sysdeps/pthread/aio_suspend.c
@@ -94,7 +94,7 @@  cleanup (void *arg)
 #ifdef DONT_NEED_AIO_MISC_COND
 static int
 __attribute__ ((noinline))
-do_aio_misc_wait (unsigned int *cntr, const struct timespec *timeout)
+do_aio_misc_wait (unsigned int *cntr, const struct __timespec64 *timeout)
 {
   int result = 0;
 
@@ -104,9 +104,9 @@  do_aio_misc_wait (unsigned int *cntr, const struct timespec *timeout)
 }
 #endif
 
-int
-aio_suspend (const struct aiocb *const list[], int nent,
-	     const struct timespec *timeout)
+static int
+__aio_suspend_common (const struct aiocb *const list[], int nent,
+                      const struct __timespec64 *timeout)
 {
   if (__glibc_unlikely (nent < 0))
     {
@@ -183,10 +183,10 @@  aio_suspend (const struct aiocb *const list[], int nent,
 	{
 	  /* We have to convert the relative timeout value into an
 	     absolute time value with pthread_cond_timedwait expects.  */
-	  struct timespec now;
-	  struct timespec abstime;
+	  struct __timespec64 now;
+	  struct __timespec64 abstime;
 
-	  __clock_gettime (CLOCK_REALTIME, &now);
+	  __clock_gettime64 (CLOCK_REALTIME, &now);
 	  abstime.tv_nsec = timeout->tv_nsec + now.tv_nsec;
 	  abstime.tv_sec = timeout->tv_sec + now.tv_sec;
 	  if (abstime.tv_nsec >= 1000000000)
@@ -250,4 +250,26 @@  aio_suspend (const struct aiocb *const list[], int nent,
   return result;
 }
 
+int
+__aio_suspend64 (const struct aiocb *const list[], int nent,
+                 const struct __timespec64 *timeout)
+{
+  return __aio_suspend_common (list, nent, timeout);
+}
+
+#if __TIMESIZE != 64
+libc_hidden_def (__aio_suspend64)
+
+int
+__aio_suspend (const struct aiocb *const list[], int nent,
+               const struct timespec *timeout)
+{
+  struct __timespec64 ts64;
+  if (timeout != NULL)
+    ts64 = valid_timespec_to_timespec64 (*timeout);
+
+  return __aio_suspend64 (list, nent, timeout != NULL ? &ts64 : NULL);
+}
+#endif
+weak_alias (__aio_suspend, aio_suspend)
 weak_alias (aio_suspend, aio_suspend64)