mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-25 11:11:35 +01:00
Host insane unsafe usage
This commit is contained in:
@@ -6,7 +6,7 @@ ccflags-y := -Wno-declaration-after-statement -std=gnu99
|
||||
all: hello.ko
|
||||
|
||||
hello.ko: hello.c
|
||||
make -C '/lib/modules/$(shell uname -r)/build' M='$(PWD)' modules
|
||||
$(MAKE) -C '/lib/modules/$(shell uname -r)/build' M='$(PWD)' modules
|
||||
|
||||
clean:
|
||||
make -C '/lib/modules/$(shell uname -r)/build' M='$(PWD)' clean
|
||||
$(MAKE) -C '/lib/modules/$(shell uname -r)/build' M='$(PWD)' clean
|
||||
|
||||
@@ -1,35 +1,3 @@
|
||||
# Host
|
||||
|
||||
Simple things that can be demonstrated by inserting a module into the currently running host. Tested on Ubuntu 16.04.
|
||||
|
||||
1. [hello](hello.c)
|
||||
|
||||
## Rationale
|
||||
|
||||
This method easier to setup, but it is not recommended for development, as:
|
||||
|
||||
- it may break your system
|
||||
- you can't control which kernel version to use
|
||||
|
||||
Use VMs instead.
|
||||
|
||||
## Usage
|
||||
|
||||
We only use it for super simple examples.
|
||||
|
||||
Build, insert and remove a hello world module:
|
||||
|
||||
make
|
||||
|
||||
sudo insmod hello.ko
|
||||
|
||||
# Our module should be there.
|
||||
sudo lsmod | grep hello
|
||||
|
||||
# Last message should be: init_module
|
||||
dmest -T
|
||||
|
||||
sudo rmmod hello
|
||||
|
||||
# Last message should be: cleanup_module
|
||||
dmest -T
|
||||
Minimal host build system sanity check example.
|
||||
|
||||
12
host/hello.c
12
host/hello.c
@@ -1,13 +1,17 @@
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
|
||||
int init_module(void)
|
||||
static int myinit(void)
|
||||
{
|
||||
printk(KERN_INFO "init_module\n");
|
||||
pr_info("hello init\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void cleanup_module(void)
|
||||
static void myexit(void)
|
||||
{
|
||||
printk(KERN_INFO "cleanup_module\n");
|
||||
pr_info("hello exit\n");
|
||||
}
|
||||
|
||||
module_init(myinit)
|
||||
module_exit(myexit)
|
||||
MODULE_LICENSE("GPL");
|
||||
|
||||
Reference in New Issue
Block a user