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

Implement unwind safety #21

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Coder-256
Copy link

Currently it is UB for Rust code to unwind into FFI (except when using extern "C-unwind", but I don't know if that would be safe to use within libdispatch).

For async functions, this PR simply aborts the process if the closure panics. For synchronous functions, the panic will be automatically resumed once the dispatch call returns.

While I don't believe this should have a major impact on performance, it's possible, and should probably be benchmarked if possible.

@MarijnS95
Copy link

Note that this unsoundness is no longer a problem since Rust 1.81, where any panics that would unwind across extern "C" will abort instead: https://blog.rust-lang.org/2024/09/05/Rust-1.81.0.html#abort-on-uncaught-panics-in-extern-c-functions

extern "C-unwind" seems to exist to opt-out of that behaviour, when the caller expects to (safely?) unwind across the FFI boundary.
(which I think should allow panic!()s across an FFI boundary when it was Rust code invoking the FFI function, such as what ash does in the loaders.)

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