Merge c and rust modules
This commit is contained in:
parent
8e0721c2fb
commit
311e9be037
21 changed files with 4 additions and 11 deletions
10
01_basic_module/Makefile
Normal file
10
01_basic_module/Makefile
Normal 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
|
22
01_basic_module/basic_module_in_c.c
Normal file
22
01_basic_module/basic_module_in_c.c
Normal 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");
|
25
01_basic_module/basic_module_in_rust.rs
Normal file
25
01_basic_module/basic_module_in_rust.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
Add a link
Reference in a new issue