try implement 02_module_params in rust
params: in module! macro don't exist yet
This commit is contained in:
parent
0d471911dd
commit
a407e656b6
4 changed files with 43 additions and 10 deletions
|
@ -1,24 +1,24 @@
|
||||||
use kernel::prelude::*;
|
use kernel::prelude::*;
|
||||||
|
|
||||||
module! {
|
module! {
|
||||||
type: RustOutOfTree,
|
type: BasicModule,
|
||||||
name: "test_module",
|
name: "basic_module",
|
||||||
author: "Florian RICHER <florian.richer@protonmail.com>",
|
author: "Florian RICHER <florian.richer@protonmail.com>",
|
||||||
description: "Un module noyau qui affiche un message",
|
description: "Un module noyau qui affiche un message",
|
||||||
license: "GPL",
|
license: "GPL",
|
||||||
}
|
}
|
||||||
|
|
||||||
struct RustOutOfTree;
|
struct BasicModule;
|
||||||
|
|
||||||
impl kernel::Module for RustOutOfTree {
|
impl kernel::Module for BasicModule {
|
||||||
fn init(_module: &'static ThisModule) -> Result<Self> {
|
fn init(_module: &'static ThisModule) -> Result<Self> {
|
||||||
pr_info!("Bonjour! Le module est chargé.\n");
|
pr_info!("Bonjour! Le module est chargé.\n");
|
||||||
|
|
||||||
Ok(RustOutOfTree)
|
Ok(BasicModule)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for RustOutOfTree {
|
impl Drop for BasicModule {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
pr_info!("Au revoir! Le module est déchargé.\n");
|
pr_info!("Au revoir! Le module est déchargé.\n");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
obj-m += test_module.o
|
MODULE_NAME = module_params
|
||||||
|
|
||||||
|
obj-m += $(MODULE_NAME)_in_c.o
|
||||||
|
obj-m += $(MODULE_NAME)_in_rust.o
|
||||||
|
|
||||||
all:
|
all:
|
||||||
make -C $(LINUX_MODULES_FOLDER)/build M=$(PWD) modules
|
make -C $(LINUX_MODULES_FOLDER)/build M=$(PWD) modules
|
||||||
|
|
|
@ -37,13 +37,13 @@ static int __init module_params_init(void)
|
||||||
|
|
||||||
pr_info("%d arguments for myintarray.\n", arr_argc);
|
pr_info("%d arguments for myintarray.\n", arr_argc);
|
||||||
|
|
||||||
pr_info("Module avec paramètre chargé.\n");
|
pr_info("Module avec paramètres chargé.\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __exit module_params_exit(void)
|
static void __exit module_params_exit(void)
|
||||||
{
|
{
|
||||||
pr_info("Module avec paramètre déchargé.\n");
|
pr_info("Module avec paramètres déchargé.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
module_init(module_params_init);
|
module_init(module_params_init);
|
||||||
|
@ -51,5 +51,5 @@ module_exit(module_params_exit);
|
||||||
|
|
||||||
MODULE_LICENSE("MIT License");
|
MODULE_LICENSE("MIT License");
|
||||||
MODULE_AUTHOR("Florian RICHER <florian.richer@protonmail.com>");
|
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ètres.");
|
||||||
MODULE_VERSION("1.0");
|
MODULE_VERSION("1.0");
|
30
02_module_params/module_params_in_rust.rs
Normal file
30
02_module_params/module_params_in_rust.rs
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
use kernel::prelude::*;
|
||||||
|
|
||||||
|
module! {
|
||||||
|
type: ModuleWithParams,
|
||||||
|
name: "test_module",
|
||||||
|
author: "Florian RICHER <florian.richer@protonmail.com>",
|
||||||
|
description: "Un module noyau avec paramètres déchargé.",
|
||||||
|
license: "GPL"
|
||||||
|
// Syntax as below not supported yet see https://patchew.org/linux/20250218-module-params-v3-v7-0-5e1afabcac1b%40kernel.org/
|
||||||
|
// params: type {
|
||||||
|
// default: default_value,
|
||||||
|
// description: "Description",
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ModuleWithParams;
|
||||||
|
|
||||||
|
impl kernel::Module for ModuleWithParams {
|
||||||
|
fn init(_module: &'static ThisModule) -> Result<Self> {
|
||||||
|
pr_info!("Module avec paramètres chargé.\n");
|
||||||
|
|
||||||
|
Ok(ModuleWithParams)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for ModuleWithParams {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
pr_info!("Module avec paramètres.\n");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue