pulley: Implement interpreter-to-host calls #9665
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit is an initial stab at implementing interpreter-to-host communication in Pulley. The basic problem is that Pulley needs the ability to call back into Wasmtime to implement tasks such as
memory.grow
, imported functions, etc. For native platforms this is a simplecall_indirect
operation in Cranelift but the story for Pulley must be different because it's effectively switching from interpreted code to native code.The initial idea for this in #9651 is replaced here and looks mostly similar but with a few changes. The overall structure of how this works is:
call_indirect_host
opcode is added to Pulley.call_indirect_host
to take an immediate of which signature is being used and cast the function pointer to the right type.RelocDistance::Far
calls to a name trigger the use ofcall_indirect_host
.NS_*
value for user-function namespaces is reserved inwasmtime-cranelift
for this new namespace of functions.wasmtime-cranelift
now has Pulley-specific handling of the wasm-to-host transition where all previouscall_indirect
instructions are replaced with a call to a "backend intrinsic" which gets lowered to acall_indirect_host
.Note that most of this still isn't hooked up everywhere in Wasmtime. That means that the testing here is pretty light at this time. It'll require a fair bit more work to get everything fully integrated from Wasmtime in Pulley. This is expected to be one of the significant remaining chunks of work and should help unblock future testing (or make those diffs smaller ideally).