You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
wiggle: copy guest strings from shared memory (#5475)
* wiggle: copy guest strings from shared memory
Along the same lines as #5471, this change adds a new smart pointer,
`GuestStrCow`, to copy the string bytes over from Wasm memory to the
host when the string is found in shared memory. This is necessary to
maintain Rust guarantees: with shared memory, the bytes backing a
`GuestStr` could be altered by another thread and this would invalidate
the assumption that we can dereference at any point to `&str`.
`GuestStrCow` is essentially a wrapper around `GuestStr` when the memory
is not shared but copies the memory region into a `String` when the
memory is shared.
This change updates the uses of Wiggle strings in both wasi-common and
wasi-crypto.
* review: perform UTF-8 check on `GuestStr` construction
@@ -736,9 +736,9 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
736
736
737
737
src_dir
738
738
.hard_link(
739
-
src_path.as_str()?.expect("cannot use with shared memories; see https://github.com/bytecodealliance/wasmtime/issues/5235 (TODO)").deref(),
739
+
src_path.as_cow()?.deref(),
740
740
target_dir.deref(),
741
-
target_path.as_str()?.expect("cannot use with shared memories; see https://github.com/bytecodealliance/wasmtime/issues/5235 (TODO)").deref(),
741
+
target_path.as_cow()?.deref(),
742
742
)
743
743
.await
744
744
}
@@ -764,7 +764,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
764
764
765
765
let oflags = OFlags::from(&oflags);
766
766
let fdflags = FdFlags::from(fdflags);
767
-
let path = path.as_str()?.expect("cannot use with shared memories; see https://github.com/bytecodealliance/wasmtime/issues/5235 (TODO)");
767
+
let path = path.as_cow()?;
768
768
if oflags.contains(OFlags::DIRECTORY){
769
769
if oflags.contains(OFlags::CREATE)
770
770
|| oflags.contains(OFlags::EXCLUSIVE)
@@ -813,7 +813,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
813
813
.table()
814
814
.get_dir(u32::from(dirfd))?
815
815
.get_cap(DirCaps::READLINK)?
816
-
.read_link(path.as_str()?.expect("cannot use with shared memories; see https://github.com/bytecodealliance/wasmtime/issues/5235 (TODO)").deref())
816
+
.read_link(path.as_cow()?.deref())
817
817
.await?
818
818
.into_os_string()
819
819
.into_string()
@@ -835,7 +835,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
835
835
self.table()
836
836
.get_dir(u32::from(dirfd))?
837
837
.get_cap(DirCaps::REMOVE_DIRECTORY)?
838
-
.remove_dir(path.as_str()?.expect("cannot use with shared memories; see https://github.com/bytecodealliance/wasmtime/issues/5235 (TODO)").deref())
838
+
.remove_dir(path.as_cow()?.deref())
839
839
.await
840
840
}
841
841
@@ -855,9 +855,9 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
855
855
.get_cap(DirCaps::RENAME_TARGET)?;
856
856
src_dir
857
857
.rename(
858
-
src_path.as_str()?.expect("cannot use with shared memories; see https://github.com/bytecodealliance/wasmtime/issues/5235 (TODO)").deref(),
858
+
src_path.as_cow()?.deref(),
859
859
dest_dir.deref(),
860
-
dest_path.as_str()?.expect("cannot use with shared memories; see https://github.com/bytecodealliance/wasmtime/issues/5235 (TODO)").deref(),
860
+
dest_path.as_cow()?.deref(),
861
861
)
862
862
.await
863
863
}
@@ -871,7 +871,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
871
871
self.table()
872
872
.get_dir(u32::from(dirfd))?
873
873
.get_cap(DirCaps::SYMLINK)?
874
-
.symlink(src_path.as_str()?.expect("cannot use with shared memories; see https://github.com/bytecodealliance/wasmtime/issues/5235 (TODO)").deref(), dest_path.as_str()?.expect("cannot use with shared memories; see https://github.com/bytecodealliance/wasmtime/issues/5235 (TODO)").deref())
Copy file name to clipboardExpand all lines: crates/wasi-crypto/src/wiggle_interfaces/common.rs
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,7 @@ impl super::wasi_ephemeral_crypto_common::WasiEphemeralCryptoCommon for WasiCryp
27
27
value_ptr:&wiggle::GuestPtr<'_,u8>,
28
28
value_len: guest_types::Size,
29
29
) -> Result<(), guest_types::CryptoErrno>{
30
-
let name_str:&str = &*name_str.as_str()?.expect("cannot use with shared memories; see https://github.com/bytecodealliance/wasmtime/issues/5235 (TODO)");
30
+
let name_str:&str = &*name_str.as_cow()?;
31
31
let value:&[u8] = {
32
32
&*value_ptr
33
33
.as_array(value_len)
@@ -44,7 +44,7 @@ impl super::wasi_ephemeral_crypto_common::WasiEphemeralCryptoCommon for WasiCryp
44
44
buffer_ptr:&wiggle::GuestPtr<'_,u8>,
45
45
buffer_len: guest_types::Size,
46
46
) -> Result<(), guest_types::CryptoErrno>{
47
-
let name_str:&str = &*name_str.as_str()?.expect("cannot use with shared memories; see https://github.com/bytecodealliance/wasmtime/issues/5235 (TODO)");
47
+
let name_str:&str = &*name_str.as_cow()?;
48
48
let buffer:&'staticmut[u8] = unsafe{
49
49
std::mem::transmute(
50
50
&mut*buffer_ptr
@@ -62,7 +62,7 @@ impl super::wasi_ephemeral_crypto_common::WasiEphemeralCryptoCommon for WasiCryp
62
62
name_str:&wiggle::GuestPtr<'_,str>,
63
63
value:u64,
64
64
) -> Result<(), guest_types::CryptoErrno>{
65
-
let name_str:&str = &*name_str.as_str()?.expect("cannot use with shared memories; see https://github.com/bytecodealliance/wasmtime/issues/5235 (TODO)");
let name_str:&str = &*name_str.as_str()?.expect("cannot use with shared memories; see https://github.com/bytecodealliance/wasmtime/issues/5235 (TODO)");
181
+
let name_str:&str = &*name_str.as_cow()?;
182
182
let value = &mut*value_ptr
183
183
.as_array(value_max_len)
184
184
.as_slice_mut()?
@@ -193,7 +193,7 @@ impl super::wasi_ephemeral_crypto_symmetric::WasiEphemeralCryptoSymmetric for Wa
let name_str:&str = &*name_str.as_str()?.expect("cannot use with shared memories; see https://github.com/bytecodealliance/wasmtime/issues/5235 (TODO)");
0 commit comments