diff --git a/libc-bottom-half/cloudlibc/src/libc/poll/poll.c b/libc-bottom-half/cloudlibc/src/libc/poll/poll.c index b55651aab..de15c018d 100644 --- a/libc-bottom-half/cloudlibc/src/libc/poll/poll.c +++ b/libc-bottom-half/cloudlibc/src/libc/poll/poll.c @@ -79,7 +79,13 @@ int poll(struct pollfd *fds, size_t nfds, int timeout) { __wasi_poll_oneoff(subscriptions, events, nevents, &nevents); #endif if (error != 0) { - errno = error; + // WASI's poll requires at least one subscription, or else it returns + // `EINVAL`. Since a `poll` with nothing to wait for is valid in POSIX, + // return `ENOTSUP` to indicate that we don't support that case. + if (nevents == 0) + errno = ENOTSUP; + else + errno = error; return -1; } diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/select/pselect.c b/libc-bottom-half/cloudlibc/src/libc/sys/select/pselect.c index b31741e30..bcd271a34 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/select/pselect.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/select/pselect.c @@ -108,7 +108,13 @@ int pselect(int nfds, fd_set *restrict readfds, fd_set *restrict writefds, __wasi_poll_oneoff(subscriptions, events, nevents, &nevents); #endif if (error != 0) { - errno = error; + // WASI's poll requires at least one subscription, or else it returns + // `EINVAL`. Since a `pselect` with nothing to wait for is valid in POSIX, + // return `ENOTSUP` to indicate that we don't support that case. + if (nevents == 0) + errno = ENOTSUP; + else + errno = error; return -1; } diff --git a/libc-bottom-half/sources/pause.c b/libc-bottom-half/sources/pause.c deleted file mode 100644 index 0e3e71250..000000000 --- a/libc-bottom-half/sources/pause.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include -#include -#include - -int pause(void) { - size_t n; - __wasi_errno_t error = __wasi_poll_oneoff(0, 0, 0, &n); - if (error != 0) { - errno = error; - return -1; - } - __builtin_trap(); -} diff --git a/libc-top-half/musl/include/unistd.h b/libc-top-half/musl/include/unistd.h index 302e536a2..754d27b3b 100644 --- a/libc-top-half/musl/include/unistd.h +++ b/libc-top-half/musl/include/unistd.h @@ -128,7 +128,9 @@ char *getcwd(char *, size_t); unsigned alarm(unsigned); #endif unsigned sleep(unsigned); +#ifdef __wasilibc_unmodified_upstream /* WASI has no pause */ int pause(void); +#endif #ifdef __wasilibc_unmodified_upstream /* WASI has no fork/exec */ pid_t fork(void);