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