Merge "Restore __futex_wake and __futex_wait for LP32."
diff --git a/libc/bionic/ndk_cruft.cpp b/libc/bionic/ndk_cruft.cpp
index 295418b..46cc1f0 100644
--- a/libc/bionic/ndk_cruft.cpp
+++ b/libc/bionic/ndk_cruft.cpp
@@ -31,10 +31,12 @@
#include <ctype.h>
#include <inttypes.h>
+#include <linux/futex.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/resource.h>
+#include <sys/syscall.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/wait.h>
@@ -199,4 +201,25 @@
return vdprintf(fd, fmt, ap);
}
+static inline int __futex(volatile void* ftx, int op, int value, const struct timespec* timeout) {
+ // Our generated syscall assembler sets errno, but our callers (pthread functions) don't want to.
+ int saved_errno = errno;
+ if (syscall(__NR_futex, ftx, op, value, timeout) == 0) {
+ return 0;
+ }
+ int result = -errno;
+ errno = saved_errno;
+ return result;
+}
+
+// This used to be in <sys/atomics.h>.
+extern "C" int __futex_wake(volatile void* ftx, int count) {
+ return __futex(ftx, FUTEX_WAKE, count, NULL);
+}
+
+// This used to be in <sys/atomics.h>.
+extern "C" int __futex_wait(volatile void* ftx, int value, const struct timespec* timeout) {
+ return __futex(ftx, FUTEX_WAIT, value, timeout);
+}
+
#endif