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

wasmtime: Check stack limits only on exit from wasm #9093

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Commits on Aug 8, 2024

  1. wasmtime: Collect stack pointer during traps

    Nothing uses this yet but I want to get collection of this register
    right on our many supported platforms before introducing the changes
    that need it.
    jameysharp committed Aug 8, 2024
    Configuration menu
    Copy the full SHA
    dc4fd61 View commit details
    Browse the repository at this point in the history
  2. wasmtime: Check stack limits only on exit from wasm

    Currently, we do an explicit check for stack overflow on entry to every
    WebAssembly function. But that costs some time, and is a significant
    performance hit for very short functions.
    
    This commit instead switches Wasmtime to relying on guard pages at the
    end of the stack to catch stack overflow, so the MMU does this check for
    "free". This means we may allow deeper recursion in guest code than we
    did before.
    
    To make this work, we need Wasmtime's signal handlers to recognize when
    a guest memory fault is in a stack guard page and report the appropriate
    stack-overflow trap code.
    
    Note that we can't turn host-code signals into guest traps, so the
    signal handlers have to verify that the signal occurred in guest code.
    
    When the guest calls host code (explicitly due to calling an imported
    host function, or implicitly due to a libcall inserted by Wasmtime or
    Cranelift), we also need to ensure that there is enough stack space
    available for the host code to not hit the guard pages. We do that by
    checking the stack limit that the embedder provided in the trampolines
    where we exit wasm.
    jameysharp committed Aug 8, 2024
    Configuration menu
    Copy the full SHA
    213c0df View commit details
    Browse the repository at this point in the history