wasi-common: snapshots 0 and 1 traits are all async now

This commit is contained in:
Pat Hickey
2021-04-14 15:05:38 -07:00
parent 228096c840
commit 025a1ecff4
2 changed files with 211 additions and 171 deletions

View File

@@ -16,7 +16,7 @@ use wiggle::GuestPtr;
wiggle::from_witx!({ wiggle::from_witx!({
witx: ["$WASI_ROOT/phases/old/snapshot_0/witx/wasi_unstable.witx"], witx: ["$WASI_ROOT/phases/old/snapshot_0/witx/wasi_unstable.witx"],
errors: { errno => Error }, errors: { errno => Error },
async: { wasi_unstable::{poll_oneoff, sched_yield} } async: *,
}); });
impl wiggle::GuestErrorType for types::Errno { impl wiggle::GuestErrorType for types::Errno {
@@ -334,79 +334,79 @@ convert_flags_bidirectional!(
// This implementation, wherever possible, delegates directly to the Snapshot1 implementation, // This implementation, wherever possible, delegates directly to the Snapshot1 implementation,
// performing the no-op type conversions along the way. // performing the no-op type conversions along the way.
#[wiggle::async_trait] #[wiggle::async_trait]
impl<'a> wasi_unstable::WasiUnstable for WasiCtx { impl wasi_unstable::WasiUnstable for WasiCtx {
fn args_get<'b>( async fn args_get<'a>(
&self, &self,
argv: &GuestPtr<'b, GuestPtr<'b, u8>>, argv: &GuestPtr<'a, GuestPtr<'a, u8>>,
argv_buf: &GuestPtr<'b, u8>, argv_buf: &GuestPtr<'a, u8>,
) -> Result<(), Error> { ) -> Result<(), Error> {
Snapshot1::args_get(self, argv, argv_buf) Snapshot1::args_get(self, argv, argv_buf).await
} }
fn args_sizes_get(&self) -> Result<(types::Size, types::Size), Error> { async fn args_sizes_get(&self) -> Result<(types::Size, types::Size), Error> {
Snapshot1::args_sizes_get(self) Snapshot1::args_sizes_get(self).await
} }
fn environ_get<'b>( async fn environ_get<'a>(
&self, &self,
environ: &GuestPtr<'b, GuestPtr<'b, u8>>, environ: &GuestPtr<'a, GuestPtr<'a, u8>>,
environ_buf: &GuestPtr<'b, u8>, environ_buf: &GuestPtr<'a, u8>,
) -> Result<(), Error> { ) -> Result<(), Error> {
Snapshot1::environ_get(self, environ, environ_buf) Snapshot1::environ_get(self, environ, environ_buf).await
} }
fn environ_sizes_get(&self) -> Result<(types::Size, types::Size), Error> { async fn environ_sizes_get(&self) -> Result<(types::Size, types::Size), Error> {
Snapshot1::environ_sizes_get(self) Snapshot1::environ_sizes_get(self).await
} }
fn clock_res_get(&self, id: types::Clockid) -> Result<types::Timestamp, Error> { async fn clock_res_get(&self, id: types::Clockid) -> Result<types::Timestamp, Error> {
Snapshot1::clock_res_get(self, id.into()) Snapshot1::clock_res_get(self, id.into()).await
} }
fn clock_time_get( async fn clock_time_get(
&self, &self,
id: types::Clockid, id: types::Clockid,
precision: types::Timestamp, precision: types::Timestamp,
) -> Result<types::Timestamp, Error> { ) -> Result<types::Timestamp, Error> {
Snapshot1::clock_time_get(self, id.into(), precision) Snapshot1::clock_time_get(self, id.into(), precision).await
} }
fn fd_advise( async fn fd_advise(
&self, &self,
fd: types::Fd, fd: types::Fd,
offset: types::Filesize, offset: types::Filesize,
len: types::Filesize, len: types::Filesize,
advice: types::Advice, advice: types::Advice,
) -> Result<(), Error> { ) -> Result<(), Error> {
Snapshot1::fd_advise(self, fd.into(), offset, len, advice.into()) Snapshot1::fd_advise(self, fd.into(), offset, len, advice.into()).await
} }
fn fd_allocate( async fn fd_allocate(
&self, &self,
fd: types::Fd, fd: types::Fd,
offset: types::Filesize, offset: types::Filesize,
len: types::Filesize, len: types::Filesize,
) -> Result<(), Error> { ) -> Result<(), Error> {
Snapshot1::fd_allocate(self, fd.into(), offset, len) Snapshot1::fd_allocate(self, fd.into(), offset, len).await
} }
fn fd_close(&self, fd: types::Fd) -> Result<(), Error> { async fn fd_close(&self, fd: types::Fd) -> Result<(), Error> {
Snapshot1::fd_close(self, fd.into()) Snapshot1::fd_close(self, fd.into()).await
} }
fn fd_datasync(&self, fd: types::Fd) -> Result<(), Error> { async fn fd_datasync(&self, fd: types::Fd) -> Result<(), Error> {
Snapshot1::fd_datasync(self, fd.into()) Snapshot1::fd_datasync(self, fd.into()).await
} }
fn fd_fdstat_get(&self, fd: types::Fd) -> Result<types::Fdstat, Error> { async fn fd_fdstat_get(&self, fd: types::Fd) -> Result<types::Fdstat, Error> {
Ok(Snapshot1::fd_fdstat_get(self, fd.into())?.into()) Ok(Snapshot1::fd_fdstat_get(self, fd.into()).await?.into())
} }
fn fd_fdstat_set_flags(&self, fd: types::Fd, flags: types::Fdflags) -> Result<(), Error> { async fn fd_fdstat_set_flags(&self, fd: types::Fd, flags: types::Fdflags) -> Result<(), Error> {
Snapshot1::fd_fdstat_set_flags(self, fd.into(), flags.into()) Snapshot1::fd_fdstat_set_flags(self, fd.into(), flags.into()).await
} }
fn fd_fdstat_set_rights( async fn fd_fdstat_set_rights(
&self, &self,
fd: types::Fd, fd: types::Fd,
fs_rights_base: types::Rights, fs_rights_base: types::Rights,
@@ -418,24 +418,29 @@ impl<'a> wasi_unstable::WasiUnstable for WasiCtx {
fs_rights_base.into(), fs_rights_base.into(),
fs_rights_inheriting.into(), fs_rights_inheriting.into(),
) )
.await
} }
fn fd_filestat_get(&self, fd: types::Fd) -> Result<types::Filestat, Error> { async fn fd_filestat_get(&self, fd: types::Fd) -> Result<types::Filestat, Error> {
Ok(Snapshot1::fd_filestat_get(self, fd.into())?.into()) Ok(Snapshot1::fd_filestat_get(self, fd.into())?.into()).await
} }
fn fd_filestat_set_size(&self, fd: types::Fd, size: types::Filesize) -> Result<(), Error> { async fn fd_filestat_set_size(
Snapshot1::fd_filestat_set_size(self, fd.into(), size) &self,
fd: types::Fd,
size: types::Filesize,
) -> Result<(), Error> {
Snapshot1::fd_filestat_set_size(self, fd.into(), size).await
} }
fn fd_filestat_set_times( async fn fd_filestat_set_times(
&self, &self,
fd: types::Fd, fd: types::Fd,
atim: types::Timestamp, atim: types::Timestamp,
mtim: types::Timestamp, mtim: types::Timestamp,
fst_flags: types::Fstflags, fst_flags: types::Fstflags,
) -> Result<(), Error> { ) -> Result<(), Error> {
Snapshot1::fd_filestat_set_times(self, fd.into(), atim, mtim, fst_flags.into()) Snapshot1::fd_filestat_set_times(self, fd.into(), atim, mtim, fst_flags.into()).await
} }
// NOTE on fd_read, fd_pread, fd_write, fd_pwrite implementations: // NOTE on fd_read, fd_pread, fd_write, fd_pwrite implementations:
@@ -446,7 +451,11 @@ impl<'a> wasi_unstable::WasiUnstable for WasiCtx {
// The bodies of these functions is mostly about converting the GuestPtr and types::-based // The bodies of these functions is mostly about converting the GuestPtr and types::-based
// representation to a std::io::IoSlice(Mut) representation. // representation to a std::io::IoSlice(Mut) representation.
fn fd_read(&self, fd: types::Fd, iovs: &types::IovecArray<'_>) -> Result<types::Size, Error> { async fn fd_read<'a>(
&self,
fd: types::Fd,
iovs: &types::IovecArray<'a>,
) -> Result<types::Size, Error> {
let table = self.table(); let table = self.table();
let f = table.get_file(u32::from(fd))?.get_cap(FileCaps::READ)?; let f = table.get_file(u32::from(fd))?.get_cap(FileCaps::READ)?;
@@ -468,10 +477,10 @@ impl<'a> wasi_unstable::WasiUnstable for WasiCtx {
Ok(types::Size::try_from(bytes_read)?) Ok(types::Size::try_from(bytes_read)?)
} }
fn fd_pread( async fn fd_pread<'a>(
&self, &self,
fd: types::Fd, fd: types::Fd,
iovs: &types::IovecArray<'_>, iovs: &types::IovecArray<'a>,
offset: types::Filesize, offset: types::Filesize,
) -> Result<types::Size, Error> { ) -> Result<types::Size, Error> {
let table = self.table(); let table = self.table();
@@ -497,10 +506,10 @@ impl<'a> wasi_unstable::WasiUnstable for WasiCtx {
Ok(types::Size::try_from(bytes_read)?) Ok(types::Size::try_from(bytes_read)?)
} }
fn fd_write( async fn fd_write<'a>(
&self, &self,
fd: types::Fd, fd: types::Fd,
ciovs: &types::CiovecArray<'_>, ciovs: &types::CiovecArray<'a>,
) -> Result<types::Size, Error> { ) -> Result<types::Size, Error> {
let table = self.table(); let table = self.table();
let f = table.get_file(u32::from(fd))?.get_cap(FileCaps::WRITE)?; let f = table.get_file(u32::from(fd))?.get_cap(FileCaps::WRITE)?;
@@ -523,10 +532,10 @@ impl<'a> wasi_unstable::WasiUnstable for WasiCtx {
Ok(types::Size::try_from(bytes_written)?) Ok(types::Size::try_from(bytes_written)?)
} }
fn fd_pwrite( async fn fd_pwrite<'a>(
&self, &self,
fd: types::Fd, fd: types::Fd,
ciovs: &types::CiovecArray<'_>, ciovs: &types::CiovecArray<'a>,
offset: types::Filesize, offset: types::Filesize,
) -> Result<types::Size, Error> { ) -> Result<types::Size, Error> {
let table = self.table(); let table = self.table();
@@ -552,72 +561,76 @@ impl<'a> wasi_unstable::WasiUnstable for WasiCtx {
Ok(types::Size::try_from(bytes_written)?) Ok(types::Size::try_from(bytes_written)?)
} }
fn fd_prestat_get(&self, fd: types::Fd) -> Result<types::Prestat, Error> { async fn fd_prestat_get(&self, fd: types::Fd) -> Result<types::Prestat, Error> {
Ok(Snapshot1::fd_prestat_get(self, fd.into())?.into()) Ok(Snapshot1::fd_prestat_get(self, fd.into()).await?.into())
} }
fn fd_prestat_dir_name( async fn fd_prestat_dir_name<'a>(
&self, &self,
fd: types::Fd, fd: types::Fd,
path: &GuestPtr<u8>, path: &GuestPtr<'a, u8>,
path_max_len: types::Size, path_max_len: types::Size,
) -> Result<(), Error> { ) -> Result<(), Error> {
Snapshot1::fd_prestat_dir_name(self, fd.into(), path, path_max_len) Snapshot1::fd_prestat_dir_name(self, fd.into(), path, path_max_len).await
} }
fn fd_renumber(&self, from: types::Fd, to: types::Fd) -> Result<(), Error> { async fn fd_renumber(&self, from: types::Fd, to: types::Fd) -> Result<(), Error> {
Snapshot1::fd_renumber(self, from.into(), to.into()) Snapshot1::fd_renumber(self, from.into(), to.into()).await
} }
fn fd_seek( async fn fd_seek(
&self, &self,
fd: types::Fd, fd: types::Fd,
offset: types::Filedelta, offset: types::Filedelta,
whence: types::Whence, whence: types::Whence,
) -> Result<types::Filesize, Error> { ) -> Result<types::Filesize, Error> {
Snapshot1::fd_seek(self, fd.into(), offset, whence.into()) Snapshot1::fd_seek(self, fd.into(), offset, whence.into()).await
} }
fn fd_sync(&self, fd: types::Fd) -> Result<(), Error> { async fn fd_sync(&self, fd: types::Fd) -> Result<(), Error> {
Snapshot1::fd_sync(self, fd.into()) Snapshot1::fd_sync(self, fd.into()).await
} }
fn fd_tell(&self, fd: types::Fd) -> Result<types::Filesize, Error> { async fn fd_tell(&self, fd: types::Fd) -> Result<types::Filesize, Error> {
Snapshot1::fd_tell(self, fd.into()) Snapshot1::fd_tell(self, fd.into()).await
} }
fn fd_readdir( async fn fd_readdir<'a>(
&self, &self,
fd: types::Fd, fd: types::Fd,
buf: &GuestPtr<u8>, buf: &GuestPtr<'a, u8>,
buf_len: types::Size, buf_len: types::Size,
cookie: types::Dircookie, cookie: types::Dircookie,
) -> Result<types::Size, Error> { ) -> Result<types::Size, Error> {
Snapshot1::fd_readdir(self, fd.into(), buf, buf_len, cookie) Snapshot1::fd_readdir(self, fd.into(), buf, buf_len, cookie).await
} }
fn path_create_directory( async fn path_create_directory<'a>(
&self, &self,
dirfd: types::Fd, dirfd: types::Fd,
path: &GuestPtr<'_, str>, path: &GuestPtr<'a, str>,
) -> Result<(), Error> { ) -> Result<(), Error> {
Snapshot1::path_create_directory(self, dirfd.into(), path) Snapshot1::path_create_directory(self, dirfd.into(), path).await
} }
fn path_filestat_get( async fn path_filestat_get<'a>(
&self, &self,
dirfd: types::Fd, dirfd: types::Fd,
flags: types::Lookupflags, flags: types::Lookupflags,
path: &GuestPtr<'_, str>, path: &GuestPtr<'a, str>,
) -> Result<types::Filestat, Error> { ) -> Result<types::Filestat, Error> {
Ok(Snapshot1::path_filestat_get(self, dirfd.into(), flags.into(), path)?.into()) Ok(
Snapshot1::path_filestat_get(self, dirfd.into(), flags.into(), path)
.await?
.into(),
)
} }
fn path_filestat_set_times( async fn path_filestat_set_times<'a>(
&self, &self,
dirfd: types::Fd, dirfd: types::Fd,
flags: types::Lookupflags, flags: types::Lookupflags,
path: &GuestPtr<'_, str>, path: &GuestPtr<'a, str>,
atim: types::Timestamp, atim: types::Timestamp,
mtim: types::Timestamp, mtim: types::Timestamp,
fst_flags: types::Fstflags, fst_flags: types::Fstflags,
@@ -631,15 +644,16 @@ impl<'a> wasi_unstable::WasiUnstable for WasiCtx {
mtim, mtim,
fst_flags.into(), fst_flags.into(),
) )
.await
} }
fn path_link( async fn path_link<'a>(
&self, &self,
src_fd: types::Fd, src_fd: types::Fd,
src_flags: types::Lookupflags, src_flags: types::Lookupflags,
src_path: &GuestPtr<'_, str>, src_path: &GuestPtr<'a, str>,
target_fd: types::Fd, target_fd: types::Fd,
target_path: &GuestPtr<'_, str>, target_path: &GuestPtr<'a, str>,
) -> Result<(), Error> { ) -> Result<(), Error> {
Snapshot1::path_link( Snapshot1::path_link(
self, self,
@@ -649,13 +663,14 @@ impl<'a> wasi_unstable::WasiUnstable for WasiCtx {
target_fd.into(), target_fd.into(),
target_path, target_path,
) )
.await
} }
fn path_open( async fn path_open<'a>(
&self, &self,
dirfd: types::Fd, dirfd: types::Fd,
dirflags: types::Lookupflags, dirflags: types::Lookupflags,
path: &GuestPtr<'_, str>, path: &GuestPtr<'a, str>,
oflags: types::Oflags, oflags: types::Oflags,
fs_rights_base: types::Rights, fs_rights_base: types::Rights,
fs_rights_inheriting: types::Rights, fs_rights_inheriting: types::Rights,
@@ -670,49 +685,54 @@ impl<'a> wasi_unstable::WasiUnstable for WasiCtx {
fs_rights_base.into(), fs_rights_base.into(),
fs_rights_inheriting.into(), fs_rights_inheriting.into(),
fdflags.into(), fdflags.into(),
)? )
.await?
.into()) .into())
} }
fn path_readlink( async fn path_readlink<'a>(
&self, &self,
dirfd: types::Fd, dirfd: types::Fd,
path: &GuestPtr<'_, str>, path: &GuestPtr<'a, str>,
buf: &GuestPtr<u8>, buf: &GuestPtr<'a, u8>,
buf_len: types::Size, buf_len: types::Size,
) -> Result<types::Size, Error> { ) -> Result<types::Size, Error> {
Snapshot1::path_readlink(self, dirfd.into(), path, buf, buf_len) Snapshot1::path_readlink(self, dirfd.into(), path, buf, buf_len).await
} }
fn path_remove_directory( async fn path_remove_directory<'a>(
&self, &self,
dirfd: types::Fd, dirfd: types::Fd,
path: &GuestPtr<'_, str>, path: &GuestPtr<'a, str>,
) -> Result<(), Error> { ) -> Result<(), Error> {
Snapshot1::path_remove_directory(self, dirfd.into(), path) Snapshot1::path_remove_directory(self, dirfd.into(), path).await
} }
fn path_rename( async fn path_rename<'a>(
&self, &self,
src_fd: types::Fd, src_fd: types::Fd,
src_path: &GuestPtr<'_, str>, src_path: &GuestPtr<'a, str>,
dest_fd: types::Fd, dest_fd: types::Fd,
dest_path: &GuestPtr<'_, str>, dest_path: &GuestPtr<'a, str>,
) -> Result<(), Error> { ) -> Result<(), Error> {
Snapshot1::path_rename(self, src_fd.into(), src_path, dest_fd.into(), dest_path) Snapshot1::path_rename(self, src_fd.into(), src_path, dest_fd.into(), dest_path).await
} }
fn path_symlink( async fn path_symlink<'a>(
&self, &self,
src_path: &GuestPtr<'_, str>, src_path: &GuestPtr<'a, str>,
dirfd: types::Fd, dirfd: types::Fd,
dest_path: &GuestPtr<'_, str>, dest_path: &GuestPtr<'a, str>,
) -> Result<(), Error> { ) -> Result<(), Error> {
Snapshot1::path_symlink(self, src_path, dirfd.into(), dest_path) Snapshot1::path_symlink(self, src_path, dirfd.into(), dest_path).await
} }
fn path_unlink_file(&self, dirfd: types::Fd, path: &GuestPtr<'_, str>) -> Result<(), Error> { async fn path_unlink_file<'a>(
Snapshot1::path_unlink_file(self, dirfd.into(), path) &self,
dirfd: types::Fd,
path: &GuestPtr<'a, str>,
) -> Result<(), Error> {
Snapshot1::path_unlink_file(self, dirfd.into(), path).await
} }
// NOTE on poll_oneoff implementation: // NOTE on poll_oneoff implementation:
@@ -722,10 +742,10 @@ impl<'a> wasi_unstable::WasiUnstable for WasiCtx {
// The implementations are identical, but the `types::` in scope locally is different. // The implementations are identical, but the `types::` in scope locally is different.
// The bodies of these functions is mostly about converting the GuestPtr and types::-based // The bodies of these functions is mostly about converting the GuestPtr and types::-based
// representation to use the Poll abstraction. // representation to use the Poll abstraction.
async fn poll_oneoff<'b>( async fn poll_oneoff<'a>(
&self, &self,
subs: &GuestPtr<'b, types::Subscription>, subs: &GuestPtr<'a, types::Subscription>,
events: &GuestPtr<'b, types::Event>, events: &GuestPtr<'a, types::Event>,
nsubscriptions: types::Size, nsubscriptions: types::Size,
) -> Result<types::Size, Error> { ) -> Result<types::Size, Error> {
if nsubscriptions == 0 { if nsubscriptions == 0 {
@@ -886,11 +906,11 @@ impl<'a> wasi_unstable::WasiUnstable for WasiCtx {
Ok(num_results.try_into().expect("results fit into memory")) Ok(num_results.try_into().expect("results fit into memory"))
} }
fn proc_exit(&self, status: types::Exitcode) -> wiggle::Trap { async fn proc_exit(&self, status: types::Exitcode) -> wiggle::Trap {
Snapshot1::proc_exit(self, status) Snapshot1::proc_exit(self, status).await
} }
fn proc_raise(&self, _sig: types::Signal) -> Result<(), Error> { async fn proc_raise(&self, _sig: types::Signal) -> Result<(), Error> {
Err(Error::trap("proc_raise unsupported")) Err(Error::trap("proc_raise unsupported"))
} }
@@ -898,29 +918,33 @@ impl<'a> wasi_unstable::WasiUnstable for WasiCtx {
Snapshot1::sched_yield(self).await Snapshot1::sched_yield(self).await
} }
fn random_get(&self, buf: &GuestPtr<u8>, buf_len: types::Size) -> Result<(), Error> { async fn random_get<'a>(
Snapshot1::random_get(self, buf, buf_len) &self,
buf: &GuestPtr<'a, u8>,
buf_len: types::Size,
) -> Result<(), Error> {
Snapshot1::random_get(self, buf, buf_len).await
} }
fn sock_recv( async fn sock_recv<'a>(
&self, &self,
_fd: types::Fd, _fd: types::Fd,
_ri_data: &types::IovecArray<'_>, _ri_data: &types::IovecArray<'a>,
_ri_flags: types::Riflags, _ri_flags: types::Riflags,
) -> Result<(types::Size, types::Roflags), Error> { ) -> Result<(types::Size, types::Roflags), Error> {
Err(Error::trap("sock_recv unsupported")) Err(Error::trap("sock_recv unsupported"))
} }
fn sock_send( async fn sock_send<'a>(
&self, &self,
_fd: types::Fd, _fd: types::Fd,
_si_data: &types::CiovecArray<'_>, _si_data: &types::CiovecArray<'a>,
_si_flags: types::Siflags, _si_flags: types::Siflags,
) -> Result<types::Size, Error> { ) -> Result<types::Size, Error> {
Err(Error::trap("sock_send unsupported")) Err(Error::trap("sock_send unsupported"))
} }
fn sock_shutdown(&self, _fd: types::Fd, _how: types::Sdflags) -> Result<(), Error> { async fn sock_shutdown(&self, _fd: types::Fd, _how: types::Sdflags) -> Result<(), Error> {
Err(Error::trap("sock_shutdown unsupported")) Err(Error::trap("sock_shutdown unsupported"))
} }
} }

