about summary refs log tree commit diff
path: root/sysdeps
diff options
context:
space:
mode:
authorLukasz Majewski <lukma@denx.de>2020-10-19 15:05:47 +0200
committerLukasz Majewski <lukma@denx.de>2020-10-21 11:43:35 +0200
commit9cb2c923844ba1b77a7b9ade777e838242a4e201 (patch)
treebc3870647b9b6f5e285d7cddaef9e63315d2102d /sysdeps
parent56b223c1c8334e4255bf11aed1386a007822702a (diff)
downloadglibc-9cb2c923844ba1b77a7b9ade777e838242a4e201.tar.gz
glibc-9cb2c923844ba1b77a7b9ade777e838242a4e201.tar.xz
glibc-9cb2c923844ba1b77a7b9ade777e838242a4e201.zip
y2038: nptl: Provide __futex_clock_wait_bitset64 to support 64 bit bitset
The commit:
"y2038: nptl: Convert pthread_mutex_{clock|timed}lock to support 64 bit"
SHA1: 29e9874a048f47e2d46c40253036c8d2de921548

introduced support for 64 bit timeouts. Unfortunately, it was missing the
code for bitset - i.e. lll_futex_clock_wait_bitset C preprocessor macro
was used. As a result the 64 bit struct __timespec64 was coerced to 32
bit struct timespec and regression visible as timeout was observed
(nptl/tst-robust10 on s390).

Reported-by: Stefan Liebler <stli@linux.ibm.com>
Tested-by: Stefan Liebler <stli@linux.ibm.com>
Diffstat (limited to 'sysdeps')
-rw-r--r--sysdeps/nptl/futex-internal.c48
-rw-r--r--sysdeps/nptl/futex-internal.h5
2 files changed, 52 insertions, 1 deletions
diff --git a/sysdeps/nptl/futex-internal.c b/sysdeps/nptl/futex-internal.c
index 2e1919f056..457cd3cd69 100644
--- a/sysdeps/nptl/futex-internal.c
+++ b/sysdeps/nptl/futex-internal.c
@@ -70,7 +70,28 @@ __futex_abstimed_wait32 (unsigned int* futex_word,
                                 abstime != NULL ? &ts32 : NULL,
                                 NULL /* Unused.  */, FUTEX_BITSET_MATCH_ANY);
 }
-#endif
+
+static int
+__futex_clock_wait_bitset32 (int *futexp, int val, clockid_t clockid,
+                             const struct __timespec64 *abstime, int private)
+{
+  struct timespec ts32;
+
+  if (abstime != NULL && ! in_time_t_range (abstime->tv_sec))
+    return -EOVERFLOW;
+
+  const unsigned int clockbit =
+    (clockid == CLOCK_REALTIME) ? FUTEX_CLOCK_REALTIME : 0;
+  const int op = __lll_private_flag (FUTEX_WAIT_BITSET | clockbit, private);
+
+  if (abstime != NULL)
+    ts32 = valid_timespec64_to_timespec (*abstime);
+
+  return INTERNAL_SYSCALL_CALL (futex, futexp, op, val,
+                                abstime != NULL ? &ts32 : NULL,
+                                NULL /* Unused.  */, FUTEX_BITSET_MATCH_ANY);
+}
+#endif /* ! __ASSUME_TIME64_SYSCALLS */
 
 int
 __futex_abstimed_wait_cancelable64 (unsigned int* futex_word,
@@ -222,3 +243,28 @@ __futex_clocklock_wait64 (int *futex, int val, clockid_t clockid,
 
   return -err;
 }
+
+int
+__futex_clock_wait_bitset64 (int *futexp, int val, clockid_t clockid,
+                             const struct __timespec64 *abstime,
+                             int private)
+{
+  int ret;
+  if (! lll_futex_supported_clockid (clockid))
+    {
+      return -EINVAL;
+    }
+
+  const unsigned int clockbit =
+    (clockid == CLOCK_REALTIME) ? FUTEX_CLOCK_REALTIME : 0;
+  const int op = __lll_private_flag (FUTEX_WAIT_BITSET | clockbit, private);
+
+  ret = INTERNAL_SYSCALL_CALL (futex_time64, futexp, op, val,
+                               abstime, NULL /* Unused.  */,
+                               FUTEX_BITSET_MATCH_ANY);
+#ifndef __ASSUME_TIME64_SYSCALLS
+  if (ret == -ENOSYS)
+    ret = __futex_clock_wait_bitset32 (futexp, val, clockid, abstime, private);
+#endif
+  return ret;
+}
diff --git a/sysdeps/nptl/futex-internal.h b/sysdeps/nptl/futex-internal.h
index 8a5f62768f..cd356e4fa8 100644
--- a/sysdeps/nptl/futex-internal.h
+++ b/sysdeps/nptl/futex-internal.h
@@ -603,4 +603,9 @@ __futex_clocklock64 (int *futex, clockid_t clockid,
   return err;
 }
 
+int
+__futex_clock_wait_bitset64 (int *futexp, int val, clockid_t clockid,
+                             const struct __timespec64 *abstime,
+                             int private) attribute_hidden;
+
 #endif  /* futex-internal.h */