Embedded 版 (精华区)

发信人: snows (花自飘零水自流), 信区: Embedded
标  题: The do_initcalls() Function
发信站: 哈工大紫丁香 (2004年03月16日13:30:15 星期二), 站内信件

The do_initcalls() Function
Do_initcalls() is located in init/main.c.

Do_initcalls() runs the list of functions registered with the __initcall
attribute, which usually only applies to compiled-in kernel modules and
device drivers. The __initcall attribute eliminates the need for a
hand-maintained list of device driver initialization functions.

The __initcall mechanism works by creating a constant function pointer in a
memory section called .initcall.init, that points to the initialization
function itself. When the kernel image is linked, the linker organizes all of
these function pointers into a single memory section, and do_initcalls()
invokes them in the order they appear there.

The macros and type definitions that implement the __initcall attribute are
shown in Figure 9; the code for do_initcalls() is shown in Figure 10.

typedef int (*initcall_t)(void);
typedef void (*exitcall_t)(void);

#define __initcall(fn)  \
    static initcall_t __initcall_##fn __init_call = fn

#define __init_call __attribute__ ((unused,__section__ (".initcall.init")))


Figure 9. The __initcall macros and typedefs.

extern initcall_t __initcall_start, __initcall_end;

static void __init do_initcalls(void)
{
    initcall_t *call;

    call = &__initcall_start;
    do {
        (*call)();
        call++;
    } while (call < &__initcall_end);

    flush_scheduled_tasks();
}

Figure 10. The do_initcalls() function.
  
--
-
 ╭────────────────────────────╮
 │   风萧传瑟声,叶落根深处,青阶入野无归途,他乡不知顾   │
 │   泣下问和谁,叹者行已暮,寒眉傲骨今尚在,奈何入凡土   │
 ╰────────────────────────────╯
                                                                             

※ 来源:·哈工大紫丁香 bbs.hit.edu.cn·[FROM: 202.118.229.154]
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:4.859毫秒