wasi-common: update trait methods to take &GuestPtr args.

This commit is contained in:
Pat Hickey
2020-03-20 14:14:47 -07:00
parent 0e72edb80e
commit 73fe49cd65

View File

@@ -14,11 +14,14 @@ use wiggle_runtime::{GuestBorrows, GuestPtr};
impl<'a> WasiSnapshotPreview1 for WasiCtx { impl<'a> WasiSnapshotPreview1 for WasiCtx {
fn args_get<'b>( fn args_get<'b>(
&self, &self,
mut argv: GuestPtr<'b, GuestPtr<'b, u8>>, argv: &GuestPtr<'b, GuestPtr<'b, u8>>,
mut argv_buf: GuestPtr<'b, u8>, argv_buf: &GuestPtr<'b, u8>,
) -> Result<()> { ) -> Result<()> {
trace!("args_get(argv_ptr={:?}, argv_buf={:?})", argv, argv_buf); trace!("args_get(argv_ptr={:?}, argv_buf={:?})", argv, argv_buf);
let mut argv = argv.clone();
let mut argv_buf = argv_buf.clone();
for arg in &self.args { for arg in &self.args {
let arg_bytes = arg.as_bytes_with_nul(); let arg_bytes = arg.as_bytes_with_nul();
let elems = arg_bytes.len().try_into()?; let elems = arg_bytes.len().try_into()?;
@@ -49,8 +52,8 @@ impl<'a> WasiSnapshotPreview1 for WasiCtx {
fn environ_get<'b>( fn environ_get<'b>(
&self, &self,
mut environ: GuestPtr<'b, GuestPtr<'b, u8>>, environ: &GuestPtr<'b, GuestPtr<'b, u8>>,
mut environ_buf: GuestPtr<'b, u8>, environ_buf: &GuestPtr<'b, u8>,
) -> Result<()> { ) -> Result<()> {
trace!( trace!(
"environ_get(environ={:?}, environ_buf={:?})", "environ_get(environ={:?}, environ_buf={:?})",
@@ -58,6 +61,9 @@ impl<'a> WasiSnapshotPreview1 for WasiCtx {
environ_buf environ_buf
); );
let mut environ = environ.clone();
let mut environ_buf = environ_buf.clone();
for e in &self.env { for e in &self.env {
let environ_bytes = e.as_bytes_with_nul(); let environ_bytes = e.as_bytes_with_nul();
let elems = environ_bytes.len().try_into()?; let elems = environ_bytes.len().try_into()?;
@@ -409,7 +415,7 @@ impl<'a> WasiSnapshotPreview1 for WasiCtx {
fn fd_prestat_dir_name( fn fd_prestat_dir_name(
&self, &self,
fd: types::Fd, fd: types::Fd,
path: GuestPtr<u8>, path: &GuestPtr<u8>,
path_len: types::Size, path_len: types::Size,
) -> Result<()> { ) -> Result<()> {
trace!( trace!(
@@ -536,7 +542,7 @@ impl<'a> WasiSnapshotPreview1 for WasiCtx {
fn fd_readdir( fn fd_readdir(
&self, &self,
fd: types::Fd, fd: types::Fd,
buf: GuestPtr<u8>, buf: &GuestPtr<u8>,
buf_len: types::Size, buf_len: types::Size,
cookie: types::Dircookie, cookie: types::Dircookie,
) -> Result<types::Size> { ) -> Result<types::Size> {
@@ -555,10 +561,11 @@ impl<'a> WasiSnapshotPreview1 for WasiCtx {
fn copy_entities<T: Iterator<Item = Result<(types::Dirent, String)>>>( fn copy_entities<T: Iterator<Item = Result<(types::Dirent, String)>>>(
iter: T, iter: T,
mut buf: GuestPtr<u8>, buf: &GuestPtr<u8>,
buf_len: types::Size, buf_len: types::Size,
) -> Result<types::Size> { ) -> Result<types::Size> {
let mut bufused = 0; let mut bufused = 0;
let mut buf = buf.clone();
for pair in iter { for pair in iter {
let (dirent, name) = pair?; let (dirent, name) = pair?;
let dirent_raw = dirent.as_bytes()?; let dirent_raw = dirent.as_bytes()?;
@@ -971,7 +978,7 @@ impl<'a> WasiSnapshotPreview1 for WasiCtx {
&self, &self,
dirfd: types::Fd, dirfd: types::Fd,
path: &GuestPtr<'_, str>, path: &GuestPtr<'_, str>,
buf: GuestPtr<u8>, buf: &GuestPtr<u8>,
buf_len: types::Size, buf_len: types::Size,
) -> Result<types::Size> { ) -> Result<types::Size> {
trace!( trace!(
@@ -1140,8 +1147,8 @@ impl<'a> WasiSnapshotPreview1 for WasiCtx {
fn poll_oneoff( fn poll_oneoff(
&self, &self,
in_: GuestPtr<types::Subscription>, in_: &GuestPtr<types::Subscription>,
out: GuestPtr<types::Event>, out: &GuestPtr<types::Event>,
nsubscriptions: types::Size, nsubscriptions: types::Size,
) -> Result<types::Size> { ) -> Result<types::Size> {
trace!( trace!(
@@ -1294,7 +1301,7 @@ impl<'a> WasiSnapshotPreview1 for WasiCtx {
Ok(()) Ok(())
} }
fn random_get(&self, buf: GuestPtr<u8>, buf_len: types::Size) -> Result<()> { fn random_get(&self, buf: &GuestPtr<u8>, buf_len: types::Size) -> Result<()> {
trace!("random_get(buf={:?}, buf_len={:?})", buf, buf_len); trace!("random_get(buf={:?}, buf_len={:?})", buf, buf_len);
let slice = unsafe { let slice = unsafe {