From 8e04380436866e5d35fc674232774cb51faee9c7 Mon Sep 17 00:00:00 2001 From: FreeArtMan Date: Mon, 22 Aug 2016 18:12:37 +0100 Subject: Added kernel hello world compilation --- md/writeup/kernel_hello_world.md | 54 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 md/writeup/kernel_hello_world.md (limited to 'md/writeup/kernel_hello_world.md') diff --git a/md/writeup/kernel_hello_world.md b/md/writeup/kernel_hello_world.md new file mode 100644 index 0000000..efad275 --- /dev/null +++ b/md/writeup/kernel_hello_world.md @@ -0,0 +1,54 @@ +# Kernel compile "Hello world" + +Compile minimal linux kernel module. + +## Files + +You need to create to files __Makefile__ and __hello_world.c__. + +__Makefile__ +``` +obj-m += hello_world.o + +KDIR ?= /lib/modules/$(shell uname -r)/build + +all: + make -C $(KDIR) M=$(PWD) modules + +clean: + make -C $(KDIR) M=$(PWD) clean +``` + + +__hello_world.c__ +``` +//http://www.tldp.org/LDP/lkmpg/2.4/html/c147.htm +#include /* Needed by all modules */ +#include + +int hello_world_init( void ) +{ + printk(KERN_DEBUG "Hello World!\n"); + return 0; +} + +void hello_world_exit( void ) +{ + printk(KERN_DEBUG "Exit Hello World!\n"); +} + +module_init( hello_world_init ); +module_exit( hello_world_exit ); + +MODULE_LICENSE("GPL"); +``` + + + +##Compile + +Now if you havent done so ... install kernel headers of kernel that your system have now. And everything should be there. + +``` +make +``` -- cgit v1.2.3