module_init(), module_exit() をみる
モジュールのロード/アンロードで使われているらしい
module_init(), module_exit() をみる。
/usr/src/linux-2.6.16/include/linux/init.h をみる
/** * module_init() - driver initialization entry point * @x: function to be run at kernel boot time or module insertion * * module_init() will either be called during do_initcalls (if * builtin) or at module insertion time (if a module). There can only * be one per module. */ #define module_init(x) __initcall(x); /** * module_exit() - driver exit entry point * @x: function to be run when driver is removed * * module_exit() will wrap the driver clean-up code * with cleanup_module() when used with rmmod when * the driver is a module. If the driver is statically * compiled into the kernel, module_exit() has no effect. * There can only be one per module. */ #define module_exit(x) __exitcall(x);
マクロ関数だった。
ふむふむ。
/usr/src/linux-2.6.16/include/linux/module.h をみる
Hello, Worldプログラムでは
あとひとつ、module.hをインクルードしているので、みてみる。
module構造体に、module_initでポインタが用意されている。
ふむふむ。
struct module { enum module_state state; /* Member of list of modules */ struct list_head list; /* Unique handle for this module */ char name[MODULE_NAME_LEN]; /* Sysfs stuff. */ struct module_kobject mkobj; struct module_param_attrs *param_attrs; const char *version; const char *srcversion; /* Exported symbols */ const struct kernel_symbol *syms; unsigned int num_syms; const unsigned long *crcs; /* GPL-only exported symbols. */ const struct kernel_symbol *gpl_syms; unsigned int num_gpl_syms; const unsigned long *gpl_crcs; /* Exception table */ unsigned int num_exentries; const struct exception_table_entry *extable; /* Startup function. */ int (*init)(void); /* If this is non-NULL, vfree after init() returns */ void *module_init; /* Here is the actual code + data, vfree'd on unload. */ void *module_core; /* Here are the sizes of the init and core sections */ unsigned long init_size, core_size; /* The size of the executable code in each section. */ unsigned long init_text_size, core_text_size; /* Arch-specific module values */ struct mod_arch_specific arch; /* Am I unsafe to unload? */ int unsafe; /* Am I GPL-compatible */ int license_gplok; #ifdef CONFIG_MODULE_UNLOAD /* Reference counts */ struct module_ref ref[NR_CPUS]; /* What modules depend on me? */ struct list_head modules_which_use_me; /* Who is waiting for us to be unloaded */ struct task_struct *waiter; /* Destruction function. */ void (*exit)(void); #endif #ifdef CONFIG_KALLSYMS /* We keep the symbol and string tables for kallsyms. */ Elf_Sym *symtab; unsigned long num_symtab; char *strtab; /* Section attributes */ struct module_sect_attrs *sect_attrs; #endif /* Per-cpu data. */ void *percpu; /* The command line arguments (may be mangled). People like keeping pointers to this stuff */ char *args; };