Closed dshiell15 closed 3 years ago
@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:
nwritten
output parameter in the hostcall so the host can return to the guest how many bytes were written by a successful copy.nwritten
as the guest checks for the error case).Excellent, thank you! - got a little too hung up on the other approach...
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