-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path@
More file actions
32 lines (27 loc) · 975 Bytes
/
@
File metadata and controls
32 lines (27 loc) · 975 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use kernel::prelude::*;
use kernel::error::Result; // Use this for the return type
// Import the `module` item itself, plus the `KernelModule` trait and `Module` type
use kernel::module::{self, KernelModule, Module};
struct HelloWorldModule;
/// This is called when you `insmod` the module.
// Use the full path `module::KernelModule` to be unambiguous
impl module::KernelModule for HelloWorldModule {
fn init(_module: &'static Module) -> Result<Self> {
pr_info!("rust_hello: Hello, world! My first Rust module is alive!\n");
Ok(HelloWorldModule)
}
}
/// This is called when you `rmmod` the module.
impl Drop for HelloWorldModule {
fn drop(&mut self) {
pr_info!("rust_hello: Goodbye, world! Cleaning up.\n");
}
}
// Register the module with the kernel
module! {
type: HelloWorldModule,
name: b"rust_hello",
author: b"Anas",
description: b"Anas's first 'hello world' Rust kernel module",
license: b"GPL v2",
}