bkolobara opened Issue #2477:
Currently the Linker.define function takes an item that implements
Into<Extern>
andExtern
takes a Memory struct.
I would like to define a structure that implementsLinearMemory
and pass it to the linker. Would this be possible?
peterhuene commented on Issue #2477:
Hi @bkolobara! Currently the
LinearMemory
trait doesn't provide enough information to properly represent a WebAssembly linear memory for the importing; it's primarily missing the memory's "type" (i.e.MemoryType
).The
LinearMemory
trait is only intended to be used from theMemoryCreator
trait and, when configured withConfig::with_host_memory
, that's used whenever creating a linear memory, either from instantiating a module that defines one or when you create aMemory
in the host.It would be possible to implement a
Memory::new_with_creator
(or similar) method that you could use to pass aMemoryCreator
to use just for that specificMemory
.Before implementing that, though, does
Config::with_host_memory
not suit your needs? Do you need control over the way memory is allocated for a specificMemory
and are okay with Wasmtime handling the allocation for any other linear memories?
peterhuene edited a comment on Issue #2477:
Hi @bkolobara! Currently the
LinearMemory
trait doesn't provide enough information to properly represent a WebAssembly linear memory for importing; it's primarily missing the memory's "type" (i.e.MemoryType
).The
LinearMemory
trait is only intended to be used from theMemoryCreator
trait and, when configured withConfig::with_host_memory
, that's used whenever creating a linear memory, either from instantiating a module that defines one or when you create aMemory
in the host.It would be possible to implement a
Memory::new_with_creator
(or similar) method that you could use to pass aMemoryCreator
to use just for that specificMemory
.Before implementing that, though, does
Config::with_host_memory
not suit your needs? Do you need control over the way memory is allocated for a specificMemory
and are okay with Wasmtime handling the allocation for any other linear memories?
bkolobara commented on Issue #2477:
Thanks for the explanation. Maybe I should provided some more context, I wanted to create a memory that I could share between threads as
Memory
is notSend
orSync
. I assume, this is something you will support in the future, but I was looking for a short term solution for testing.
bkolobara edited a comment on Issue #2477:
Thanks for the explanation. Maybe I should provided more context, I wanted to create a memory that I could share between threads as
Memory
is notSend
orSync
. I assume, this is something you will support in the future, but I was looking for a short term solution for testing.
peterhuene commented on Issue #2477:
A
Memory
isn'tSend
orSync
because of this general issue for instances not beingSend
orSync
and currentlyMemory
stores a representation of an instance internally (a module is defined to export the memory and then is instantiated to create it).Right now the Wasmtime API expects everything in a
Store
to be on the same thread. A consequence of this is that thememory.grow
operation is not synchronized as only a singleInstance
can interact with the imported memory at a time asInstance
is notSend
. I can't think of any solutions to this problem that would be safe to do.This needs to change to fully support the Wasm threads proposal; for example, it should be possible to have multiple instances running on different threads import the same shared linear memory and synchronize any growth operations. However, Wasmtime doesn't support shared linear memories today.
bkolobara commented on Issue #2477:
Thanks for the clarification, I will close this issue as there are others tracking the threading support.
bkolobara closed Issue #2477:
Currently the Linker.define function takes an item that implements
Into<Extern>
andExtern
takes a Memory struct.
I would like to define a structure that implementsLinearMemory
and pass it to the linker. Would this be possible?
peterhuene edited a comment on Issue #2477:
A
Memory
isn'tSend
orSync
because of this general issue for instances not beingSend
orSync
and currentlyMemory
stores a representation of an instance internally (a module is defined to export the memory and then is instantiated to create it).Right now the Wasmtime API expects everything in a
Store
to be on the same thread. A consequence of this is that thememory.grow
operation is not synchronized as only a singleInstance
can interact with the imported memory at a time asInstance
is notSend
. I can't think of any workaround solutions to this problem that would be safe to do.This needs to change to fully support the Wasm threads proposal; for example, it should be possible to have multiple instances running on different threads import the same shared linear memory and synchronize any growth operations. However, Wasmtime doesn't support shared linear memories today.
Last updated: Nov 22 2024 at 17:03 UTC