-
Notifications
You must be signed in to change notification settings - Fork 192
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
Should __getrandom_custom use "Rust" ABI? #345
Comments
Panic safety is a strong argument for using the |
In theory, you could also catch the panic and either abort on it or pass it around later as an error. |
The ABI instability of Aborting on panic is not all that difficult. It can be done most easily with a drop guard that causes a double panic: extern "C" fn example() -> Output {
struct PanicOnDrop;
impl Drop for PanicOnDrop {
fn drop(&mut self) {
panic!("callback panicked");
}
}
let guard = PanicOnDrop;
let output = callback();
core::mem::forget(guard);
output
} It would be a lot trickier to pass the full payload across the boundary, since, as before, neither a full |
I think A LOT of crates will break under such scenario, since doing so is not officially supported by Rust toolchain right now. We probably can safely ignore this concern. Not catching potential panics will be the least surprising behavior for users, so I don't think we should do it unless absolutely necessary. |
Closes #345 This change makes the code safe against potential panics in custom functions.
Right now, the implementation of the
custom
feature uses a#[no_mangle]
function named__getrandom_custom
with signature:extern "C" fn(*mut u8, usize) -> u32
.When implementing this feature in #109, I initially used the
extern "Rust"
ABI, but after some discussion, we decided to useextern "C"
due to issues around the stability of the"Rust"
ABI.However, @LegionMammal978 noted in #341 (comment) that panicking across an
extern "C"
function is unsafe, and it's very possible that a custom implementation could panic (certainly we do nothing to prevent that).So should we switch to using the
"Rust"
ABI? If so, should we continue passing a raw pointer/length pair, or pass a slice?The text was updated successfully, but these errors were encountered: