[RFC,09/10] y2038: Convert gai_suspend to support 64 bit timeout

Message ID 20200707150827.20899-10-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.
This patch converts gai_suspend to support 64 bit timeout.
It uses internally futex syscall to achieve this goal.
---
 resolv/gai_misc.h    |  7 +++++++
 resolv/gai_suspend.c | 33 ++++++++++++++++++++++++++++-----
 2 files changed, 35 insertions(+), 5 deletions(-)

-- 
2.20.1

Patch

diff --git a/resolv/gai_misc.h b/resolv/gai_misc.h
index 008d6a4ad6..4ac2a24859 100644
--- a/resolv/gai_misc.h
+++ b/resolv/gai_misc.h
@@ -97,4 +97,11 @@  extern int __gai_notify_only (struct sigevent *sigev, pid_t caller_pid)
 /* Send the signal.  */
 extern int __gai_sigqueue (int sig, const union sigval val, pid_t caller_pid);
 
+# if __TIMESIZE == 64
+#  define __gai_suspend64 __gai_suspend
+# else
+extern int __gai_suspend64 (const struct gaicb *const list[], int ent,
+                            const struct __timespec64 *timeout);
+libc_hidden_proto (__gai_suspend64)
+# endif
 #endif /* gai_misc.h */
diff --git a/resolv/gai_suspend.c b/resolv/gai_suspend.c
index 734f9b4500..79b183681d 100644
--- a/resolv/gai_suspend.c
+++ b/resolv/gai_suspend.c
@@ -26,8 +26,8 @@ 
 
 
 int
-gai_suspend (const struct gaicb *const list[], int ent,
-	     const struct timespec *timeout)
+__gai_suspend_common (const struct gaicb *const list[], int ent,
+		      const struct __timespec64 *timeout)
 {
   struct waitlist waitlist[ent];
   struct requestlist *requestlist[ent];
@@ -91,10 +91,10 @@  gai_suspend (const struct gaicb *const list[], int ent,
 	{
 	  /* 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)
@@ -155,3 +155,26 @@  gai_suspend (const struct gaicb *const list[], int ent,
 
   return result;
 }
+
+int
+__gai_suspend64 (const struct gaicb *const list[], int ent,
+		 const struct __timespec64 *timeout)
+{
+  return __gai_suspend_common (list, ent, timeout);
+}
+
+#if __TIMESIZE != 64
+libc_hidden_def (__gai_suspend64)
+
+int
+__gai_suspend (const struct gaicb *const list[], int ent,
+	       const struct timespec *timeout)
+{
+  struct __timespec64 ts64;
+  if (timeout != NULL)
+    ts64 = valid_timespec_to_timespec64 (*timeout);
+
+  return __gai_suspend64 (list, ent, timeout != NULL ? &ts64 : NULL);
+}
+#endif
+weak_alias (__gai_suspend, gai_suspend)