linux _setup()

1. system.map分析

 

2.__setup(str, fn)

路径:linux-3.10.x\include\linux\init.h

源码如下

 

/*
 * Only for really core code.  See moduleparam.h for the normal way.
 *
 * Force the alignment so the compiler doesn't space elements of the
 * obs_kernel_param "array" too far apart in .init.setup.
 */
#define __setup_param(str, unique_id, fn, early)			\
	static const char __setup_str_##unique_id[] __initconst	\
		__aligned(1) = str; \
	static struct obs_kernel_param __setup_##unique_id	\
		__used __section(.init.setup)			\
		__attribute__((aligned((sizeof(long)))))	\
		= { __setup_str_##unique_id, fn, early }

#define __setup(str, fn)					\
	__setup_param(str, fn, fn, 0)

 

其中obs_kernel_param如下:

struct obs_kernel_param {
	const char *str;
	int (*setup_func)(char *);
	int early;
};

 

 

 

3.__setup("console=", console_setup)

路径:\linux-3.10.x\kernel\printk.c

展开如下:

 

#define __setup_param("console=", console_setup, console_setup, 0)			\
	static const char __setup_str_##console_setup[] __initconst	\
		__aligned(1) = "console="; \
	static struct obs_kernel_param __setup_##console_setup	\
		__used __section(.init.setup)			\	//使用.init.setup保存相应的数据
		__attribute__((aligned((sizeof(long)))))	\
		= { __setup_str_##console_setup, console_setup, 0 }

#define __setup("console=", console_setup)					\
	__setup_param("console=", console_setup, console_setup, 0)

__setup("console=", console_setup)	//使用.init.setup保存相应的数据
		__attribute__((aligned((sizeof(long)))))	\
		= { __setup_str_##console_setup, console_setup, 0 }

#define __setup("console=", console_setup)					\
	__setup_param("console=", console_setup, console_setup, 0)

__setup("console=", console_setup)


所以struct obs_kernel_param为

 

 

struct obs_kernel_param {
	const char *str=“console”
	int (*setup_func)(char *)=console_setup
	int early=0
};

 

所以最终会生成__setup_console_setup结构体地址,我们可以通过查看system.map表看到

 

c04373e0 T __setup_start
c04373ec t __setup_init_setup
c04373f8 t __setup_loglevel
c0437404 t __setup_quiet_kernel
......
c0437560 t __setup_console_setup //注意这里
......
c0437788 T __setup_end

 

 

至此,__setup("console=", console_setup)关系已分析完!
 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值