Skip to content

Instantly share code, notes, and snippets.

@zhustec
Created January 21, 2015 06:03
Show Gist options
  • Select an option

  • Save zhustec/370ff7ad0cc3572f692d to your computer and use it in GitHub Desktop.

Select an option

Save zhustec/370ff7ad0cc3572f692d to your computer and use it in GitHub Desktop.
Linux kernel module
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
MODULE_AUTHOR("sloger");
MODULE_LICENSE("GPLv3");
MODULE_DESCRIPTION("Hello Kernel");
static int __init printk_init(void)
{
printk(KERN_ALERT "Hello Kernel!\n");
return 0;
}
static void __exit printk_exit(void)
{
printk(KERN_ALERT "Good Bye!\n");
}
module_init(printk_init);
module_exit(printk_exit);
ifneq ($(KERNELRELEASE),)
obj-m := hello.o
else
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
all:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
clean:
$(MAKE) -C $(KERNELDIR) M=$(PWD) clean
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment