最簡單的核心模組例子

2021-08-31 05:42:53 字數 1030 閱讀 5471

#include #include #include static int __init hello_init(void) 

static void __exit hello_exit(void)

module_init(hello_init);

module_exit(hello_exit);

•static int __init hello_init(void)  

•static void __exit hello_exit(void)

–static

宣告,因為這種函式在特定檔案之外沒有其它意義

–__init

標記,

該函式只在初始化期間使用。模組裝載後,將該函式佔

用的記憶體空間釋放 –

__exit

標記該**僅用於模組解除安裝。 •

init/exit

–巨集:module_init/module_exit

–宣告模組初始化及清除函式所在的位置

–裝載和解除安裝模組時,核心可以自動找到相應的函式

module_init(hello_init);

module_exit(hello_exit);

•makefile

檔案

obj-m := hello.o

all:

make -c /lib/modules/$(shell uname -r)/build m=$(shell pwd) modules

clean:

make -c /lib/modules/$(shell uname -r)/build m=$(shell pwd) clean

•module includes more files

obj-m:=hello.o

hello-objs := a.o b.o

• 相關命令

–lsmod

–insmod hello.ko

–rmmod hello.ko

拆解最簡單的核心模組(隨記)

include include static int init hello init void static void exit hello exit void module license dual bsd gpl module author zhou module init hello init...

乙個最簡單的Linux核心模組

include include static int init hello init void static void exit hello exit module init hello init module exit hello exit module license gpl 這個最簡單的核心模...

最簡單的remoting的例子

節選部分 備查 1 遠端物件 建立類庫專案 remoteobject using system namespace remoteobject 2 服務端 建立控制台專案 remoteserver using system using system.runtime.remoting namespace...