I wrote that years ago for the LK project.

Basically it was to call C++ constructors, which are put into a
special section. On a normal OS, this is handled by the loader, but in
this case there is no loader so it called explicitly at the start of
the kernel. If there's no C++ in the system it wont matter at all.

Travis

On Tue, Sep 27, 2011 at 11:11 PM, ivan <ivan.9ki...@gmail.com> wrote:
> William,
> Thanks for the reply.
> Basically, I understand it's useful for the constructor.
> I'm confused about why we should call it explicitly in the code,
> because in the other codes, we needn't do this, maybe the gcc will
> handle it.
>
> On Sep 28, 10:21 am, "William W.-Y. Liang" <wyli...@mail.ntut.edu.tw>
> wrote:
>> Hi, Ivan,
>>
>> __ctor_list and __ctor_end are defined by the linker script, for a special
>> section for 'constructors' defined in the kernel.
>>
>> William Lianghttp://www.ntut.edu.tw/~wyliang
>>
>> 2011/9/27 ivan <ivan.9ki...@gmail.com>
>>
>>
>>
>>
>>
>>
>>
>> > Hi, guys
>>
>> > When I read the code of lk/kernel/main.c, I feel confused about using
>> > "call_constructors()" during the
>> > initialization, as below.  Could anyone interpret it to me? Your kind
>> > help will be appreciated very much.
>>
>> > ******************************
>> > void kmain(void)
>> > {
>> >        // get us into some sort of thread context
>> >        thread_init_early();
>>
>> >        .....
>>
>> >        call_constructors();
>> >        ......
>> > }
>>
>> > static void call_constructors(void)
>> > {
>> >        void **ctor;
>> >        ctor = &__ctor_list;
>> >        while(ctor != &__ctor_end) {
>> >                void (*func)(void);
>>
>> >                func = (void (*)())*ctor;
>>
>> >                func();
>> >                ctor++;
>> >        }
>> > }
>>
>> > ******************************
>>
>> > --
>> > unsubscribe: android-kernel+unsubscr...@googlegroups.com
>> > website:http://groups.google.com/group/android-kernel
>
> --
> unsubscribe: android-kernel+unsubscr...@googlegroups.com
> website: http://groups.google.com/group/android-kernel

-- 
unsubscribe: android-kernel+unsubscr...@googlegroups.com
website: http://groups.google.com/group/android-kernel

Reply via email to