From 21a85a19b31d96dba38a031d094046f9009e7635 Mon Sep 17 00:00:00 2001 From: Wedson Almeida Filho Date: Sat, 13 Nov 2021 13:51:12 +0000 Subject: [PATCH] rust: add `PointerWrapper` implementation for `*mut T`. The implementation is straightforward: converting to `void *` and borrowing are just pointer casts. This is used by the GPIO subsystem where some context data is controlled by the C side, so it is necessarily a raw pointer. (This is hidden from driver writers though.) Signed-off-by: Wedson Almeida Filho --- rust/kernel/types.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/rust/kernel/types.rs b/rust/kernel/types.rs index e961e68568868b..80aa3037cf1a35 100644 --- a/rust/kernel/types.rs +++ b/rust/kernel/types.rs @@ -128,6 +128,22 @@ impl PointerWrapper for Pin { } } +impl PointerWrapper for *mut T { + type Borrowed<'a> = *mut T; + + fn into_pointer(self) -> *const c_types::c_void { + self as _ + } + + unsafe fn borrow<'a>(ptr: *const c_types::c_void) -> Self::Borrowed<'a> { + ptr as _ + } + + unsafe fn from_pointer(ptr: *const c_types::c_void) -> Self { + ptr as _ + } +} + /// Runs a cleanup function/closure when dropped. /// /// The [`ScopeGuard::dismiss`] function prevents the cleanup function from running.