Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In resume instruction, update StackLimits from generated code #223

Merged
merged 4 commits into from
Sep 11, 2024

Conversation

frank-emrich
Copy link

This PR is part of a series that implements native stack switching.

This particular PR moves one particular aspect out of the tc_resume libcall: Updating the StackLimits object of the parent of the continuation being resumed.

Doing this inside the libcall had practical reasons: We needed access to the updated last_wasm_exit_pc/last_wasm_exit_fp value in the VMRuntimeLimits in order to copy them into the StackLimits. However, these values are only updated by the libcall mechanism itself, so they are only available inside the libcall implementation itself.

This PR obtains the corresponding values using code generated for resume, before the actual tc_resume libcall happening, and writes them into the StackLimits.

  1. We use the get_frame_pointer instruction to obtain a value for last_wasm_exit_fp.
  2. The value for last_wasm_exit_pc is obtained using a new CLIF instruction, get_instruction_pointer. All this does is giving us some instruction pointer that is guaranteed to be associated with the current Wasm instruction being translated (i.e., resume in our case). While this means that we will write slightly different values for last_wasm_exit_pc into the StackLimits than before, this difference does not matter at all for backtrace creation. last_wasm_exit_pc is never used for control flow (i.e., it is never branched to), all that matters is what Wasm instruction it is associated with.

I consider this to be a workaround, once native stack switching is fully rolled out it would be nice to overhaul the whole backtrace generation mechanism in the longer term. But this PR's goal is to make it possible to move to native stack switching with as little changes to backtrace creation as possible.

Copy link
Member

@dhil dhil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I have a question regarding GetRip.

cranelift/codegen/src/isa/x64/inst/emit.rs Show resolved Hide resolved
@frank-emrich frank-emrich merged commit 46da60f into wasmfx:main Sep 11, 2024
50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants