Per the waPC specifications it looks like after the guest is invoked initially, the supported flow is the guest is allowed to make 0..N __host_call before returning.
There's another flow, where communication is bi-directional, or where multiple __guest_calls occur from a single invoke:
- Guest is invoked
- Guest does some work, and calls host
- Host starts a new
__guest_call
- ... new flow starts. Guest eventually returns results to host
- Host returns results to guest
- Guest returns
This flow currently fails for the final __guest_call in wasmer (assumption is it also fails in wasmtime), but works for wazero. This is due to the use of invokeContext. In wasmer / wasmtime this is a pointer stored on the shared instance and the response copied to it (here), but the return value of invoke is read from the original invokeContext (here). With multiple __guest_call in a single flow, the shared context is replaced. The output is copied to the invokeContext of the previous __guest_call and the final __guest_call in the chain returns a zero value.
wazero supports this flow since each __guest_call via invoke using wazero gets its own context, not a shared context on the instance (here).
Whew, with that out of the way. Is the above bi-directional flow supported? If not, should it be supported and the implementation for wasmer and wasmtime changed to allow it?
Per the waPC specifications it looks like after the guest is invoked initially, the supported flow is the guest is allowed to make 0..N
__host_callbefore returning.There's another flow, where communication is bi-directional, or where multiple
__guest_calls occur from a singleinvoke:__guest_callThis flow currently fails for the final
__guest_callinwasmer(assumption is it also fails inwasmtime), but works forwazero. This is due to the use ofinvokeContext. Inwasmer/wasmtimethis is a pointer stored on the shared instance and the response copied to it (here), but the return value ofinvokeis read from the originalinvokeContext(here). With multiple__guest_callin a single flow, the shared context is replaced. The output is copied to theinvokeContextof the previous__guest_calland the final__guest_callin the chain returns a zero value.wazerosupports this flow since each__guest_callviainvokeusingwazerogets its own context, not a shared context on the instance (here).Whew, with that out of the way. Is the above bi-directional flow supported? If not, should it be supported and the implementation for
wasmerandwasmtimechanged to allow it?