Upgrade to witx 0.8.0 with tagged unions (#921)

* witx tagged unions: updates to wig to use new semantics

* wig: emit a `#variant: ()` union variant for empty variants

* wasi-common: translate to use tagged unions

* update to flattened layout of event struct

* wig: generate layout tests, and delete bindgen ones

the bindgen tests became out-of-date with the latest changes to the
representation of unions, and the re-jiggering of various struct
definitions that went along with it.

* wasi: point at master with tagged union PR merged

* fix event struct repr on windows
This commit is contained in:
Pat Hickey
2020-02-20 07:52:03 -08:00
committed by GitHub
parent 80b095f2e2
commit 4460e569cf
19 changed files with 270 additions and 2170 deletions

View File

@@ -225,9 +225,9 @@ pub(crate) fn poll_oneoff(
return Err(Error::EINVAL);
}
for subscription in subscriptions {
match subscription.r#type {
match subscription.u.tag {
wasi::__WASI_EVENTTYPE_CLOCK => {
let clock = unsafe { subscription.u.clock };
let clock = unsafe { subscription.u.u.clock };
let delay = wasi_clock_to_relative_ns_delay(clock)?;
log::debug!("poll_oneoff event.u.clock = {:?}", clock);
@@ -242,17 +242,9 @@ pub(crate) fn poll_oneoff(
*timeout = current;
}
}
r#type
if r#type == wasi::__WASI_EVENTTYPE_FD_READ
|| r#type == wasi::__WASI_EVENTTYPE_FD_WRITE =>
{
let wasi_fd = unsafe { subscription.u.fd_readwrite.file_descriptor };
let rights = if r#type == wasi::__WASI_EVENTTYPE_FD_READ {
wasi::__WASI_RIGHTS_FD_READ | wasi::__WASI_RIGHTS_POLL_FD_READWRITE
} else {
wasi::__WASI_RIGHTS_FD_WRITE | wasi::__WASI_RIGHTS_POLL_FD_READWRITE
};
wasi::__WASI_EVENTTYPE_FD_READ => {
let wasi_fd = unsafe { subscription.u.u.fd_read.file_descriptor };
let rights = wasi::__WASI_RIGHTS_FD_READ | wasi::__WASI_RIGHTS_POLL_FD_READWRITE;
match unsafe {
wasi_ctx
.get_fd_entry(wasi_fd)
@@ -260,25 +252,52 @@ pub(crate) fn poll_oneoff(
} {
Ok(descriptor) => fd_events.push(FdEventData {
descriptor,
r#type: subscription.r#type,
r#type: wasi::__WASI_EVENTTYPE_FD_READ,
userdata: subscription.userdata,
}),
Err(err) => {
let event = wasi::__wasi_event_t {
userdata: subscription.userdata,
r#type,
error: err.as_wasi_error().as_raw_errno(),
u: wasi::__wasi_event_u_t {
fd_readwrite: wasi::__wasi_event_fd_readwrite_t {
nbytes: 0,
flags: 0,
},
r#type: wasi::__WASI_EVENTTYPE_FD_READ,
fd_readwrite: wasi::__wasi_event_fd_readwrite_t {
nbytes: 0,
flags: 0,
},
};
events.push(event);
}
};
}
wasi::__WASI_EVENTTYPE_FD_WRITE => {
let wasi_fd = unsafe { subscription.u.u.fd_write.file_descriptor };
let rights = wasi::__WASI_RIGHTS_FD_WRITE | wasi::__WASI_RIGHTS_POLL_FD_READWRITE;
match unsafe {
wasi_ctx
.get_fd_entry(wasi_fd)
.and_then(|fe| fe.as_descriptor(rights, 0))
} {
Ok(descriptor) => fd_events.push(FdEventData {
descriptor,
r#type: wasi::__WASI_EVENTTYPE_FD_WRITE,
userdata: subscription.userdata,
}),
Err(err) => {
let event = wasi::__wasi_event_t {
userdata: subscription.userdata,
error: err.as_wasi_error().as_raw_errno(),
r#type: wasi::__WASI_EVENTTYPE_FD_WRITE,
fd_readwrite: wasi::__wasi_event_fd_readwrite_t {
nbytes: 0,
flags: 0,
},
};
events.push(event);
}
};
}
_ => unreachable!(),
}
}