module_exit源码分析
上一章节我们讲述了module_init的源码分析及调用流程,本章节我们一块来看一下module_exit(x)这个函数。参考代码:linux/include/linux/module.h。
/**
* module_exit() - driver exit entry point
* @x: function to be run when driver is removed
*
* module_exit() will wrap the driver clean-up code
* with cleanup_module() when used with rmmod when
* the driver is a module. If the driver is statically
* compiled into the kernel, module_exit() has no effect.
* There can only be one per module.
*/
#define module_exit(x) __exitcall(x);
注释:当驱动程序是模块时,当与rmmod一起使用时,module_exit()将使用cleanup_module()包装驱动程序清理代码。如果驱动程序是静态编译到内核中的,则module_exit()不起作用。每个模块只能有一个。
我们继续看__exitcall(fn)的定义:
#define __exitcall(fn) \
static exitcall_t __exitcall_##fn __exit_call = fn
继续看exitcall_t的定义:
typedef void (*exitcall_t)(void);
它是一个函数指针,所指向的函数只有一个void类型的参数,返回类型为void。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?