Sherlock-Holo opened issue #6116:
I'm using
component-model
feature to write a host function, however I can't get theCaller
orStore
to access the wasm memory through https://docs.rs/wasmtime/latest/wasmtime/struct.Memory.html#method.data_mut
alexcrichton commented on issue #6116:
At the component model layer of abstraction embedders don't have access to core wasm primitives such as
Memory
orFunc
. That means that the answer to your question is that theMemory
cannot be accessed.Could you perhaps elaborate though the intention for accessing memory? We can try to help out with the problem at hand via an alternative means.
Sherlock-Holo commented on issue #6116:
I'm writing my udp/tcp helper, allow wasm codes can read write tcp/udp
I want to let wasm codes pass the buffer offset and length to the host function, then rust codes can write data into the wasm linear memory directly or read from linear memory directly
but withcomponent-model
feature, rust codes can't access the linear memory throughCaller
for now
alexcrichton commented on issue #6116:
Ah ok, thanks for the info! For that you'll probably want to take a look at the
stream
type that WASI is working on. Otherwise with the component model you need to model operations withlist<u8>
for now. Eventually the component model will have a native stream type for these sorts of operations, but that's not available and/or designed yet.Given though that the lack of access to linear memory is an intentional design decision I'm going to close this issue. If you're having trouble with streams from WASI it might be best to wait for some of the WASI bits to settle to have more examples to draw from. Otherwise though feel free to open an issue.
alexcrichton closed issue #6116:
I'm using
component-model
feature to write a host function, however I can't get theCaller
orStore
to access the wasm memory through https://docs.rs/wasmtime/latest/wasmtime/struct.Memory.html#method.data_mut
BrytonLee commented on issue #6116:
@alexcrichton , I have some huge data structs want to be send from host side to wasm module, can I intercept wasi file operation and encapsulate data that can be passed via file descriptor? Do you think that WASI
stream
type would help?Thank you for your guidance.
alexcrichton commented on issue #6116:
@BrytonLee that cannot be easily done today as far as I'm aware. Nowadays we'd recommend using a
resource
to model your large structure. That way the guest can have a handle on it and only request the parts it needs.
BrytonLee commented on issue #6116:
Thank you very much, @alexcrichton .
I think most developer care about accessing memory is due to performance concerns. Is there any other suggestion for reducing memory copy cost?
From my best knowledge, 1). wasmtime component module doesn't allow to upper code access wasm module memory (return area and linear memory). 2).
stream
type implementation in wasmtime doesn't directly access linear memory neither, so it also need to copy data in/out from wasm modue. 3).resource
is more suitable for wasm module when it only consumes part of whole data. Are they true?I saw that wasmedge rust-sdk async-wasi support VFS, it seems that async-wasi allows developer to build a virtual memory file for WASI file I/O, does wasmtime have simillar ones? Also would wasm module develop to use something like
mmap
to share memory with wasmtime?Thanks,
Bryton
BrytonLee edited a comment on issue #6116:
Thank you very much, @alexcrichton .
I think most developer care about accessing memory is due to performance concerns. Is there any other suggestion for reducing memory copy cost?
From my best knowledge, 1). wasmtime component module doesn't allow to upper code access wasm module memory (return area and linear memory). 2).
stream
type implementation in wasmtime doesn't directly access linear memory neither, so it also need to copy data in/out from wasm modue. 3).resource
is more suitable for wasm module when it only consumes part of whole data. Are they true?I saw that wasmedge rust-sdk async-wasi support VFS, it seems that async-wasi allows developer to build a virtual memory file for WASI file I/O, does wasmtime have simillar ones? Also would wasm module developer can use something like
mmap
to share memory with wasmtime?Thanks,
Bryton
alexcrichton commented on issue #6116:
Ah I see that this discussion has been taken to zulip, so dropping a link here for context.
Last updated: Nov 22 2024 at 16:03 UTC