module_exit源码分析
  qrJHiMhufrJ3 2023年11月13日 15 0


        上一章节我们讲述了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。

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月13日 0

暂无评论

推荐阅读
  UYSNSBVoGd8R   2023年12月08日   13   0   0 引脚#include#define
qrJHiMhufrJ3
最新推荐 更多