Skip to content

Commit

Permalink
looper: Also abort on panic in FFI callback (#421)
Browse files Browse the repository at this point in the history
As with #412 we shouldn't let panics unwind into the FFI boundary; use
the new helper `abort_on_panic()` utility to catch these and abort the
process instead.
  • Loading branch information
MarijnS95 committed Aug 23, 2023
1 parent 574aee0 commit d64c8b6
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions ndk/src/looper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ use std::ptr;
use std::time::Duration;
use thiserror::Error;

use crate::utils::abort_on_panic;

/// A thread-local native [`ALooper *`]. This promises that there is a looper associated with the
/// current thread.
///
Expand Down Expand Up @@ -309,14 +311,14 @@ impl ForeignLooper {
_events: i32,
data: *mut c_void,
) -> i32 {
unsafe {
abort_on_panic(|| unsafe {
let mut cb = ManuallyDrop::new(Box::<F>::from_raw(data as *mut _));
let keep_registered = cb(BorrowedFd::borrow_raw(fd));
if !keep_registered {
ManuallyDrop::into_inner(cb);
}
keep_registered as i32
}
})
}
let data = Box::into_raw(Box::new(callback)) as *mut _;
match unsafe {
Expand Down

0 comments on commit d64c8b6

Please sign in to comment.