diff --git a/0.0_Basic/Makefile b/0.0_Basic/Makefile new file mode 100644 index 0000000..68f5950 --- /dev/null +++ b/0.0_Basic/Makefile @@ -0,0 +1,7 @@ +obj-m += example.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 diff --git a/0.0_Basic/README.md b/0.0_Basic/README.md new file mode 100644 index 0000000..55c6a28 --- /dev/null +++ b/0.0_Basic/README.md @@ -0,0 +1,13 @@ +# Linux Kernel Hacking + +## 0.0: Basic LKM Example + +This is about as simple as it gets. + +To use: +* Build with `make` +* Load with `insmod example.ko` +* Check output in kernel buffer with `dmesg` +* See the module loaded in `lsmod | grep example` +* Unload with `rmmod example.ko` +* Check the second output in the kernel buffer with `dmesg` diff --git a/0.0_Basic/example.c b/0.0_Basic/example.c new file mode 100644 index 0000000..7405b96 --- /dev/null +++ b/0.0_Basic/example.c @@ -0,0 +1,22 @@ +#include +#include +#include + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Example"); +MODULE_DESCRIPTION("Basic"); +MODULE_VERSION("0.01"); + +static int __init example_init(void) +{ + printk(KERN_INFO "Hello, World!\n"); + return 0; +} + +static void __exit example_exit(void) +{ + printk(KERN_INFO "Goodbye, World!\n"); +} + +module_init(example_init); +module_exit(example_exit);