Skip to content

Commit edd21fa

Browse files
author
Danilo Krummrich
committed
rust: module: add trait ModuleMetadata
In order to access static metadata of a Rust kernel module, add the `ModuleMetadata` trait. In particular, this trait provides the name of a Rust kernel module as specified by the `module!` macro. Signed-off-by: Danilo Krummrich <[email protected]>
1 parent c80dd3f commit edd21fa

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

rust/kernel/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ impl<T: Module> InPlaceModule for T {
115115
}
116116
}
117117

118+
/// Metadata attached to a [`Module`] or [`InPlaceModule`].
119+
pub trait ModuleMetadata {
120+
/// The name of the module as specified in the `module!` macro.
121+
const NAME: &'static crate::str::CStr;
122+
}
123+
118124
/// Equivalent to `THIS_MODULE` in the C API.
119125
///
120126
/// C header: [`include/linux/init.h`](srctree/include/linux/init.h)

rust/macros/module.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,10 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream {
228228
kernel::ThisModule::from_ptr(core::ptr::null_mut())
229229
}};
230230
231+
impl kernel::ModuleMetadata for {type_} {{
232+
const NAME: &'static kernel::str::CStr = kernel::c_str!(\"{name}\");
233+
}}
234+
231235
// Double nested modules, since then nobody can access the public items inside.
232236
mod __module_init {{
233237
mod __module_init {{

0 commit comments

Comments
 (0)