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
I'm instantiating a long-lived Engine and Linker, and then I'm adding some host functions to the linker (Rust API). Some of these functions should receive a string as a parameter, so an offset and a length in a guest's memory, for example:
letmut linker = wasmtime::Linker::new(&engine);
linker.func_wrap("logging","info",
|mutcaller:Caller<'_,()>,(offset, size):(u32,u32)| {// How do I access instance's memory here and read from it?},)?;
I could use a closure as suggested in #2491 (comment), but I'm going to support a plugin system, and a shared host function may be called from any plugin. Also, Store is short-lived, and I wouldn't like to re-instantiate a Linker together with the closures for every host-to-guest call
Should I put a reference to Instance or to the instance's Memory into the instance's Store? That smells a little, since Caller already contains Store and all the memories are already owned by Store – so that would effectively be making a loop of references. Am I missing something?
The text was updated successfully, but these errors were encountered:
let mem = match caller.get_export("memory"){Some(Extern::Memory(mem)) => mem,
_ => anyhow::bail!("failed to find host memory"),};
One option is to store a Memory in the T of Store<T> (i.e. replace the () you're using currently), but the easiest option is probably to call caller.get_export(...)
👋 Hi team,
I'm instantiating a long-lived
Engine
andLinker
, and then I'm adding some host functions to the linker (Rust API). Some of these functions should receive a string as a parameter, so an offset and a length in a guest's memory, for example:I could use a closure as suggested in #2491 (comment), but I'm going to support a plugin system, and a shared host function may be called from any plugin. Also,
Store
is short-lived, and I wouldn't like to re-instantiate aLinker
together with the closures for every host-to-guest callShould I put a reference to
Instance
or to the instance'sMemory
into the instance'sStore
? That smells a little, sinceCaller
already containsStore
and all the memories are already owned byStore
– so that would effectively be making a loop of references. Am I missing something?The text was updated successfully, but these errors were encountered: