jeffcharles opened issue #4018:
Feature
I'd like a way to retrieve the name of the invoked hostcall in a call hook. Ideally getting the arguments and return values would also be useful.
Benefit
Adding this feature would allow me to log the name of the invoked hostcall. We have third party developers writing wasm modules running on something we've built around wasmtime and we'd like to offer a trace feature so those developers can see what hostcalls are being invoked and roughly when they are invoked relative to other parts of their modules. Including arguments and return values could also be useful in that context.
Implementation
I do not have an implementation plan at this time.
Alternatives
I'd be open to using a different API than the call hook one if it allows me to do something similar where a callback is invoked with sufficient context available to determine the hostcall name. Alternatively, if there were a way to define a decorator around the WASI hostcalls, that could also work, since I could just instrument other hostcalls.
alexcrichton commented on issue #4018:
One idea I had for this is some sort of injection wrapper in
Linker
where you could have something likeLinker::pre_hook
or similar. A small caveat is that you'd have to define saidpre_hook
before calling any otherLinker
function to define an item, but that's not necessarily the end of the world.Another idea is a specific hook on
WasiCtxt
itself, although that would probably want integration withwiggle
to generate calls to such a hook rather than us having to manually do it.In both of these schemes though you wouldn't have access to parameters or return values. That's actually pretty difficult to do I think in the sense that having a uniform representation for arguments and returns can generally be quite inefficient.
If all you need is logging though
wasi-common
should already have logs for arguments in/out of hostcalls, so if the end goal is just a few prints that may suffice as well?
jeffcharles commented on issue #4018:
If all you need is logging though wasi-common should already have logs for arguments in/out of hostcalls, so if the end goal is just a few prints that may suffice as well?
I confirmed that it does and this seems to work for our purposes for the time being. Thank you! That being said, having this be part of an API instead of an implementation detail would help us avoid relying on the these log calls being present as part of how we provide hostcall tracing. But what's currently there is good enough for now.
Last updated: Dec 23 2024 at 12:05 UTC