From 2f7a04b08d07e8ba4185916d4f3df286b626a27f Mon Sep 17 00:00:00 2001 From: Fenrir Date: Tue, 20 Feb 2024 22:07:34 -0700 Subject: [PATCH] Add comment clarifying callback pointer safety --- ctru-rs/src/applets/swkbd.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ctru-rs/src/applets/swkbd.rs b/ctru-rs/src/applets/swkbd.rs index f5d7c68..db2f34e 100644 --- a/ctru-rs/src/applets/swkbd.rs +++ b/ctru-rs/src/applets/swkbd.rs @@ -727,8 +727,10 @@ impl SoftwareKeyboard { swkbd_shared_mem_ptr, }; - if let Some(callback) = self.callback.as_ref() { - callback_data.callback = std::ptr::addr_of!(*callback); + // We need to pass a thin pointer to the boxed closure over FFI. Since we know that the callback will finish before + // `self` is allowed to be moved again, we can safely use a pointer to the local value contained in `self.callback` + if let Some(ref_to_boxed_closure) = self.callback.as_ref() { + callback_data.callback = ref_to_boxed_closure as *const _; aptSetMessageCallback( Some(Self::swkbd_message_callback),