From d64c8b6eff00906d977f09979815d1af52e573da Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Thu, 24 Aug 2023 00:22:01 +0200 Subject: [PATCH] looper: Also abort on panic in FFI callback (#421) 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. --- ndk/src/looper.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ndk/src/looper.rs b/ndk/src/looper.rs index fb707df3..f17be74d 100644 --- a/ndk/src/looper.rs +++ b/ndk/src/looper.rs @@ -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. /// @@ -309,14 +311,14 @@ impl ForeignLooper { _events: i32, data: *mut c_void, ) -> i32 { - unsafe { + abort_on_panic(|| unsafe { let mut cb = ManuallyDrop::new(Box::::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 {