diff --git a/Cargo.lock b/Cargo.lock index 51d2e86130..e149baca57 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -496,6 +496,12 @@ dependencies = [ "synstructure", ] +[[package]] +name = "diff" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e25ea47919b1560c4e3b7fe0aaab9becf5b84a10325ddf7db0f0ba5e1026499" + [[package]] name = "digest" version = "0.8.1" @@ -2231,13 +2237,13 @@ dependencies = [ [[package]] name = "witx" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6ee25990cb94f39b8d5637b8c7d9b9eaaed76795d95f45342a7ef3d2e574931" +version = "0.8.0" dependencies = [ - "clap", + "anyhow", + "diff", "log", "pretty_env_logger", + "structopt", "thiserror", "wast 3.0.4", ] diff --git a/crates/wasi-common/src/host.rs b/crates/wasi-common/src/host.rs index 2b79007517..946d7feb12 100644 --- a/crates/wasi-common/src/host.rs +++ b/crates/wasi-common/src/host.rs @@ -78,91 +78,3 @@ impl Dirent { Ok(raw) } } - -#[cfg(test)] -mod test { - use super::*; - #[test] - fn bindgen_test_layout___wasi_prestat_t() { - assert_eq!( - ::std::mem::size_of::<__wasi_prestat_t>(), - 16usize, - concat!("Size of: ", stringify!(__wasi_prestat_t)) - ); - assert_eq!( - ::std::mem::align_of::<__wasi_prestat_t>(), - 8usize, - concat!("Alignment of ", stringify!(__wasi_prestat_t)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_prestat_t>())).pr_type as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_prestat_t), - "::", - stringify!(pr_type) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_prestat_t>())).u as *const _ as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(__wasi_prestat_t), - "::", - stringify!(u) - ) - ); - } - - #[test] - fn bindgen_test_layout___wasi_prestat_t___wasi_prestat_u___wasi_prestat_u_dir_t() { - assert_eq!( - ::std::mem::size_of::<__wasi_prestat_dir_t>(), - 8usize, - concat!("Size of: ", stringify!(__wasi_prestat_dir_t)) - ); - assert_eq!( - ::std::mem::align_of::<__wasi_prestat_dir_t>(), - 8usize, - concat!("Alignment of ", stringify!(__wasi_prestat_dir_t)) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<__wasi_prestat_dir_t>())).pr_name_len as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_prestat_dir_t), - "::", - stringify!(pr_name_len) - ) - ); - } - - #[test] - fn bindgen_test_layout___wasi_prestat_t___wasi_prestat_u() { - assert_eq!( - ::std::mem::size_of::<__wasi_prestat_u_t>(), - 8usize, - concat!("Size of: ", stringify!(__wasi_prestat_u)) - ); - assert_eq!( - ::std::mem::align_of::<__wasi_prestat_u_t>(), - 8usize, - concat!("Alignment of ", stringify!(__wasi_prestat_u)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_prestat_u_t>())).dir as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_prestat_u_t), - "::", - stringify!(dir) - ) - ); - } -} diff --git a/crates/wasi-common/src/hostcalls_impl/fs.rs b/crates/wasi-common/src/hostcalls_impl/fs.rs index f4ed12822a..d5ecb8bc69 100644 --- a/crates/wasi-common/src/hostcalls_impl/fs.rs +++ b/crates/wasi-common/src/hostcalls_impl/fs.rs @@ -1002,7 +1002,7 @@ pub(crate) unsafe fn fd_prestat_get( memory, prestat_ptr, host::__wasi_prestat_t { - pr_type: wasi::__WASI_PREOPENTYPE_DIR, + tag: wasi::__WASI_PREOPENTYPE_DIR, u: host::__wasi_prestat_u_t { dir: host::__wasi_prestat_dir_t { pr_name_len: path.len(), diff --git a/crates/wasi-common/src/hostcalls_impl/misc.rs b/crates/wasi-common/src/hostcalls_impl/misc.rs index b198c9963d..ca3225e0a7 100644 --- a/crates/wasi-common/src/hostcalls_impl/misc.rs +++ b/crates/wasi-common/src/hostcalls_impl/misc.rs @@ -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!(), } } diff --git a/crates/wasi-common/src/memory.rs b/crates/wasi-common/src/memory.rs index 4171631d42..fa6752002f 100644 --- a/crates/wasi-common/src/memory.rs +++ b/crates/wasi-common/src/memory.rs @@ -329,9 +329,9 @@ pub(crate) fn dec_prestat_byref( ) -> Result { let raw = dec_raw_byref::(memory, prestat_ptr)?; - match PrimInt::from_le(raw.pr_type) { + match PrimInt::from_le(raw.tag) { wasi::__WASI_PREOPENTYPE_DIR => Ok(host::__wasi_prestat_t { - pr_type: wasi::__WASI_PREOPENTYPE_DIR, + tag: wasi::__WASI_PREOPENTYPE_DIR, u: host::__wasi_prestat_u_t { dir: host::__wasi_prestat_dir_t { pr_name_len: dec_usize(PrimInt::from_le(unsafe { raw.u.dir.pr_name_len })), @@ -347,9 +347,9 @@ pub(crate) fn enc_prestat_byref( prestat_ptr: wasi32::uintptr_t, prestat: host::__wasi_prestat_t, ) -> Result<()> { - let raw = match prestat.pr_type { + let raw = match prestat.tag { wasi::__WASI_PREOPENTYPE_DIR => Ok(wasi32::__wasi_prestat_t { - pr_type: PrimInt::to_le(wasi::__WASI_PREOPENTYPE_DIR), + tag: PrimInt::to_le(wasi::__WASI_PREOPENTYPE_DIR), u: wasi32::__wasi_prestat_u_t { dir: wasi32::__wasi_prestat_dir_t { pr_name_len: enc_usize(unsafe { prestat.u.dir.pr_name_len }), @@ -410,10 +410,10 @@ pub(crate) fn dec_subscriptions( .into_iter() .map(|raw_subscription| { let userdata = PrimInt::from_le(raw_subscription.userdata); - let r#type = PrimInt::from_le(raw_subscription.r#type); - let raw_u = raw_subscription.u; - let u = match r#type { - wasi::__WASI_EVENTTYPE_CLOCK => wasi::__wasi_subscription_u_t { + let tag = PrimInt::from_le(raw_subscription.u.tag); + let raw_u = raw_subscription.u.u; + let u = match tag { + wasi::__WASI_EVENTTYPE_CLOCK => wasi::__wasi_subscription_u_u_t { clock: unsafe { wasi::__wasi_subscription_clock_t { id: PrimInt::from_le(raw_u.clock.id), @@ -423,21 +423,23 @@ pub(crate) fn dec_subscriptions( } }, }, - wasi::__WASI_EVENTTYPE_FD_READ | wasi::__WASI_EVENTTYPE_FD_WRITE => { - wasi::__wasi_subscription_u_t { - fd_readwrite: wasi::__wasi_subscription_fd_readwrite_t { - file_descriptor: PrimInt::from_le(unsafe { - raw_u.fd_readwrite.file_descriptor - }), - }, - } - } + wasi::__WASI_EVENTTYPE_FD_READ => wasi::__wasi_subscription_u_u_t { + fd_read: wasi::__wasi_subscription_fd_readwrite_t { + file_descriptor: PrimInt::from_le(unsafe { raw_u.fd_read.file_descriptor }), + }, + }, + wasi::__WASI_EVENTTYPE_FD_WRITE => wasi::__wasi_subscription_u_u_t { + fd_write: wasi::__wasi_subscription_fd_readwrite_t { + file_descriptor: PrimInt::from_le(unsafe { + raw_u.fd_write.file_descriptor + }), + }, + }, _ => return Err(Error::EINVAL), }; Ok(wasi::__wasi_subscription_t { userdata, - r#type, - u, + u: wasi::__wasi_subscription_u_t { tag, u }, }) }) .collect::>>() @@ -456,17 +458,16 @@ pub(crate) fn enc_events( *raw_output_iter .next() .expect("the number of events cannot exceed the number of subscriptions") = { - let fd_readwrite = unsafe { event.u.fd_readwrite }; + let userdata = PrimInt::to_le(event.userdata); + let error = PrimInt::to_le(event.error); + let r#type = PrimInt::to_le(event.r#type); + let flags = PrimInt::to_le(event.fd_readwrite.flags); + let nbytes = PrimInt::to_le(event.fd_readwrite.nbytes); wasi::__wasi_event_t { - userdata: PrimInt::to_le(event.userdata), - r#type: PrimInt::to_le(event.r#type), - error: PrimInt::to_le(event.error), - u: wasi::__wasi_event_u_t { - fd_readwrite: wasi::__wasi_event_fd_readwrite_t { - nbytes: PrimInt::to_le(fd_readwrite.nbytes), - flags: PrimInt::to_le(fd_readwrite.flags), - }, - }, + userdata, + error, + r#type, + fd_readwrite: wasi::__wasi_event_fd_readwrite_t { flags, nbytes }, } }; } diff --git a/crates/wasi-common/src/old/snapshot_0/host.rs b/crates/wasi-common/src/old/snapshot_0/host.rs index 711b81f869..b029fcf10e 100644 --- a/crates/wasi-common/src/old/snapshot_0/host.rs +++ b/crates/wasi-common/src/old/snapshot_0/host.rs @@ -78,91 +78,3 @@ impl Dirent { Ok(raw) } } - -#[cfg(test)] -mod test { - use super::*; - #[test] - fn bindgen_test_layout___wasi_prestat_t() { - assert_eq!( - ::std::mem::size_of::<__wasi_prestat_t>(), - 16usize, - concat!("Size of: ", stringify!(__wasi_prestat_t)) - ); - assert_eq!( - ::std::mem::align_of::<__wasi_prestat_t>(), - 8usize, - concat!("Alignment of ", stringify!(__wasi_prestat_t)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_prestat_t>())).pr_type as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_prestat_t), - "::", - stringify!(pr_type) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_prestat_t>())).u as *const _ as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(__wasi_prestat_t), - "::", - stringify!(u) - ) - ); - } - - #[test] - fn bindgen_test_layout___wasi_prestat_t___wasi_prestat_u___wasi_prestat_u_dir_t() { - assert_eq!( - ::std::mem::size_of::<__wasi_prestat_dir_t>(), - 8usize, - concat!("Size of: ", stringify!(__wasi_prestat_dir_t)) - ); - assert_eq!( - ::std::mem::align_of::<__wasi_prestat_dir_t>(), - 8usize, - concat!("Alignment of ", stringify!(__wasi_prestat_dir_t)) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<__wasi_prestat_dir_t>())).pr_name_len as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_prestat_dir_t), - "::", - stringify!(pr_name_len) - ) - ); - } - - #[test] - fn bindgen_test_layout___wasi_prestat_t___wasi_prestat_u() { - assert_eq!( - ::std::mem::size_of::<__wasi_prestat_u_t>(), - 8usize, - concat!("Size of: ", stringify!(__wasi_prestat_u_t)) - ); - assert_eq!( - ::std::mem::align_of::<__wasi_prestat_u_t>(), - 8usize, - concat!("Alignment of ", stringify!(__wasi_prestat_u_t)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_prestat_u_t>())).dir as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_prestat_u_t), - "::", - stringify!(dir) - ) - ); - } -} diff --git a/crates/wasi-common/src/old/snapshot_0/hostcalls_impl/fs.rs b/crates/wasi-common/src/old/snapshot_0/hostcalls_impl/fs.rs index 5428b49b20..ff23ae0a5e 100644 --- a/crates/wasi-common/src/old/snapshot_0/hostcalls_impl/fs.rs +++ b/crates/wasi-common/src/old/snapshot_0/hostcalls_impl/fs.rs @@ -985,7 +985,7 @@ pub(crate) unsafe fn fd_prestat_get( memory, prestat_ptr, host::__wasi_prestat_t { - pr_type: wasi::__WASI_PREOPENTYPE_DIR, + tag: wasi::__WASI_PREOPENTYPE_DIR, u: host::__wasi_prestat_u_t { dir: host::__wasi_prestat_dir_t { pr_name_len: path.len(), diff --git a/crates/wasi-common/src/old/snapshot_0/hostcalls_impl/misc.rs b/crates/wasi-common/src/old/snapshot_0/hostcalls_impl/misc.rs index 6cf01355ea..14820a3e66 100644 --- a/crates/wasi-common/src/old/snapshot_0/hostcalls_impl/misc.rs +++ b/crates/wasi-common/src/old/snapshot_0/hostcalls_impl/misc.rs @@ -219,9 +219,9 @@ pub(crate) fn poll_oneoff( let mut timeout: Option = None; let mut fd_events = Vec::new(); 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); @@ -236,17 +236,10 @@ 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 - } else { - wasi::__WASI_RIGHTS_FD_WRITE - }; + 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) @@ -254,19 +247,45 @@ 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); diff --git a/crates/wasi-common/src/old/snapshot_0/memory.rs b/crates/wasi-common/src/old/snapshot_0/memory.rs index 5854c3ee93..c4f1d007ec 100644 --- a/crates/wasi-common/src/old/snapshot_0/memory.rs +++ b/crates/wasi-common/src/old/snapshot_0/memory.rs @@ -329,9 +329,9 @@ pub(crate) fn dec_prestat_byref( ) -> Result { let raw = dec_raw_byref::(memory, prestat_ptr)?; - match PrimInt::from_le(raw.pr_type) { + match PrimInt::from_le(raw.tag) { wasi::__WASI_PREOPENTYPE_DIR => Ok(host::__wasi_prestat_t { - pr_type: wasi::__WASI_PREOPENTYPE_DIR, + tag: wasi::__WASI_PREOPENTYPE_DIR, u: host::__wasi_prestat_u_t { dir: host::__wasi_prestat_dir_t { pr_name_len: dec_usize(PrimInt::from_le(unsafe { raw.u.dir.pr_name_len })), @@ -347,9 +347,9 @@ pub(crate) fn enc_prestat_byref( prestat_ptr: wasi32::uintptr_t, prestat: host::__wasi_prestat_t, ) -> Result<()> { - let raw = match prestat.pr_type { + let raw = match prestat.tag { wasi::__WASI_PREOPENTYPE_DIR => Ok(wasi32::__wasi_prestat_t { - pr_type: PrimInt::to_le(wasi::__WASI_PREOPENTYPE_DIR), + tag: PrimInt::to_le(wasi::__WASI_PREOPENTYPE_DIR), u: wasi32::__wasi_prestat_u_t { dir: wasi32::__wasi_prestat_dir_t { pr_name_len: enc_usize(unsafe { prestat.u.dir.pr_name_len }), @@ -410,10 +410,10 @@ pub(crate) fn dec_subscriptions( .into_iter() .map(|raw_subscription| { let userdata = PrimInt::from_le(raw_subscription.userdata); - let r#type = PrimInt::from_le(raw_subscription.r#type); - let raw_u = raw_subscription.u; - let u = match r#type { - wasi::__WASI_EVENTTYPE_CLOCK => wasi::__wasi_subscription_u_t { + let tag = PrimInt::from_le(raw_subscription.u.tag); + let raw_u = raw_subscription.u.u; + let u = match tag { + wasi::__WASI_EVENTTYPE_CLOCK => wasi::__wasi_subscription_u_u_t { clock: unsafe { wasi::__wasi_subscription_clock_t { identifier: PrimInt::from_le(raw_u.clock.identifier), @@ -424,21 +424,23 @@ pub(crate) fn dec_subscriptions( } }, }, - wasi::__WASI_EVENTTYPE_FD_READ | wasi::__WASI_EVENTTYPE_FD_WRITE => { - wasi::__wasi_subscription_u_t { - fd_readwrite: wasi::__wasi_subscription_fd_readwrite_t { - file_descriptor: PrimInt::from_le(unsafe { - raw_u.fd_readwrite.file_descriptor - }), - }, - } - } + wasi::__WASI_EVENTTYPE_FD_READ => wasi::__wasi_subscription_u_u_t { + fd_read: wasi::__wasi_subscription_fd_readwrite_t { + file_descriptor: PrimInt::from_le(unsafe { raw_u.fd_read.file_descriptor }), + }, + }, + wasi::__WASI_EVENTTYPE_FD_WRITE => wasi::__wasi_subscription_u_u_t { + fd_write: wasi::__wasi_subscription_fd_readwrite_t { + file_descriptor: PrimInt::from_le(unsafe { + raw_u.fd_write.file_descriptor + }), + }, + }, _ => return Err(Error::EINVAL), }; Ok(wasi::__wasi_subscription_t { userdata, - r#type, - u, + u: wasi::__wasi_subscription_u_t { tag, u }, }) }) .collect::>>() @@ -457,17 +459,16 @@ pub(crate) fn enc_events( *raw_output_iter .next() .expect("the number of events cannot exceed the number of subscriptions") = { - let fd_readwrite = unsafe { event.u.fd_readwrite }; + let userdata = PrimInt::to_le(event.userdata); + let error = PrimInt::to_le(event.error); + let r#type = PrimInt::to_le(event.r#type); + let flags = PrimInt::to_le(event.fd_readwrite.flags); + let nbytes = PrimInt::to_le(event.fd_readwrite.nbytes); wasi::__wasi_event_t { - userdata: PrimInt::to_le(event.userdata), - r#type: PrimInt::to_le(event.r#type), - error: PrimInt::to_le(event.error), - u: wasi::__wasi_event_u_t { - fd_readwrite: wasi::__wasi_event_fd_readwrite_t { - nbytes: PrimInt::to_le(fd_readwrite.nbytes), - flags: PrimInt::to_le(fd_readwrite.flags), - }, - }, + userdata, + error, + r#type, + fd_readwrite: wasi::__wasi_event_fd_readwrite_t { flags, nbytes }, } }; } diff --git a/crates/wasi-common/src/old/snapshot_0/sys/unix/hostcalls_impl/misc.rs b/crates/wasi-common/src/old/snapshot_0/sys/unix/hostcalls_impl/misc.rs index 42f67c1178..f6dfbe96ea 100644 --- a/crates/wasi-common/src/old/snapshot_0/sys/unix/hostcalls_impl/misc.rs +++ b/crates/wasi-common/src/old/snapshot_0/sys/unix/hostcalls_impl/misc.rs @@ -111,13 +111,11 @@ fn poll_oneoff_handle_timeout_event( ) { events.push(wasi::__wasi_event_t { userdata: timeout.userdata, - r#type: wasi::__WASI_EVENTTYPE_CLOCK, error: wasi::__WASI_ERRNO_SUCCESS, - u: wasi::__wasi_event_u_t { - fd_readwrite: wasi::__wasi_event_fd_readwrite_t { - nbytes: 0, - flags: 0, - }, + r#type: wasi::__WASI_EVENTTYPE_CLOCK, + fd_readwrite: wasi::__wasi_event_fd_readwrite_t { + flags: 0, + nbytes: 0, }, }); } @@ -149,49 +147,41 @@ fn poll_oneoff_handle_fd_event<'a>( let output_event = if revents.contains(PollFlags::POLLNVAL) { wasi::__wasi_event_t { userdata: fd_event.userdata, - r#type: fd_event.r#type, error: wasi::__WASI_ERRNO_BADF, - u: wasi::__wasi_event_u_t { - fd_readwrite: wasi::__wasi_event_fd_readwrite_t { - nbytes: 0, - flags: wasi::__WASI_EVENTRWFLAGS_FD_READWRITE_HANGUP, - }, + r#type: fd_event.r#type, + fd_readwrite: wasi::__wasi_event_fd_readwrite_t { + nbytes: 0, + flags: wasi::__WASI_EVENTRWFLAGS_FD_READWRITE_HANGUP, }, } } else if revents.contains(PollFlags::POLLERR) { wasi::__wasi_event_t { userdata: fd_event.userdata, - r#type: fd_event.r#type, error: wasi::__WASI_ERRNO_IO, - u: wasi::__wasi_event_u_t { - fd_readwrite: wasi::__wasi_event_fd_readwrite_t { - nbytes: 0, - flags: wasi::__WASI_EVENTRWFLAGS_FD_READWRITE_HANGUP, - }, + r#type: fd_event.r#type, + fd_readwrite: wasi::__wasi_event_fd_readwrite_t { + nbytes: 0, + flags: wasi::__WASI_EVENTRWFLAGS_FD_READWRITE_HANGUP, }, } } else if revents.contains(PollFlags::POLLHUP) { wasi::__wasi_event_t { userdata: fd_event.userdata, - r#type: fd_event.r#type, error: wasi::__WASI_ERRNO_SUCCESS, - u: wasi::__wasi_event_u_t { - fd_readwrite: wasi::__wasi_event_fd_readwrite_t { - nbytes: 0, - flags: wasi::__WASI_EVENTRWFLAGS_FD_READWRITE_HANGUP, - }, + r#type: fd_event.r#type, + fd_readwrite: wasi::__wasi_event_fd_readwrite_t { + nbytes: 0, + flags: wasi::__WASI_EVENTRWFLAGS_FD_READWRITE_HANGUP, }, } } else if revents.contains(PollFlags::POLLIN) | revents.contains(PollFlags::POLLOUT) { wasi::__wasi_event_t { userdata: fd_event.userdata, - r#type: fd_event.r#type, error: wasi::__WASI_ERRNO_SUCCESS, - u: wasi::__wasi_event_u_t { - fd_readwrite: wasi::__wasi_event_fd_readwrite_t { - nbytes: nbytes.try_into()?, - flags: 0, - }, + r#type: fd_event.r#type, + fd_readwrite: wasi::__wasi_event_fd_readwrite_t { + nbytes: nbytes.try_into()?, + flags: 0, }, } } else { diff --git a/crates/wasi-common/src/old/snapshot_0/wasi.rs b/crates/wasi-common/src/old/snapshot_0/wasi.rs index 864585cbdf..63a08e8c5e 100644 --- a/crates/wasi-common/src/old/snapshot_0/wasi.rs +++ b/crates/wasi-common/src/old/snapshot_0/wasi.rs @@ -117,758 +117,3 @@ pub fn whence_to_str(whence: __wasi_whence_t) -> &'static str { } pub const __WASI_DIRCOOKIE_START: __wasi_dircookie_t = 0; - -#[cfg(test)] -mod test { - use super::*; - - #[test] - fn bindgen_test_layout_wasi_dirent_t() { - assert_eq!( - ::std::mem::size_of::<__wasi_dirent_t>(), - 24usize, - concat!("Size of: ", stringify!(__wasi_dirent_t)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_dirent_t>())).d_next as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_dirent_t), - "::", - stringify!(d_next) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_dirent_t>())).d_ino as *const _ as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(__wasi_dirent_t), - "::", - stringify!(d_ino) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_dirent_t>())).d_namlen as *const _ as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(__wasi_dirent_t), - "::", - stringify!(d_namlen) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_dirent_t>())).d_type as *const _ as usize }, - 20usize, - concat!( - "Offset of field: ", - stringify!(__wasi_dirent_t), - "::", - stringify!(d_type) - ) - ); - } - - #[test] - fn bindgen_test_layout___wasi_event_t___wasi_event_u___wasi_event_u_fd_readwrite_t() { - assert_eq!( - ::std::mem::size_of::<__wasi_event_fd_readwrite_t>(), - 16usize, - concat!("Size of: ", stringify!(__wasi_event_fd_readwrite_t)) - ); - assert_eq!( - ::std::mem::align_of::<__wasi_event_fd_readwrite_t>(), - 8usize, - concat!("Alignment of ", stringify!(__wasi_event_fd_readwrite_t)) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<__wasi_event_fd_readwrite_t>())).nbytes as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_event_fd_readwrite_t), - "::", - stringify!(nbytes) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<__wasi_event_fd_readwrite_t>())).flags as *const _ as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(__wasi_event_fd_readwrite_t), - "::", - stringify!(flags) - ) - ); - } - - #[test] - fn bindgen_test_layout___wasi_event_t___wasi_event_u() { - assert_eq!( - ::std::mem::size_of::<__wasi_event_u_t>(), - 16usize, - concat!("Size of: ", stringify!(__wasi_event_u_t)) - ); - assert_eq!( - ::std::mem::align_of::<__wasi_event_u_t>(), - 8usize, - concat!("Alignment of ", stringify!(__wasi_event_u_t)) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<__wasi_event_u_t>())).fd_readwrite as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_event_u_t), - "::", - stringify!(fd_readwrite) - ) - ); - } - - #[test] - fn bindgen_test_layout___wasi_event_t() { - assert_eq!( - ::std::mem::size_of::<__wasi_event_t>(), - 32usize, - concat!("Size of: ", stringify!(__wasi_event_t)) - ); - assert_eq!( - ::std::mem::align_of::<__wasi_event_t>(), - 8usize, - concat!("Alignment of ", stringify!(__wasi_event_t)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_event_t>())).userdata as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_event_t), - "::", - stringify!(userdata) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_event_t>())).error as *const _ as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(__wasi_event_t), - "::", - stringify!(error) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_event_t>())).r#type as *const _ as usize }, - 10usize, - concat!( - "Offset of field: ", - stringify!(__wasi_event_t), - "::", - stringify!(r#type) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_event_t>())).u as *const _ as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(__wasi_event_t), - "::", - stringify!(u) - ) - ); - } - - #[test] - fn bindgen_test_layout_wasi_event_t() { - assert_eq!( - ::std::mem::size_of::<__wasi_event_t>(), - 32usize, - concat!("Size of: ", stringify!(__wasi_event_t)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_event_t>())).userdata as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_event_t), - "::", - stringify!(userdata) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_event_t>())).error as *const _ as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(__wasi_event_t), - "::", - stringify!(error) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_event_t>())).r#type as *const _ as usize }, - 10usize, - concat!( - "Offset of field: ", - stringify!(__wasi_event_t), - "::", - stringify!(r#type) - ) - ); - } - - #[test] - fn bindgen_test_layout_wasi_fdstat_t() { - assert_eq!( - ::std::mem::size_of::<__wasi_fdstat_t>(), - 24usize, - concat!("Size of: ", stringify!(__wasi_fdstat_t)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_fdstat_t>())).fs_filetype as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_fdstat_t), - "::", - stringify!(fs_filetype) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_fdstat_t>())).fs_flags as *const _ as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(__wasi_fdstat_t), - "::", - stringify!(fs_flags) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<__wasi_fdstat_t>())).fs_rights_base as *const _ as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(__wasi_fdstat_t), - "::", - stringify!(fs_rights_base) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<__wasi_fdstat_t>())).fs_rights_inheriting as *const _ - as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(__wasi_fdstat_t), - "::", - stringify!(fs_rights_inheriting) - ) - ); - } - - #[test] - fn bindgen_test_layout_wasi_filestat_t() { - assert_eq!( - ::std::mem::size_of::<__wasi_filestat_t>(), - 56usize, - concat!("Size of: ", stringify!(__wasi_filestat_t)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).dev as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_filestat_t), - "::", - stringify!(st_dev) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).ino as *const _ as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(__wasi_filestat_t), - "::", - stringify!(st_ino) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).filetype as *const _ as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(__wasi_filestat_t), - "::", - stringify!(st_filetype) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).nlink as *const _ as usize }, - 20usize, - concat!( - "Offset of field: ", - stringify!(__wasi_filestat_t), - "::", - stringify!(st_nlink) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).size as *const _ as usize }, - 24usize, - concat!( - "Offset of field: ", - stringify!(__wasi_filestat_t), - "::", - stringify!(st_size) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).atim as *const _ as usize }, - 32usize, - concat!( - "Offset of field: ", - stringify!(__wasi_filestat_t), - "::", - stringify!(st_atim) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).mtim as *const _ as usize }, - 40usize, - concat!( - "Offset of field: ", - stringify!(__wasi_filestat_t), - "::", - stringify!(st_mtim) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).ctim as *const _ as usize }, - 48usize, - concat!( - "Offset of field: ", - stringify!(__wasi_filestat_t), - "::", - stringify!(st_ctim) - ) - ); - } - - #[test] - fn bindgen_test_layout___wasi_subscription_clock_t() { - assert_eq!( - ::std::mem::size_of::<__wasi_subscription_clock_t>(), - 40usize, - concat!("Size of: ", stringify!(__wasi_subscription_clock_t)) - ); - assert_eq!( - ::std::mem::align_of::<__wasi_subscription_clock_t>(), - 8usize, - concat!("Alignment of ", stringify!(__wasi_subscription_clock_t)) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<__wasi_subscription_clock_t>())).identifier as *const _ - as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_subscription_clock_t), - "::", - stringify!(identifier) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<__wasi_subscription_clock_t>())).id as *const _ as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(__wasi_subscription_clock_t), - "::", - stringify!(clock_id) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<__wasi_subscription_clock_t>())).timeout as *const _ as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(__wasi_subscription_clock_t), - "::", - stringify!(timeout) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<__wasi_subscription_clock_t>())).precision as *const _ - as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(__wasi_subscription_clock_t), - "::", - stringify!(precision) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<__wasi_subscription_clock_t>())).flags as *const _ as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(__wasi_subscription_clock_t), - "::", - stringify!(flags) - ) - ); - } - - #[test] - fn bindgen_test_layout___wasi_subscription_t___wasi_subscription_u___wasi_subscription_u_fd_readwrite_t( - ) { - assert_eq!( - ::std::mem::size_of::<__wasi_subscription_fd_readwrite_t>(), - 4usize, - concat!("Size of: ", stringify!(__wasi_subscription_fd_readwrite_t)) - ); - assert_eq!( - ::std::mem::align_of::<__wasi_subscription_fd_readwrite_t>(), - 4usize, - concat!( - "Alignment of ", - stringify!(__wasi_subscription_fd_readwrite_t) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<__wasi_subscription_fd_readwrite_t>())).file_descriptor - as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_subscription_fd_readwrite_t), - "::", - stringify!(fd) - ) - ); - } - - #[test] - fn bindgen_test_layout___wasi_subscription_t___wasi_subscription_u() { - assert_eq!( - ::std::mem::size_of::<__wasi_subscription_u_t>(), - 40usize, - concat!("Size of: ", stringify!(__wasi_subscription_u_t)) - ); - assert_eq!( - ::std::mem::align_of::<__wasi_subscription_u_t>(), - 8usize, - concat!("Alignment of ", stringify!(__wasi_subscription_u_t)) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<__wasi_subscription_u_t>())).clock as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_subscription_u_t), - "::", - stringify!(clock) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<__wasi_subscription_u_t>())).fd_readwrite as *const _ - as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_subscription_u_t), - "::", - stringify!(fd_readwrite) - ) - ); - } - - #[test] - fn bindgen_test_layout___wasi_subscription_t() { - assert_eq!( - ::std::mem::size_of::<__wasi_subscription_t>(), - 56usize, - concat!("Size of: ", stringify!(__wasi_subscription_t)) - ); - assert_eq!( - ::std::mem::align_of::<__wasi_subscription_t>(), - 8usize, - concat!("Alignment of ", stringify!(__wasi_subscription_t)) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<__wasi_subscription_t>())).userdata as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_subscription_t), - "::", - stringify!(userdata) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<__wasi_subscription_t>())).r#type as *const _ as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(__wasi_subscription_t), - "::", - stringify!(r#type) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_subscription_t>())).u as *const _ as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(__wasi_subscription_t), - "::", - stringify!(u) - ) - ); - } - - #[test] - fn bindgen_test_layout___wasi_filestat_t() { - assert_eq!( - ::std::mem::size_of::<__wasi_filestat_t>(), - 56usize, - concat!("Size of: ", stringify!(__wasi_filestat_t)) - ); - assert_eq!( - ::std::mem::align_of::<__wasi_filestat_t>(), - 8usize, - concat!("Alignment of ", stringify!(__wasi_filestat_t)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).dev as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_filestat_t), - "::", - stringify!(st_dev) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).ino as *const _ as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(__wasi_filestat_t), - "::", - stringify!(st_ino) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).filetype as *const _ as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(__wasi_filestat_t), - "::", - stringify!(st_filetype) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).nlink as *const _ as usize }, - 20usize, - concat!( - "Offset of field: ", - stringify!(__wasi_filestat_t), - "::", - stringify!(st_nlink) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).size as *const _ as usize }, - 24usize, - concat!( - "Offset of field: ", - stringify!(__wasi_filestat_t), - "::", - stringify!(st_size) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).atim as *const _ as usize }, - 32usize, - concat!( - "Offset of field: ", - stringify!(__wasi_filestat_t), - "::", - stringify!(st_atim) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).mtim as *const _ as usize }, - 40usize, - concat!( - "Offset of field: ", - stringify!(__wasi_filestat_t), - "::", - stringify!(st_mtim) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).ctim as *const _ as usize }, - 48usize, - concat!( - "Offset of field: ", - stringify!(__wasi_filestat_t), - "::", - stringify!(st_ctim) - ) - ); - } - - #[test] - fn bindgen_test_layout___wasi_fdstat_t() { - assert_eq!( - ::std::mem::size_of::<__wasi_fdstat_t>(), - 24usize, - concat!("Size of: ", stringify!(__wasi_fdstat_t)) - ); - assert_eq!( - ::std::mem::align_of::<__wasi_fdstat_t>(), - 8usize, - concat!("Alignment of ", stringify!(__wasi_fdstat_t)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_fdstat_t>())).fs_filetype as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_fdstat_t), - "::", - stringify!(fs_filetype) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_fdstat_t>())).fs_flags as *const _ as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(__wasi_fdstat_t), - "::", - stringify!(fs_flags) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<__wasi_fdstat_t>())).fs_rights_base as *const _ as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(__wasi_fdstat_t), - "::", - stringify!(fs_rights_base) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<__wasi_fdstat_t>())).fs_rights_inheriting as *const _ - as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(__wasi_fdstat_t), - "::", - stringify!(fs_rights_inheriting) - ) - ); - } - - #[test] - fn bindgen_test_layout___wasi_dirent_t() { - assert_eq!( - ::std::mem::size_of::<__wasi_dirent_t>(), - 24usize, - concat!("Size of: ", stringify!(__wasi_dirent_t)) - ); - assert_eq!( - ::std::mem::align_of::<__wasi_dirent_t>(), - 8usize, - concat!("Alignment of ", stringify!(__wasi_dirent_t)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_dirent_t>())).d_next as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_dirent_t), - "::", - stringify!(d_next) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_dirent_t>())).d_ino as *const _ as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(__wasi_dirent_t), - "::", - stringify!(d_ino) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_dirent_t>())).d_namlen as *const _ as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(__wasi_dirent_t), - "::", - stringify!(d_namlen) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_dirent_t>())).d_type as *const _ as usize }, - 20usize, - concat!( - "Offset of field: ", - stringify!(__wasi_dirent_t), - "::", - stringify!(d_type) - ) - ); - } -} diff --git a/crates/wasi-common/src/old/snapshot_0/wasi32.rs b/crates/wasi-common/src/old/snapshot_0/wasi32.rs index 9a102f9b48..9afc0fc5e9 100644 --- a/crates/wasi-common/src/old/snapshot_0/wasi32.rs +++ b/crates/wasi-common/src/old/snapshot_0/wasi32.rs @@ -13,160 +13,3 @@ pub type uintptr_t = u32; pub type size_t = u32; witx_wasi32_types!("old/snapshot_0" "wasi_unstable"); - -#[cfg(test)] -mod test { - use super::*; - - #[test] - fn bindgen_test_layout_wasi_ciovec_t() { - assert_eq!( - ::std::mem::size_of::<__wasi_ciovec_t>(), - 8usize, - concat!("Size of: ", stringify!(__wasi_ciovec_t)) - ); - assert_eq!( - ::std::mem::align_of::<__wasi_ciovec_t>(), - 4usize, - concat!("Alignment of ", stringify!(__wasi_ciovec_t)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_ciovec_t>())).buf as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_ciovec_t), - "::", - stringify!(buf) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_ciovec_t>())).buf_len as *const _ as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(__wasi_ciovec_t), - "::", - stringify!(buf_len) - ) - ); - } - - #[test] - fn bindgen_test_layout_wasi_iovec_t() { - assert_eq!( - ::std::mem::size_of::<__wasi_iovec_t>(), - 8usize, - concat!("Size of: ", stringify!(__wasi_iovec_t)) - ); - assert_eq!( - ::std::mem::align_of::<__wasi_iovec_t>(), - 4usize, - concat!("Alignment of ", stringify!(__wasi_iovec_t)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_iovec_t>())).buf as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_iovec_t), - "::", - stringify!(buf) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_iovec_t>())).buf_len as *const _ as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(__wasi_iovec_t), - "::", - stringify!(buf_len) - ) - ); - } - - #[test] - fn bindgen_test_layout___wasi_prestat_t___wasi_prestat_u___wasi_prestat_u_dir_t() { - assert_eq!( - ::std::mem::size_of::<__wasi_prestat_dir_t>(), - 4usize, - concat!("Size of: ", stringify!(__wasi_prestat_dir_t)) - ); - assert_eq!( - ::std::mem::align_of::<__wasi_prestat_dir_t>(), - 4usize, - concat!("Alignment of ", stringify!(__wasi_prestat_dir_t)) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<__wasi_prestat_dir_t>())).pr_name_len as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_prestat_dir_t), - "::", - stringify!(pr_name_len) - ) - ); - } - - #[test] - fn bindgen_test_layout___wasi_prestat_t___wasi_prestat_u() { - assert_eq!( - ::std::mem::size_of::<__wasi_prestat_u_t>(), - 4usize, - concat!("Size of: ", stringify!(__wasi_prestat_u_t)) - ); - assert_eq!( - ::std::mem::align_of::<__wasi_prestat_u_t>(), - 4usize, - concat!("Alignment of ", stringify!(__wasi_prestat_u_t)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_prestat_u_t>())).dir as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_prestat_u_t), - "::", - stringify!(dir) - ) - ); - } - - #[test] - fn bindgen_test_layout___wasi_prestat_t() { - assert_eq!( - ::std::mem::size_of::<__wasi_prestat_t>(), - 8usize, - concat!("Size of: ", stringify!(__wasi_prestat_t)) - ); - assert_eq!( - ::std::mem::align_of::<__wasi_prestat_t>(), - 4usize, - concat!("Alignment of ", stringify!(__wasi_prestat_t)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_prestat_t>())).pr_type as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_prestat_t), - "::", - stringify!(pr_type) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_prestat_t>())).u as *const _ as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(__wasi_prestat_t), - "::", - stringify!(u) - ) - ); - } -} diff --git a/crates/wasi-common/src/sys/unix/hostcalls_impl/misc.rs b/crates/wasi-common/src/sys/unix/hostcalls_impl/misc.rs index 30adda29ed..6094395a22 100644 --- a/crates/wasi-common/src/sys/unix/hostcalls_impl/misc.rs +++ b/crates/wasi-common/src/sys/unix/hostcalls_impl/misc.rs @@ -111,13 +111,11 @@ fn poll_oneoff_handle_timeout_event( ) { events.push(wasi::__wasi_event_t { userdata: timeout.userdata, - r#type: wasi::__WASI_EVENTTYPE_CLOCK, error: wasi::__WASI_ERRNO_SUCCESS, - u: wasi::__wasi_event_u_t { - fd_readwrite: wasi::__wasi_event_fd_readwrite_t { - nbytes: 0, - flags: 0, - }, + r#type: wasi::__WASI_EVENTTYPE_CLOCK, + fd_readwrite: wasi::__wasi_event_fd_readwrite_t { + flags: 0, + nbytes: 0, }, }); } @@ -149,49 +147,41 @@ fn poll_oneoff_handle_fd_event<'a>( let output_event = if revents.contains(PollFlags::POLLNVAL) { wasi::__wasi_event_t { userdata: fd_event.userdata, - r#type: fd_event.r#type, error: wasi::__WASI_ERRNO_BADF, - u: wasi::__wasi_event_u_t { - fd_readwrite: wasi::__wasi_event_fd_readwrite_t { - nbytes: 0, - flags: wasi::__WASI_EVENTRWFLAGS_FD_READWRITE_HANGUP, - }, + r#type: fd_event.r#type, + fd_readwrite: wasi::__wasi_event_fd_readwrite_t { + nbytes: 0, + flags: wasi::__WASI_EVENTRWFLAGS_FD_READWRITE_HANGUP, }, } } else if revents.contains(PollFlags::POLLERR) { wasi::__wasi_event_t { userdata: fd_event.userdata, - r#type: fd_event.r#type, error: wasi::__WASI_ERRNO_IO, - u: wasi::__wasi_event_u_t { - fd_readwrite: wasi::__wasi_event_fd_readwrite_t { - nbytes: 0, - flags: wasi::__WASI_EVENTRWFLAGS_FD_READWRITE_HANGUP, - }, + r#type: fd_event.r#type, + fd_readwrite: wasi::__wasi_event_fd_readwrite_t { + nbytes: 0, + flags: wasi::__WASI_EVENTRWFLAGS_FD_READWRITE_HANGUP, }, } } else if revents.contains(PollFlags::POLLHUP) { wasi::__wasi_event_t { userdata: fd_event.userdata, - r#type: fd_event.r#type, error: wasi::__WASI_ERRNO_SUCCESS, - u: wasi::__wasi_event_u_t { - fd_readwrite: wasi::__wasi_event_fd_readwrite_t { - nbytes: 0, - flags: wasi::__WASI_EVENTRWFLAGS_FD_READWRITE_HANGUP, - }, + r#type: fd_event.r#type, + fd_readwrite: wasi::__wasi_event_fd_readwrite_t { + nbytes: 0, + flags: wasi::__WASI_EVENTRWFLAGS_FD_READWRITE_HANGUP, }, } } else if revents.contains(PollFlags::POLLIN) | revents.contains(PollFlags::POLLOUT) { wasi::__wasi_event_t { userdata: fd_event.userdata, - r#type: fd_event.r#type, error: wasi::__WASI_ERRNO_SUCCESS, - u: wasi::__wasi_event_u_t { - fd_readwrite: wasi::__wasi_event_fd_readwrite_t { - nbytes: nbytes.try_into()?, - flags: 0, - }, + r#type: fd_event.r#type, + fd_readwrite: wasi::__wasi_event_fd_readwrite_t { + nbytes: nbytes.try_into()?, + flags: 0, }, } } else { diff --git a/crates/wasi-common/src/sys/windows/hostcalls_impl/misc.rs b/crates/wasi-common/src/sys/windows/hostcalls_impl/misc.rs index 1e2db73404..7c5330127b 100644 --- a/crates/wasi-common/src/sys/windows/hostcalls_impl/misc.rs +++ b/crates/wasi-common/src/sys/windows/hostcalls_impl/misc.rs @@ -175,9 +175,7 @@ fn make_rw_event(event: &FdEventData, nbytes: Result) -> wasi::__wasi_event userdata: event.userdata, r#type: event.r#type, error: error.as_raw_errno(), - u: wasi::__wasi_event_u_t { - fd_readwrite: wasi::__wasi_event_fd_readwrite_t { nbytes, flags: 0 }, - }, + fd_readwrite: wasi::__wasi_event_fd_readwrite_t { nbytes, flags: 0 }, } } @@ -186,11 +184,9 @@ fn make_timeout_event(timeout: &ClockEventData) -> wasi::__wasi_event_t { userdata: timeout.userdata, r#type: wasi::__WASI_EVENTTYPE_CLOCK, error: wasi::__WASI_ERRNO_SUCCESS, - u: wasi::__wasi_event_u_t { - fd_readwrite: wasi::__wasi_event_fd_readwrite_t { - nbytes: 0, - flags: 0, - }, + fd_readwrite: wasi::__wasi_event_fd_readwrite_t { + nbytes: 0, + flags: 0, }, } } diff --git a/crates/wasi-common/src/wasi.rs b/crates/wasi-common/src/wasi.rs index 2c05d03957..e418546a07 100644 --- a/crates/wasi-common/src/wasi.rs +++ b/crates/wasi-common/src/wasi.rs @@ -117,745 +117,3 @@ pub fn whence_to_str(whence: __wasi_whence_t) -> &'static str { } pub const __WASI_DIRCOOKIE_START: __wasi_dircookie_t = 0; - -#[cfg(test)] -mod test { - use super::*; - - #[test] - fn bindgen_test_layout_wasi_dirent_t() { - assert_eq!( - ::std::mem::size_of::<__wasi_dirent_t>(), - 24usize, - concat!("Size of: ", stringify!(__wasi_dirent_t)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_dirent_t>())).d_next as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_dirent_t), - "::", - stringify!(d_next) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_dirent_t>())).d_ino as *const _ as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(__wasi_dirent_t), - "::", - stringify!(d_ino) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_dirent_t>())).d_namlen as *const _ as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(__wasi_dirent_t), - "::", - stringify!(d_namlen) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_dirent_t>())).d_type as *const _ as usize }, - 20usize, - concat!( - "Offset of field: ", - stringify!(__wasi_dirent_t), - "::", - stringify!(d_type) - ) - ); - } - - #[test] - fn bindgen_test_layout___wasi_event_t___wasi_event_u___wasi_event_u_fd_readwrite_t() { - assert_eq!( - ::std::mem::size_of::<__wasi_event_fd_readwrite_t>(), - 16usize, - concat!("Size of: ", stringify!(__wasi_event_fd_readwrite_t)) - ); - assert_eq!( - ::std::mem::align_of::<__wasi_event_fd_readwrite_t>(), - 8usize, - concat!("Alignment of ", stringify!(__wasi_event_fd_readwrite_t)) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<__wasi_event_fd_readwrite_t>())).nbytes as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_event_fd_readwrite_t), - "::", - stringify!(nbytes) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<__wasi_event_fd_readwrite_t>())).flags as *const _ as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(__wasi_event_fd_readwrite_t), - "::", - stringify!(flags) - ) - ); - } - - #[test] - fn bindgen_test_layout___wasi_event_t___wasi_event_u() { - assert_eq!( - ::std::mem::size_of::<__wasi_event_u_t>(), - 16usize, - concat!("Size of: ", stringify!(__wasi_event_u_t)) - ); - assert_eq!( - ::std::mem::align_of::<__wasi_event_u_t>(), - 8usize, - concat!("Alignment of ", stringify!(__wasi_event_u_t)) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<__wasi_event_u_t>())).fd_readwrite as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_event_u_t), - "::", - stringify!(fd_readwrite) - ) - ); - } - - #[test] - fn bindgen_test_layout___wasi_event_t() { - assert_eq!( - ::std::mem::size_of::<__wasi_event_t>(), - 32usize, - concat!("Size of: ", stringify!(__wasi_event_t)) - ); - assert_eq!( - ::std::mem::align_of::<__wasi_event_t>(), - 8usize, - concat!("Alignment of ", stringify!(__wasi_event_t)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_event_t>())).userdata as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_event_t), - "::", - stringify!(userdata) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_event_t>())).error as *const _ as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(__wasi_event_t), - "::", - stringify!(error) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_event_t>())).r#type as *const _ as usize }, - 10usize, - concat!( - "Offset of field: ", - stringify!(__wasi_event_t), - "::", - stringify!(r#type) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_event_t>())).u as *const _ as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(__wasi_event_t), - "::", - stringify!(u) - ) - ); - } - - #[test] - fn bindgen_test_layout_wasi_event_t() { - assert_eq!( - ::std::mem::size_of::<__wasi_event_t>(), - 32usize, - concat!("Size of: ", stringify!(__wasi_event_t)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_event_t>())).userdata as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_event_t), - "::", - stringify!(userdata) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_event_t>())).error as *const _ as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(__wasi_event_t), - "::", - stringify!(error) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_event_t>())).r#type as *const _ as usize }, - 10usize, - concat!( - "Offset of field: ", - stringify!(__wasi_event_t), - "::", - stringify!(r#type) - ) - ); - } - - #[test] - fn bindgen_test_layout_wasi_fdstat_t() { - assert_eq!( - ::std::mem::size_of::<__wasi_fdstat_t>(), - 24usize, - concat!("Size of: ", stringify!(__wasi_fdstat_t)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_fdstat_t>())).fs_filetype as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_fdstat_t), - "::", - stringify!(fs_filetype) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_fdstat_t>())).fs_flags as *const _ as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(__wasi_fdstat_t), - "::", - stringify!(fs_flags) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<__wasi_fdstat_t>())).fs_rights_base as *const _ as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(__wasi_fdstat_t), - "::", - stringify!(fs_rights_base) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<__wasi_fdstat_t>())).fs_rights_inheriting as *const _ - as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(__wasi_fdstat_t), - "::", - stringify!(fs_rights_inheriting) - ) - ); - } - - #[test] - fn bindgen_test_layout_wasi_filestat_t() { - assert_eq!( - ::std::mem::size_of::<__wasi_filestat_t>(), - 64usize, - concat!("Size of: ", stringify!(__wasi_filestat_t)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).dev as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_filestat_t), - "::", - stringify!(st_dev) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).ino as *const _ as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(__wasi_filestat_t), - "::", - stringify!(st_ino) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).filetype as *const _ as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(__wasi_filestat_t), - "::", - stringify!(st_filetype) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).nlink as *const _ as usize }, - 24usize, - concat!( - "Offset of field: ", - stringify!(__wasi_filestat_t), - "::", - stringify!(st_nlink) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).size as *const _ as usize }, - 32usize, - concat!( - "Offset of field: ", - stringify!(__wasi_filestat_t), - "::", - stringify!(st_size) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).atim as *const _ as usize }, - 40usize, - concat!( - "Offset of field: ", - stringify!(__wasi_filestat_t), - "::", - stringify!(st_atim) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).mtim as *const _ as usize }, - 48usize, - concat!( - "Offset of field: ", - stringify!(__wasi_filestat_t), - "::", - stringify!(st_mtim) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).ctim as *const _ as usize }, - 56usize, - concat!( - "Offset of field: ", - stringify!(__wasi_filestat_t), - "::", - stringify!(st_ctim) - ) - ); - } - - #[test] - fn bindgen_test_layout___wasi_subscription_clock_t() { - assert_eq!( - ::std::mem::size_of::<__wasi_subscription_clock_t>(), - 32usize, - concat!("Size of: ", stringify!(__wasi_subscription_clock_t)) - ); - assert_eq!( - ::std::mem::align_of::<__wasi_subscription_clock_t>(), - 8usize, - concat!("Alignment of ", stringify!(__wasi_subscription_clock_t)) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<__wasi_subscription_clock_t>())).id as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_subscription_clock_t), - "::", - stringify!(clock_id) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<__wasi_subscription_clock_t>())).timeout as *const _ as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(__wasi_subscription_clock_t), - "::", - stringify!(timeout) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<__wasi_subscription_clock_t>())).precision as *const _ - as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(__wasi_subscription_clock_t), - "::", - stringify!(precision) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<__wasi_subscription_clock_t>())).flags as *const _ as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(__wasi_subscription_clock_t), - "::", - stringify!(flags) - ) - ); - } - - #[test] - fn bindgen_test_layout___wasi_subscription_t___wasi_subscription_u___wasi_subscription_u_fd_readwrite_t( - ) { - assert_eq!( - ::std::mem::size_of::<__wasi_subscription_fd_readwrite_t>(), - 4usize, - concat!("Size of: ", stringify!(__wasi_subscription_fd_readwrite_t)) - ); - assert_eq!( - ::std::mem::align_of::<__wasi_subscription_fd_readwrite_t>(), - 4usize, - concat!( - "Alignment of ", - stringify!(__wasi_subscription_fd_readwrite_t) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<__wasi_subscription_fd_readwrite_t>())).file_descriptor - as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_subscription_fd_readwrite_t), - "::", - stringify!(fd) - ) - ); - } - - #[test] - fn bindgen_test_layout___wasi_subscription_t___wasi_subscription_u() { - assert_eq!( - ::std::mem::size_of::<__wasi_subscription_u_t>(), - 32usize, - concat!("Size of: ", stringify!(__wasi_subscription_u_t)) - ); - assert_eq!( - ::std::mem::align_of::<__wasi_subscription_u_t>(), - 8usize, - concat!("Alignment of ", stringify!(__wasi_subscription_u_t)) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<__wasi_subscription_u_t>())).clock as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_subscription_u_t), - "::", - stringify!(clock) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<__wasi_subscription_u_t>())).fd_readwrite as *const _ - as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_subscription_u_t), - "::", - stringify!(fd_readwrite) - ) - ); - } - - #[test] - fn bindgen_test_layout___wasi_subscription_t() { - assert_eq!( - ::std::mem::size_of::<__wasi_subscription_t>(), - 48usize, - concat!("Size of: ", stringify!(__wasi_subscription_t)) - ); - assert_eq!( - ::std::mem::align_of::<__wasi_subscription_t>(), - 8usize, - concat!("Alignment of ", stringify!(__wasi_subscription_t)) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<__wasi_subscription_t>())).userdata as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_subscription_t), - "::", - stringify!(userdata) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<__wasi_subscription_t>())).r#type as *const _ as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(__wasi_subscription_t), - "::", - stringify!(r#type) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_subscription_t>())).u as *const _ as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(__wasi_subscription_t), - "::", - stringify!(u) - ) - ); - } - - #[test] - fn bindgen_test_layout___wasi_filestat_t() { - assert_eq!( - ::std::mem::size_of::<__wasi_filestat_t>(), - 64usize, - concat!("Size of: ", stringify!(__wasi_filestat_t)) - ); - assert_eq!( - ::std::mem::align_of::<__wasi_filestat_t>(), - 8usize, - concat!("Alignment of ", stringify!(__wasi_filestat_t)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).dev as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_filestat_t), - "::", - stringify!(st_dev) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).ino as *const _ as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(__wasi_filestat_t), - "::", - stringify!(st_ino) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).filetype as *const _ as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(__wasi_filestat_t), - "::", - stringify!(st_filetype) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).nlink as *const _ as usize }, - 24usize, - concat!( - "Offset of field: ", - stringify!(__wasi_filestat_t), - "::", - stringify!(st_nlink) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).size as *const _ as usize }, - 32usize, - concat!( - "Offset of field: ", - stringify!(__wasi_filestat_t), - "::", - stringify!(st_size) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).atim as *const _ as usize }, - 40usize, - concat!( - "Offset of field: ", - stringify!(__wasi_filestat_t), - "::", - stringify!(st_atim) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).mtim as *const _ as usize }, - 48usize, - concat!( - "Offset of field: ", - stringify!(__wasi_filestat_t), - "::", - stringify!(st_mtim) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).ctim as *const _ as usize }, - 56usize, - concat!( - "Offset of field: ", - stringify!(__wasi_filestat_t), - "::", - stringify!(st_ctim) - ) - ); - } - - #[test] - fn bindgen_test_layout___wasi_fdstat_t() { - assert_eq!( - ::std::mem::size_of::<__wasi_fdstat_t>(), - 24usize, - concat!("Size of: ", stringify!(__wasi_fdstat_t)) - ); - assert_eq!( - ::std::mem::align_of::<__wasi_fdstat_t>(), - 8usize, - concat!("Alignment of ", stringify!(__wasi_fdstat_t)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_fdstat_t>())).fs_filetype as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_fdstat_t), - "::", - stringify!(fs_filetype) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_fdstat_t>())).fs_flags as *const _ as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(__wasi_fdstat_t), - "::", - stringify!(fs_flags) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<__wasi_fdstat_t>())).fs_rights_base as *const _ as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(__wasi_fdstat_t), - "::", - stringify!(fs_rights_base) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<__wasi_fdstat_t>())).fs_rights_inheriting as *const _ - as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(__wasi_fdstat_t), - "::", - stringify!(fs_rights_inheriting) - ) - ); - } - - #[test] - fn bindgen_test_layout___wasi_dirent_t() { - assert_eq!( - ::std::mem::size_of::<__wasi_dirent_t>(), - 24usize, - concat!("Size of: ", stringify!(__wasi_dirent_t)) - ); - assert_eq!( - ::std::mem::align_of::<__wasi_dirent_t>(), - 8usize, - concat!("Alignment of ", stringify!(__wasi_dirent_t)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_dirent_t>())).d_next as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_dirent_t), - "::", - stringify!(d_next) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_dirent_t>())).d_ino as *const _ as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(__wasi_dirent_t), - "::", - stringify!(d_ino) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_dirent_t>())).d_namlen as *const _ as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(__wasi_dirent_t), - "::", - stringify!(d_namlen) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_dirent_t>())).d_type as *const _ as usize }, - 20usize, - concat!( - "Offset of field: ", - stringify!(__wasi_dirent_t), - "::", - stringify!(d_type) - ) - ); - } -} diff --git a/crates/wasi-common/src/wasi32.rs b/crates/wasi-common/src/wasi32.rs index 974ba53b74..11460010c8 100644 --- a/crates/wasi-common/src/wasi32.rs +++ b/crates/wasi-common/src/wasi32.rs @@ -13,160 +13,3 @@ pub type uintptr_t = u32; pub type size_t = u32; witx_wasi32_types!("snapshot" "wasi_snapshot_preview1"); - -#[cfg(test)] -mod test { - use super::*; - - #[test] - fn bindgen_test_layout_wasi_ciovec_t() { - assert_eq!( - ::std::mem::size_of::<__wasi_ciovec_t>(), - 8usize, - concat!("Size of: ", stringify!(__wasi_ciovec_t)) - ); - assert_eq!( - ::std::mem::align_of::<__wasi_ciovec_t>(), - 4usize, - concat!("Alignment of ", stringify!(__wasi_ciovec_t)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_ciovec_t>())).buf as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_ciovec_t), - "::", - stringify!(buf) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_ciovec_t>())).buf_len as *const _ as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(__wasi_ciovec_t), - "::", - stringify!(buf_len) - ) - ); - } - - #[test] - fn bindgen_test_layout_wasi_iovec_t() { - assert_eq!( - ::std::mem::size_of::<__wasi_iovec_t>(), - 8usize, - concat!("Size of: ", stringify!(__wasi_iovec_t)) - ); - assert_eq!( - ::std::mem::align_of::<__wasi_iovec_t>(), - 4usize, - concat!("Alignment of ", stringify!(__wasi_iovec_t)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_iovec_t>())).buf as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_iovec_t), - "::", - stringify!(buf) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_iovec_t>())).buf_len as *const _ as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(__wasi_iovec_t), - "::", - stringify!(buf_len) - ) - ); - } - - #[test] - fn bindgen_test_layout___wasi_prestat_t___wasi_prestat_u___wasi_prestat_u_dir_t() { - assert_eq!( - ::std::mem::size_of::<__wasi_prestat_dir_t>(), - 4usize, - concat!("Size of: ", stringify!(__wasi_prestat_dir_t)) - ); - assert_eq!( - ::std::mem::align_of::<__wasi_prestat_dir_t>(), - 4usize, - concat!("Alignment of ", stringify!(__wasi_prestat_dir_t)) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::<__wasi_prestat_dir_t>())).pr_name_len as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_prestat_dir_t), - "::", - stringify!(pr_name_len) - ) - ); - } - - #[test] - fn bindgen_test_layout___wasi_prestat_t___wasi_prestat_u() { - assert_eq!( - ::std::mem::size_of::<__wasi_prestat_u_t>(), - 4usize, - concat!("Size of: ", stringify!(__wasi_prestat_u_t)) - ); - assert_eq!( - ::std::mem::align_of::<__wasi_prestat_u_t>(), - 4usize, - concat!("Alignment of ", stringify!(__wasi_prestat_u_t)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_prestat_u_t>())).dir as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_prestat_u_t), - "::", - stringify!(dir) - ) - ); - } - - #[test] - fn bindgen_test_layout___wasi_prestat_t() { - assert_eq!( - ::std::mem::size_of::<__wasi_prestat_t>(), - 8usize, - concat!("Size of: ", stringify!(__wasi_prestat_t)) - ); - assert_eq!( - ::std::mem::align_of::<__wasi_prestat_t>(), - 4usize, - concat!("Alignment of ", stringify!(__wasi_prestat_t)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_prestat_t>())).pr_type as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__wasi_prestat_t), - "::", - stringify!(pr_type) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__wasi_prestat_t>())).u as *const _ as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(__wasi_prestat_t), - "::", - stringify!(u) - ) - ); - } -} diff --git a/crates/wasi-common/wig/Cargo.toml b/crates/wasi-common/wig/Cargo.toml index 4d1a62579f..f38e94b7ee 100644 --- a/crates/wasi-common/wig/Cargo.toml +++ b/crates/wasi-common/wig/Cargo.toml @@ -17,7 +17,7 @@ proc-macro = true quote = "1.0.2" proc-macro2 = "1.0.6" heck = "0.3.1" -witx = "0.7.0" +witx = { path = "WASI/tools/witx" } [badges] maintenance = { status = "actively-developed" } diff --git a/crates/wasi-common/wig/WASI b/crates/wasi-common/wig/WASI index 04d4eba571..85df508517 160000 --- a/crates/wasi-common/wig/WASI +++ b/crates/wasi-common/wig/WASI @@ -1 +1 @@ -Subproject commit 04d4eba571dc1d6fe9ab129ea9343911bcc256dc +Subproject commit 85df5085172a75f2a490a89833821c85cdbfaba7 diff --git a/crates/wasi-common/wig/src/raw_types.rs b/crates/wasi-common/wig/src/raw_types.rs index b0f176c93a..04cbd26fc6 100644 --- a/crates/wasi-common/wig/src/raw_types.rs +++ b/crates/wasi-common/wig/src/raw_types.rs @@ -39,17 +39,41 @@ pub fn gen(args: TokenStream, mode: Mode) -> TokenStream { } fn gen_datatypes(output: &mut TokenStream, doc: &witx::Document, mode: Mode) { + let mut test_contents = TokenStream::new(); for namedtype in doc.typenames() { if mode.include_target_types() != namedtype_has_target_size(&namedtype) { continue; } - - gen_datatype(output, mode, &namedtype); + gen_datatype(output, &mut test_contents, mode, &namedtype); + } + match mode { + Mode::Wasi | Mode::Wasi32 => output.extend(quote! { + #[cfg(test)] + mod test { + use super::*; + #test_contents + } + }), + Mode::Host => {} // Don't emit tests for host reprs - the layout is different } } -fn gen_datatype(output: &mut TokenStream, mode: Mode, namedtype: &witx::NamedType) { +fn gen_datatype( + output: &mut TokenStream, + test_contents: &mut TokenStream, + mode: Mode, + namedtype: &witx::NamedType, +) { let wasi_name = format_ident!("__wasi_{}_t", namedtype.name.as_str()); + let (size, align) = { + use witx::Layout; + let sa = namedtype.type_().mem_size_align(); + (sa.size, sa.align) + }; + let mut test_code = quote! { + assert_eq!(::std::mem::size_of::<#wasi_name>(), #size, concat!("Size of: ", stringify!(#wasi_name))); + assert_eq!(::std::mem::align_of::<#wasi_name>(), #align, concat!("Align of: ", stringify!(#wasi_name))); + }; match &namedtype.tref { witx::TypeRef::Name(alias_to) => { let to = tref_tokens(mode, &alias_to.tref); @@ -102,29 +126,59 @@ fn gen_datatype(output: &mut TokenStream, mode: Mode, namedtype: &witx::NamedTyp output.extend(quote!(pub struct #wasi_name)); let mut inner = TokenStream::new(); - for member in &s.members { - let member_name = format_ident!("r#{}", member.name.as_str()); - let member_type = tref_tokens(mode, &member.tref); + for ml in s.member_layout().iter() { + let member_name = format_ident!("r#{}", ml.member.name.as_str()); + let member_type = tref_tokens(mode, &ml.member.tref); + let offset = ml.offset; inner.extend(quote!(pub #member_name: #member_type,)); + test_code.extend(quote!{ + assert_eq!( + unsafe { &(*(::std::ptr::null::<#wasi_name>())).#member_name as *const _ as usize }, + #offset, + concat!( + "Offset of field: ", + stringify!(#wasi_name), + "::", + stringify!(#member_name), + ) + ); + }); } let braced = Group::new(Delimiter::Brace, inner); output.extend(TokenStream::from(TokenTree::Group(braced))); } witx::Type::Union(u) => { + let u_name = format_ident!("__wasi_{}_u_t", namedtype.name.as_str()); output.extend(quote!(#[repr(C)])); output.extend(quote!(#[derive(Copy, Clone)])); output.extend(quote!(#[allow(missing_debug_implementations)])); - output.extend(quote!(pub union #wasi_name)); + output.extend(quote!(pub union #u_name)); let mut inner = TokenStream::new(); for variant in &u.variants { let variant_name = format_ident!("r#{}", variant.name.as_str()); - let variant_type = tref_tokens(mode, &variant.tref); - inner.extend(quote!(pub #variant_name: #variant_type,)); + if let Some(ref tref) = variant.tref { + let variant_type = tref_tokens(mode, tref); + inner.extend(quote!(pub #variant_name: #variant_type,)); + } else { + inner.extend(quote!(pub #variant_name: (),)); + } } let braced = Group::new(Delimiter::Brace, inner); output.extend(TokenStream::from(TokenTree::Group(braced))); + + output.extend(quote!(#[repr(C)])); + output.extend(quote!(#[derive(Copy, Clone)])); + output.extend(quote!(#[allow(missing_debug_implementations)])); + + output.extend(quote!(pub struct #wasi_name)); + let tag_name = format_ident!("__wasi_{}_t", u.tag.name.as_str()); + let inner = quote!(pub tag: #tag_name, pub u: #u_name,); + output.extend(TokenStream::from(TokenTree::Group(Group::new( + Delimiter::Brace, + inner, + )))); } witx::Type::Handle(_h) => { output.extend(quote!(pub type #wasi_name = u32;)); @@ -154,6 +208,14 @@ fn gen_datatype(output: &mut TokenStream, mode: Mode, namedtype: &witx::NamedTyp // Generate strerror for errno type gen_errno_strerror(output, namedtype); } + + let test_func_name = format_ident!("wig_test_layout_{}", namedtype.name.as_str()); + test_contents.extend(quote! { + #[test] + fn #test_func_name() { + #test_code + } + }); } fn gen_errno_strerror(output: &mut TokenStream, namedtype: &witx::NamedType) { @@ -288,7 +350,10 @@ fn type_has_target_size(ty: &witx::Type) -> bool { witx::Type::Pointer { .. } | witx::Type::ConstPointer { .. } => true, witx::Type::Array(elem) => tref_has_target_size(elem), witx::Type::Struct(s) => s.members.iter().any(|m| tref_has_target_size(&m.tref)), - witx::Type::Union(u) => u.variants.iter().any(|v| tref_has_target_size(&v.tref)), + witx::Type::Union(u) => u + .variants + .iter() + .any(|v| v.tref.as_ref().map(tref_has_target_size).unwrap_or(false)), _ => false, } }