017_linux内核导出符号

本文介绍了如何在Linux内核中导出符号,通过示例代码`export_module.c`和`test.c`阐述了导出模块的创建和使用。测试步骤包括:先加载导出模块,拷贝Module.symvers文件,然后加载测试模块。在卸载时,必须先卸载使用导出模块的驱动,再卸载导出模块,否则会导致错误。
摘要由CSDN通过智能技术生成

一、导出模块的源码

export_module.c

#include <linux/kernel.h>

#include <linux/init.h>

#include <linux/module.h>





#define __DEBUG__  

#ifdef  __DEBUG__  

#define DEBUG(format,...) printk("File: "__FILE__", Line: %05d, Func: %s ++++ "format"\n", __LINE__,__func__, ##__VA_ARGS__)  

#else  

#define DEBUG(format,...)  

#endif 



MODULE_LICENSE("GPL");



int export_mult(int x,int y)

{

	DEBUG("enter export_mult");



	return x*y;

}





int export_div(int x,int y)

{

	DEBUG("enter export_mult");



	return x/y;

}



EXPORT_SYMBOL(export_mult);

EXPORT_SYMBOL(export_div);



static int __init export_module_init(void)

{

	DEBUG("enter export_mod
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值