
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);
…
}
시도하면 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
/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
답변1
모듈은 액세스만 가능내보낸 기호이며 exit_task_namespaces
내보내지지 않습니다. 따라서 헤더 파일에 표시되더라도 모듈에서는 사용할 수 없습니다.
내보낸 기호는 특별한 조치 없이 예상한 방식으로 액세스할 수 있습니다.