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

Wrap all exported functions to catch and unwind #2

Open
uselessgoddess opened this issue Jul 29, 2022 · 2 comments
Open

Wrap all exported functions to catch and unwind #2

uselessgoddess opened this issue Jul 29, 2022 · 2 comments
Labels
FFI:UB FFI: our ffi has undefined behaviour Issue:Easy Issue: a good way to start contributing, mentoring is available

Comments

@uselessgoddess
Copy link
Member

uselessgoddess commented Jul 29, 2022

All panics must be catch and unwind otherwise it is UB.
I recommend use catch_unwind with the following if let:

let result = panic::catch_unwind(|| {
    // ffi function call
});

if let Err(err) = result {
    // if `err` panic in `Drop` we will be sad
    forget(err);
}

You can create macro or function to resolve it
In currently implementation:

#[ffi::specialize_for(
    . . .
)]
unsafe fn drop_links<T: LinkType>(this: *mut c_void) {
    let links: &mut WrappedLinks<T> = unnull_or_panic(this);
    drop_in_place(links);
}

We can split to:

unsafe fn drop_links_impl<T: LinkType>(this: *mut c_void) {
    // impl
}

#[ffi::specialize_for(
    . . .
)]
unsafe fn drop_links<T: LinkType>(this: *mut c_void) {
    catch_unwind(/* some */)
}

Or add this behavior to ffi::specialize_for

@uselessgoddess uselessgoddess added Issue:Easy Issue: a good way to start contributing, mentoring is available FFI:UB FFI: our ffi has undefined behaviour labels Jul 29, 2022
@uselessgoddess
Copy link
Member Author

uselessgoddess commented Jul 29, 2022

Also check out unwind_api RFC – advanced

@uselessgoddess uselessgoddess changed the title Wrap all export functions to catch unwind Wrap all exported functions to catch unwind Jul 29, 2022
@uselessgoddess uselessgoddess changed the title Wrap all exported functions to catch unwind Wrap all exported functions to catch and unwind Jul 29, 2022
@uselessgoddess
Copy link
Member Author

uselessgoddess commented Aug 16, 2022

In my new PR(#10) I try use log-panics crate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FFI:UB FFI: our ffi has undefined behaviour Issue:Easy Issue: a good way to start contributing, mentoring is available
Projects
None yet
Development

No branches or pull requests

1 participant