From 73fe49cd65f955d55f092db9a7ff2a3a93e62ccc Mon Sep 17 00:00:00 2001 From: Pat Hickey Date: Fri, 20 Mar 2020 14:14:47 -0700 Subject: [PATCH] wasi-common: update trait methods to take &GuestPtr args. --- .../src/snapshots/wasi_snapshot_preview1.rs | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/crates/wasi-common/src/snapshots/wasi_snapshot_preview1.rs b/crates/wasi-common/src/snapshots/wasi_snapshot_preview1.rs index 60d788df13..5838a43254 100644 --- a/crates/wasi-common/src/snapshots/wasi_snapshot_preview1.rs +++ b/crates/wasi-common/src/snapshots/wasi_snapshot_preview1.rs @@ -14,11 +14,14 @@ use wiggle_runtime::{GuestBorrows, GuestPtr}; impl<'a> WasiSnapshotPreview1 for WasiCtx { fn args_get<'b>( &self, - mut argv: GuestPtr<'b, GuestPtr<'b, u8>>, - mut argv_buf: GuestPtr<'b, u8>, + argv: &GuestPtr<'b, GuestPtr<'b, u8>>, + argv_buf: &GuestPtr<'b, u8>, ) -> Result<()> { 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 { let arg_bytes = arg.as_bytes_with_nul(); let elems = arg_bytes.len().try_into()?; @@ -49,8 +52,8 @@ impl<'a> WasiSnapshotPreview1 for WasiCtx { fn environ_get<'b>( &self, - mut environ: GuestPtr<'b, GuestPtr<'b, u8>>, - mut environ_buf: GuestPtr<'b, u8>, + environ: &GuestPtr<'b, GuestPtr<'b, u8>>, + environ_buf: &GuestPtr<'b, u8>, ) -> Result<()> { trace!( "environ_get(environ={:?}, environ_buf={:?})", @@ -58,6 +61,9 @@ impl<'a> WasiSnapshotPreview1 for WasiCtx { environ_buf ); + let mut environ = environ.clone(); + let mut environ_buf = environ_buf.clone(); + for e in &self.env { let environ_bytes = e.as_bytes_with_nul(); let elems = environ_bytes.len().try_into()?; @@ -409,7 +415,7 @@ impl<'a> WasiSnapshotPreview1 for WasiCtx { fn fd_prestat_dir_name( &self, fd: types::Fd, - path: GuestPtr, + path: &GuestPtr, path_len: types::Size, ) -> Result<()> { trace!( @@ -536,7 +542,7 @@ impl<'a> WasiSnapshotPreview1 for WasiCtx { fn fd_readdir( &self, fd: types::Fd, - buf: GuestPtr, + buf: &GuestPtr, buf_len: types::Size, cookie: types::Dircookie, ) -> Result { @@ -555,10 +561,11 @@ impl<'a> WasiSnapshotPreview1 for WasiCtx { fn copy_entities>>( iter: T, - mut buf: GuestPtr, + buf: &GuestPtr, buf_len: types::Size, ) -> Result { let mut bufused = 0; + let mut buf = buf.clone(); for pair in iter { let (dirent, name) = pair?; let dirent_raw = dirent.as_bytes()?; @@ -971,7 +978,7 @@ impl<'a> WasiSnapshotPreview1 for WasiCtx { &self, dirfd: types::Fd, path: &GuestPtr<'_, str>, - buf: GuestPtr, + buf: &GuestPtr, buf_len: types::Size, ) -> Result { trace!( @@ -1140,8 +1147,8 @@ impl<'a> WasiSnapshotPreview1 for WasiCtx { fn poll_oneoff( &self, - in_: GuestPtr, - out: GuestPtr, + in_: &GuestPtr, + out: &GuestPtr, nsubscriptions: types::Size, ) -> Result { trace!( @@ -1294,7 +1301,7 @@ impl<'a> WasiSnapshotPreview1 for WasiCtx { Ok(()) } - fn random_get(&self, buf: GuestPtr, buf_len: types::Size) -> Result<()> { + fn random_get(&self, buf: &GuestPtr, buf_len: types::Size) -> Result<()> { trace!("random_get(buf={:?}, buf_len={:?})", buf, buf_len); let slice = unsafe {