Hi, say I have a wiggle::GuestMemory, how to access the address of the starting address of the linear memory instance?
For that you'll want GuestMemory::base
Yeah I think I need that, but I didn't see the the base() function defined here https://github.com/bytecodealliance/wasmtime/blob/main/crates/wiggle/src/lib.rs
Basically I just want to know the start address of the linear memory, when I'm in a host function exposed the wasm module, like fd_write
Ah yes wiggle
changed on the main
branch of wasmtime, for the base address you can look at the payloads of GuestMemory
this is the documentation for main
and you can do a match
on a GuestMemory
. The Shared
and Unshared
variants both hold the entire contents of linear memory, so the base address of those arrays is the base address of linear memory
If you'd like I think it would also be reasonable to re-add the base
method as fn(&GuestMemory) -> &[UnsafeCell<u8>]
too
Thank you! This makes a lot of sense. I added a simple implementation, works fine
pub fn base(&self) -> *const u8 {
match self {
GuestMemory::Unshared(slice) => slice.as_ptr(),
GuestMemory::Shared(slice) => slice.as_ptr() as *const u8,
}
}
Last updated: Dec 23 2024 at 12:05 UTC