diff --git a/README.md b/README.md index 4e0288a..b719ae7 100644 --- a/README.md +++ b/README.md @@ -15,16 +15,38 @@ Please note that: Example: ```sh -$ make KDIR=.../linux-with-rust-support LLVM=1 -make -C .../linux-with-rust-support M=$PWD +# Basic build (LLVM=1 is now default) +$ make +make -C .../linux-with-rust-support M=$PWD LLVM=1 make[1]: Entering directory '.../linux-with-rust-support' RUSTC [M] .../rust-out-of-tree-module/rust_out_of_tree.o MODPOST .../rust-out-of-tree-module/Module.symvers CC [M] .../rust-out-of-tree-module/rust_out_of_tree.mod.o LD [M] .../rust-out-of-tree-module/rust_out_of_tree.ko make[1]: Leaving directory '.../linux-with-rust-support' + +# Verify the build +$ make check + +# See all available targets +$ make help ``` +## Usage + +After building, you can load and test the module: + +```sh +# Load the module +sudo insmod rust_out_of_tree.ko + +# Check kernel logs for output +sudo dmesg | tail + +# Unload the module +sudo rmmod rust_out_of_tree + + ```txt [ 1.076945] rust_out_of_tree: Rust out-of-tree sample (init) [ 1.084944] rust_out_of_tree: My numbers are [72, 108, 200] diff --git a/rust_out_of_tree.rs b/rust_out_of_tree.rs index c8e5cf2..8f7d78b 100644 --- a/rust_out_of_tree.rs +++ b/rust_out_of_tree.rs @@ -12,6 +12,9 @@ module! { license: "GPL", } +// Sample values to demonstrate kernel vector usage +const SAMPLE_VALUES: [i32; 3] = [72, 108, 200]; + struct RustOutOfTree { numbers: KVec, } @@ -21,9 +24,9 @@ impl kernel::Module for RustOutOfTree { pr_info!("Rust out-of-tree sample (init)\n"); let mut numbers = KVec::new(); - numbers.push(72, GFP_KERNEL)?; - numbers.push(108, GFP_KERNEL)?; - numbers.push(200, GFP_KERNEL)?; + for &value in &SAMPLE_VALUES { + numbers.push(value, GFP_KERNEL)?; + } Ok(RustOutOfTree { numbers }) }