Merge branch 'feature/wasi' of github.com:wasmerio/wasmer into feature/wasi

This commit is contained in:
Mark McCaskey 2019-04-02 12:06:51 -07:00
commit 04a80739e1
2 changed files with 72 additions and 25 deletions

View File

@ -201,10 +201,13 @@ impl WasiFs {
let inode_val = &self.inodes[fd.inode]; let inode_val = &self.inodes[fd.inode];
if inode_val.is_preopened { if inode_val.is_preopened {
Ok(PrestatEnum::PreOpenDir { Ok(__wasi_prestat_t {
pr_name_len: inode_val.name.len() as u32, pr_type: __WASI_PREOPENTYPE_DIR,
} u: PrestatEnum::Dir {
.get_untagged()) pr_name_len: inode_val.name.len() as u32,
}
.untagged(),
})
} else { } else {
Err(__WASI_EBADF) Err(__WASI_EBADF)
} }

View File

@ -134,6 +134,24 @@ pub union __wasi_event_u {
fd_readwrite: __wasi_event_fd_readwrite_t, fd_readwrite: __wasi_event_fd_readwrite_t,
} }
#[derive(Copy, Clone)]
pub enum EventEnum {
FdReadWrite {
nbytes: __wasi_filesize_t,
flags: __wasi_eventrwflags_t,
},
}
impl EventEnum {
pub fn untagged(self) -> __wasi_event_u {
match self {
EventEnum::FdReadWrite { nbytes, flags } => __wasi_event_u {
fd_readwrite: __wasi_event_fd_readwrite_t { nbytes, flags },
},
}
}
}
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
#[repr(C)] #[repr(C)]
pub struct __wasi_event_t { pub struct __wasi_event_t {
@ -143,6 +161,18 @@ pub struct __wasi_event_t {
pub u: __wasi_event_u, pub u: __wasi_event_u,
} }
impl __wasi_event_t {
pub fn tagged(&self) -> Option<EventEnum> {
match self.type_ {
__WASI_EVENTTYPE_FD_READ | __WASI_EVENTTYPE_FD_WRITE => Some(EventEnum::FdReadWrite {
nbytes: unsafe { self.u.fd_readwrite.nbytes },
flags: unsafe { self.u.fd_readwrite.flags },
}),
_ => None,
}
}
}
pub type __wasi_eventrwflags_t = u16; pub type __wasi_eventrwflags_t = u16;
pub const __WASI_EVENT_FD_READWRITE_HANGUP: u16 = 1 << 0; pub const __WASI_EVENT_FD_READWRITE_HANGUP: u16 = 1 << 0;
@ -171,7 +201,7 @@ pub const __WASI_PREOPENTYPE_DIR: u8 = 0;
#[derive(Debug, Copy, Clone, PartialEq, Eq)] #[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[repr(C)] #[repr(C)]
pub struct __wasi_prestat_u_dir_t { pub struct __wasi_prestat_u_dir_t {
pr_name_len: u32, pub pr_name_len: u32,
} }
unsafe impl ValueType for __wasi_prestat_u_dir_t {} unsafe impl ValueType for __wasi_prestat_u_dir_t {}
@ -187,37 +217,32 @@ unsafe impl ValueType for __wasi_prestat_u {}
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
#[repr(C)] #[repr(C)]
pub struct __wasi_prestat_t { pub struct __wasi_prestat_t {
pr_type: __wasi_preopentype_t, pub pr_type: __wasi_preopentype_t,
u: __wasi_prestat_u, pub u: __wasi_prestat_u,
} }
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub enum PrestatEnum { pub enum PrestatEnum {
PreOpenDir { pr_name_len: u32 }, Dir { pr_name_len: u32 },
} }
impl __wasi_prestat_t { impl PrestatEnum {
pub fn get_tagged(&self) -> PrestatEnum { pub fn untagged(self) -> __wasi_prestat_u {
match self.pr_type { match self {
__WASI_PREOPENTYPE_DIR => PrestatEnum::PreOpenDir { PrestatEnum::Dir { pr_name_len } => __wasi_prestat_u {
pr_name_len: unsafe { self.u.dir.pr_name_len }, dir: __wasi_prestat_u_dir_t { pr_name_len },
}, },
_ => panic!("Invalid enum variant in __wasi_prestat_t: {}", self.pr_type),
} }
} }
} }
impl PrestatEnum { impl __wasi_prestat_t {
pub fn get_untagged(&self) -> __wasi_prestat_t { pub fn tagged(&self) -> Option<PrestatEnum> {
match self { match self.pr_type {
PrestatEnum::PreOpenDir { pr_name_len } => __wasi_prestat_t { __WASI_PREOPENTYPE_DIR => Some(PrestatEnum::Dir {
pr_type: __WASI_PREOPENTYPE_DIR, pr_name_len: unsafe { self.u.dir.pr_name_len },
u: __wasi_prestat_u { }),
dir: __wasi_prestat_u_dir_t { _ => None,
pr_name_len: *pr_name_len,
},
},
},
} }
} }
} }
@ -398,6 +423,25 @@ pub struct __wasi_subscription_t {
pub u: __wasi_subscription_u, pub u: __wasi_subscription_u,
} }
pub enum SubscriptionEnum {
Clock(__wasi_subscription_clock_t),
FdReadWrite(__wasi_subscription_fs_readwrite_t),
}
impl __wasi_subscription_t {
pub fn tagged(&self) -> Option<SubscriptionEnum> {
match self.type_ {
__WASI_EVENTTYPE_CLOCK => Some(SubscriptionEnum::Clock(unsafe { self.u.clock })),
__WASI_EVENTTYPE_FD_READ | __WASI_EVENTTYPE_FD_WRITE => {
Some(SubscriptionEnum::FdReadWrite(unsafe {
self.u.fd_readwrite
}))
}
_ => None,
}
}
}
pub type __wasi_timestamp_t = u64; pub type __wasi_timestamp_t = u64;
pub type __wasi_userdata_t = u64; pub type __wasi_userdata_t = u64;