LoginSignup
1
3

More than 5 years have passed since last update.

シンプルなカーネルモジュールメモ

Last updated at Posted at 2017-08-13

前提

  • Ubuntu 16.04
  • Windows/VMWare
  • ロードしてログの出力をするだけ

メモ

simple_kernelmodule.c
#include <linux/module.h>
#include <linux/init.h>

MODULE_LICENSE("Dual BSD/GPL");

static int kure_init(void){
        printk("kure_init\n");
        return 0;
}

static void kure_exit(void){
        printk("kure_exit\n");
}

module_init(kure_init);
module_exit(kure_exit);
Makefile
KERNEL_DIR = /lib/modules/$(shell uname -r)/build
BUILD_DIR := $(shell pwd)
VERBOSE   := 0
obj-m := simple_kernelmodule.o
all:
        make -C $(KERNEL_DIR) SUBDIRS=$(BUILD_DIR) KBUILD_VERBOSE=$(VERBOSE) modules
clean:
        rm -rf  *.o *.ko *.mod.c *.symvers *.order .tmp_versions .helloworld.*

実行

# make
# insmod simple_kernelmodule.ko

実行結果(/var/log/syslog)

Aug 13 02:30:43 ubuntu kernel: [  109.905030] kure_init
Aug 13 02:30:48 ubuntu kernel: [  114.971318] kure_exit
1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3