eigenein opened issue #7786:
:wave: 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: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,
Store
is short-lived, and I wouldn't like to re-instantiate aLinker
together with the closures for every host→guest callShould I put a reference to instance's
Memory
to the instance'sStore
? That smells a little, sinceCaller
already containsStore
and all the memories are already owned byStore
. Am I missing something?
eigenein edited issue #7786:
:wave: 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: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,
Store
is short-lived, and I wouldn't like to re-instantiate aLinker
together with the closures for every host→guest callShould I put a reference to instance's
Memory
to the instance'sStore
? That smells a little, sinceCaller
already containsStore
and all the memories are already owned byStore
. Am I missing something?
eigenein edited issue #7786:
:wave: 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: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,
Store
is short-lived, and I wouldn't like to re-instantiate aLinker
together with the closures for every host→guest callShould I put a reference to instance's
Memory
to the instance'sStore
? That smells a little, sinceCaller
already containsStore
and all the memories are already owned byStore
. Am I missing something?
eigenein edited issue #7786:
:wave: 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: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,
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's
Memory
to the instance'sStore
? That smells a little, sinceCaller
already containsStore
and all the memories are already owned byStore
. Am I missing something?
eigenein edited issue #7786:
:wave: 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: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,
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's
Memory
to the instance'sStore
? That smells a little, sinceCaller
already containsStore
and all the memories are already owned byStore
. Am I missing something?
eigenein edited issue #7786:
:wave: 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: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,
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
to the instance'sStore
? That smells a little, sinceCaller
already containsStore
and all the memories are already owned byStore
. Am I missing something?
eigenein edited issue #7786:
:wave: 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: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,
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
to the instance'sStore
? That smells a little, sinceCaller
already containsStore
and 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
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: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,
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
to the instance'sStore
? That smells a little, sinceCaller
already containsStore
and 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
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: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,
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
to 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?
eigenein edited issue #7786:
:wave: 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: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,
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
to 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?
eigenein edited issue #7786:
:wave: 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: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,
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
to 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?
eigenein edited issue #7786:
:wave: 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: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,
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?
alexcrichton commented on issue #7786:
There's an example for this on the documentation of
Func::wrap
where 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
Memory
in theT
ofStore<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
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: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,
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?
Last updated: Dec 23 2024 at 13:07 UTC