module_init的调用过程

不知不觉,其实也已经做bsp快三年了. 有些知识点,开始大概知道一点,但是还是比较抽象的. 经过这么长时间的使用,还是觉得有必要好好整理一下的.比如module_init.

下面的code是在Android p,kernel/msm-4.14.

首先是module_init(x)函数.在kernel/msm-4.14/include/linux/module.h中:

/**
 * module_init() - driver initialization entry point
 * @x: function to be run at kernel boot time or module insertion
 *
 * module_init() will either be called during do_initcalls() (if
 * builtin) or at module insertion time (if a module).  There can only
 * be one per module.
 */
#define module_init(x)	__initcall(x);

/**
 * 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);

注释中说,如果是常驻的driver,那么会在do_initcalls的时候调到module_init添加的函数.那么先看看do_initcalls怎么调过来的吧. 在kernel/msm-4.14/init/main.c中有do_initcalls().  实际上前面还有这样的调用过程:start_kernel->rest_init->kernel_init->kernel_init_freeable->do_basic_setup->do_initcalls.

static void __init do_initcalls(void)
{
	int level;

	for (level = 0; level < ARRAY_SIZE(initcall_levels) - 1; level++)
		do_initcall_level(leve
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值