Skip to content

Commit

Permalink
Avoid calling poll_oneoff with zero subscriptions.
Browse files Browse the repository at this point in the history
With WebAssembly/WASI#193 merged, WASI is moving
to make `poll_oneoff` with no arguments an error. Even though that's in
ephemeral and not yet in a snapshot, we can start to anticipate it in
libc:
 - Remove the `pause` function, since WASI has no signals and thus no
   way to ever wake it up short of having the host terminate it.
 - Make `poll` and `pselect` return `ENOTSUP` in the case of having no
   events to wait for.
  • Loading branch information
sunfishcode committed Mar 3, 2020
1 parent 0cc57ac commit 11ec052
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
8 changes: 7 additions & 1 deletion libc-bottom-half/cloudlibc/src/libc/poll/poll.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,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;
}

Expand Down
8 changes: 7 additions & 1 deletion libc-bottom-half/cloudlibc/src/libc/sys/select/pselect.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,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;
}

Expand Down
14 changes: 0 additions & 14 deletions libc-bottom-half/sources/pause.c

This file was deleted.

2 changes: 2 additions & 0 deletions libc-top-half/musl/include/unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 11ec052

Please sign in to comment.