Skip to content

Commit

Permalink
Return EINVAL in poll_oneoff with no events.
Browse files Browse the repository at this point in the history
We adhere to WebAssembly/WASI#193.
  • Loading branch information
marmistrz committed Jan 17, 2020
1 parent 448faed commit ea779fd
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions crates/wasi-common/src/hostcalls_impl/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ pub(crate) fn poll_oneoff(

let mut timeout: Option<ClockEventData> = None;
let mut fd_events = Vec::new();

if subscriptions.is_empty() {
return Err(Error::EINVAL);
}
for subscription in subscriptions {
match subscription.r#type {
wasi::__WASI_EVENTTYPE_CLOCK => {
Expand Down Expand Up @@ -280,6 +284,9 @@ pub(crate) fn poll_oneoff(
log::debug!("poll_oneoff timeout = {:?}", timeout);
log::debug!("poll_oneoff fd_events = {:?}", fd_events);

// The underlying implementation should successfully and immediately return
// if no events have been passed. Such situation may occur if all provided
// events have been filtered out as errors in the code above.
hostcalls_impl::poll_oneoff(timeout, fd_events, &mut events)?;

let events_count = u32::try_from(events.len()).map_err(|_| Error::EOVERFLOW)?;
Expand Down

0 comments on commit ea779fd

Please sign in to comment.