-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbabysfirst_module.c
More file actions
30 lines (26 loc) · 984 Bytes
/
babysfirst_module.c
File metadata and controls
30 lines (26 loc) · 984 Bytes
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
/*###########################################################
# Baby's first dynamic loadable kernel module!
# As basic as it gets.
# Usage: (sudo) insmod ./babysfirst_module.ko
###########################################################*/
#include <linux/init.h>
#include <linux/module.h>
// Seems to be needed if our kernel has version suppport is enabled.
MODULE_LICENSE("Dual BSD/GPL");
// Init function (called by insmod)
static int baby_init(void)
{
// We are no longer in user space, so no glibc for us. Print message to syslog:
printk(KERN_ALERT "My first module just got loaded into kernel space. Yay!\n");
// Signal that we are correctly initialized:
return 0;
}
// Exit function (called by rmmod)
static void baby_exit(void)
{
// Again, all we do is print a syslog message.
printk(KERN_ALERT "My first module got unloaded. Doh!\n");
}
// Use kernel macros to declare init and exit functions:
module_init(baby_init);
module_exit(baby_exit);