自定义系统调用加功能给出错误的答案
我正在尝试在虚拟框中在Ubuntu中创建自定义系统调用。这是驱动程序程序,该程序返回一个非常大的负数而不是答案:
#include <stdio.h>
#include <stdlib.h>
#include<sys/syscall.h>
#include <unistd.h>
long plus (int, int);
int main (int agrc, char* argv[]){
int arg1=atoi(argv[1]);
int arg2=atoi(argv[2]);
long x= syscall(436, (long)arg1, (long)arg2);
printf ("Sum: %ld\n", x);
return x;
}
plus.c系统呼叫的定义:
#include <linux/kernel.h>
#include <linux/syscalls.h>
asmlinkage long sys_plus(long a, long b){
return a + b;
}
plus.c的makefile for.c
obj-y := plus.o
makefile更改了主Linux-5.3.7目录中的线路:
core-y += kernel/ certs/ mm/ fs/ ipc/ security/ crypto/ block/ plus/
SYSCALL_64.TBL条目:
436 64 plus sys_plus
syscalls.h条目:
asmlinkage long sys_plus (long, long);
之后,我将随着时间的时间-j4和sudo make install编译内核。看来我做的一切都很好,但最终输出是错误的。有什么问题?
I am trying to create a custom system call in Ubuntu in Virtual Box. Here is the driver program which returns a very large negative number instead of the answer:
#include <stdio.h>
#include <stdlib.h>
#include<sys/syscall.h>
#include <unistd.h>
long plus (int, int);
int main (int agrc, char* argv[]){
int arg1=atoi(argv[1]);
int arg2=atoi(argv[2]);
long x= syscall(436, (long)arg1, (long)arg2);
printf ("Sum: %ld\n", x);
return x;
}
The definition of plus.c system call:
#include <linux/kernel.h>
#include <linux/syscalls.h>
asmlinkage long sys_plus(long a, long b){
return a + b;
}
Makefile for plus.c
obj-y := plus.o
The Makefile changed line in the main linux-5.3.7 directory:
core-y += kernel/ certs/ mm/ fs/ ipc/ security/ crypto/ block/ plus/
The syscall_64.tbl entry:
436 64 plus sys_plus
The syscalls.h entry:
asmlinkage long sys_plus (long, long);
After this I am compiling the kernel with time make -j4 and the sudo make install. It appears I am doing everything fine yet the final output is wrong. What could be the issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论