Skip to content
This repository has been archived by the owner on Mar 24, 2022. It is now read-only.

Stack unwinding improvements #254

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open

Commits on Jun 19, 2020

  1. appears to be a start

    awortman-fastly authored and iximeow committed Jun 19, 2020
    Configuration menu
    Copy the full SHA
    68df400 View commit details
    Browse the repository at this point in the history
  2. temporarily disable panic_unwind in hostcall macro

    This is for debugging purposes so that we have a test case that unwinds to `lucet_context_backstop`.
    
    This causes several of the existing test cases to fail, but if you want one that is solely focused
    on this behavior, run:
    
    ```
    cargo test -p lucet-runtime --test host unwind
    ```
    acfoltzer authored and iximeow committed Jun 19, 2020
    Configuration menu
    Copy the full SHA
    dfd8e25 View commit details
    Browse the repository at this point in the history
  3. WIP, get pieces in place for backstop CFI directives to work

    ... when guest code has correct .eh_frame information, anyway.
    
    this currently results in the personality function being called if you
    run the lucet-runtime hostcall tests under gdb with the following
    commands
    ```
    set args unwind --test-threads=1 --nocapture
    b rust_panic
    r
    ```
    then, when the breakpoint (`rust_panic`) is hit, replace the first
    return into guest code with a return to `lucet_context_backstop`:
    ```
    `#      v-- this is the address of lucet_context_backstop`
    printf '\x61\x7f\xa0\x56\x55\x55\x00\x00' \
      | dd `# because gdb doesnt like "set *(long long*)0xaddr = value ` \
        `#         v--- just finding the pid of the test debugee ` \
        of=/proc/$(ps -ef | grep lucet | grep unwind | cut -d' ' -f2)/mem \
        `#           v-- this is where the first guest return address is `\
        `#           v   ..for me anyway. replaces 0x00007ffff6878685` \
        `#           v   for "guest_func___original_main". `\
        bs=1 seek=$((0x7ffff6872fa8)) \
        `# dd would try to truncate guest memory by default. do not do this. `\
        conv=notrunc
    ```
    (if you can figure out how to do this standalone in gdb, i'm all ears)
    
    at this point, continuing in gdb to allow the panic mechanism to run
    should ... call into the provided personality function!
    awortman-fastly authored and iximeow committed Jun 19, 2020
    Configuration menu
    Copy the full SHA
    6c0916d View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    bf50796 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    e6d35dc View commit details
    Browse the repository at this point in the history
  6. experimental checkin of CFA calculation expression

    Also includes a not-quite-working personality function for the backstop that fails because the
    system unwinder doesn't want us to be able to set rdi, even though that's explicitly one of the
    registers listed as being supported for landing pad passing purposes.
    acfoltzer authored and iximeow committed Jun 19, 2020
    Configuration menu
    Copy the full SHA
    2d2bb60 View commit details
    Browse the repository at this point in the history
  7. 🎉 add CFI for all saved registers in the backstop

    This means backtraces and panics now work across the host/guest stack boundary
    acfoltzer authored and iximeow committed Jun 19, 2020
    Configuration menu
    Copy the full SHA
    f5255b2 View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    d5b2306 View commit details
    Browse the repository at this point in the history
  9. add nested hostcall unwinding test

    acfoltzer authored and iximeow committed Jun 19, 2020
    Configuration menu
    Copy the full SHA
    75ab740 View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    1bd449d View commit details
    Browse the repository at this point in the history
  11. Configuration menu
    Copy the full SHA
    cc36826 View commit details
    Browse the repository at this point in the history
  12. add (currently-ignored) callee-saved registers test

    This test works with the nightly-only `#[unwind(allowed)]` attribute, which we'll hopefully be able
    to help move along.
    acfoltzer authored and iximeow committed Jun 19, 2020
    Configuration menu
    Copy the full SHA
    65beada View commit details
    Browse the repository at this point in the history
  13. Configuration menu
    Copy the full SHA
    829124a View commit details
    Browse the repository at this point in the history
  14. Configuration menu
    Copy the full SHA
    e7026d2 View commit details
    Browse the repository at this point in the history
  15. Configuration menu
    Copy the full SHA
    e96dd2d View commit details
    Browse the repository at this point in the history
  16. wip: induce unwinding when resetting a faulted instance

    The current state of the repo is such that only the `fault_unwind` test is currently relevant:
    
    ```
    cargo test -p lucet-runtime --test host fault_unwind -- --nocapture
    ```
    
    Currently stuck figuring out how to set up the stack properly in order to return into the function
    that panics. If I pad the stack with a zero word in order to keep it 16-byte aligned, the unwinding
    runtime interprets that zero as a return address and fails. If I don't add the padding, later
    instructions fault because of unaligned arguments.
    
    We probably need to add a shim that uses `.cfi` directives in order to make the unwinding runtime
    skip over the padding.
    acfoltzer authored and iximeow committed Jun 19, 2020
    Configuration menu
    Copy the full SHA
    84d9394 View commit details
    Browse the repository at this point in the history
  17. Configuration menu
    Copy the full SHA
    c988266 View commit details
    Browse the repository at this point in the history
  18. Configuration menu
    Copy the full SHA
    91a777e View commit details
    Browse the repository at this point in the history
  19. found some sharp bits

    awortman-fastly authored and iximeow committed Jun 19, 2020
    Configuration menu
    Copy the full SHA
    a6d2262 View commit details
    Browse the repository at this point in the history
  20. Configuration menu
    Copy the full SHA
    2cbbd9f View commit details
    Browse the repository at this point in the history
  21. Configuration menu
    Copy the full SHA
    01b1ea3 View commit details
    Browse the repository at this point in the history
  22. improve forced unwinding in cases with termination and yield

    - adds a `catch_unwind` around each hostcall to make sure we decrement `hostcall_count` when
    unwinding
    - handles `State::Yielded` instances by setting a pending termination flag, and then resuming
    acfoltzer authored and iximeow committed Jun 19, 2020
    Configuration menu
    Copy the full SHA
    61e083c View commit details
    Browse the repository at this point in the history
  23. simplify unwinding implementation by using Faulted state

    This state already had the context information we needed to initiate unwinding, so we didn't need to
    add an extra field on our `Context`, or preemptively overwrite the guest context in the signal handler
    acfoltzer authored and iximeow committed Jun 19, 2020
    Configuration menu
    Copy the full SHA
    8d98bc8 View commit details
    Browse the repository at this point in the history
  24. Configuration menu
    Copy the full SHA
    9b627e2 View commit details
    Browse the repository at this point in the history
  25. Configuration menu
    Copy the full SHA
    7460113 View commit details
    Browse the repository at this point in the history
  26. Configuration menu
    Copy the full SHA
    ff3a4d7 View commit details
    Browse the repository at this point in the history
  27. adjust cfi expressions to use the correct parent_ctx offset

    the struct at rbp changed between first authorship and today, to fix a bug where lucet instances were accidentally tied to their starting thread
    iximeow committed Jun 19, 2020
    Configuration menu
    Copy the full SHA
    4af7b7e View commit details
    Browse the repository at this point in the history
  28. fix conflict from rebase

    iximeow committed Jun 19, 2020
    Configuration menu
    Copy the full SHA
    ce5b86f View commit details
    Browse the repository at this point in the history
  29. Configuration menu
    Copy the full SHA
    0d9db26 View commit details
    Browse the repository at this point in the history
  30. forced unwinding of guests has had its assumptions challenged

    when forced unwinding was first envisioned, guests did not run at all
    from the point they faulted. this mean that the fault address would be a
    simple `guest_ctx.get_ip()` away. in the mean time, the Lucet signal
    handler learning how to be crossplatform broke this assumption: it now
    works by *overwriting* the guest's instruction pointer, swapping to the
    guest, and letting a function run. consequently, the guest instruction
    pointer is replaced and when a guest unwind is instigated after a guest
    faults, the return address before `initiate_unwind` (or `unwind_stub`,
    if present) will no longer be correct. libgcc_s will then fail to locate
    an FDE to describe the call frame above runtime-added unwind machinery,
    fail to unwind, and SIGABRT.
    
    the solution is quite simple: since the rip-accessing code is already
    handling a guest fault, we know the original faulting guest `rip` is
    preserved in the fault's `details`. insted of `guest_ctx.get_ip()`, get
    the address from `details.rip_addr`.
    iximeow committed Jun 19, 2020
    Configuration menu
    Copy the full SHA
    6ddb7a3 View commit details
    Browse the repository at this point in the history
  31. Configuration menu
    Copy the full SHA
    a0aa813 View commit details
    Browse the repository at this point in the history
  32. rustfmt

    iximeow committed Jun 19, 2020
    Configuration menu
    Copy the full SHA
    bb27ee7 View commit details
    Browse the repository at this point in the history
  33. tidy a little more

    iximeow committed Jun 19, 2020
    Configuration menu
    Copy the full SHA
    6510c4c View commit details
    Browse the repository at this point in the history

Commits on Jun 23, 2020

  1. Configuration menu
    Copy the full SHA
    486ae6a View commit details
    Browse the repository at this point in the history
  2. fix macos sysdeps

    iximeow committed Jun 23, 2020
    Configuration menu
    Copy the full SHA
    4d68f0b View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    caa1152 View commit details
    Browse the repository at this point in the history

Commits on Jun 25, 2020

  1. Configuration menu
    Copy the full SHA
    d10bd0a View commit details
    Browse the repository at this point in the history