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。

posted @   Coder个人博客  阅读(63)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
点击右上角即可分享
微信分享提示