From 8ae5f0197d7c0628f3cceb69601754f6223acb7e Mon Sep 17 00:00:00 2001 From: pnewell Date: Mon, 11 Aug 2025 13:56:35 -0400 Subject: [PATCH 1/2] Fix none/some mistake and include 0 in some - Include 0 in some so behavior matches other platforms - Set timeout value to u.some when value is 0 or greater --- libc-bottom-half/sources/__wasilibc_futex.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libc-bottom-half/sources/__wasilibc_futex.c b/libc-bottom-half/sources/__wasilibc_futex.c index d018c42e6..b9c642656 100644 --- a/libc-bottom-half/sources/__wasilibc_futex.c +++ b/libc-bottom-half/sources/__wasilibc_futex.c @@ -12,9 +12,9 @@ int __wasilibc_futex_wait_wasix(volatile void *addr, int op, int expected, int64 __wasi_bool_t woken = __WASI_BOOL_FALSE; __wasi_option_timestamp_t timeout; - if (max_wait_ns > 0) { + if (max_wait_ns >= 0) { timeout.tag = __WASI_OPTION_SOME; - timeout.u.none = max_wait_ns; + timeout.u.some = max_wait_ns; } else { timeout.tag = __WASI_OPTION_NONE; timeout.u.none = 0; From 6239ac216b3a3b270a45f3ca95e1c5d5ec537fd2 Mon Sep 17 00:00:00 2001 From: pnewell Date: Mon, 11 Aug 2025 14:03:35 -0400 Subject: [PATCH 2/2] Fix __timedwait_cp - __futex4_cp is implemented and __wasilibc_futex_wait_wasix is now working properly, so removing fallback infinite wait --- libc-top-half/musl/src/thread/__timedwait.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/libc-top-half/musl/src/thread/__timedwait.c b/libc-top-half/musl/src/thread/__timedwait.c index e0d3fc528..2a0a18f20 100644 --- a/libc-top-half/musl/src/thread/__timedwait.c +++ b/libc-top-half/musl/src/thread/__timedwait.c @@ -60,7 +60,6 @@ int __timedwait_cp(volatile int *addr, int val, top = &to; } -#ifdef __wasilibc_unmodified_upstream r = -__futex4_cp(addr, FUTEX_WAIT|priv, val, top); if (r != EINTR && r != ETIMEDOUT && r != ECANCELED) r = 0; /* Mitigate bug in old kernels wrongly reporting EINTR for non- @@ -68,11 +67,6 @@ int __timedwait_cp(volatile int *addr, int val, * when NO interrupting signal handlers have been installed, and * works by sigaction tracking whether that's the case. */ if (r == EINTR && !__eintr_valid_flag) r = 0; -#else - volatile int waiters = 0; - __wait(addr, &waiters, val, 0); - r = 0; -#endif return r; }