自定义系统调用加功能给出错误的答案

发布于 2025-01-23 18:46:21 字数 1026 浏览 4 评论 0原文

我正在尝试在虚拟框中在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文