“__this_module”变量的内存分配在哪里?
Where is the memory allocation of "__this_module" variable?
来自 <linux/module.h>
:
#ifdef MODULE
#define MODULE_GENERIC_TABLE(gtype,name) \
extern const struct gtype##_id __mod_##gtype##_table \
__attribute__ ((unused, alias(__stringify(name))))
extern struct module __this_module;
#define THIS_MODULE (&__this_module)
#else /* !MODULE */
#define MODULE_GENERIC_TABLE(gtype,name)
#define THIS_MODULE ((struct module *)0)
#endif
我可以看到“extern struct module __this_module;
”只是 __this_module
的声明,而不是 __this_module
的定义。那么__this_module
的内存分配在哪里呢?我在 kernel
代码中找不到它。
根据an obscure and dark spot in the LKML...
Does this mean that the module structure (struct module) and it's various
ubstructures are filled in by insmod?
Regards,
Naren
On Sun, 5 Nov 2000, Tigran Aivazian wrote:
On Sun, 5 Nov 2000, Naren Devaiah wrote:
>
>
I've looked in the 2.4.0-pre10 source tree and found it defined as
extern struct module __this_module;
in module.h (among other files), but where is it actually defined?
它不是——当然是魔法 :)。它的工作方式是让 insmod
以 &__this_module 解决指向的方式安排事情
模块地址 space 的开头,恰好包含 'struct
模块'在开头。
此致,
蒂格兰
Follow-up...
On Sun, 5 Nov 2000, Naren Devaiah wrote:
Does this mean that the module structure (struct module) and it's various
substructures are filled in by insmod?
Regards,
Naren
是的,部分,即看看 sys_create_module() 和
sys_init_module() 系统调用,它们在kernel/module.c
sys_create_module() 只是分配 space 并将模块链接到列表中,但是 sys_init_module() 从用户 space 传递了一个 'struct module'
其内容经过严格验证(不要相信任何人!),然后安装到
一个真正的内核 'struct module' 和模块的 init_module() 例程是
已调用。
此致,
蒂格兰
来自 <linux/module.h>
:
#ifdef MODULE
#define MODULE_GENERIC_TABLE(gtype,name) \
extern const struct gtype##_id __mod_##gtype##_table \
__attribute__ ((unused, alias(__stringify(name))))
extern struct module __this_module;
#define THIS_MODULE (&__this_module)
#else /* !MODULE */
#define MODULE_GENERIC_TABLE(gtype,name)
#define THIS_MODULE ((struct module *)0)
#endif
我可以看到“extern struct module __this_module;
”只是 __this_module
的声明,而不是 __this_module
的定义。那么__this_module
的内存分配在哪里呢?我在 kernel
代码中找不到它。
根据an obscure and dark spot in the LKML...
Does this mean that the module structure (struct module) and it's various ubstructures are filled in by insmod?
Regards, Naren
On Sun, 5 Nov 2000, Tigran Aivazian wrote:
On Sun, 5 Nov 2000, Naren Devaiah wrote: > >
I've looked in the 2.4.0-pre10 source tree and found it defined as extern struct module __this_module; in module.h (among other files), but where is it actually defined?
它不是——当然是魔法 :)。它的工作方式是让 insmod 以 &__this_module 解决指向的方式安排事情 模块地址 space 的开头,恰好包含 'struct 模块'在开头。
此致, 蒂格兰
Follow-up...
On Sun, 5 Nov 2000, Naren Devaiah wrote:
Does this mean that the module structure (struct module) and it's various substructures are filled in by insmod?
Regards, Naren
是的,部分,即看看 sys_create_module() 和 sys_init_module() 系统调用,它们在kernel/module.c
sys_create_module() 只是分配 space 并将模块链接到列表中,但是 sys_init_module() 从用户 space 传递了一个 'struct module' 其内容经过严格验证(不要相信任何人!),然后安装到 一个真正的内核 'struct module' 和模块的 init_module() 例程是 已调用。
此致, 蒂格兰