Skip to content

Instantly share code, notes, and snippets.

@aita
Created February 11, 2019 14:40
Show Gist options
  • Select an option

  • Save aita/0eab60e682f7d9ca7c6c787ea1060ef7 to your computer and use it in GitHub Desktop.

Select an option

Save aita/0eab60e682f7d9ca7c6c787ea1060ef7 to your computer and use it in GitHub Desktop.
Hello World Kernel Module
#include <linux/module.h>
MODULE_LICENSE("GPL v2");
MODULE_DESCRIPTION("Hello world kernel module");
static int mymodule_init(void) {
printk(KERN_ALERT "Hello world!\n");
return 0;
}
static void mymodule_exit(void) {
printk(KERN_ALERT "Good Bye world!\n");
}
module_init(mymodule_init);
module_exit(mymodule_exit);
obj-m := hello.o
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
VERBOSE = 0
default:
$(MAKE) -C $(KDIR) M=$(PWD) KBUILD_VERBOSE=$(VERBOSE) modules
clean:
rm -f *.o *.ko *.mod.c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment