-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Open
Labels
wasmtime:apiRelated to the API of the `wasmtime` crate itselfRelated to the API of the `wasmtime` crate itself
Description
Feature
Hello, I need to access the imported memory inside a functions, then I realized the Caller only show exports, not imports, so I had a lot of trouble to get Wasmtime store working with MaybeUnit, this simple solution segfaults:
pub struct State {
pub memory: Memory,
}
let state = MaybeUninit::<State>::uninit();
let mut store = Store::new(engine, state);
let memory_type = MemoryType::new(16, None);
store.data_mut().memory.write(Memory::new(&mut store, memory_type)?);
let store = unsafe {
std::mem::transmute::<Store<MaybeUninit<State>>, Store<State>>(store)
};
// ...
let imports = [memory.into()];
// segfaults below
let instance = Instance::new(&mut store, &module, &imports)?;Then I realized the issue is that there's no way for me transmute only the State, I need to transmute the Store which is not recommended, once rust doesn't guarantee the same memory layout:
assert_eq!(size_of::<Option<bool>>(), 1);
assert_eq!(size_of::<Option<MaybeUninit<bool>>>(), 2);Actually I haven't find any way to use MaybeUnit that doesn't look hacky, and I want to avoid the usage of Option and unwraps in the code, once it bloats the binary with panic data.
Alternatives
- Make the imported memory easily available inside Functions, ex: expose it in the Caller.
- Use
#[repr(C)]onStore, so we can safely transmute it.
ZylosLumen
Metadata
Metadata
Assignees
Labels
wasmtime:apiRelated to the API of the `wasmtime` crate itselfRelated to the API of the `wasmtime` crate itself