View File

@@ -22,7 +22,7 @@ use wiggle::GuestPtr;
wiggle::from_witx!({ wiggle::from_witx!({
witx: ["$WASI_ROOT/phases/snapshot/witx/wasi_snapshot_preview1.witx"], witx: ["$WASI_ROOT/phases/snapshot/witx/wasi_snapshot_preview1.witx"],
errors: { errno => Error }, errors: { errno => Error },
async: { wasi_snapshot_preview1::{poll_oneoff, sched_yield} } async: *
}); });
impl wiggle::GuestErrorType for types::Errno { impl wiggle::GuestErrorType for types::Errno {
@@ -191,7 +191,7 @@ impl TryFrom<std::io::Error> for types::Errno {
#[wiggle::async_trait] #[wiggle::async_trait]
impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx { impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
fn args_get<'b>( async fn args_get<'b>(
&self, &self,
argv: &GuestPtr<'b, GuestPtr<'b, u8>>, argv: &GuestPtr<'b, GuestPtr<'b, u8>>,
argv_buf: &GuestPtr<'b, u8>, argv_buf: &GuestPtr<'b, u8>,
@@ -199,11 +199,11 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
self.args.write_to_guest(argv_buf, argv) self.args.write_to_guest(argv_buf, argv)
} }
fn args_sizes_get(&self) -> Result<(types::Size, types::Size), Error> { async fn args_sizes_get(&self) -> Result<(types::Size, types::Size), Error> {
Ok((self.args.number_elements(), self.args.cumulative_size())) Ok((self.args.number_elements(), self.args.cumulative_size()))
} }
fn environ_get<'b>( async fn environ_get<'b>(
&self, &self,
environ: &GuestPtr<'b, GuestPtr<'b, u8>>, environ: &GuestPtr<'b, GuestPtr<'b, u8>>,
environ_buf: &GuestPtr<'b, u8>, environ_buf: &GuestPtr<'b, u8>,
@@ -211,11 +211,11 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
self.env.write_to_guest(environ_buf, environ) self.env.write_to_guest(environ_buf, environ)
} }
fn environ_sizes_get(&self) -> Result<(types::Size, types::Size), Error> { async fn environ_sizes_get(&self) -> Result<(types::Size, types::Size), Error> {
Ok((self.env.number_elements(), self.env.cumulative_size())) Ok((self.env.number_elements(), self.env.cumulative_size()))
} }
fn clock_res_get(&self, id: types::Clockid) -> Result<types::Timestamp, Error> { async fn clock_res_get(&self, id: types::Clockid) -> Result<types::Timestamp, Error> {
let resolution = match id { let resolution = match id {
types::Clockid::Realtime => Ok(self.clocks.system.resolution()), types::Clockid::Realtime => Ok(self.clocks.system.resolution()),
types::Clockid::Monotonic => Ok(self.clocks.monotonic.resolution()), types::Clockid::Monotonic => Ok(self.clocks.monotonic.resolution()),
@@ -226,7 +226,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
Ok(resolution.as_nanos().try_into()?) Ok(resolution.as_nanos().try_into()?)
} }
fn clock_time_get( async fn clock_time_get(
&self, &self,
id: types::Clockid, id: types::Clockid,
precision: types::Timestamp, precision: types::Timestamp,
@@ -251,7 +251,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
} }
} }
fn fd_advise( async fn fd_advise(
&self, &self,
fd: types::Fd, fd: types::Fd,
offset: types::Filesize, offset: types::Filesize,
@@ -265,7 +265,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
Ok(()) Ok(())
} }
fn fd_allocate( async fn fd_allocate(
&self, &self,
fd: types::Fd, fd: types::Fd,
offset: types::Filesize, offset: types::Filesize,
@@ -278,7 +278,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
Ok(()) Ok(())
} }
fn fd_close(&self, fd: types::Fd) -> Result<(), Error> { async fn fd_close(&self, fd: types::Fd) -> Result<(), Error> {
let mut table = self.table(); let mut table = self.table();
let fd = u32::from(fd); let fd = u32::from(fd);
@@ -304,7 +304,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
Ok(()) Ok(())
} }
fn fd_datasync(&self, fd: types::Fd) -> Result<(), Error> { async fn fd_datasync(&self, fd: types::Fd) -> Result<(), Error> {
self.table() self.table()
.get_file(u32::from(fd))? .get_file(u32::from(fd))?
.get_cap(FileCaps::DATASYNC)? .get_cap(FileCaps::DATASYNC)?
@@ -312,7 +312,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
Ok(()) Ok(())
} }
fn fd_fdstat_get(&self, fd: types::Fd) -> Result<types::Fdstat, Error> { async fn fd_fdstat_get(&self, fd: types::Fd) -> Result<types::Fdstat, Error> {
let table = self.table(); let table = self.table();
let fd = u32::from(fd); let fd = u32::from(fd);
if table.is::<FileEntry>(fd) { if table.is::<FileEntry>(fd) {
@@ -328,14 +328,14 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
} }
} }
fn fd_fdstat_set_flags(&self, fd: types::Fd, flags: types::Fdflags) -> Result<(), Error> { async fn fd_fdstat_set_flags(&self, fd: types::Fd, flags: types::Fdflags) -> Result<(), Error> {
self.table() self.table()
.get_file_mut(u32::from(fd))? .get_file_mut(u32::from(fd))?
.get_cap(FileCaps::FDSTAT_SET_FLAGS)? .get_cap(FileCaps::FDSTAT_SET_FLAGS)?
.set_fdflags(FdFlags::from(flags)) .set_fdflags(FdFlags::from(flags))
} }
fn fd_fdstat_set_rights( async fn fd_fdstat_set_rights(
&self, &self,
fd: types::Fd, fd: types::Fd,
fs_rights_base: types::Rights, fs_rights_base: types::Rights,
@@ -357,7 +357,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
} }
} }
fn fd_filestat_get(&self, fd: types::Fd) -> Result<types::Filestat, Error> { async fn fd_filestat_get(&self, fd: types::Fd) -> Result<types::Filestat, Error> {
let table = self.table(); let table = self.table();
let fd = u32::from(fd); let fd = u32::from(fd);
if table.is::<FileEntry>(fd) { if table.is::<FileEntry>(fd) {
@@ -377,7 +377,11 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
} }
} }
fn fd_filestat_set_size(&self, fd: types::Fd, size: types::Filesize) -> Result<(), Error> { async fn fd_filestat_set_size(
&self,
fd: types::Fd,
size: types::Filesize,
) -> Result<(), Error> {
self.table() self.table()
.get_file(u32::from(fd))? .get_file(u32::from(fd))?
.get_cap(FileCaps::FILESTAT_SET_SIZE)? .get_cap(FileCaps::FILESTAT_SET_SIZE)?
@@ -385,7 +389,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
Ok(()) Ok(())
} }
fn fd_filestat_set_times( async fn fd_filestat_set_times(
&self, &self,
fd: types::Fd, fd: types::Fd,
atim: types::Timestamp, atim: types::Timestamp,
@@ -420,7 +424,11 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
} }
} }
fn fd_read(&self, fd: types::Fd, iovs: &types::IovecArray<'_>) -> Result<types::Size, Error> { async fn fd_read<'a>(
&self,
fd: types::Fd,
iovs: &types::IovecArray<'a>,
) -> Result<types::Size, Error> {
let table = self.table(); let table = self.table();
let f = table.get_file(u32::from(fd))?.get_cap(FileCaps::READ)?; let f = table.get_file(u32::from(fd))?.get_cap(FileCaps::READ)?;
@@ -442,10 +450,10 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
Ok(types::Size::try_from(bytes_read)?) Ok(types::Size::try_from(bytes_read)?)
} }
fn fd_pread( async fn fd_pread<'a>(
&self, &self,
fd: types::Fd, fd: types::Fd,
iovs: &types::IovecArray<'_>, iovs: &types::IovecArray<'a>,
offset: types::Filesize, offset: types::Filesize,
) -> Result<types::Size, Error> { ) -> Result<types::Size, Error> {
let table = self.table(); let table = self.table();
@@ -471,10 +479,10 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
Ok(types::Size::try_from(bytes_read)?) Ok(types::Size::try_from(bytes_read)?)
} }
fn fd_write( async fn fd_write<'a>(
&self, &self,
fd: types::Fd, fd: types::Fd,
ciovs: &types::CiovecArray<'_>, ciovs: &types::CiovecArray<'a>,
) -> Result<types::Size, Error> { ) -> Result<types::Size, Error> {
let table = self.table(); let table = self.table();
let f = table.get_file(u32::from(fd))?.get_cap(FileCaps::WRITE)?; let f = table.get_file(u32::from(fd))?.get_cap(FileCaps::WRITE)?;
@@ -497,10 +505,10 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
Ok(types::Size::try_from(bytes_written)?) Ok(types::Size::try_from(bytes_written)?)
} }
fn fd_pwrite( async fn fd_pwrite<'a>(
&self, &self,
fd: types::Fd, fd: types::Fd,
ciovs: &types::CiovecArray<'_>, ciovs: &types::CiovecArray<'a>,
offset: types::Filesize, offset: types::Filesize,
) -> Result<types::Size, Error> { ) -> Result<types::Size, Error> {
let table = self.table(); let table = self.table();
@@ -526,7 +534,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
Ok(types::Size::try_from(bytes_written)?) Ok(types::Size::try_from(bytes_written)?)
} }
fn fd_prestat_get(&self, fd: types::Fd) -> Result<types::Prestat, Error> { async fn fd_prestat_get(&self, fd: types::Fd) -> Result<types::Prestat, Error> {
let table = self.table(); let table = self.table();
let dir_entry: Ref<DirEntry> = table.get(u32::from(fd)).map_err(|_| Error::badf())?; let dir_entry: Ref<DirEntry> = table.get(u32::from(fd)).map_err(|_| Error::badf())?;
if let Some(ref preopen) = dir_entry.preopen_path() { if let Some(ref preopen) = dir_entry.preopen_path() {
@@ -538,10 +546,10 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
} }
} }
fn fd_prestat_dir_name( async fn fd_prestat_dir_name<'a>(
&self, &self,
fd: types::Fd, fd: types::Fd,
path: &GuestPtr<u8>, path: &GuestPtr<'a, u8>,
path_max_len: types::Size, path_max_len: types::Size,
) -> Result<(), Error> { ) -> Result<(), Error> {
let table = self.table(); let table = self.table();
@@ -562,7 +570,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
Err(Error::not_supported()) Err(Error::not_supported())
} }
} }
fn fd_renumber(&self, from: types::Fd, to: types::Fd) -> Result<(), Error> { async fn fd_renumber(&self, from: types::Fd, to: types::Fd) -> Result<(), Error> {
let mut table = self.table(); let mut table = self.table();
let from = u32::from(from); let from = u32::from(from);
let to = u32::from(to); let to = u32::from(to);
@@ -579,7 +587,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
Ok(()) Ok(())
} }
fn fd_seek( async fn fd_seek(
&self, &self,
fd: types::Fd, fd: types::Fd,
offset: types::Filedelta, offset: types::Filedelta,
@@ -606,7 +614,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
Ok(newoffset) Ok(newoffset)
} }
fn fd_sync(&self, fd: types::Fd) -> Result<(), Error> { async fn fd_sync(&self, fd: types::Fd) -> Result<(), Error> {
self.table() self.table()
.get_file(u32::from(fd))? .get_file(u32::from(fd))?
.get_cap(FileCaps::SYNC)? .get_cap(FileCaps::SYNC)?
@@ -614,7 +622,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
Ok(()) Ok(())
} }
fn fd_tell(&self, fd: types::Fd) -> Result<types::Filesize, Error> { async fn fd_tell(&self, fd: types::Fd) -> Result<types::Filesize, Error> {
// XXX should this be stream_position? // XXX should this be stream_position?
let offset = self let offset = self
.table() .table()
@@ -624,10 +632,10 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
Ok(offset) Ok(offset)
} }
fn fd_readdir( async fn fd_readdir<'a>(
&self, &self,
fd: types::Fd, fd: types::Fd,
buf: &GuestPtr<u8>, buf: &GuestPtr<'a, u8>,
buf_len: types::Size, buf_len: types::Size,
cookie: types::Dircookie, cookie: types::Dircookie,
) -> Result<types::Size, Error> { ) -> Result<types::Size, Error> {
@@ -677,10 +685,10 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
Ok(bufused) Ok(bufused)
} }
fn path_create_directory( async fn path_create_directory<'a>(
&self, &self,
dirfd: types::Fd, dirfd: types::Fd,
path: &GuestPtr<'_, str>, path: &GuestPtr<'a, str>,
) -> Result<(), Error> { ) -> Result<(), Error> {
self.table() self.table()
.get_dir(u32::from(dirfd))? .get_dir(u32::from(dirfd))?
@@ -688,11 +696,11 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
.create_dir(path.as_str()?.deref()) .create_dir(path.as_str()?.deref())
} }
fn path_filestat_get( async fn path_filestat_get<'a>(
&self, &self,
dirfd: types::Fd, dirfd: types::Fd,
flags: types::Lookupflags, flags: types::Lookupflags,
path: &GuestPtr<'_, str>, path: &GuestPtr<'a, str>,
) -> Result<types::Filestat, Error> { ) -> Result<types::Filestat, Error> {
let filestat = self let filestat = self
.table() .table()
@@ -705,11 +713,11 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
Ok(types::Filestat::from(filestat)) Ok(types::Filestat::from(filestat))
} }
fn path_filestat_set_times( async fn path_filestat_set_times<'a>(
&self, &self,
dirfd: types::Fd, dirfd: types::Fd,
flags: types::Lookupflags, flags: types::Lookupflags,
path: &GuestPtr<'_, str>, path: &GuestPtr<'a, str>,
atim: types::Timestamp, atim: types::Timestamp,
mtim: types::Timestamp, mtim: types::Timestamp,
fst_flags: types::Fstflags, fst_flags: types::Fstflags,
@@ -732,13 +740,13 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
) )
} }
fn path_link( async fn path_link<'a>(
&self, &self,
src_fd: types::Fd, src_fd: types::Fd,
src_flags: types::Lookupflags, src_flags: types::Lookupflags,
src_path: &GuestPtr<'_, str>, src_path: &GuestPtr<'a, str>,
target_fd: types::Fd, target_fd: types::Fd,
target_path: &GuestPtr<'_, str>, target_path: &GuestPtr<'a, str>,
) -> Result<(), Error> { ) -> Result<(), Error> {
let table = self.table(); let table = self.table();
let src_dir = table let src_dir = table
@@ -760,11 +768,11 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
) )
} }
fn path_open( async fn path_open<'a>(
&self, &self,
dirfd: types::Fd, dirfd: types::Fd,
dirflags: types::Lookupflags, dirflags: types::Lookupflags,
path: &GuestPtr<'_, str>, path: &GuestPtr<'a, str>,
oflags: types::Oflags, oflags: types::Oflags,
fs_rights_base: types::Rights, fs_rights_base: types::Rights,
fs_rights_inheriting: types::Rights, fs_rights_inheriting: types::Rights,
@@ -817,11 +825,11 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
} }
} }
fn path_readlink( async fn path_readlink<'a>(
&self, &self,
dirfd: types::Fd, dirfd: types::Fd,
path: &GuestPtr<'_, str>, path: &GuestPtr<'a, str>,
buf: &GuestPtr<u8>, buf: &GuestPtr<'a, u8>,
buf_len: types::Size, buf_len: types::Size,
) -> Result<types::Size, Error> { ) -> Result<types::Size, Error> {
let link = self let link = self
@@ -842,10 +850,10 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
Ok(link_len as types::Size) Ok(link_len as types::Size)
} }
fn path_remove_directory( async fn path_remove_directory<'a>(
&self, &self,
dirfd: types::Fd, dirfd: types::Fd,
path: &GuestPtr<'_, str>, path: &GuestPtr<'a, str>,
) -> Result<(), Error> { ) -> Result<(), Error> {
self.table() self.table()
.get_dir(u32::from(dirfd))? .get_dir(u32::from(dirfd))?
@@ -853,12 +861,12 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
.remove_dir(path.as_str()?.deref()) .remove_dir(path.as_str()?.deref())
} }
fn path_rename( async fn path_rename<'a>(
&self, &self,
src_fd: types::Fd, src_fd: types::Fd,
src_path: &GuestPtr<'_, str>, src_path: &GuestPtr<'a, str>,
dest_fd: types::Fd, dest_fd: types::Fd,
dest_path: &GuestPtr<'_, str>, dest_path: &GuestPtr<'a, str>,
) -> Result<(), Error> { ) -> Result<(), Error> {
let table = self.table(); let table = self.table();
let src_dir = table let src_dir = table
@@ -874,11 +882,11 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
) )
} }
fn path_symlink( async fn path_symlink<'a>(
&self, &self,
src_path: &GuestPtr<'_, str>, src_path: &GuestPtr<'a, str>,
dirfd: types::Fd, dirfd: types::Fd,
dest_path: &GuestPtr<'_, str>, dest_path: &GuestPtr<'a, str>,
) -> Result<(), Error> { ) -> Result<(), Error> {
self.table() self.table()
.get_dir(u32::from(dirfd))? .get_dir(u32::from(dirfd))?
@@ -886,17 +894,21 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
.symlink(src_path.as_str()?.deref(), dest_path.as_str()?.deref()) .symlink(src_path.as_str()?.deref(), dest_path.as_str()?.deref())
} }
fn path_unlink_file(&self, dirfd: types::Fd, path: &GuestPtr<'_, str>) -> Result<(), Error> { async fn path_unlink_file<'a>(
&self,
dirfd: types::Fd,
path: &GuestPtr<'a, str>,
) -> Result<(), Error> {
self.table() self.table()
.get_dir(u32::from(dirfd))? .get_dir(u32::from(dirfd))?
.get_cap(DirCaps::UNLINK_FILE)? .get_cap(DirCaps::UNLINK_FILE)?
.unlink_file(path.as_str()?.deref()) .unlink_file(path.as_str()?.deref())
} }
async fn poll_oneoff<'b>( async fn poll_oneoff<'a>(
&self, &self,
subs: &GuestPtr<'b, types::Subscription>, subs: &GuestPtr<'a, types::Subscription>,
events: &GuestPtr<'b, types::Event>, events: &GuestPtr<'a, types::Event>,
nsubscriptions: types::Size, nsubscriptions: types::Size,
) -> Result<types::Size, Error> { ) -> Result<types::Size, Error> {
if nsubscriptions == 0 { if nsubscriptions == 0 {
@@ -1057,7 +1069,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
Ok(num_results.try_into().expect("results fit into memory")) Ok(num_results.try_into().expect("results fit into memory"))
} }
fn proc_exit(&self, status: types::Exitcode) -> wiggle::Trap { async fn proc_exit(&self, status: types::Exitcode) -> wiggle::Trap {
// Check that the status is within WASI's range. // Check that the status is within WASI's range.
if status < 126 { if status < 126 {
wiggle::Trap::I32Exit(status as i32) wiggle::Trap::I32Exit(status as i32)
@@ -1066,7 +1078,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
} }
} }
fn proc_raise(&self, _sig: types::Signal) -> Result<(), Error> { async fn proc_raise(&self, _sig: types::Signal) -> Result<(), Error> {
Err(Error::trap("proc_raise unsupported")) Err(Error::trap("proc_raise unsupported"))
} }
@@ -1074,31 +1086,35 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
self.sched.sched_yield().await self.sched.sched_yield().await
} }
fn random_get(&self, buf: &GuestPtr<u8>, buf_len: types::Size) -> Result<(), Error> { async fn random_get<'a>(
&self,
buf: &GuestPtr<'a, u8>,
buf_len: types::Size,
) -> Result<(), Error> {
let mut buf = buf.as_array(buf_len).as_slice_mut()?; let mut buf = buf.as_array(buf_len).as_slice_mut()?;
self.random.borrow_mut().try_fill_bytes(buf.deref_mut())?; self.random.borrow_mut().try_fill_bytes(buf.deref_mut())?;
Ok(()) Ok(())
} }
fn sock_recv( async fn sock_recv<'a>(
&self, &self,
_fd: types::Fd, _fd: types::Fd,
_ri_data: &types::IovecArray<'_>, _ri_data: &types::IovecArray<'a>,
_ri_flags: types::Riflags, _ri_flags: types::Riflags,
) -> Result<(types::Size, types::Roflags), Error> { ) -> Result<(types::Size, types::Roflags), Error> {
Err(Error::trap("sock_recv unsupported")) Err(Error::trap("sock_recv unsupported"))
} }
fn sock_send( async fn sock_send<'a>(
&self, &self,
_fd: types::Fd, _fd: types::Fd,
_si_data: &types::CiovecArray<'_>, _si_data: &types::CiovecArray<'a>,
_si_flags: types::Siflags, _si_flags: types::Siflags,
) -> Result<types::Size, Error> { ) -> Result<types::Size, Error> {
Err(Error::trap("sock_send unsupported")) Err(Error::trap("sock_send unsupported"))
} }
fn sock_shutdown(&self, _fd: types::Fd, _how: types::Sdflags) -> Result<(), Error> { async fn sock_shutdown(&self, _fd: types::Fd, _how: types::Sdflags) -> Result<(), Error> {
Err(Error::trap("sock_shutdown unsupported")) Err(Error::trap("sock_shutdown unsupported"))
} }
} }