Kernel Modul erstellen

Aus Xinux Wiki
Version vom 26. Juni 2023, 12:07 Uhr von Thomas.will (Diskussion | Beiträge) (Die Seite wurde neu angelegt: „=Module Quellcode hello.c= <pre> #include <linux/init.h> #include <linux/module.h> #include <linux/kernel.h> static int __init hello_init(void) { printk(K…“)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Zur Navigation springen Zur Suche springen

Module Quellcode hello.c

#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>

static int __init hello_init(void) {
    printk(KERN_INFO "Hello, World!\n");
    return 0;
}

static void __exit hello_exit(void) {
    printk(KERN_INFO "Goodbye, World!\n");
}

module_init(hello_init);
module_exit(hello_exit);

MODULE_LICE/NSE("GPL");
MODULE_DESCRIPTION("A simple Hello World module");
MODULE_AUTHOR("Your Name");

Makefile

obj-m += hello.o

all:
	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

Kompilierung

  • make

Laden

  • insmod hello

Entladen

  • rmmod hello