Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
9 changes: 6 additions & 3 deletions rust_out_of_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<i32>,
}
Expand All @@ -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 })
}
Expand Down