@@ -19,6 +19,25 @@ pub mod user_ptr;
1919pub use crate :: error:: { Error , KernelResult } ;
2020pub use crate :: types:: { CStr , Mode } ;
2121
22+ /// Declares the entrypoint for a kernel module. The first argument should be a type which
23+ /// implements the [`KernelModule`] trait. Also accepts various forms of kernel metadata.
24+ ///
25+ /// Example:
26+ /// ```rust,no_run
27+ /// use linux_kernel_module;
28+ /// struct MyKernelModule;
29+ /// impl linux_kernel_module::KernelModule for MyKernelModule {
30+ /// fn init() -> linux_kernel_module::KernelResult<Self> {
31+ /// Ok(MyKernelModule)
32+ /// }
33+ /// }
34+ ///
35+ /// linux_kernel_module::kernel_module!(
36+ /// MyKernelModule,
37+ /// author: "Fish in a Barrel Contributors",
38+ /// description: "My very own kernel module!",
39+ /// license: "GPL"
40+ /// );
2241#[ macro_export]
2342macro_rules! kernel_module {
2443 ( $module: ty, $( $name: ident : $value: expr) ,* ) => {
@@ -61,6 +80,12 @@ macro_rules! kernel_module {
6180 } ;
6281}
6382
83+ /// KernelModule is the top level entrypoint to implementing a kernel module. Your kernel module
84+ /// should implement the `init` method on it, which maps to the `module_init` macro in Linux C API.
85+ /// You can use this method to do whatever setup or registration your module should do. For any
86+ /// teardown or cleanup operations, your type may implement [`Drop`].
87+ ///
88+ /// [`Drop`]: https://doc.rust-lang.org/stable/core/ops/trait.Drop.html
6489pub trait KernelModule : Sized + Sync {
6590 fn init ( ) -> KernelResult < Self > ;
6691}
0 commit comments