LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 10-05-2008, 10:06 AM   #1
smoking81
LQ Newbie
 
Registered: Sep 2008
Posts: 8

Rep: Reputation: 0
A question about MODULE macro


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
 
Old 10-05-2008, 10:36 AM   #2
smoking81
LQ Newbie
 
Registered: Sep 2008
Posts: 8

Original Poster
Rep: Reputation: 0
I wrote things which are not correct I guess: if a config. flag evaluets to "m" the corresponding file is compiled as a module, otherwise it's compiled normally.. But unfortunately my problems with the MODULE macro aren't solved yet...


PS: Do you know a good tutorial/overview of linux's makefile? thanks! Bye
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
openoffice macro question tanoatlq Linux - Software 9 05-05-2008 02:44 PM
Use of MODULE macro while compiling a module fssengg Linux - Newbie 0 03-31-2006 07:13 AM
Yet Another Module Question Frenchyp Linux - Newbie 3 01-18-2006 02:44 AM
#defining a macro inside a macro? saravkrish Programming 1 05-24-2005 09:48 PM
module question wr3ck3d Slackware 2 02-27-2003 11:28 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 03:33 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration