Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 无法编译定义新系统调用的内核模块_C_Linux_Linux Kernel_X86 64_Kernel Module - Fatal编程技术网

C 无法编译定义新系统调用的内核模块

C 无法编译定义新系统调用的内核模块,c,linux,linux-kernel,x86-64,kernel-module,C,Linux,Linux Kernel,X86 64,Kernel Module,我无法编译以下内核模块。我试图用syscall\u DEFINE0实现一个小的系统调用,它几乎什么都不做。以下是内核模块: #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 模块许可证(“GPL”); #ifndef\uuu NR\u TESTSYSCALL #定义测试系统调用436 #恩迪夫 char*addr; SYSCALL\u DEFINE0(testsyscall){ printk(KERN_INFO“Test\n”); 返回0; } in

我无法编译以下内核模块。我试图用
syscall\u DEFINE0
实现一个小的系统调用,它几乎什么都不做。以下是内核模块:

#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
模块许可证(“GPL”);
#ifndef\uuu NR\u TESTSYSCALL
#定义测试系统调用436
#恩迪夫
char*addr;
SYSCALL\u DEFINE0(testsyscall){
printk(KERN_INFO“Test\n”);
返回0;
}
int init_模块(){
addr=kmalloc(32,GFP_内核);
返回0;
}
void cleanup_模块(){
printk(内核信息“模块已删除”\n);
}
我已经检查过没有使用系统调用号码436。但是我不能编译这个。我得到这个错误:

make -C /lib/modules/5.4.0-72-generic/build M=/root/beginner modules
make[1]: Entering directory '/usr/src/linux-headers-5.4.0-72-generic'
  CC [M]  /root/beginner/testme.o
  Building modules, stage 2.
  MODPOST 1 modules
ERROR: "enter_syscall_print_funcs" [/root/beginner/testme.ko] undefined!
ERROR: "event_class_syscall_enter" [/root/beginner/testme.ko] undefined!
ERROR: "exit_syscall_print_funcs" [/root/beginner/testme.ko] undefined!
ERROR: "event_class_syscall_exit" [/root/beginner/testme.ko] undefined!
make[2]: *** [scripts/Makefile.modpost:94: __modpost] Error 1
make[1]: *** [Makefile:1667: modules] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-5.4.0-72-generic'
make: *** [Makefile:4: all] Error 2
我使用此脚本编译:

obj-m += testme.o

all:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

有人能帮我吗?

我认为您不能在模块中添加系统调用,因为系统调用表是静态的。请看,我怀疑链接错误在于
SYSCALL\u DEFINE0
宏调用未导出到模块的函数,这正是因为模块不应该尝试定义系统调用。正如@NateEldredge所说,系统调用不能作为模块添加,因为系统调用表是静态的。如果你真的想添加一个自定义系统调用,你必须用这个自定义系统调用重新编译你的内核。你可以参考这个链接