Merge c and rust modules

This commit is contained in:
Florian RICHER 2025-03-01 18:01:07 +01:00
parent 8e0721c2fb
commit 311e9be037
Signed by: florian.richer
GPG key ID: C73D37CBED7BFC77
21 changed files with 4 additions and 11 deletions

10
01_basic_module/Makefile Normal file
View file

@ -0,0 +1,10 @@
MODULE_NAME = basic_module
obj-m += $(MODULE_NAME)_in_c.o
obj-m += $(MODULE_NAME)_in_rust.o
all:
make -C $(LINUX_MODULES_FOLDER)/build M=$(PWD) modules
clean:
make -C $(LINUX_MODULES_FOLDER)/build M=$(PWD) clean

View file

@ -0,0 +1,22 @@
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
static int __init basic_module_init(void)
{
pr_info("Bonjour! Le module est chargé.\n");
return 0;
}
static void __exit basic_module_exit(void)
{
pr_info("Au revoir! Le module est déchargé.\n");
}
module_init(basic_module_init);
module_exit(basic_module_exit);
MODULE_LICENSE("MIT License");
MODULE_AUTHOR("Florian RICHER <florian.richer@protonmail.com>");
MODULE_DESCRIPTION("Un module noyau qui affiche un message");
MODULE_VERSION("1.0");

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