mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
update
This commit is contained in:
@@ -1,33 +1,16 @@
|
||||
OUT_EXT := .ko
|
||||
OBJ_EXT := .o
|
||||
RUN := hello
|
||||
RUN_EXT := $(RUN)$(OUT_EXT)
|
||||
|
||||
obj-m += hello.o
|
||||
ccflags-y := -Wno-declaration-after-statement -std=gnu99
|
||||
|
||||
.PHONY: clean ins log rm run my-ins
|
||||
.PHONY: all clean
|
||||
|
||||
all: $(RUN_EXT) ins_rm_mod.out
|
||||
all: hello.ko ins_rm_mod.out
|
||||
|
||||
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
|
||||
rm -f *.out
|
||||
make -C '/lib/modules/$(shell uname -r)/build' M='$(PWD)' clean
|
||||
rm -f ins_rm_mod.out
|
||||
|
||||
ins: all
|
||||
sudo insmod '$(RUN_EXT)'
|
||||
|
||||
log:
|
||||
dmesg
|
||||
|
||||
rm:
|
||||
if lsmod | grep -Eq '^$(RUN) '; then sudo rmmod '$(RUN_EXT)'; fi
|
||||
|
||||
ins_rm_mod.out: ins_rm_mod.c
|
||||
gcc -Wall -std=gnu99 -o '$@' '$<'
|
||||
|
||||
ins_rm_run: ins_rm_mod.out $(RUN_EXT)
|
||||
sudo ./ins_rm_mod.out
|
||||
ins_rm_mod.out: ins_rm_mod.c hello.c
|
||||
gcc -Wall -std=gnu99 -o ins_rm_mod.out ins_rm_mod.c
|
||||
|
||||
@@ -9,7 +9,7 @@ Simple things that can be demonstrated by inserting a module into the currently
|
||||
|
||||
This method easier to setup, but it is not recommended for development, as:
|
||||
|
||||
- it may break your system.
|
||||
- it may break your system
|
||||
- you can't control which kernel version to use
|
||||
|
||||
Use VMs instead.
|
||||
@@ -20,15 +20,21 @@ We only use it for super simple examples.
|
||||
|
||||
Build, insert and remove a hello world module:
|
||||
|
||||
make ins
|
||||
make rm
|
||||
make log
|
||||
make
|
||||
|
||||
The last lines of the log should contain:
|
||||
sudo insmod hello.ko
|
||||
|
||||
init_module
|
||||
cleanup_module
|
||||
# Our module should be there.
|
||||
sudo lsmod | grep hello
|
||||
|
||||
Insert and remove a module from a C program:
|
||||
# Last message should be: init_module
|
||||
dmest -T
|
||||
|
||||
make ins_rm_run
|
||||
sudo rmmod hello
|
||||
|
||||
# Last message should be: cleanup_module
|
||||
dmest -T
|
||||
|
||||
Insert and remove the `hello.ko` module from a C program with system calls:
|
||||
|
||||
sudo ./ins_rm_mod.out
|
||||
|
||||
Reference in New Issue
Block a user