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。