elliottt opened PR #9196 from elliottt:trevor/component-host-call-hooks
to bytecodealliance:main
:
We never implemented calling the CallingHost and ReturningFromHost hooks
for component host calls.co-authored-by: Nick Fitzgerald <fitzgen@gmail.com>
<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
alexcrichton submitted PR review:
Thanks! Mind also adding some tests for this? There's some previous call-hook-related tests which might be good to copy/augment.
Additionally can you double-check that invoking the malloc function calls the hook as well? And also that we call the hooks on entry to wasm?
alexcrichton created PR review comment:
Could you expand the
catch_unwind_and_longjmp
to encompass the invocation of the call hooks too?
elliottt updated PR #9196.
elliottt has marked PR #9196 as ready for review.
elliottt requested alexcrichton for a review on PR #9196.
elliottt requested wasmtime-core-reviewers for a review on PR #9196.
elliottt updated PR #9196.
elliottt updated PR #9196.
elliottt submitted PR review.
elliottt created PR review comment:
This differs from the core wasm behavior, in that trapping in
f
does not register the return from host or return from wasm hooks. @alexcrichton, is this reasonable, or is there something missing from this PR?
elliottt submitted PR review.
elliottt created PR review comment:
I think I've answered my own question: we shouldn't be using
and_then
to guard the exiting hook.
elliottt updated PR #9196.
elliottt edited PR #9196:
We never implemented calling the CallingHost and ReturningFromHost hooks for component host calls. This PR supports those hooks, and adds some tests.
co-authored-by: Nick Fitzgerald <fitzgen@gmail.com>
<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
elliottt updated PR #9196.
alexcrichton submitted PR review:
Nice tests :+1:
I think this will be good to go with additional tests for using the
realloc
andpost-return
canonical options since I suspect those aren't covered by call hooks just yet
alexcrichton created PR review comment:
I think this is the same as
call_wrapped_async_func
?
alexcrichton created PR review comment:
To avoid needing to call this twice could the above use
store.as_context_mut()
as an argument? That should effectively reborrow to allowstore
to be used here again
alexcrichton created PR review comment:
Could this perhaps be
use
'd from the other call hook test?
alexcrichton created PR review comment:
Could this be
call_hook(...)?
? (notably using?
instead ofif let
)
elliottt updated PR #9196.
elliottt updated PR #9196.
elliottt updated PR #9196.
alexcrichton created PR review comment:
Could you shift this to being a result of a list? As-is this doesn't require a realloc, but as a return value it'll require a realloc
alexcrichton submitted PR review.
alexcrichton created PR review comment:
Instead of defining this here you can also use the
"realloc"
export of the$libc
module
elliottt updated PR #9196.
elliottt updated PR #9196.
elliottt updated PR #9196.
elliottt submitted PR review.
elliottt created PR review comment:
Here are the assertions about
post-return
, you can see that the wasm calls increment after the.post_return()
call.
elliottt updated PR #9196.
elliottt submitted PR review.
elliottt created PR review comment:
Here's the handling of the allocated result, and the assertions about the number of host calls encountered. There is only one host call counted, as only
realloc
is used. However, there are two wasm calls for therealloc
of thelist<u8>
argument, and thelist8-to-str
call itself.
elliottt updated PR #9196.
alexcrichton submitted PR review.
alexcrichton created PR review comment:
Here and below I think this is
CallingWasm
andReturningFromWasm
?Also would it be possible to push this further down into the
realloc
call below? Or, I'm not sure if this works, even further intoTypedFunc::unchecked_call
? (or w/e API this bottoms out to)
elliottt updated PR #9196.
elliottt submitted PR review.
elliottt created PR review comment:
It turns out this is already counted as a wasm call, and the host call hooks were just unnecessary and incorrect. I had an incorrect assumption about what the
Options::realloc
function was doing, and assumed it was handling host-side reallocs. Given that those aren't a thing and we're already accounting for wasm hooks, the changes to this module were unnecessary.
elliottt merged PR #9196.
Last updated: Dec 23 2024 at 12:05 UTC