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

Fix Rust panics in exception::catch, and make it safe #669

Merged
merged 3 commits into from
Nov 15, 2024

Conversation

madsmtm
Copy link
Owner

@madsmtm madsmtm commented Nov 14, 2024

The behaviour of foreign exceptions unwinding into Rust is defined since rust-lang/rust#128321 (see also the yet unmerged reference PR: rust-lang/reference#1226).

My understanding of how the Objective-C runtime deals with exceptions leads me to believe that the reverse is also defined, i.e. that Rust exceptions unwinding into Objective-C is sound. The big hint is that Objective-C literally has a language primitive for catching foreign exceptions, @catch(...).

I am yet unsure about x86 macOS (old Objective-C runtime), I think they use longjumps and whatnot, will have to test that.

@madsmtm madsmtm added enhancement New feature or request A-objc2 Affects the `objc2`, `objc2-exception-helper` and/or `objc2-encode` crates labels Nov 14, 2024
@madsmtm
Copy link
Owner Author

madsmtm commented Nov 15, 2024

I tested x86 macOS, Rust panics are turned into aborts (probably because in the search phase, it tries to unwind through a frame that doesn't have CFI information). So that's fine!

@madsmtm madsmtm merged commit 4ea22f2 into master Nov 15, 2024
20 checks passed
@madsmtm madsmtm deleted the exception-unwind branch November 15, 2024 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-objc2 Affects the `objc2`, `objc2-exception-helper` and/or `objc2-encode` crates enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant