第1页 / 共1页
linux内核模块思维导图.pdf
{
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_attribute *modinfo_attrs;
const char *version;
const char *srcversion;
struct kobject *holders_dir;
/* Exported symbols */
const struct kernel_symbol *syms;
const unsigned long *crcs;
unsigned int num_syms;
/* Kernel parameters. */
struct kernel_param *kp;
unsigned int num_kp;
/* GPL-only exported symbols. */
unsigned int num_gpl_syms;
const struct kernel_symbol *gpl_syms;
const unsigned long *gpl_crcs;
#ifdef CONFIG_UNUSED_SYMBOLS
/* unused exported symbols. */
const struct kernel_symbol *unused_syms;
const unsigned long *unused_crcs;
unsigned int num_unused_syms;
/* GPL-only, unused exported symbols. */
unsigned int num_unused_gpl_syms;
const struct kernel_symbol *unused_gpl_syms;
const unsigned long *unused_gpl_crcs;
#endif
/* symbols that will be GPL-only in the near future. */
const struct kernel_symbol *gpl_future_syms;
const unsigned long *gpl_future_crcs;
unsigned int num_gpl_future_syms;
/* Exception table */
unsigned int num_exentries;
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 int init_size, core_size;
/* The size of the executable code in each section. */
unsigned int init_text_size, core_text_size;
/* Size of RO sections of the module (text+rodata) */
unsigned int init_ro_size, core_ro_size;
/* Arch-specific module values */
struct mod_arch_specific arch;
unsigned int taints; /* same bits as kernel:tainted */
#ifdef CONFIG_GENERIC_BUG
/* Support for BUG */
unsigned num_bugs;
struct list_head bug_list;
struct bug_entry *bug_table;
#endif
#ifdef CONFIG_KALLSYMS
/*
* We keep the symbol and string tables for kallsyms.
* The core_* fields below are temporary, loader-only (they
* could really be discarded after module init).
*/
Elf_Sym *symtab, *core_symtab;
unsigned int num_symtab, core_num_syms;
char *strtab, *core_strtab;
/* Section attributes */
struct module_sect_attrs *sect_attrs;
/* Notes attributes */
struct module_notes_attrs *notes_attrs;
#endif
#ifdef CONFIG_SMP
/* Per-cpu data. */
void __percpu *percpu;
unsigned int percpu_size;
#endif
/* The command line arguments (may be mangled). People
like
keeping pointers to this stuff */
char *args;
#ifdef CONFIG_TRACEPOINTS
struct tracepoint * const *tracepoints_ptrs;
unsigned int num_tracepoints;
#endif
#ifdef HAVE_JUMP_LABEL
struct jump_entry *jump_entries;
unsigned int num_jump_entries;
#endif
#ifdef CONFIG_TRACING
const char **trace_bprintk_fmt_start;
unsigned int num_trace_bprintk_fmt;
#endif
#ifdef CONFIG_EVENT_TRACING
struct ftrace_event_call **trace_events;
unsigned int num_trace_events;
#endif
#ifdef CONFIG_FTRACE_MCOUNT_RECORD
unsigned long *ftrace_callsites;
unsigned int num_ftrace_callsites;
#endif
#ifdef CONFIG_MODULE_UNLOAD
/* What modules depend on me? */
struct list_head source_list;
/* What modules do I depend on? */
struct list_head target_list;
/* Who is waiting for us to be unloaded */
struct task_struct *waiter;
/* Destruction function. */
void (*exit)(void);
struct module_ref {
unsigned int incs;
unsigned int decs;
} __percpu *refptr;
#endif
#ifdef CONFIG_CONSTRUCTORS
/* Constructor functions. */
ctor_fn_t *ctors;
unsigned int num_ctors;
#endif
}
enum module_state
{
MODULE_STATE_LIVE,
MODULE_STATE_COMING,
MODULE_STATE_GOING,
};
struct
modules
struct module_stat state
struct list_head list
COMING,
STATE_LIVE.
init
,
init
init
init
MODULE_STATE_
MODULE_
MODULE_STATE_GOING
module * modules
64 - sizeof(unsigned int long)
char name[MODULE_NAME_LEN];
module/holder
sysfs
holders_dir
/sys/module/
/* Sysfs stuff. */
struct module_kobject mkobj;
struct module_attribute *modinfo_attrs;
const char *version;
const char *srcversion;
struct kobject *holders_dir;
/* Exported symbols */
const struct kernel_symbol *syms;
const unsigned long *crcs;
unsigned int num_syms;
module_param/module_param_array/module_
param_string
name/module/
/sys/module/module_
/* Kernel parameters. */
struct kernel_param *kp;
unsigned int num_kp;
struct module
/* GPL-only exported symbols. */
unsigned int num_gpl_syms;
const struct kernel_symbol *gpl_syms;
const unsigned long *gpl_crcs;
/* symbols that will be GPL-only in the near future. */
const struct kernel_symbol *gpl_future_syms;
const unsigned long *gpl_future_crcs;
unsigned int num_gpl_future_syms;
/* Exception table */
unsigned int num_exentries;
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 int init_size, core_size;
/* The size of the executable code in each section. */
unsigned int init_text_size, core_text_size;
/* Size of RO sections of the module (text+rodata) */
unsigned int init_ro_size, core_ro_size;
MODULE_LICENSE(
)
data+
/* Arch-specific module values */
struct mod_arch_specific arch;
unsigned int taints; /* same bits as kernel:tainted */
by Alexander
#ifdef MODULE
//
/**
* 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);
#else
//
/* Each module must use one module_init(). */
#define module_init(initfn) \
static inline initcall_t __inittest(void) \
{ return initfn; } \
int init_module(void) __attribute__((alias(#initfn)));
1.
2.
module*
mmap
.ko
3.
mod->init
mod
struct
insmod
struct module*
struct module
fn(void)/void exit_fn(void)
int init_
module_init/module_exit
#define module_init(initfn) \
static inline initcall_t __inittest(void) \
{ return initfn; } \
int init_module(void) __attribute__((alias(#initfn)));
1.
2.
modprobe
.ko
insmode
init_module
insmod
modprobe
1
kernel 2.4
alias
initfn
init_module
init_module
load module
GPL
module_param
mod->init=initfn,
module_init(initfn),
mod->module_init
+
+
core
core.taints
init_module
module“
struct module*
STATE_COMING,
mmap
elf
load_info
“.gnu.linkonce.this_
core_size, init_size
setup_load_info
core
init
module_init,module_core
module->init
module->state
MODULE_
module->init
module_mutex
moudles
模
块
模
块
初
始
化
函
数
模
块
的
初
始
化
函
数
和
退
出
函
数
,
要
传
入
的
函
数
原
型
为
:
初
始
化
相
关
的
内
容
直
接
编
译
进
入
内
核
编
译
成
模
块
运
行
方
式
直
接
编
译
进
内
核
生
成
模
块
化
的
代
码
,
生
成
文
件
,
然
后
使
用
或
者
命
令
加
载
进
入
内
核
初
始
化
相
关
的
代
码
在
此
种
方
式
种
是
编
译
进
入
内
核
镜
像
由
内
核
镜
像
直
接
加
载
此
种
方
式
是
以
模
块
化
的
方
式
加
入
进
内
核
当
我
们
使
用
或
者
命
令
加
载
模
块
时
候
,
会
调
用
做
为
函
数
入
口
重
点
在
第
三
句
,
是
使
用
将
变
名
为
,
我
们
知
道
,
版
本
之
前
都
是
用
来
加
载
模
块
的
。
这
样
做
应
该
是
为
了
不
用
修
改
的
那
块
代
码
吧
。
子
主
题
模
块
加
载
的
过
程
加
载
步
骤
权
限
检
查
(
用
户
权
限
和
模
块
是
否
可
执
行
)
拷
贝
模
块
,
把
二
进
制
模
块
内
容
从
用
户
空
间
拷
贝
到
(
先
拷
贝
到
)
开
头
的
内
核
空
间
去
(
过
程
实
际
上
是
进
行
了
一
个
映
射
,
把
文
件
映
射
到
内
核
空
间
去
)
执
行
其
中
为
类
型
关
键
数
据
结
构
模
块
状
态
标
示
三
种
模
块
状
态
:
正
常
状
态
模
块
已
经
完
成
,
在
卸
载
模
块
之
前
;
在
执
行
模
块
的
真
正
之
前
会
置
为
正
在
状
态
,
完
成
之
后
会
置
为
卸
载
过
程
中
会
置
为
模
块
在
加
载
进
入
内
核
之
后
会
以
链
表
的
形
式
存
储
在
开
头
的
内
存
中
,
可
以
以
为
索
引
查
找
到
所
有
加
载
到
内
存
中
模
块
模
块
的
名
字
,
最
大
长
度
为
:
和
模
块
有
关
的
的
文
件
,
其
中
是
在
文
件
夹
模
块
从
内
核
导
入
的
符
号
表
模
块
参
数
:
由
导
入
,
在
初
始
化
的
时
候
会
把
上
述
导
入
的
参
数
导
入
此
,
来
完
成
内
核
相
关
的
参
数
,
然
后
在
目
录
下
简
历
以
参
数
名
命
名
的
文
件
,
可
以
通
过
此
修
改
导
入
参
数
有
些
参
数
是
预
留
的
,
和
参
数
大
致
相
同
模
块
初
始
化
函
数
,
在
加
载
模
块
的
时
候
会
调
然
后
执
行
此
初
始
化
函
数
,
待
查
询
赋
值
点
,
暂
时
未
找
到
模
块
的
可
执
行
程
序
起
点
数
据
起
点
,
包
括
初
始
化
长
度
,
真
正
的
执
行
长
度
,
初
始
化
只
读
数
据
只
读
数
据
起
点
模
块
架
构
,
指
识
出
模
块
在
的
各
个
处
理
程
序
在
哪
里
,
比
如
标
记
识
是
否
是
标
记
模
块
初
始
化
过
程
中
,
先
调
用
系
统
中
的
函
数
,
把
二
进
制
模
块
中
的
数
据
映
射
到
内
存
中
,
然
后
调
用
函
数
,
把
用
户
空
间
存
放
的
二
进
制
模
块
内
容
拷
贝
到
内
核
空
间
的
结
构
体
中
,
并
且
申
请
内
存
,
此
结
构
体
可
以
解
析
文
件
,
并
且
找
到
模
块
中
的
字
段
所
在
的
索
引
,
然
后
根
据
此
索
引
找
到
真
正
的
模
块
所
在
的
内
存
,
并
且
把
指
针
赋
予
结
构
体
指
针
(
赋
予
结
构
体
指
针
操
作
是
在
起
作
用
,
注
意
此
指
针
中
知
识
藏
了
一
些
数
据
长
度
,
比
如
等
,
实
际
的
和
的
二
进
制
指
针
还
没
有
真
正
赋
予
。
在
调
用
之
前
先
置
为
然
后
调
用
函
数
这
才
是
真
正
的
模
块
初
始
化
函
数
,
初
始
化
函
数
完
成
之
后
,
调
用
大
的
内
核
锁
:
。
把
模
块
信
息
加
入
全
局
参
数
中
,
模
块
初
始
化
完
成
成
功
。
我
们
可
以
正
常
使
用
这
个
模
块
了
模
块
初
始
化
概
述
相关推荐
- 2023年江西萍乡中考道德与法治真题及答案.doc
- 2012年重庆南川中考生物真题及答案.doc
- 2013年江西师范大学地理学综合及文艺理论基础考研真题.doc
- 2020年四川甘孜小升初语文真题及答案I卷.doc
- 2020年注册岩土工程师专业基础考试真题及答案.doc
- 2023-2024学年福建省厦门市九年级上学期数学月考试题及答案.doc
- 2021-2022学年辽宁省沈阳市大东区九年级上学期语文期末试题及答案.doc
- 2022-2023学年北京东城区初三第一学期物理期末试卷及答案.doc
- 2018上半年江西教师资格初中地理学科知识与教学能力真题及答案.doc
- 2012年河北国家公务员申论考试真题及答案-省级.doc
- 2020-2021学年江苏省扬州市江都区邵樊片九年级上学期数学第一次质量检测试题及答案.doc
- 2022下半年黑龙江教师资格证中学综合素质真题及答案.doc