Skip to content

Commit f823a22

Browse files
committed
Fixups for THIS_MODULE
1 parent f778905 commit f823a22

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

rust/module.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,10 @@ pub fn module(ts: TokenStream) -> TokenStream {
282282
#[used]
283283
static __{name}_{param_name}_struct: __{name}_{param_name}_RacyKernelParam = __{name}_{param_name}_RacyKernelParam(kernel::bindings::kernel_param {{
284284
name: __{name}_{param_name}_name,
285-
// TODO: `THIS_MODULE`
285+
// SAFETY: `__this_module` is constructed by the kernel at load time and will not be freed until the module is unloaded.
286+
#[cfg(MODULE)]
287+
mod_: unsafe {{ &kernel::bindings::__this_module as *const _ as *mut _ }},
288+
#[cfg(not(MODULE))]
286289
mod_: core::ptr::null_mut(),
287290
ops: unsafe {{ &kernel::bindings::param_ops_{param_kernel_type} }} as *const kernel::bindings::kernel_param_ops,
288291
perm: {permissions},
@@ -309,6 +312,7 @@ pub fn module(ts: TokenStream) -> TokenStream {
309312
"
310313
static mut __MOD: Option<{type_}> = None;
311314
315+
// SAFETY: `__this_module` is constructed by the kernel at load time and will not be freed until the module is unloaded.
312316
#[cfg(MODULE)]
313317
static THIS_MODULE: kernel::ThisModule = unsafe {{ kernel::ThisModule::from_ptr(&kernel::bindings::__this_module as *const _ as *mut _) }};
314318
#[cfg(not(MODULE))]

0 commit comments

Comments
 (0)