wig: wiggle now puts BorrowChecker inside GuestMemory
This commit is contained in:
@@ -467,16 +467,16 @@ pub fn define_struct_for_wiggle(args: TokenStream) -> TokenStream {
|
||||
#handle_early_error
|
||||
}
|
||||
};
|
||||
let mem: WasiMemory = mem.into();
|
||||
// Wiggle does not expose any methods for functions to re-enter the
|
||||
// WebAssembly module, or expose the memory via non-wiggle mechanisms.
|
||||
// Therefore, creating a new BorrowChecker at the root of each function
|
||||
// invocation is correct.
|
||||
// Wiggle does not expose any methods for
|
||||
// functions to re-enter the WebAssembly module,
|
||||
// or expose the memory via non-wiggle mechanisms.
|
||||
// Therefore, creating a new BorrowChecker at the
|
||||
// root of each function invocation is correct.
|
||||
let bc = wiggle::BorrowChecker::new();
|
||||
let mem: WasiMemory { mem, bc };
|
||||
wasi_common::wasi::#module_id::#name_ident(
|
||||
&mut my_cx.borrow_mut(),
|
||||
&mem,
|
||||
&bc,
|
||||
#(#hostcall_args),*
|
||||
) #cvt_ret
|
||||
}
|
||||
@@ -490,18 +490,18 @@ pub fn define_struct_for_wiggle(args: TokenStream) -> TokenStream {
|
||||
/// Lightweight `wasmtime::Memory` wrapper so that we can
|
||||
/// implement `wiggle::GuestMemory` trait on it which is
|
||||
/// now required to interface with `wasi-common`.
|
||||
struct WasiMemory(wasmtime::Memory);
|
||||
|
||||
impl From<wasmtime::Memory> for WasiMemory {
|
||||
fn from(mem: wasmtime::Memory) -> Self {
|
||||
Self(mem)
|
||||
}
|
||||
}
|
||||
struct WasiMemory {
|
||||
mem: wasmtime::Memory,
|
||||
bc: wiggle::BorrowChecker,
|
||||
};
|
||||
|
||||
unsafe impl wiggle::GuestMemory for WasiMemory {
|
||||
fn base(&self) -> (*mut u8, u32) {
|
||||
(self.0.data_ptr(), self.0.data_size() as _)
|
||||
}
|
||||
fn borrow_checker(&self) -> &wiggle::BorrowChecker {
|
||||
&self.bc
|
||||
}
|
||||
}
|
||||
|
||||
/// An instantiated instance of the wasi exports.
|
||||
|
||||
Reference in New Issue
Block a user