linux内核模块基础知识
来源:互联网 发布:java txt换行符 编辑:程序博客网 时间:2024/05/29 18:36
#include<linux/module.h>
#include<linux/init.h> -----这两个头文件所有模块都有
MODULE_LICENSE(“Dual BSD/GPL”); ----声明许可证
MODULE_AUTHOR(“XXX”) ----作者
EXPORT_SYMBOL(func) ----将给定函数func设置为其他模块可调用
使用方法{
1)在模块函数定义之后使用EXPORT_SYMBOL(函数名) 模块A
2)在掉用该函数的模块中使用extern对之声明 模块B
3)首先加载定义该函数的模块A,再加载调用该函数的模块B
mode A.c static int func1(void)
{
printk("In Func: %s.../n",__func__);
return 0;
}
EXPORT_SYMBOL(func1);
modeB.c extern int func1(void);
static int func2(void)
{
func1();
printk("In Func: %s.../n",__func__);
return 0;
}
#insmod ./mod1.ko (执行)
#insmod ./mod2.ko
#rmmod mod2
#rmmod mod1
}
module_param(name,type,perm) -------向当前模块传入参数
{
name:变量名type:数据类型(int,charp)perm:读写
static char *who= "world";
static int times = 1;
module_param(times,int,S_IRUSR);
module_param(who,charp,S_IRUSR);
# insmod hello who="world" times=5 (执行)
}
insmod xxx.ko
rmmod xxx.ko
Hello.c
#include<linux/module.h>
#include<linux/init.h>
static int hello_init(void)
{
printk(KERN_ALERT "hello world.\n");
return 0;
}
static int hello_exit(void)
{
printk(KERN_ALERT "good bye.\n")
}
module_init(hello_init);
module_exit(hello_exit);
Makefile
ifneq ($(KERNELRELEASE),)
obj-m := hello.o
else
KDIR := /home/linux-2.6.29
all:
make -C $(KDIR) M=$(PWD) modules ARCH=arm CROSS_COMPILE=arm-linux-
clean:
rm -f *.ko *.o *.mod.o *.mod.c *.symvers modul*
endif
insmod hello.ko
rmmod hello.ko
- linux内核模块基础知识
- Linux内核模块的编译基础知识
- Linux内核模块的编译基础知识
- Linux内核模块的编译基础知识
- Linux内核模块的编译基础知识
- Linux内核模块的编译基础知识
- linux模块基础知识
- linux内核基础知识总结
- Linux内核基础知识
- Linux内核模块:模块参数
- Linux 内核模块
- linux内核模块加载
- Linux内核模块
- Linux内核模块编程
- Linux内核模块编程
- Linux内核模块使用指南
- linux内核模块解析
- Linux内核驱动模块
- hibernate-入门xml配置文件
- MySQL内连接
- Given-When-Then
- HTML5表单新增属性
- hadoop2.7.3集群安装配置
- linux内核模块基础知识
- android contentProvider例子
- 虚拟机中 CentOS7网络配置
- Python网络爬虫——Beautiful Soup库
- hive的安装
- Mybatis学习笔记(二)-Mybatis配置文件与映射文件详解
- 一些实用的开源炫酷框架—值得你去了解
- VS2013 密钥
- Leetcode 76. Minimum Window Substring