-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbasic_module.c
More file actions
52 lines (43 loc) · 1.31 KB
/
basic_module.c
File metadata and controls
52 lines (43 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <linux/module.h>
#include <linux/kernel.h>
/*
Si specifica il nome del modulo; nel log del kernel pertanto sara' visualizzato
il nome associato a MODULE_NAME, naturalmente solo se lo si inserisse con una
loglevel macro, tipicamente KERN_ALERT e/o KERN_INFO.
*/
#define MODULE_NAME "hello_md"
/*
Gli headers dei moduli sono diversi dagli headers delle normali applicazioni in
UserSpace, si deve far presente infatti che si sta interagendo con il kernel,
per cui sono necessari gli headers specifici del kernel in uso; le tipiche
sistem call sono implementate ad un livello piu' alto.
MACRO documentative, collocate in ../linux/module.h
*/
MODULE_LICENSE("GPL");
MODULE_AUTHOR("B3h3m0th");
MODULE_DESCRIPTION("Basic LKM; hello world module");
MODULE_VERSION("0.0");
/* routine di inizializzazione del modulo */
static int __init insert_mod(void)
{
printk(KERN_ALERT "[%s] Init: \"Hello World\"\n", MODULE_NAME);
return 0;
}
/* routine di pulizia/disattivazione del modulo */
static void __exit remove_mod(void)
{
printk(KERN_ALERT "[%s] Exit\n", MODULE_NAME);
}
module_init(insert_mod);
module_exit(remove_mod);
/*
Loglevel MACRO (collocate in ../linux/kernel.h):
KERN_EMERG <0>
KERN_ALERT <1>
KERN_CRIT <2>
KERN_ERR <3>
KERN_WARNING <4>
KERN_NOTICE <5>
KERN_INFO <6>
KERN_DEBUG <7>
*/