programming Linux Kernel modules
Linux kernel modules run in a priviledged space. But what does this mean? Let's find out.
First let's program a "hello world" Linux kernel module:
- create a folder kernel
mkdir kernel
- create a file hello.c:
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
MODULE_DESCRIPTION("Insert description");
MODULE_AUTHOR("Insert author");
MODULE_LICENSE("GPL");
static int __init hello_init(void)
{
printk(KERN_INFO "Hello world\n");
return 0;
}
module_init(hello_init);
- create a file Makefile:
obj-m += hello.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
- run make:
make
- insert the module:
sudo insmod hello.ko
- verify the syslog:
sudo dmesg
- and I see in it the following line that confirms me it works:
[49694.489768] Hello world
Comments
Post a Comment