无法在x86 ubuntu linux上添加自定义系统调用 [英] Unable to add a custom system call on x86 ubuntu linux

查看:670
本文介绍了无法在x86 ubuntu linux上添加自定义系统调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对此并不陌生,只是了解内核,因此我试图向内核4.20.4添加自定义调用.这是我所做的步骤.

I am new to this and just learning about the kernel, and I am trying to add a custom call to kernel 4.20.4. This is the steps that I did.

  1. 首先,我创建包含代码的文件(kernel/printmsg.c).

#include <linux/kernel.h>
#include <linux/syscalls.h>

SYSCALL_DEFINE1(printmsg, int, i)
{
    printk(KERN_DEBUG, "TESTING %d", i);
    return 1;
}

  1. 接下来,我将此文件添加到kernel/Makefile

obj-y = fork.o exec_domain.o panic.o \
        // A few more lines
obj-y += printmsg.o // I added this line

  1. 最后,通过添加以下行,将系统调用添加到arch/x86/entry/syscalls/syscall_64.tbl上的syscall表中(我正在64位Ubuntu上构建它):
  1. Finally, I add the system call to the syscall table on arch/x86/entry/syscalls/syscall_64.tbl(I'm building this on a 64-bit Ubuntu) by appending this line:

548 64 printmsg sys_printmsg

现在,我继续运行make.但是,它有此错误:

Now, I proceed to run make. However, it has this error:

arch/x86/entry/syscall_64.o:(.rodata+0x1120): undefined reference to `sys_printmsg'
Makefile:1034: recipe for target 'vmlinux' failed
make: *** [vmlinux] Error 1

为此我已经挠了很长时间,但我似乎不知道出了什么问题.

I've been scratching my head for a long time for this but I can't seem to realised what went wrong.

希望任何设法找到问题的人都能帮助穷人.预先感谢!

Hope that anyone that managed to find a problem can help out a poor soul. Thanks in advance!

推荐答案

好吧,经过数小时的反复试验,我终于找到了问题所在.从Linux内核v4.17开始,x86_64系统调用可能以"__x64_sys"开头.

Okay, after hours of trial and error, I have finally found the problem. From linux kernel v4.17 onwards, x86_64 system calls may begin with "__x64_sys".

因此,我没有使用548 64 printmsg sys_printmsg,而是将其更改为548 64 printmsg __x64_sys_printmsg.然后一切正常.

So, instead of using 548 64 printmsg sys_printmsg, I changed it to 548 64 printmsg __x64_sys_printmsg. Then everything works.

希望这对可能遇到此问题的所有人有所帮助.

Hoped this helped everyone that might have this problem.

这篇关于无法在x86 ubuntu linux上添加自定义系统调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