wasmtime icon indicating copy to clipboard operation
wasmtime copied to clipboard

winch: Move the stack overflow check to the function prologue

Open elliottt opened this issue 1 year ago • 2 comments

Move the stack check to the function prologue in winch generated code by adding the final stack maximum to the stack min bound before comparing against the current SP.

This new approach is more accurate than the previous implementation that would only check the size of locals, but does require that we patch the function during MacroAssembler::finalize, as we don't know the stack high water mark until then. Enabling the patching required the addition of the start_patchable/end_patchable api to MachBuffer, which gives a way to name sections of the code buffer (with some restrictions) that can be edited later. We use this then to modify an add-with-immediate instruction to add the used stack space to the stack lower bound from vmctx, when finalizing the function.

elliottt avatar Feb 15 '24 20:02 elliottt

The tests are failing due to the addition of stack checking to one of the trampolines (as the vmctx isn't setup yet in one case). I might roll those back so that this can be debugged separately.

elliottt avatar Feb 15 '24 21:02 elliottt

Subscribe to Label Action

cc @saulecabrera

This issue or pull request has been labeled: "cranelift", "cranelift:area:machinst", "winch"

Thus the following users have been cc'd because of the following labels:

  • saulecabrera: winch

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

github-actions[bot] avatar Feb 15 '24 23:02 github-actions[bot]