jump to navigation

linux kernel source tracing (1) March 8, 2007

Posted by TSAI HONG-BIN in Linux.
trackback

There are macros scattered all around the kernel source code. I believe that for newbies like me, the first contact must be quite scaring. This time I started from seeking for the code that loads/decompresses/mounts initial ramdisk. Basically, they are all located in ~/linux-2.6.20/init/. There are less than 10 files within, kindda a good place to start.

During the trace, I’m terribly bugged by hundreds of macros, storage classes and type synonym. Most of them are defined in ~/linux-2.6.20/include/linux/init.h. noted as follows:

macros:

#define __init __attribute__ ((__session__ (“.init.text”)))

#define __exit __attribute__ ((__session__(“.exit.text”)))

As for the purpose of these macros, go check http://kernelnewbies.org/FAQ/InitExitMacros. There is another strange macro __setup(), people kept asking the meaning of this macro in kernel-related mailing lists. Here you may find some helpful info. (In simplified chinese) http://www.linuxforum.net/forum/showflat.php?Cat=&Board=linuxK&Number=470221&page=&view=&sb=&o=&vc=1 And here is a English thread http://mail.nl.linux.org/kernelnewbies/2005-07/msg00172.htmlThe definition is shown below

#define __setup(str, fun) __setup_param(str, fn, fn, 0)

the definition of __setup_param is here

#define __setup_param(str, unique_id, fn, early) \
static char __setup_str_##unique_id[] __initdata = str; \
static struct obs_kernel_param __setup_##unique_id \
__attribute_used__ \
__attribute__((__section__(“.init.setup”))) \
__attribute__((aligned((sizeof(long))))) \
= { __setup_str_##unique_id, fn, early }

in short, __setup replaces the default value matched with str with fun, which is assigned at kernel command line (ex. in grub.conf: kernel “blah blah”).

Ooops! did you see a prefix obs? Right, it’s an abbreviation for “obsolete,” which implies that the code here is out of time. Knowledge almost died before I can manage to learn it. So, the up-to-date functionality of old “kernel_param” is now handled by “module_param,” defined in ~/linux-2.6.20/include/linux/moduleparam.h.

Now, what does __attribute__ mean? Well it’s a GCC keyword. Please see this http://gcc.gnu.org/onlinedocs/gcc-4.0.0/gcc/Variable-Attributes.html for detail.

.. Gosh, I don’t even start to cut in the topic yet…

Advertisements

Comments»

No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: