Some confusing code of the kernel

Janis Danisevskis werwurm at snafu.de
Wed May 28 11:12:10 CEST 2014


Am 28.05.2014 00:55, schrieb Adam Lackorzynski:
> Hi,
> 
> On Tue May 27, 2014 at 13:51:31 -0800, Yuxin Ren wrote:
>> Now I am learning the kernel code of Fiasco.
>> But as I do not know much about C++, I feel confused about some code.
> 
> Some C++ knowledge is required I think...

Also Fiasco is written in a strange dialect that is not easily
comprehensible even if you are acquainted with C++.
"EXTENSION" for example is a keyword of the fiasco specific preprocessor
and does neither belong to C++ nor the C-preprocessor.

Hint:
When I browse the fiasco code I usually extract the preprocessed files -
the ones that end up in "<your fiasco build dir>/auto" - then use a sed
script to remove the #line directives and have them indexed by an IDE
(Eclipse CDT in my case).
That way you will find out that actually pretty decent C++ code hides
under the "preprocess"-clutter. ;-)

This helps me to browse and understand fiasco code. If you want to
modify it there is no way around getting used to this dialect though.

Janis

> 
>> In the file obj_space-virt.cpp, we have such code
>> EXTENSION class Generic_obj_space : Obj_space_virt<Generic_obj_space<SPACE>
>>>
>>
>> And similarly, in the file obj_space-phys.cpp, we have
>> EXTENSION class Generic_obj_space : Obj_space_phys<Generic_obj_space< SPACE
>>>>
>>
>> 1. What's the meaning of these tow line code? Does it mean that the class
>> Generic_obj_space
>> inherit from both class Obj_space_virt and class Obj_space_phys?
> 
> It inherits from just Obj_space_phys which however takes another class
> as a parameter to implement some specific functionality at compile time.
> 
>> 2. I note that class Obj_space_virt and Obj_space_phys have some methods
>> with the same name,
>> such as lookup_local method. When such a method is called, how can I know
>> which class is invoked?
> 
> That depends on the type of the object the method is called on. In this
> particular case with obj_space-*.cpp, only one file of the two files is
> compiled, so only one version of Generic_obj_space can ever exist.
> 
> 
> 
> Adam
> 





More information about the l4-hackers mailing list