void *__symbol_get(const char * symbol)
symbol: 符号名
ret:    符号的地址,不存在则返回空
头文件: #include  <linux/module.h>

内核符号之获得内核符号地址1__symbol_get
此函数在内核中的实现如下: (2.6.32)

void *__symbol_get(const char *symbol)
{
struct module *owner;
const struct kernel_symbol *sym;
preempt_disable();
sym = find_symbol(symbol, &owner, NULL, true, true);
if (sym && strong_try_module_get(owner))
sym = NULL;
preempt_enable();
return sym ? (void *)sym->value : NULL;
}
从strong_try_module_get可以看出__symbol_get会对符号所对应的模块引用计数增加 1
并且获取符号的地址具体是由find_symbol来实现的,查看find_symbol发现find_symbol也是一个导出函数

那么直接使用此函数的例子如下

const struct kernel_symbol *find_symbol(const char *name,
struct module **owner,
const unsigned long **crc,
bool gplok,

bool warn)

name:符号名

owner: 二级指针 输出参数 获得模块的地址

crc:二级指针 输出参数 内核符号的crc值所在的地址

gplok:模块支持GPL许可

warn: 允许输出警告信息

头文件: #include  <linux/module.h>

内核符号之获得内核符号地址1__symbol_get

相关文章:

  • 2022-01-26
  • 2022-12-23
  • 2022-01-15
  • 2021-07-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-03-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-17
  • 2022-12-23
相关资源
相似解决方案