bytecodealliance / wasmtime

A fast and secure runtime for WebAssembly
https://wasmtime.dev/
Apache License 2.0
15.43k stars 1.31k forks source link

Add the concept of "backend intrinsics" to Cranelift #9651

Open alexcrichton opened 19 hours ago

alexcrichton commented 19 hours ago

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 simple call_indirect operation in Cranelift but the story for Pulley must be different because it's effectively switching from interpreted code to native code.

The solution I've ended up settling on looks pretty similar to native platforms but with a few important tweaks:

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).

alexcrichton commented 18 hours ago

cc @cfallin as you're also no doubt interested in this as well

github-actions[bot] commented 17 hours ago

Subscribe to Label Action

cc @fitzgen

This issue or pull request has been labeled: "cranelift", "cranelift:module", "pulley" Thus the following users have been cc'd because of the following labels: * fitzgen: pulley To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file. [Learn more.](https://github.com/bytecodealliance/subscribe-to-label-action)
bjorn3 commented 10 hours ago

Instead of adding a whole new instruction, would it be possible to use a UserExternalName with a reserved namespace like u32::MAX? Or the Pulley interpreter could have a set of UserExternalName for which to call the specified host function without reserving any namespace.