rust: add `Module::as_ptr`
Alice Ryhl
reviewerPATCH 1/1 rust: add `Module::as_ptr`
This allows you to get a raw pointer to THIS_MODULE for use in unsafe code. The Rust Binder RFC uses it when defining fops for the binderfs component [1].
This doesn't really need to go in now - it could go in together with Rust Binder like how it is sent in the Rust Binder RFC. However, the upcoming 1.77.0 release of the Rust compiler introduces a new warning, and applying this patch now will silence that warning. That allows us to avoid adding the #[allow(dead_code)] annotation seen in [2].
--- rust/kernel/lib.rs | 7 +++++++ 1 file changed, 7 insertions(+)
rust/kernel/lib.rs +7 -0
@@ -92,6 +92,13 @@ impl ThisModule {pub const unsafe fn from_ptr (ptr: *mut bindings::module ) ->ThisModule {ThisModule (ptr) } + +/// Access the raw pointer for this module. +/// +/// It is up to the user to use it correctly. +pub const fn as_ptr (&self) -> *mut bindings::module { + self.0 + } }#[cfg(not(any(testlib, test)))]
---
base-commit: e944171070b65521c0513c01c56174ec8fd7d249
change-id: 20240226-module-as-ptr-08300b88525b
Best regards,
Signature · 1 line
Alice Ryhl <[email protected]>
Quoted 10 lines · Alice Ryhl
This allows you to get a raw pointer to
THIS_MODULEfor use in unsafe code. The Rust Binder RFC uses it when defining fops for the binderfs component [1].This doesn't really need to go in now - it could go in together with Rust Binder like how it is sent in the Rust Binder RFC. However, the upcoming 1.77.0 release of the Rust compiler introduces a new warning, and applying this patch now will silence that warning. That allows us to avoid adding the #[allow(dead_code)] annotation seen in [2].
Quoted 3 lines
Signature · 2 lines
Cheers, Benno
Quoted 11 lines · Alice Ryhl
This allows you to get a raw pointer to
THIS_MODULEfor use in unsafe code. The Rust Binder RFC uses it when defining fops for the binderfs component [1].This doesn't really need to go in now - it could go in together with Rust Binder like how it is sent in the Rust Binder RFC. However, the upcoming 1.77.0 release of the Rust compiler introduces a new warning, and applying this patch now will silence that warning. That allows us to avoid adding the #[allow(dead_code)] annotation seen in [2].
Quoted 4 lines
Signed-off-by Alice Ryhl <[email protected]>---
This exposes a bindings type to the user which we don't really do in many other places, but it makes sense here of course.
Miguel Ojeda
AppliedQuoted 11 lines · Alice Ryhl
This allows you to get a raw pointer to
THIS_MODULEfor use in unsafe code. The Rust Binder RFC uses it when defining fops for the binderfs component [1].This doesn't really need to go in now - it could go in together with Rust Binder like how it is sent in the Rust Binder RFC. However, the upcoming 1.77.0 release of the Rust compiler introduces a new warning, and applying this patch now will silence that warning. That allows us to avoid adding the #[allow(dead_code)] annotation seen in [2].
Quoted 3 lines
Applied to rust-next (before the Rust version upgrade) -- thanks everyone!
Cheers,
Miguel