eigenein opened issue #7786:
:wave: Hi team,
I'm instantiating a long-lived
EngineandLinker, 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:let mut linker = wasmtime::Linker::new(&engine); linker.func_wrap("logging", "info", |mut caller: Caller<'_, String>, offset: u32, size: u32| { // How do I access instance's memory here and read from there? }, )?;I could use a closure, but I'm going to support a plugin system, and a shared host function may be called from any of them. Also,
Storeis short-lived, and I wouldn't like to re-instantiate aLinkertogether with the closures for every host→guest callShould I put a reference to instance's
Memoryto the instance'sStore? That smells a little, sinceCalleralready containsStoreand all the memories are already owned byStore. Am I missing something?
eigenein edited issue #7786:
:wave: Hi team,
I'm instantiating a long-lived
EngineandLinker, 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:let mut linker = wasmtime::Linker::new(&engine); linker.func_wrap("logging", "info", |mut caller: Caller<'_, ()>, offset: u32, size: u32| { // How do I access instance's memory here and read from there? }, )?;I could use a closure, but I'm going to support a plugin system, and a shared host function may be called from any of them. Also,
Storeis short-lived, and I wouldn't like to re-instantiate aLinkertogether with the closures for every host→guest callShould I put a reference to instance's
Memoryto the instance'sStore? That smells a little, sinceCalleralready containsStoreand all the memories are already owned byStore. Am I missing something?
eigenein edited issue #7786:
:wave: Hi team,
I'm instantiating a long-lived
EngineandLinker, 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:let mut linker = wasmtime::Linker::new(&engine); linker.func_wrap("logging", "info", |mut caller: Caller<'_, ()>, offset: u32, size: u32| { // How do I access instance's memory here and read from there? }, )?;I could use a closure, but I'm going to support a plugin system, and a shared host function may be called from any plugin. Also,
Storeis short-lived, and I wouldn't like to re-instantiate aLinkertogether with the closures for every host→guest callShould I put a reference to instance's
Memoryto the instance'sStore? That smells a little, sinceCalleralready containsStoreand all the memories are already owned byStore. Am I missing something?
eigenein edited issue #7786:
:wave: Hi team,
I'm instantiating a long-lived
EngineandLinker, 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:let mut linker = wasmtime::Linker::new(&engine); linker.func_wrap("logging", "info", |mut caller: Caller<'_, ()>, offset: u32, size: u32| { // How do I access instance's memory here and read from there? }, )?;I could use a closure, but I'm going to support a plugin system, and a shared host function may be called from any plugin. Also,
Storeis short-lived, and I wouldn't like to re-instantiate aLinkertogether with the closures for every host-to-guest callShould I put a reference to instance's
Memoryto the instance'sStore? That smells a little, sinceCalleralready containsStoreand all the memories are already owned byStore. Am I missing something?
eigenein edited issue #7786:
:wave: Hi team,
I'm instantiating a long-lived
EngineandLinker, 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:let mut linker = wasmtime::Linker::new(&engine); linker.func_wrap("logging", "info", |mut caller: Caller<'_, ()>, (offset, size): (u32, u32)| { // How do I access instance's memory here and read from there? }, )?;I could use a closure, but I'm going to support a plugin system, and a shared host function may be called from any plugin. Also,
Storeis short-lived, and I wouldn't like to re-instantiate aLinkertogether with the closures for every host-to-guest callShould I put a reference to instance's
Memoryto the instance'sStore? That smells a little, sinceCalleralready containsStoreand all the memories are already owned byStore. Am I missing something?
eigenein edited issue #7786:
:wave: Hi team,
I'm instantiating a long-lived
EngineandLinker, 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:let mut linker = wasmtime::Linker::new(&engine); linker.func_wrap("logging", "info", |mut caller: Caller<'_, ()>, (offset, size): (u32, u32)| { // How do I access instance's memory here and read from there? }, )?;I could use a closure, but I'm going to support a plugin system, and a shared host function may be called from any plugin. Also,
Storeis short-lived, and I wouldn't like to re-instantiate aLinkertogether with the closures for every host-to-guest callShould I put a reference to
Instanceor to the instance'sMemoryto the instance'sStore? That smells a little, sinceCalleralready containsStoreand all the memories are already owned byStore. Am I missing something?
eigenein edited issue #7786:
:wave: Hi team,
I'm instantiating a long-lived
EngineandLinker, 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:let mut linker = wasmtime::Linker::new(&engine); linker.func_wrap("logging", "info", |mut caller: Caller<'_, ()>, (offset, size): (u32, u32)| { // How do I access instance's memory here and read from there? }, )?;I could use a closure, but I'm going to support a plugin system, and a shared host function may be called from any plugin. Also,
Storeis short-lived, and I wouldn't like to re-instantiate aLinkertogether with the closures for every host-to-guest callShould I put a reference to
Instanceor to the instance'sMemoryto the instance'sStore? That smells a little, sinceCalleralready containsStoreand all the memories are already owned byStore, that is effeectively making a loop of references. Am I missing something?
eigenein edited issue #7786:
:wave: Hi team,
I'm instantiating a long-lived
EngineandLinker, 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:let mut linker = wasmtime::Linker::new(&engine); linker.func_wrap("logging", "info", |mut caller: Caller<'_, ()>, (offset, size): (u32, u32)| { // How do I access instance's memory here and read from there? }, )?;I could use a closure, but I'm going to support a plugin system, and a shared host function may be called from any plugin. Also,
Storeis short-lived, and I wouldn't like to re-instantiate aLinkertogether with the closures for every host-to-guest callShould I put a reference to
Instanceor to the instance'sMemoryto the instance'sStore? That smells a little, sinceCalleralready containsStoreand all the memories are already owned byStore, that is effectively making a loop of references. Am I missing something?
eigenein edited issue #7786:
:wave: Hi team,
I'm instantiating a long-lived
EngineandLinker, 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:let mut linker = wasmtime::Linker::new(&engine); linker.func_wrap("logging", "info", |mut caller: Caller<'_, ()>, (offset, size): (u32, u32)| { // How do I access instance's memory here and read from there? }, )?;I could use a closure, but I'm going to support a plugin system, and a shared host function may be called from any plugin. Also,
Storeis short-lived, and I wouldn't like to re-instantiate aLinkertogether with the closures for every host-to-guest callShould I put a reference to
Instanceor to the instance'sMemoryto the instance'sStore? That smells a little, sinceCalleralready containsStoreand all the memories are already owned byStore– so that would effectively be making a loop of references. Am I missing something?
eigenein edited issue #7786:
:wave: Hi team,
I'm instantiating a long-lived
EngineandLinker, 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:let mut linker = wasmtime::Linker::new(&engine); linker.func_wrap("logging", "info", |mut caller: Caller<'_, ()>, (offset, size): (u32, u32)| { // How do I access instance's memory here and read from it? }, )?;I could use a closure, but I'm going to support a plugin system, and a shared host function may be called from any plugin. Also,
Storeis short-lived, and I wouldn't like to re-instantiate aLinkertogether with the closures for every host-to-guest callShould I put a reference to
Instanceor to the instance'sMemoryto the instance'sStore? That smells a little, sinceCalleralready containsStoreand all the memories are already owned byStore– so that would effectively be making a loop of references. Am I missing something?
eigenein edited issue #7786:
:wave: Hi team,
I'm instantiating a long-lived
EngineandLinker, 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:let mut linker = wasmtime::Linker::new(&engine); linker.func_wrap("logging", "info", |mut caller: 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 https://github.com/bytecodealliance/wasmtime/issues/2491#issuecomment-742352722, but I'm going to support a plugin system, and a shared host function may be called from any plugin. Also,
Storeis short-lived, and I wouldn't like to re-instantiate aLinkertogether with the closures for every host-to-guest callShould I put a reference to
Instanceor to the instance'sMemoryto the instance'sStore? That smells a little, sinceCalleralready containsStoreand all the memories are already owned byStore– so that would effectively be making a loop of references. Am I missing something?
eigenein edited issue #7786:
:wave: Hi team,
I'm instantiating a long-lived
EngineandLinker, 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:let mut linker = wasmtime::Linker::new(&engine); linker.func_wrap("logging", "info", |mut caller: 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 https://github.com/bytecodealliance/wasmtime/issues/2491#issuecomment-742352722, but I'm going to support a plugin system, and a shared host function may be called from any plugin. Also,
Storeis short-lived, and I wouldn't like to re-instantiate aLinkertogether with the closures for every host-to-guest callShould I put a reference to
Instanceor to the instance'sMemoryinto the instance'sStore? That smells a little, sinceCalleralready containsStoreand all the memories are already owned byStore– so that would effectively be making a loop of references. Am I missing something?
alexcrichton commented on issue #7786:
There's an example for this on the documentation of
Func::wrapwhere the gist of it is: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
Memoryin theTofStore<T>(i.e. replace the()you're using currently), but the easiest option is probably to callcaller.get_export(...)
eigenein commented on issue #7786:
@alexcrichton Thank you, just exactly what I needed and completely overlooked!
eigenein closed issue #7786:
:wave: Hi team,
I'm instantiating a long-lived
EngineandLinker, 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:let mut linker = wasmtime::Linker::new(&engine); linker.func_wrap("logging", "info", |mut caller: 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 https://github.com/bytecodealliance/wasmtime/issues/2491#issuecomment-742352722, but I'm going to support a plugin system, and a shared host function may be called from any plugin. Also,
Storeis short-lived, and I wouldn't like to re-instantiate aLinkertogether with the closures for every host-to-guest callShould I put a reference to
Instanceor to the instance'sMemoryinto the instance'sStore? That smells a little, sinceCalleralready containsStoreand all the memories are already owned byStore– so that would effectively be making a loop of references. Am I missing something?
Last updated: Dec 06 2025 at 06:05 UTC