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
{{ message }}
This repository has been archived by the owner on Mar 24, 2022. It is now read-only.
Apologies if I am missing something obvious here. I am working on embedding Lucet in a runtime with hostcalls which require copying host information back into the guest. To this end I've attempted to follow the memory management design outlined in the Fastly blog here: https://www.fastly.com/blog/webassembly-memory-management-guide-for-c-rust-programmers.
What I'm finding is that I am triggering this panic message: "Invalid state: Instance marked as in a hostcall while entering a hostcall." because when I call the registered guest memory allocation function (via the function table idx) it in turn is triggering a hostcall to grow the wasm memory (lucet_vmctx_grow_memory).
Any suggestions or pointers to workarounds would be appreciated. Thank you!
P.S. - I am using Lucet v0.6.1
The text was updated successfully, but these errors were encountered:
@dshiell15 we don't currently recommend calling back into Wasm from hostcalls. The memory management strategy I'd recommend is to have the guest provide the host with a pointer to a pre-allocated buffer that the host can copy results into. This of course means having to get the buffer size right, but we have had good results with the following approach:
Return a status/error code from the hostcall so that you can identify when the write succeeds or fails.
Use an nwritten output parameter in the hostcall so the host can return to the guest how many bytes were written by a successful copy.
When the hostcall fails because the guest-provided buffer is not large enough, write the number of bytes that are necessary to an output parameter (you can reuse nwritten as the guest checks for the error case).
Allocate a new buffer of the required size in the guest, and call the hostcall again.
Apologies if I am missing something obvious here. I am working on embedding Lucet in a runtime with hostcalls which require copying host information back into the guest. To this end I've attempted to follow the memory management design outlined in the Fastly blog here: https://www.fastly.com/blog/webassembly-memory-management-guide-for-c-rust-programmers.
What I'm finding is that I am triggering this panic message: "Invalid state: Instance marked as in a hostcall while entering a hostcall." because when I call the registered guest memory allocation function (via the function table idx) it in turn is triggering a hostcall to grow the wasm memory (lucet_vmctx_grow_memory).
Any suggestions or pointers to workarounds would be appreciated. Thank you!
P.S. - I am using Lucet v0.6.1
The text was updated successfully, but these errors were encountered: