Where is the memory allocation of the variable __this_module?

From <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 

I see that " extern struct module __this_module; " is just a declaration of __this_module , but not a definition of __this_module . So where is the __this_module memory __this_module ? I can not find it in kernel code.

+5
source share
1 answer

According to the obscure and dark spot in LKML ...

Does this mean that the module structure (structural module) and its various ubstructures are filled with insmod?

Regards, Naren

On Sunday, November 5, 2000, Tigran Ayvazyan wrote:

On Sunday, November 5, 2000, Naren Devaya wrote:>>

I looked at the source tree 2.4.0-pre10 and found that it was defined as an extern struct __this_module module; in module.h (among other files), but where is it defined?

no - it's magic, of course :). How it works, for insmod to arrange things in such a way that & __ this_module allows you to point to the beginning of the address space of the module, which, as it turned out, contains the 'struct module' at the beginning.

Regards, Tigran

Follow-up ...

On Sunday, November 5, 2000, Naren Devaya wrote:

Does this mean that the module structure (structural module) and its various substructures are filled with insmod?

Regards, Naren

Yes, in part, that is, take a look at sys_create_module () and sys_init_module (), they are in kernel / module.c

sys_create_module () just allocates space and links the module to a list, but sys_init_module () is passed a 'struct module' from a user space whose content is hard-checked (no one trusts!), and then installed in the module of the real module 'struct module' and the init_module module ( ) is called.

Regards, Tigran

+4
source

Source: https://habr.com/ru/post/1235331/


All Articles