Linux kernel module hello world!
authorThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Sat, 5 Dec 2009 14:34:34 +0000 (12:34 -0200)
committerThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Sat, 5 Dec 2009 14:34:34 +0000 (12:34 -0200)
Makefile [new file with mode: 0644]
hello.c [new file with mode: 0644]

diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..d26e7c6
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,11 @@
+ifneq ($(KERNELRELEASE),)
+       obj-m := hello.o
+else
+       KERNELDIR ?= /lib/modules/$(shell uname -r)/build
+       PWD := $(shell pwd)
+default:
+       $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
+
+clean:
+       $(MAKE) -C $(KERNELDIR) M=$(PWD) clean
+endif
diff --git a/hello.c b/hello.c
new file mode 100644 (file)
index 0000000..01e8c26
--- /dev/null
+++ b/hello.c
@@ -0,0 +1,17 @@
+#include <linux/module.h>
+
+MODULE_LICENSE("GPL");
+
+static int hello_init(void)
+{
+       printk(KERN_ALERT "Hello, world!\n");
+       return 0;
+}
+
+static void hello_exit(void)
+{
+       printk(KERN_ALERT "Goodbye, cruel world!\n");
+}
+
+module_init(hello_init);
+module_exit(hello_exit);