Begin work on rust versions of modules
This commit is contained in:
parent
1f2cc50f26
commit
91f8ca7f49
23 changed files with 53 additions and 9 deletions
3
.vscode/extensions.json
vendored
3
.vscode/extensions.json
vendored
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"recommendations": [
|
"recommendations": [
|
||||||
"ms-vscode.cpptools-extension-pack"
|
"ms-vscode.cpptools-extension-pack",
|
||||||
|
"rust-lang.rust-analyzer"
|
||||||
]
|
]
|
||||||
}
|
}
|
10
README.md
10
README.md
|
@ -18,7 +18,14 @@ On other distros:
|
||||||
|
|
||||||
2. With nix only, use `nix develop .#other`
|
2. With nix only, use `nix develop .#other`
|
||||||
|
|
||||||
3. Otherwise, you need to setup LINUX_MODULES_FOLDER to linux modules folder of your distro (ex: `/lib/modules/$(uname -r)`) in your shell (ex: .bashrc)
|
3. Otherwise, you need `kernel-devel` to compile C code and `rust rust-src bindgen-cli rustfmt clippy` to compile rust
|
||||||
|
And also to setup LINUX_MODULES_FOLDER to linux modules folder of your distro (ex: `/lib/modules/$(uname -r)`) in your shell (ex: .bashrc)
|
||||||
|
|
||||||
|
### Note for Rust
|
||||||
|
|
||||||
|
`cat /boot/config-$(uname -r) | grep CONFIG_RUST`
|
||||||
|
|
||||||
|
Must contains CONFIG_RUST=y
|
||||||
|
|
||||||
## make : targets list
|
## make : targets list
|
||||||
|
|
||||||
|
@ -55,6 +62,7 @@ sudo rmmod [module_name].ko
|
||||||
- https://elixir.bootlin.com/linux/v6.13/source/
|
- https://elixir.bootlin.com/linux/v6.13/source/
|
||||||
- https://static.lwn.net/images/pdf/LDD3/ch01.pdf
|
- https://static.lwn.net/images/pdf/LDD3/ch01.pdf
|
||||||
- https://sysprog21.github.io/lkmpg
|
- https://sysprog21.github.io/lkmpg
|
||||||
|
- https://github.com/Rust-for-Linux/rust-out-of-tree-module
|
||||||
|
|
||||||
## Notes
|
## Notes
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,6 @@ module_init(basic_module_init);
|
||||||
module_exit(basic_module_exit);
|
module_exit(basic_module_exit);
|
||||||
|
|
||||||
MODULE_LICENSE("MIT License");
|
MODULE_LICENSE("MIT License");
|
||||||
MODULE_AUTHOR("Florian RICHER");
|
MODULE_AUTHOR("Florian RICHER <florian.richer@protonmail.com>");
|
||||||
MODULE_DESCRIPTION("Un module noyau qui affiche un message");
|
MODULE_DESCRIPTION("Un module noyau qui affiche un message");
|
||||||
MODULE_VERSION("1.0");
|
MODULE_VERSION("1.0");
|
|
@ -50,6 +50,6 @@ module_init(module_params_init);
|
||||||
module_exit(module_params_exit);
|
module_exit(module_params_exit);
|
||||||
|
|
||||||
MODULE_LICENSE("MIT License");
|
MODULE_LICENSE("MIT License");
|
||||||
MODULE_AUTHOR("Florian RICHER");
|
MODULE_AUTHOR("Florian RICHER <florian.richer@protonmail.com>");
|
||||||
MODULE_DESCRIPTION("Un module noyau avec paramètre déchargé.");
|
MODULE_DESCRIPTION("Un module noyau avec paramètre déchargé.");
|
||||||
MODULE_VERSION("1.0");
|
MODULE_VERSION("1.0");
|
|
@ -87,6 +87,6 @@ module_init(basic_module_init);
|
||||||
module_exit(basic_module_exit);
|
module_exit(basic_module_exit);
|
||||||
|
|
||||||
MODULE_LICENSE("MIT License");
|
MODULE_LICENSE("MIT License");
|
||||||
MODULE_AUTHOR("Florian RICHER");
|
MODULE_AUTHOR("Florian RICHER <florian.richer@protonmail.com>");
|
||||||
MODULE_DESCRIPTION("Un module noyau avec un périphérique de caractère");
|
MODULE_DESCRIPTION("Un module noyau avec un périphérique de caractère");
|
||||||
MODULE_VERSION("1.0");
|
MODULE_VERSION("1.0");
|
|
@ -33,6 +33,6 @@ module_init(basic_module_init);
|
||||||
module_exit(basic_module_exit);
|
module_exit(basic_module_exit);
|
||||||
|
|
||||||
MODULE_LICENSE("MIT License");
|
MODULE_LICENSE("MIT License");
|
||||||
MODULE_AUTHOR("Florian RICHER");
|
MODULE_AUTHOR("Florian RICHER <florian.richer@protonmail.com>");
|
||||||
MODULE_DESCRIPTION("Un module noyau qui affiche les processus en cours");
|
MODULE_DESCRIPTION("Un module noyau qui affiche les processus en cours");
|
||||||
MODULE_VERSION("1.0");
|
MODULE_VERSION("1.0");
|
|
@ -44,6 +44,6 @@ module_init(packet_filter_init);
|
||||||
module_exit(packet_filter_exit);
|
module_exit(packet_filter_exit);
|
||||||
|
|
||||||
MODULE_LICENSE("MIT License");
|
MODULE_LICENSE("MIT License");
|
||||||
MODULE_AUTHOR("Florian RICHER");
|
MODULE_AUTHOR("Florian RICHER <florian.richer@protonmail.com>");
|
||||||
MODULE_DESCRIPTION("Un module noyau pour filtrer les paquets réseau");
|
MODULE_DESCRIPTION("Un module noyau pour filtrer les paquets réseau");
|
||||||
MODULE_VERSION("1.0");
|
MODULE_VERSION("1.0");
|
|
@ -53,6 +53,6 @@ module_init(virtual_led_init);
|
||||||
module_exit(virtual_led_exit);
|
module_exit(virtual_led_exit);
|
||||||
|
|
||||||
MODULE_LICENSE("GPL");
|
MODULE_LICENSE("GPL");
|
||||||
MODULE_AUTHOR("Florian RICHER");
|
MODULE_AUTHOR("Florian RICHER <florian.richer@protonmail.com>");
|
||||||
MODULE_DESCRIPTION("Un module noyau qui ajoute une LED virtuelle");
|
MODULE_DESCRIPTION("Un module noyau qui ajoute une LED virtuelle");
|
||||||
MODULE_VERSION("1.0");
|
MODULE_VERSION("1.0");
|
|
@ -93,6 +93,6 @@ module_init(virtual_led_init);
|
||||||
module_exit(virtual_led_exit);
|
module_exit(virtual_led_exit);
|
||||||
|
|
||||||
MODULE_LICENSE("GPL");
|
MODULE_LICENSE("GPL");
|
||||||
MODULE_AUTHOR("Florian RICHER");
|
MODULE_AUTHOR("Florian RICHER <florian.richer@protonmail.com>");
|
||||||
MODULE_DESCRIPTION("Un module noyau qui ajoute des LEDs virtuelles");
|
MODULE_DESCRIPTION("Un module noyau qui ajoute des LEDs virtuelles");
|
||||||
MODULE_VERSION("1.0");
|
MODULE_VERSION("1.0");
|
10
lang_rust/01_basic_module/Makefile
Normal file
10
lang_rust/01_basic_module/Makefile
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
obj-m += test_module.o
|
||||||
|
|
||||||
|
all:
|
||||||
|
make -C $(LINUX_MODULES_FOLDER)/build M=$(PWD) LLVM=1 modules
|
||||||
|
|
||||||
|
clean:
|
||||||
|
make -C $(LINUX_MODULES_FOLDER)/build M=$(PWD) LLVM=1 clean
|
||||||
|
|
||||||
|
rust-analyzer:
|
||||||
|
make -C $(LINUX_MODULES_FOLDER)/build M=$(PWD) LLVM=1 rust-analyzer
|
25
lang_rust/01_basic_module/test_module.rs
Normal file
25
lang_rust/01_basic_module/test_module.rs
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
use kernel::prelude::*;
|
||||||
|
|
||||||
|
module! {
|
||||||
|
type: RustOutOfTree,
|
||||||
|
name: "test_module",
|
||||||
|
author: "Florian RICHER <florian.richer@protonmail.com>",
|
||||||
|
description: "Un module noyau qui affiche un message",
|
||||||
|
license: "GPL",
|
||||||
|
}
|
||||||
|
|
||||||
|
struct RustOutOfTree;
|
||||||
|
|
||||||
|
impl kernel::Module for RustOutOfTree {
|
||||||
|
fn init(_module: &'static ThisModule) -> Result<Self> {
|
||||||
|
pr_info!("Bonjour! Le module est chargé.\n");
|
||||||
|
|
||||||
|
Ok(RustOutOfTree)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for RustOutOfTree {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
pr_info!("Au revoir! Le module est déchargé.\n");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue