From 14ec32b1bdbe36ed721672f5a729b7201a3f0f6c Mon Sep 17 00:00:00 2001 From: paul-loedige Date: Mon, 17 Oct 2022 12:08:35 +0900 Subject: [PATCH] finished the kernel module and documentation --- Makefile | 9 +++++++++ README.md | 12 ++++++++++++ hello.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 Makefile create mode 100644 hello.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..abc0cf8 --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ +obj-m += hello.o + +PWD := $(CURDIR) + +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/README.md b/README.md index b98fad2..b92792f 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,14 @@ # Hello_World_Kernel_Module +## Prerequisits + - requires the correct linux headers to be installed + - root access is needed + +## how to run the kernel module + - `make` to build the module + - `sudo insmod hello` to run the module + - `sudo rmmod hello` to stop the module + +## viewing the log +on systems that run systemd: +``` journalctl -f -k ``` \ No newline at end of file diff --git a/hello.c b/hello.c new file mode 100644 index 0000000..91f79f5 --- /dev/null +++ b/hello.c @@ -0,0 +1,28 @@ +/** + * @file hello.c + * @author Paul Lödige (ploedige@g.ecc.u-tokyo.ac.jp) + * @brief prints "Hello World" from the Kernel + * @version 0.1 + * @date 2022-10-17 + * + * @copyright Copyright (c) 2022 + */ + +#include +#include +#include + +static int __init hello_init(void) { + printk("Hello World!"); + return 0; +} + +static void __exit hello_exit(void){ + printk("Goodbye!"); +} + +module_init(hello_init); +module_exit(hello_exit); +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("Hello World Module"); +MODULE_AUTHOR("ploedige"); \ No newline at end of file