// Rust does not allow hyphens in identifiers, use underscore instead. let ident = info.name.replace('-', "_"); letmut modinfo = ModInfoBuilder::new(ident.as_ref()); iflet Some(authors) = info.authors { for author in authors {
modinfo.emit("author", &author);
}
} iflet Some(description) = info.description {
modinfo.emit("description", &description);
}
modinfo.emit("license", &info.license); iflet Some(aliases) = info.alias { for alias in aliases {
modinfo.emit("alias", &alias);
}
} iflet Some(firmware) = info.firmware { for fw in firmware {
modinfo.emit("firmware", &fw);
}
}
// Built-in modules also export the `file` modinfo string. let file =
std::env::var("RUST_MODFILE").expect("Unable to fetch RUST_MODFILE environmental variable");
modinfo.emit_only_builtin("file", &file);
format!( " /// The module name. /// /// Used by the printing macros, e.g. [`info!`]. const __LOG_PREFIX: &[u8] = b\"{name}\\0\";
// SAFETY: `__this_module` is constructed by the kernel at load time and will not be // freed until the module is unloaded. #[cfg(MODULE)] static THIS_MODULE: ::kernel::ThisModule = unsafe {{ extern \"C\" {{ static __this_module: ::kernel::types::Opaque<::kernel::bindings::module>;
}}
/// The `LocalModule` type is the type of the module created by `module!`, /// `module_pci_driver!`, `module_platform_driver!`, etc. type LocalModule = {type_};
// Double nested modules, since then nobody can access the public items inside. mod __module_init {{ mod __module_init {{ usesuper::super::{type_}; use pin_init::PinInit;
/// The \"Rust loadable module\" mark. // // This may be best done another way later on, e.g. as a new modinfo // key or a new section. For the moment, keep it simple. #[cfg(MODULE)] #[doc(hidden)] #[used(compiler)] static __IS_RUST_MODULE: () = ();
// Loadable modules need to export the `{{init,cleanup}}_module` identifiers. /// # Safety /// /// This function must not be called after module initialization, because it may be /// freed after that completes. #[cfg(MODULE)] #[doc(hidden)] #[no_mangle] #[link_section = \".init.text\"] pubunsafeextern \"C\"fn init_module() -> ::kernel::ffi::c_int {{ // SAFETY: This function is inaccessible to the outside due to the double // module wrapping it. It is called exactly once by the C side via its // unique name. unsafe {{ __init() }}
}}
#[cfg(MODULE)] #[doc(hidden)] #[no_mangle] #[link_section = \".exit.text\"] pubextern \"C\"fn cleanup_module() {{ // SAFETY: // - This function is inaccessible to the outside due to the double // module wrapping it. It is called exactly once by the C side via its // unique name, // - furthermore it is only called after `init_module` has returned `0` // (which delegates to `__init`). unsafe {{ __exit() }}
}}
// Built-in modules are initialized through an initcall pointer // and the identifiers need to be unique. #[cfg(not(MODULE))] #[cfg(not(CONFIG_HAVE_ARCH_PREL32_RELOCATIONS))] #[doc(hidden)] #[link_section = \"{initcall_section}\"] #[used(compiler)] pubstatic __{ident}_initcall: extern \"C\"fn() ->
::kernel::ffi::c_int = __{ident}_init;
#[cfg(not(MODULE))] #[doc(hidden)] #[no_mangle] pubextern \"C\"fn __{ident}_init() -> ::kernel::ffi::c_int {{ // SAFETY: This function is inaccessible to the outside due to the double // module wrapping it. It is called exactly once by the C side via its // placement above in the initcall section. unsafe {{ __init() }}
}}
#[cfg(not(MODULE))] #[doc(hidden)] #[no_mangle] pubextern \"C\"fn __{ident}_exit() {{ // SAFETY: // - This function is inaccessible to the outside due to the double // module wrapping it. It is called exactly once by the C side via its // unique name, // - furthermore it is only called after `__{ident}_init` has // returned `0` (which delegates to `__init`). unsafe {{ __exit() }}
}}
/// # Safety /// /// This function must only be called once. unsafefn __init() -> ::kernel::ffi::c_int {{ let initer =
<{type_} as ::kernel::InPlaceModule>::init(&super::super::THIS_MODULE); // SAFETY: No data race, since `__MOD` can only be accessed by this module // and there only `__init` and `__exit` access it. These functions are only // called once and `__exit` cannot be called before or during `__init`. matchunsafe {{ initer.__pinned_init(__MOD.as_mut_ptr()) }} {{
Ok(m) => 0,
Err(e) => e.to_errno(),
}}
}}
/// # Safety /// /// This function must /// - only be called once, /// - be called after `__init` has been called and returned `0`. unsafefn __exit() {{ // SAFETY: No data race, since `__MOD` can only be accessed by this module // and there only `__init` and `__exit` access it. These functions are only // called once and `__init` was already called. unsafe {{ // Invokes `drop()` on `__MOD`, which should be used for cleanup.
__MOD.assume_init_drop();
}}
}}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.