update to wasi v0.7
This commit is contained in:
parent
37721461d4
commit
6374b8458f
12
Cargo.lock
12
Cargo.lock
@ -3866,6 +3866,7 @@ dependencies = [
|
||||
"rustc_msan",
|
||||
"rustc_tsan",
|
||||
"unwind",
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -4664,6 +4665,17 @@ dependencies = [
|
||||
"try-lock",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b89c3ce4ce14bdc6fb6beaf9ec7928ca331de5df7e5ea278375642a2f478570d"
|
||||
dependencies = [
|
||||
"compiler_builtins",
|
||||
"rustc-std-workspace-alloc",
|
||||
"rustc-std-workspace-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.2.8"
|
||||
|
@ -24,7 +24,7 @@ compiler_builtins = { version = "0.1.16" }
|
||||
profiler_builtins = { path = "../libprofiler_builtins", optional = true }
|
||||
unwind = { path = "../libunwind" }
|
||||
hashbrown = { version = "0.5.0", features = ['rustc-dep-of-std'] }
|
||||
wasi = { git = "https://github.com/newpavlov/rust-wasi", branch = "safe_rework", features = ['rustc-dep-of-std', 'alloc'] }
|
||||
wasi = { version = "0.7.0", features = ['rustc-dep-of-std', 'alloc'] }
|
||||
|
||||
[dependencies.backtrace]
|
||||
version = "0.3.35"
|
||||
|
@ -53,23 +53,23 @@ impl WasiFd {
|
||||
}
|
||||
|
||||
pub fn datasync(&self) -> io::Result<()> {
|
||||
wasi::fd_datasync(self.fd).map_err(err2io)
|
||||
unsafe { wasi::fd_datasync(self.fd).map_err(err2io) }
|
||||
}
|
||||
|
||||
pub fn pread(&self, bufs: &mut [IoSliceMut<'_>], offset: u64) -> io::Result<usize> {
|
||||
wasi::fd_pread(self.fd, iovec(bufs), offset).map_err(err2io)
|
||||
unsafe { wasi::fd_pread(self.fd, iovec(bufs), offset).map_err(err2io) }
|
||||
}
|
||||
|
||||
pub fn pwrite(&self, bufs: &[IoSlice<'_>], offset: u64) -> io::Result<usize> {
|
||||
wasi::fd_pwrite(self.fd, ciovec(bufs), offset).map_err(err2io)
|
||||
unsafe { wasi::fd_pwrite(self.fd, ciovec(bufs), offset).map_err(err2io) }
|
||||
}
|
||||
|
||||
pub fn read(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
|
||||
wasi::fd_read(self.fd, iovec(bufs)).map_err(err2io)
|
||||
unsafe { wasi::fd_read(self.fd, iovec(bufs)).map_err(err2io) }
|
||||
}
|
||||
|
||||
pub fn write(&self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
|
||||
wasi::fd_write(self.fd, ciovec(bufs)).map_err(err2io)
|
||||
unsafe { wasi::fd_write(self.fd, ciovec(bufs)).map_err(err2io) }
|
||||
}
|
||||
|
||||
pub fn seek(&self, pos: SeekFrom) -> io::Result<u64> {
|
||||
@ -78,37 +78,37 @@ impl WasiFd {
|
||||
SeekFrom::End(pos) => (wasi::WHENCE_END, pos),
|
||||
SeekFrom::Current(pos) => (wasi::WHENCE_CUR, pos),
|
||||
};
|
||||
wasi::fd_seek(self.fd, offset, whence).map_err(err2io)
|
||||
unsafe { wasi::fd_seek(self.fd, offset, whence).map_err(err2io) }
|
||||
}
|
||||
|
||||
pub fn tell(&self) -> io::Result<u64> {
|
||||
wasi::fd_tell(self.fd).map_err(err2io)
|
||||
unsafe { wasi::fd_tell(self.fd).map_err(err2io) }
|
||||
}
|
||||
|
||||
// FIXME: __wasi_fd_fdstat_get
|
||||
|
||||
pub fn set_flags(&self, flags: wasi::FdFlags) -> io::Result<()> {
|
||||
wasi::fd_fdstat_set_flags(self.fd, flags).map_err(err2io)
|
||||
unsafe { wasi::fd_fdstat_set_flags(self.fd, flags).map_err(err2io) }
|
||||
}
|
||||
|
||||
pub fn set_rights(&self, base: wasi::Rights, inheriting: wasi::Rights) -> io::Result<()> {
|
||||
wasi::fd_fdstat_set_rights(self.fd, base, inheriting).map_err(err2io)
|
||||
unsafe { wasi::fd_fdstat_set_rights(self.fd, base, inheriting).map_err(err2io) }
|
||||
}
|
||||
|
||||
pub fn sync(&self) -> io::Result<()> {
|
||||
wasi::fd_sync(self.fd).map_err(err2io)
|
||||
unsafe { wasi::fd_sync(self.fd).map_err(err2io) }
|
||||
}
|
||||
|
||||
pub fn advise(&self, offset: u64, len: u64, advice: wasi::Advice) -> io::Result<()> {
|
||||
wasi::fd_advise(self.fd, offset, len, advice).map_err(err2io)
|
||||
unsafe { wasi::fd_advise(self.fd, offset, len, advice).map_err(err2io) }
|
||||
}
|
||||
|
||||
pub fn allocate(&self, offset: u64, len: u64) -> io::Result<()> {
|
||||
wasi::fd_allocate(self.fd, offset, len).map_err(err2io)
|
||||
unsafe { wasi::fd_allocate(self.fd, offset, len).map_err(err2io) }
|
||||
}
|
||||
|
||||
pub fn create_directory(&self, path: &[u8]) -> io::Result<()> {
|
||||
wasi::path_create_directory(self.fd, path).map_err(err2io)
|
||||
unsafe { wasi::path_create_directory(self.fd, path).map_err(err2io) }
|
||||
}
|
||||
|
||||
pub fn link(
|
||||
@ -118,8 +118,10 @@ impl WasiFd {
|
||||
new_fd: &WasiFd,
|
||||
new_path: &[u8],
|
||||
) -> io::Result<()> {
|
||||
wasi::path_link(self.fd, old_flags, old_path, new_fd.fd, new_path)
|
||||
.map_err(err2io)
|
||||
unsafe {
|
||||
wasi::path_link(self.fd, old_flags, old_path, new_fd.fd, new_path)
|
||||
.map_err(err2io)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn open(
|
||||
@ -131,32 +133,35 @@ impl WasiFd {
|
||||
fs_rights_inheriting: wasi::Rights,
|
||||
fs_flags: wasi::FdFlags,
|
||||
) -> io::Result<WasiFd> {
|
||||
wasi::path_open(
|
||||
self.fd,
|
||||
dirflags,
|
||||
path,
|
||||
oflags,
|
||||
fs_rights_base,
|
||||
fs_rights_inheriting,
|
||||
fs_flags,
|
||||
).map(|fd| unsafe { WasiFd::from_raw(fd) }).map_err(err2io)
|
||||
unsafe {
|
||||
wasi::path_open(
|
||||
self.fd,
|
||||
dirflags,
|
||||
path,
|
||||
oflags,
|
||||
fs_rights_base,
|
||||
fs_rights_inheriting,
|
||||
fs_flags,
|
||||
).map(|fd| WasiFd::from_raw(fd)).map_err(err2io)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn readdir(&self, buf: &mut [u8], cookie: wasi::DirCookie) -> io::Result<usize> {
|
||||
wasi::fd_readdir(self.fd, buf, cookie).map_err(err2io)
|
||||
unsafe { wasi::fd_readdir(self.fd, buf, cookie).map_err(err2io) }
|
||||
}
|
||||
|
||||
pub fn readlink(&self, path: &[u8], buf: &mut [u8]) -> io::Result<usize> {
|
||||
wasi::path_readlink(self.fd, path, buf).map_err(err2io)
|
||||
unsafe { wasi::path_readlink(self.fd, path, buf).map_err(err2io) }
|
||||
}
|
||||
|
||||
pub fn rename(&self, old_path: &[u8], new_fd: &WasiFd, new_path: &[u8]) -> io::Result<()> {
|
||||
wasi::path_rename(self.fd, old_path, new_fd.fd, new_path)
|
||||
.map_err(err2io)
|
||||
unsafe {
|
||||
wasi::path_rename(self.fd, old_path, new_fd.fd, new_path).map_err(err2io)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn filestat_get(&self) -> io::Result<wasi::FileStat> {
|
||||
wasi::fd_filestat_get(self.fd).map_err(err2io)
|
||||
unsafe { wasi::fd_filestat_get(self.fd).map_err(err2io) }
|
||||
}
|
||||
|
||||
pub fn filestat_set_times(
|
||||
@ -165,12 +170,13 @@ impl WasiFd {
|
||||
mtim: wasi::Timestamp,
|
||||
fstflags: wasi::FstFlags,
|
||||
) -> io::Result<()> {
|
||||
wasi::fd_filestat_set_times(self.fd, atim, mtim, fstflags)
|
||||
.map_err(err2io)
|
||||
unsafe {
|
||||
wasi::fd_filestat_set_times(self.fd, atim, mtim, fstflags).map_err(err2io)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn filestat_set_size(&self, size: u64) -> io::Result<()> {
|
||||
wasi::fd_filestat_set_size(self.fd, size).map_err(err2io)
|
||||
unsafe { wasi::fd_filestat_set_size(self.fd, size).map_err(err2io) }
|
||||
}
|
||||
|
||||
pub fn path_filestat_get(
|
||||
@ -178,7 +184,7 @@ impl WasiFd {
|
||||
flags: wasi::LookupFlags,
|
||||
path: &[u8],
|
||||
) -> io::Result<wasi::FileStat> {
|
||||
wasi::path_filestat_get(self.fd, flags, path).map_err(err2io)
|
||||
unsafe { wasi::path_filestat_get(self.fd, flags, path).map_err(err2io) }
|
||||
}
|
||||
|
||||
pub fn path_filestat_set_times(
|
||||
@ -189,26 +195,28 @@ impl WasiFd {
|
||||
mtim: wasi::Timestamp,
|
||||
fstflags: wasi::FstFlags,
|
||||
) -> io::Result<()> {
|
||||
wasi::path_filestat_set_times(
|
||||
self.fd,
|
||||
flags,
|
||||
path,
|
||||
atim,
|
||||
mtim,
|
||||
fstflags,
|
||||
).map_err(err2io)
|
||||
unsafe {
|
||||
wasi::path_filestat_set_times(
|
||||
self.fd,
|
||||
flags,
|
||||
path,
|
||||
atim,
|
||||
mtim,
|
||||
fstflags,
|
||||
).map_err(err2io)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn symlink(&self, old_path: &[u8], new_path: &[u8]) -> io::Result<()> {
|
||||
wasi::path_symlink(old_path, self.fd, new_path).map_err(err2io)
|
||||
unsafe { wasi::path_symlink(old_path, self.fd, new_path).map_err(err2io) }
|
||||
}
|
||||
|
||||
pub fn unlink_file(&self, path: &[u8]) -> io::Result<()> {
|
||||
wasi::path_unlink_file(self.fd, path).map_err(err2io)
|
||||
unsafe { wasi::path_unlink_file(self.fd, path).map_err(err2io) }
|
||||
}
|
||||
|
||||
pub fn remove_directory(&self, path: &[u8]) -> io::Result<()> {
|
||||
wasi::path_remove_directory(self.fd, path).map_err(err2io)
|
||||
unsafe { wasi::path_remove_directory(self.fd, path).map_err(err2io) }
|
||||
}
|
||||
|
||||
pub fn sock_recv(
|
||||
@ -216,11 +224,11 @@ impl WasiFd {
|
||||
ri_data: &mut [IoSliceMut<'_>],
|
||||
ri_flags: wasi::RiFlags,
|
||||
) -> io::Result<(usize, wasi::RoFlags)> {
|
||||
wasi::sock_recv(self.fd, iovec(ri_data), ri_flags).map_err(err2io)
|
||||
unsafe { wasi::sock_recv(self.fd, iovec(ri_data), ri_flags).map_err(err2io) }
|
||||
}
|
||||
|
||||
pub fn sock_send(&self, si_data: &[IoSlice<'_>], si_flags: wasi::SiFlags) -> io::Result<usize> {
|
||||
wasi::sock_send(self.fd, ciovec(si_data), si_flags).map_err(err2io)
|
||||
unsafe { wasi::sock_send(self.fd, ciovec(si_data), si_flags).map_err(err2io) }
|
||||
}
|
||||
|
||||
pub fn sock_shutdown(&self, how: Shutdown) -> io::Result<()> {
|
||||
@ -229,7 +237,7 @@ impl WasiFd {
|
||||
Shutdown::Write => wasi::SHUT_WR,
|
||||
Shutdown::Both => wasi::SHUT_WR | wasi::SHUT_RD,
|
||||
};
|
||||
wasi::sock_shutdown(self.fd, how).map_err(err2io)
|
||||
unsafe { wasi::sock_shutdown(self.fd, how).map_err(err2io) }
|
||||
}
|
||||
}
|
||||
|
||||
@ -237,6 +245,6 @@ impl Drop for WasiFd {
|
||||
fn drop(&mut self) {
|
||||
// FIXME: can we handle the return code here even though we can't on
|
||||
// unix?
|
||||
let _ = wasi::fd_close(self.fd);
|
||||
let _ = unsafe { wasi::fd_close(self.fd) };
|
||||
}
|
||||
}
|
||||
|
@ -69,10 +69,17 @@ pub fn unsupported_err() -> std_io::Error {
|
||||
|
||||
pub fn decode_error_kind(errno: i32) -> std_io::ErrorKind {
|
||||
use std_io::ErrorKind::*;
|
||||
match errno as libc::c_int {
|
||||
if errno > u16::max_value() as i32 || errno < 0 {
|
||||
return Other;
|
||||
}
|
||||
let code = match wasi::Error::new(errno as u16) {
|
||||
Some(code) => code,
|
||||
None => return Other,
|
||||
};
|
||||
match code {
|
||||
wasi::ECONNREFUSED => ConnectionRefused,
|
||||
wasi::ECONNRESET => ConnectionReset,
|
||||
wasi::EPERM | libc::EACCES => PermissionDenied,
|
||||
wasi::EPERM | wasi::EACCES => PermissionDenied,
|
||||
wasi::EPIPE => BrokenPipe,
|
||||
wasi::ENOTCONN => NotConnected,
|
||||
wasi::ECONNABORTED => ConnectionAborted,
|
||||
@ -84,7 +91,7 @@ pub fn decode_error_kind(errno: i32) -> std_io::ErrorKind {
|
||||
wasi::ETIMEDOUT => TimedOut,
|
||||
wasi::EEXIST => AlreadyExists,
|
||||
wasi::EAGAIN => WouldBlock,
|
||||
_ => ErrorKind::Other,
|
||||
_ => Other,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ impl Thread {
|
||||
u: wasi::raw::__wasi_subscription_u { clock: clock },
|
||||
}];
|
||||
let mut out: [wasi::Event; 1] = [unsafe { mem::zeroed() }];
|
||||
let n = wasi::poll_oneoff(&in_, &mut out).unwrap();
|
||||
let n = unsafe { wasi::poll_oneoff(&in_, &mut out).unwrap() };
|
||||
let wasi::Event { userdata, error, type_, .. } = out[0];
|
||||
match (n, userdata, error) {
|
||||
(1, CLOCK_ID, 0) if type_ == wasi::EVENTTYPE_CLOCK => {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user