Skip to content

Add test for forced unwind - #63

Merged
nbdd0121 merged 3 commits into
nbdd0121:trunkfrom
aptgetgit:add-forced-unwind-test
Jul 22, 2026
Merged

Add test for forced unwind#63
nbdd0121 merged 3 commits into
nbdd0121:trunkfrom
aptgetgit:add-forced-unwind-test

Conversation

@aptgetgit

Copy link
Copy Markdown
Contributor

Adds basic test for forced unwinding, which had no coverage.

It runs _Unwind_ForcedUnwind to the end of the stack and checks:

  • the stop callback on every frame gets FORCE_UNWIND | CLEANUP_PHASE, with END_OF_STACK only at the actual end.
  • receives back the same exception object and stop argument it was passed.
  • Drop cleanup runs during the unwind, and the exception's own cleanup
    routine is never invoked.

Reverting #61 makes it fail on the first frame.

Comment thread test_crates/forced_unwind/src/main.rs Outdated
) -> UnwindReasonCode {
assert_eq!(version, 1);
assert_eq!(
arg, &STOP_ARG as *const u8 as *mut c_void,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
arg, &STOP_ARG as *const u8 as *mut c_void,
arg, &raw const STOP_ARG as *mut c_void,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread test_crates/forced_unwind/src/main.rs Outdated
);
assert_eq!(
exception,
EXCEPTION.load(Ordering::SeqCst),

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why SeqCst?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no real reason, just started out with SeqCst without thinking about it much. Switched to Relaxed.

Comment thread test_crates/forced_unwind/src/main.rs Outdated
let exception: *mut UnwindException =
Box::leak(Box::new(MaybeUninit::<UnwindException>::zeroed())).as_mut_ptr();
unsafe {
(*exception).exception_class = u64::from_ne_bytes(*b"TSTFRCEU");

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this string?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was experimenting with a catch_unwind here. With MOZ\0RUST the catch would read canary/payload, which we never allocate hence UB.
Dropped catch_unwind anyway since it aborts instead of reaching end of stack, and I'd rather keep this test on that path.
The made-up class just keeps it foreign so nothing reads into it.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should still be a meaningful string though, e.g. "TESTRUST"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread test_crates/forced_unwind/src/main.rs Outdated
fn foo() {
// Leak the box so it outlives `foo()`.
let exception: *mut UnwindException =
Box::leak(Box::new(MaybeUninit::<UnwindException>::zeroed())).as_mut_ptr();

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Box::leak(Box::new(MaybeUninit::<UnwindException>::zeroed())).as_mut_ptr();
Box::into_raw(Box::new(MaybeUninit::<UnwindException>::zeroed()));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@nbdd0121
nbdd0121 merged commit 6d8bbdf into nbdd0121:trunk Jul 22, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants