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

Disable unwinding for catch_unwind error payloads. #99032

Commits on Sep 26, 2022

  1. Disable unwinding for catch_unwind error payloads.

    This does something similar to what was suggested over
    rust-lang#86027 (comment)
    that is, to cheat a little bit and tweak/amend the `Box<dyn Any…>` obtained
    from `catch_unwind`:
      - keep the `.type_id()` the same to avoid breakage with downcasting;
      - but make it so the virtual `.drop_in_place()` is somehow overridden with
        a shim around the real drop glue that prevents unwinding (_e.g._, by
        aborting when that happens).
    
    This is achieved through the `DropNoUnwindSameAnyTypeId<T>`, wrapper:
      - with the very same layout as the `T` it wraps;
      - with an overridden/fake `.type_id()` so as to impersonate its inner `T`;
      - with a manual `impl Drop` which uses an abort bomb to ensure no
        unwinding can happen.
    
    That way, the `Box<DropNoUnwindSameAnyTypeId<T>>`, when box-erased to a
    `Box<dyn Any…>`, becomes, both layout-wise, and `type_id`-wise,
    undistinguishable from a `Box<T>`, thence avoiding any breakage.
    
    And yet, when that `Box<dyn Any…>` is implicitly dropped with
    `catch_unwind`s, no further unwinding can happen.
    
    Handle `resume_unwind` payloads too
    
    Clean up logic: centralize drop-override in catch_unwind & virtual method
    danielhenrymantilla committed Sep 26, 2022
    Configuration menu
    Copy the full SHA
    045d7cb View commit details
    Browse the repository at this point in the history
  2. Make the abort display a nicer message

    Mark `panic_abort` as `no-unwind`.
    
    Co-Authored-By: Christopher Durham <cad97@cad97.com>
    Co-Authored-By: Gary Guo <gary@garyguo.net>
    3 people committed Sep 26, 2022
    Configuration menu
    Copy the full SHA
    6d7ee4b View commit details
    Browse the repository at this point in the history
  3. Fix & add panic payload tests.

     1. Fix runtime UI test that expected drop of panic payload to unwind
    
     2. Add panic payload tests: ensure proper drop, and add one with catch_unwind
    
     3. Add test asserting proper abort of unwind in panic payload
    danielhenrymantilla committed Sep 26, 2022
    Configuration menu
    Copy the full SHA
    94118a4 View commit details
    Browse the repository at this point in the history