【问题标题】:Where do I add a systemcall to the linux Kernel source我在哪里向 linux 内核源添加系统调用
【发布时间】:2011-04-29 10:16:00
【问题描述】:

我正在尝试向新版本的 Linux Ubuntu 内核添加一个新的 helloworld 系统调用。我一直在浏览网络,但找不到一致的示例来显示我必须修改哪些文件才能将 helloworld 系统调用添加到内核中。

我尝试了很多并且出现编译错误。 我知道如何编译内核,但我只是不知道我在哪里添加我的 c 程序系统调用,以及我在哪里将此调用添加到系统调用表以及我必须做的任何其他事情。

我正在开发最新的 Linux Ubuntu 内核。

我用引入的新系统调用编译内核,一个名为 mycall 的简单调用,现在我在测试调用的应用程序的头文件中出现编译错误,下面是我的头文件

#include<linux/unistd.h>

#define __NR_mycall 317

_syscall1(long, mycall, int, i)

这是我遇到的语法错误

stef@ubuntu:~$ gcc -o testmycall testmycall.c
In file included from testmycall.c:3:
testmycall.h:7: error: expected declaration specifiers or ‘...’ before ‘mycall’
testmycall.h:7: error: expected declaration specifiers or ‘...’ before ‘i’
testmycall.c: In function ‘_syscall1’:
testmycall.c:7: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
testmycall.h:7: error: parameter name omitted
testmycall.h:7: error: parameter name omitted
testmycall.c:11: error: expected ‘{’ at end of in

我从 Nikolai N Fetissov 的以下链接中得到了很多帮助

【问题讨论】:

  • 你尝试了什么?发生了什么编译错误? Is this still homework? - 如果是这样,请标记。我认为,在该问题的答案中链接的文章对一般原则很有用,尽管有点过时,因为内核开发往往会迅速发展。提示:以前在旧版本中的 arch/i386 中的东西现在在 arch/x86 中(32 位和 64 位的东西合并了)。 LXR 可用于搜索当前或旧内核版本。
  • 我无意中摆脱了编译错误,我会再试一次,如果出现,我会编辑带有错误的帖子,好的,为关于 arch/x86 的建议欢呼,将尝试这个现在,大约一个小时后我会回来,当我完成所有这些并编译时!!!!!!

标签: linux linux-kernel operating-system


【解决方案1】:

第 2 章,操作系统原理 - galvin。 直接的程序。

【讨论】:

  • 发帖时请不要包含“签名”;您的用户框已显示您的姓名。另外......我不确定这个答案是什么意思。
【解决方案2】:

您使用的“_syscall1”宏已过时。请改用 syscall(2)。

示例:

#include <stdio.h>
#include <linux/unistd.h>
#include <sys/syscall.h>

#define __NR_mysyscall     317

int main(void)
{
        long return_value;

        return_value = syscall(__NR_syscall);

        printf("The return value is %ld.\n", return_value);

        return 0;
}

【讨论】:

    猜你喜欢
    • 2013-04-25
    • 2013-07-13
    • 2020-04-04
    • 2014-01-27
    • 2018-09-15
    • 1970-01-01
    • 2012-04-16
    • 2020-01-17
    • 2013-11-21
    相关资源
    最近更新 更多