Hello everybody!
I have tried to answer on my own to the following question but didn't succeed... I hope somebody here will be able to help me...
I have a module which has a tristate configuration flag: it can be set to "y", "m" or "n".
The makefile for the module looks like this:
Code:
obj-$(CONFIG_SET_KHVARS) += set_khvars.o
This means that if I choose 'y' or 'm' as a value for my flag, the set_khvars.c file will be compiled as a module while compiling the kernel. This suggests that the actions performed by the kernel are the same for both the values of the flag (= the module to be compiled).
The difference should be in terms of "when" the module is loaded (y=during the system startup, m=upon request by means of insmod or modprobe).
In the code of set_khvars.c I declare 2 functions like:
Code:
set_khvars_init()...
set_khvars_exit()...
and at the end of the same file I have something like:
Code:
#ifdef MODULE
printk(KERN_INFO "set_khvars configured as internal module\n");
module_init(set_khvars_init);
module_exit(set_khvars_exit);
#else
printk(KERN_INFO "set_khvars configured into the kernel\n");
late_initcall(set_khvars_init);
#endif
Now, I have seen that in include/linux/init.h we can find something like (the order is different, but the result is this):
Code:
#ifndef MODULE
#define module_init(x) __initcall(x);
#define __initcall(fn) device_initcall(fn)
#define device_initcall(fn)
__define_initcall("6",fn,6)
#define __define_initcall(level,fn,id) \
static initcall_t __initcall_##fn##id __attribute_used__ \
__attribute__((__section__(".initcall" level ".init"))) = fn
which can in brief br translated like "if the macro MODULE is not defined (and this happens when the config flag evaluates "y"), then module_init() has to be translated with something which has as a result that a pointer to its argument (the initialization function for the module) is put in a special section initcalli.init whose content is checked at every system startup and the corresponding functions invoked". Put in another way, we register the module for being loaded at every system startup.
The same MODULE macro is evaluated in the c file which I mentioned above..
So, my question is: since the configuration flag for every module is set by the user to y,n or m, why do we use a MODULE macro which looks to have a global value? I can guess MODULE is not global and connected in some way with the module's configuration flag actual value, but I couldn't find more hints to understand how this happens::...
Thanks in advance to all of you who'll decide to help me!
bye