]> sourceware.org Git - glibc.git/commitdiff
y2038: Convert gai_suspend to support 64 bit time
authorLukasz Majewski <lukma@denx.de>
Mon, 30 Nov 2020 13:33:12 +0000 (14:33 +0100)
committerLukasz Majewski <lukma@denx.de>
Fri, 4 Dec 2020 09:04:38 +0000 (10:04 +0100)
This change uses (in gai_misc.h):
- __futex_abstimed_wait64 (instead of futex_reltimed_wait)
- __futex_abstimed_wait_cancellable64
     (instead of futex_reltimed_wait_cancellable)
        from ./sysdeps/nptl/futex-helpers.h

The gai_suspend() accepts relative timeout, which then is converted to
absolute one.

The i686-gnu port (HURD) do not define DONT_NEED_GAI_MISC_COND and as it
doesn't (yet) support 64 bit time it uses not converted
pthread_cond_timedwait().

The __gai_suspend() is supposed to be run on ports with __TIMESIZE !=64 and
__WORDSIZE==32. It internally utilizes __gai_suspend_time64() and hence the
conversion from 32 bit struct timespec to 64 bit one is required.

For ports supporting 64 bit time the __gai_suspend_time64() will be used
either via alias (to __gai_suspend when __TIMESIZE==64) or redirection
(when -D_TIME_BITS=64 is passed).

Build tests:
./src/scripts/build-many-glibcs.py glibcs

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
include/netdb.h
resolv/gai_suspend.c
sysdeps/nptl/gai_misc.h

index 49d63c1338e7ceb44d66e5f9b90e6a5925437359..645b85dc62e562b3f93ac30cdbd9b6b07b7ce56e 100644 (file)
@@ -194,6 +194,13 @@ extern int ruserpass (const char *host, const char **aname,
                      const char **apass);
 libc_hidden_proto (ruserpass)
 
+# if __TIMESIZE == 64
+#  define __gai_suspend_time64 __gai_suspend
+# else
+extern int __gai_suspend_time64 (const struct gaicb *const list[], int ent,
+                                 const struct __timespec64 *timeout);
+libanl_hidden_proto (__gai_suspend_time64)
+# endif
 
 /* The following definition has been removed from the public header
    since we don't want people to use them.  */
index 734f9b45007da8d1b23cf25887ba8b8159dc0265..d75abeb7e38a95c3c27b66ab39741f7f9619d04d 100644 (file)
 
 #include <gai_misc.h>
 
-
 int
-gai_suspend (const struct gaicb *const list[], int ent,
-            const struct timespec *timeout)
+__gai_suspend_time64 (const struct gaicb *const list[], int ent,
+                      const struct __timespec64 *timeout)
 {
   struct waitlist waitlist[ent];
   struct requestlist *requestlist[ent];
@@ -63,6 +62,19 @@ gai_suspend (const struct gaicb *const list[], int ent,
          }
       }
 
+  struct __timespec64 ts;
+  if (timeout != NULL)
+    {
+      __clock_gettime64 (CLOCK_MONOTONIC, &ts);
+      ts.tv_sec += timeout->tv_sec;
+      ts.tv_nsec += timeout->tv_nsec;
+      if (ts.tv_nsec >= 1000000000)
+       {
+         ts.tv_nsec -= 1000000000;
+         ts.tv_sec++;
+       }
+    }
+
   if (none)
     {
       if (cnt < ent)
@@ -83,29 +95,11 @@ gai_suspend (const struct gaicb *const list[], int ent,
 
 #ifdef DONT_NEED_GAI_MISC_COND
       result = 0;
-      GAI_MISC_WAIT (result, cntr, timeout, 1);
+      GAI_MISC_WAIT (result, cntr, timeout == NULL ? NULL : &ts, 1);
 #else
-      if (timeout == NULL)
-       result = pthread_cond_wait (&cond, &__gai_requests_mutex);
-      else
-       {
-         /* We have to convert the relative timeout value into an
-            absolute time value with pthread_cond_timedwait expects.  */
-         struct timespec now;
-         struct timespec abstime;
-
-          __clock_gettime (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)
-           {
-             abstime.tv_nsec -= 1000000000;
-             abstime.tv_sec += 1;
-           }
-
-         result = pthread_cond_timedwait (&cond, &__gai_requests_mutex,
-                                          &abstime);
-       }
+      struct timespec ts32 = valid_timespec64_to_timespec (ts);
+      result = pthread_cond_timedwait (&cond, &__gai_requests_mutex,
+                                       timeout == NULL ? NULL : &ts32);
 #endif
 
       /* Now remove the entry in the waiting list for all requests
@@ -155,3 +149,20 @@ gai_suspend (const struct gaicb *const list[], int ent,
 
   return result;
 }
+
+#if __TIMESIZE != 64
+libanl_hidden_def (__gai_suspend_time64)
+
+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_suspend_time64 (list, ent, timeout != NULL ? &ts64 : NULL);
+}
+#endif
+weak_alias (__gai_suspend, gai_suspend)
index c1d5e2e6f027ee767db4042906ba237e9abf416b..c72a86397414f153df5739ac68826d22dcb50ddd 100644 (file)
        do                                                                    \
          {                                                                   \
            if (cancel)                                                       \
-             status = futex_reltimed_wait_cancelable (                       \
-               (unsigned int *) futexaddr, oldval, timeout, FUTEX_PRIVATE);  \
+             status = __futex_abstimed_wait_cancelable64 (                   \
+               (unsigned int *) futexaddr, oldval, CLOCK_MONOTONIC, timeout, \
+               FUTEX_PRIVATE);                                               \
            else                                                              \
-             status = futex_reltimed_wait ((unsigned int *) futexaddr,       \
-               oldval, timeout, FUTEX_PRIVATE);                              \
+             status = __futex_abstimed_wait64 ((unsigned int *) futexaddr,   \
+               oldval, CLOCK_REALTIME, timeout, FUTEX_PRIVATE);              \
            if (status != EAGAIN)                                             \
              break;                                                          \
                                                                              \
@@ -62,6 +63,8 @@
          result = EINTR;                                                     \
        else if (status == ETIMEDOUT)                                         \
          result = EAGAIN;                                                    \
+       else if (status == EOVERFLOW)                                         \
+         result = EOVERFLOW;                                                 \
        else                                                                  \
          assert (status == 0 || status == EAGAIN);                           \
                                                                              \
This page took 0.048333 seconds and 5 git commands to generate.