QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4525|回复: 3

module_init()宏有什么作用?

[复制链接]
发表于 2003-10-21 15:40:43 | 显示全部楼层 |阅读模式
编写内核模块时使用module_init宏与不用该宏而直接只使用init_module()有什么区别?
发表于 2003-10-21 23:05:19 | 显示全部楼层
no big difference.  allow u use different names
回复

使用道具 举报

发表于 2003-10-23 14:26:06 | 显示全部楼层
这两天,我看了一下linux2.6的source,也看到module_init(x)这个宏,当相应模块作为内核的一部分被编译的时候,其展开是:
[code:1]
#define module_init(x)        __initcall(x);

#define __initcall(fn) device_initcall(fn)
#define device_initcall(fn)                __define_initcall("6",fn)
#define __define_initcall(level, fn) \
static initcall_t __initcall_##fn __attribute_used__ \
__attribute__((__section__(".initcall" level ".init"))) = fn[/code:1]
在kernel启动的时候通过do_initcalls函数调用初始化函数x。
系统一共提供了7个级别的init section,包括在__initcall_start到__initcall_end区间里,你可以在arch/i386/kernel/vmlinux.lds.S中找到。
如果module_init相应的模块作为模块动态加载,则和dragonfly说的一样。
回复

使用道具 举报

发表于 2003-10-23 20:43:28 | 显示全部楼层
answer from jjww is more complete. when compiled to kernel (Y), it will be executed and discard, so this is why u see "free unused memory xxk" when u boot u system.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-9-28 04:18 , Processed in 0.056882 second(s), 16 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表