Compare commits

...
Sign in to create a new pull request.

3 commits

Author SHA1 Message Date
8e0721c2fb
Apply new nixos version 2025-02-26 18:54:09 +01:00
643c25e774
fix build failed in nixos 2025-02-26 18:53:53 +01:00
Florian RICHER
91f8ca7f49 Begin work on rust versions of modules 2025-02-26 17:08:49 +01:00
24 changed files with 55 additions and 11 deletions

View file

@ -1,5 +1,6 @@
{
"recommendations": [
"ms-vscode.cpptools-extension-pack"
"ms-vscode.cpptools-extension-pack",
"rust-lang.rust-analyzer"
]
}

View file

@ -18,7 +18,14 @@ On other distros:
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
@ -55,6 +62,7 @@ sudo rmmod [module_name].ko
- https://elixir.bootlin.com/linux/v6.13/source/
- https://static.lwn.net/images/pdf/LDD3/ch01.pdf
- https://sysprog21.github.io/lkmpg
- https://github.com/Rust-for-Linux/rust-out-of-tree-module
## Notes

4
flake.lock generated
View file

@ -21,8 +21,8 @@
"nixpkgs": {
"locked": {
"lastModified": 0,
"narHash": "sha256-+/bYK3DbPxMIvSL4zArkMX0LQvS7rzBKXnDXLfKyRVc=",
"path": "/nix/store/brjzz8wv5k09bq0yrvhc1j4hd8677k21-source",
"narHash": "sha256-WGaHVAjcrv+Cun7zPlI41SerRtfknGQap281+AakSAw=",
"path": "/nix/store/593xvgv994xlkm5mb7w4p1xxnzrs9wv6-source",
"type": "path"
},
"original": {

View file

@ -17,6 +17,6 @@ module_init(basic_module_init);
module_exit(basic_module_exit);
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_VERSION("1.0");

View file

@ -50,6 +50,6 @@ module_init(module_params_init);
module_exit(module_params_exit);
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_VERSION("1.0");

View file

@ -87,6 +87,6 @@ module_init(basic_module_init);
module_exit(basic_module_exit);
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_VERSION("1.0");

View file

@ -33,6 +33,6 @@ module_init(basic_module_init);
module_exit(basic_module_exit);
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_VERSION("1.0");

View file

@ -44,6 +44,6 @@ module_init(packet_filter_init);
module_exit(packet_filter_exit);
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_VERSION("1.0");

View file

@ -53,6 +53,6 @@ module_init(virtual_led_init);
module_exit(virtual_led_exit);
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_VERSION("1.0");

View file

@ -93,6 +93,6 @@ module_init(virtual_led_init);
module_exit(virtual_led_exit);
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_VERSION("1.0");

View file

@ -0,0 +1,10 @@
obj-m += test_module.o
all:
make -C $(LINUX_MODULES_FOLDER)/build M=$(PWD) modules
clean:
make -C $(LINUX_MODULES_FOLDER)/build M=$(PWD) clean
rust-analyzer:
make -C $(LINUX_MODULES_FOLDER)/build M=$(PWD) rust-analyzer

View 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");
}
}