分类:
2010-09-28 21:57:50
/* Generic info of form tag = "info" */
#define MODULE_INFO(tag, info) __MODULE_INFO(tag, tag, info)
#define __MODULE_INFO(tag, name, info) \
static const char __module_cat(name,__LINE__)[] \
__attribute__((__used__)) \
__attribute__((section(".modinfo"),unused)) = __stringify(tag) "=" info
#define ___module_cat(a,b) __mod_ ## a ## b
#define __module_cat(a,b) ___module_cat(a,b)
#define __stringify_1(x...) #x
#define __stringify(x...) __stringify_1(x)
MODULE_INFO(foo,bar) 则展开之后就是:
static const char __mod_foo##__LINE__[] __attribute__((used)) \
__attribute__((section(“.modinfo”),unused)) = “foo=bar”
##__LINE__用MODULE_INFO这个语句在源文件中所在的行数替换。
#define MODULE_ALIAS(_alias) MODULE_INFO(alias, _alias)
举一反三… MODULE_INFO(“md-raid5”) 展开就是:
static const char __mod_alias##__LINE__[] __attribute__((used)) \
__attribute__((section(“.modinfo”),unused)) = “alias=md-raid5”
#define MODULE_LICENSE(_license) MODULE_INFO(license, _license)
举一反三…MODULE_LICENSE(“Dual BSD/GPL”)展开就是:
static const char __mod_license##__LINE__[] __attribute__((used)) \
__attribute__((section(“.modinfo”),unused)) = “license=Dual BSD/GPL”
#define MODULE_AUTHOR(_author) MODULE_INFO(author, _author)
MODULE_AUTHOR(“liangtao”)展开就是:
static const char __mod_author##__LINE__[] __attribute__((used)) \
__attribute__((section(“.modinfo”),unused)) = “author=liangtao”
#define MODULE_DESCRIPTION(_description) MODULE_INFO(description, _description)
MODULE_DESCRIPTION(“dummy”)展开就是:
static const char __mod_description##__LINE__[] __attribute__((used)) \
__attribute__((section(“.modinfo”),unused)) = “description=dummy”
#define MODULE_VERSION(_version) MODULE_INFO(version, _version)
MODULE_VERSION(“0.0.1”)展开就是:
static const char __mod_version##__LINE__[] __attribute__((used)) \
__attribute__((section(“.modinfo”),unused)) = “version=0.0.1”
#define EXPORT_SYMBOL(sym) \
__EXPORT_SYMBOL(sym, "")
/* For every exported symbol, place a struct in the __ksymtab section */
#define __EXPORT_SYMBOL(sym, sec) \
extern typeof(sym) sym; \ 首先声明sym是全局可用的
__CRC_SYMBOL(sym, sec) \ 校验…version check
static const char __kstrtab_##sym[] \
__attribute__((section("__ksymtab_strings"), aligned(1))) \
= MODULE_SYMBOL_PREFIX #sym; \
static const struct kernel_symbol __ksymtab_##sym \
__used \
__attribute__((section("__ksymtab" sec), unused)) \
= { (unsigned long)&sym, __kstrtab_##sym }
例如:
EXPORT_SYMBOL(foo_var)展开为:
static const char __kstrtab_foo_var[] __attribute__((section(“__ksymtab_strings”).aligned(1))) \
= “foo_var”;
static const struct kernel_symbol __ksymtab_foo_var __attribute__((used)) \
__attribute__((section(“__ksymtab”),unused)) \
= { (unsigned long)&foo_var, __kstrtab_foo_var }
extern struct module __this_module;
#define THIS_MODULE (&__this_module)