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.
We use the get_frame_pointer instruction to obtain a value for last_wasm_exit_fp.
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.
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 theStackLimits
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 theVMRuntimeLimits
in order to copy them into theStackLimits
. 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 actualtc_resume
libcall happening, and writes them into theStackLimits
.get_frame_pointer
instruction to obtain a value forlast_wasm_exit_fp
.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 forlast_wasm_exit_pc
into theStackLimits
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.