从 Linux 中的内核模块调用 C 文件中的内核函数的正确方法是什么?
我想打电话给exit_task_namespaces
在linux/nsproxy.c
从我第一次内核模块
我正在这样做:
#include <linux/nsproxy.h>
…
static ssize_t device_read(struct file *flip, char *buffer, size_t len, loff_t *offset)
{
struct task_struct *task = current;
…
exit_task_namespaces(task);
…
}
Run Code Online (Sandbox Code Playgroud)
当我尝试时,make
出现以下错误:
ERROR: "exit_task_namespaces" [/home/.../lkm_example.ko] undefined!
make[2]: *** [scripts/Makefile.modpost:94: __modpost] Error 1
make[1]: *** [Makefile:1673: modules] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-5.4.0-73-generic'
make: *** [Makefile:3: all] Error 2
Run Code Online (Sandbox Code Playgroud)
我可以在文件中看到/usr/src/linux-headers-5.4.0-73-generic/include/linux/nsproxy.h
该方法存在。
这是我的 Makefile:
obj-m += lkm_example.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
Run Code Online (Sandbox Code Playgroud)
Ste*_*itt 21
模块只能访问导出的符号,而exit_task_namespaces
不是导出的——所以即使它在头文件中可见,也不能在模块中使用。
可以按照您的预期访问导出的符号,没有什么特别的事情要做。