我正在尝试在内核3.19中导入新的系统调用。我已经按照here提供的教程操作了!
这是我通过系统调用实现阶乘计算的简单代码。
#include <linux/kernel.h>
asmlinkage long sys_fact(int a)
{
int n;
int c;
for(n = 1;n <= a;n++)
c = c * n;
printk(KERN_INFO "Factorial calculated!\n");
return((long) c);
}当我尝试编译C代码时,我得到了对sys_fact错误的未定义引用。我使用这个系统调用的程序如下所示。
#include <stdio.h>
#include <linux/kernel.h>
#include <sys/syscall.h>
#include <unistd.h>
int main()
{
int n;
printf("Enter a number to calculate it's factorial\n");
scanf("%d", &n);
printf("Factorial of %d = %d\n", n, sys_fact(9));
return 0;
}我的系统是64位ubuntu 14.04,我已经根据我的系统遵循了上面提到的教程。
此外,我在安装内核时使用了以下命令,我认为这就是安装内核时没有出现错误的原因。
make && make modules_install && make install内核安装花了2-3个小时,我现在很沮丧。请帮帮我!!
我对syscall_64.tbl所做的编辑(最后四个条目)。
320 common kexec_file_load sys_kexec_file_load
321 common bpf sys_bpf
322 64 execveat stub_execveat
323 common fact sys_fact发布于 2015-03-19 21:21:32
原因是,尽管您可能正在使用新内核运行,但#include头文件和C库仍然很旧,因此它们对您新添加的系统调用一无所知。因此,您不能期望定义sys_fact。
正如@santosha.所建议的,站点http://linuxseekernel.blogspot.in/2014/07/adding-system-call-in-x86-qemu.html建议对系统调用编号使用syscall()函数。
发布于 2015-10-29 21:27:27
您的新syscall没有libc api,请尝试使用syscall(323, args ...)调用它,如本教程中所示。
然后检查你是否已经用你的新内核启动了?您可以按照安装步骤here进行操作。或者,使用Qemu之类的仿真器可能会更容易,这样您就不必重新启动。
https://stackoverflow.com/questions/29137244
复制相似问题