Add test for forced unwind - #63
Merged
Merged
Conversation
nbdd0121
reviewed
Jul 22, 2026
| ) -> UnwindReasonCode { | ||
| assert_eq!(version, 1); | ||
| assert_eq!( | ||
| arg, &STOP_ARG as *const u8 as *mut c_void, |
Owner
There was a problem hiding this comment.
Suggested change
| arg, &STOP_ARG as *const u8 as *mut c_void, | |
| arg, &raw const STOP_ARG as *mut c_void, |
| ); | ||
| assert_eq!( | ||
| exception, | ||
| EXCEPTION.load(Ordering::SeqCst), |
Contributor
Author
There was a problem hiding this comment.
no real reason, just started out with SeqCst without thinking about it much. Switched to Relaxed.
| let exception: *mut UnwindException = | ||
| Box::leak(Box::new(MaybeUninit::<UnwindException>::zeroed())).as_mut_ptr(); | ||
| unsafe { | ||
| (*exception).exception_class = u64::from_ne_bytes(*b"TSTFRCEU"); |
Contributor
Author
There was a problem hiding this comment.
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.
Owner
There was a problem hiding this comment.
This should still be a meaningful string though, e.g. "TESTRUST"
| fn foo() { | ||
| // Leak the box so it outlives `foo()`. | ||
| let exception: *mut UnwindException = | ||
| Box::leak(Box::new(MaybeUninit::<UnwindException>::zeroed())).as_mut_ptr(); |
Owner
There was a problem hiding this comment.
Suggested change
| Box::leak(Box::new(MaybeUninit::<UnwindException>::zeroed())).as_mut_ptr(); | |
| Box::into_raw(Box::new(MaybeUninit::<UnwindException>::zeroed())); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds basic test for forced unwinding, which had no coverage.
It runs
_Unwind_ForcedUnwindto the end of the stack and checks:FORCE_UNWIND | CLEANUP_PHASE, withEND_OF_STACKonly at the actual end.Dropcleanup runs during the unwind, and the exception's own cleanuproutine is never invoked.
Reverting #61 makes it fail on the first frame.