gpt4 book ai didi

linux - 为 Arm/Raspberry PI 扩展 Rasbian 内核(Linux 内核 3.10.28)——如何正确添加自己的系统调用?

转载 作者:太空狗 更新时间:2023-10-29 11:37:54 26 4
gpt4 key购买 nike

我需要为 Raspbian Linux 内核添加一个自己的系统调用。现在我在搜索了大约 2 天以找到解决方案后陷入困境。

要加一个系统调用,我基本上是按照大纲来的( http://elinux.org/RPi_Kernel_Compilation ) 使用来自以下 git repo 的内核源代码:

git://github.com/raspberrypi/tools.git

我已经使用 crosstool-ng ( http://www.kitware.com/blog/home/post/426 ) 安装了交叉编译环境。

以上所有这些都有效。我能够编译和部署新内核。此外,我还能够为 Raspbian 进行交叉编译。

我正在尝试添加“hello world”系统调用。该函数驻留在它自己的实现文件 (kernel/helloworld.?) 中并实现为:

helloworld.c:

#include <linux/linkage.h>
#include <linux/kernel.h>
#include <linux/random.h>
#include "helloworld.h"

asmlinkage long sys_helloworld(){
printk (KERN_EMERG "hello world!");
return get_random_int()*4;
}

helloworld.h:

#ifndef HELLO_WORLD_H
#define HELLO_WORLD_H
asmlinkage long sys_helloworld(void);
#endif

相应地扩展了 Makefile。

我现在卡在错误信息中了

AS      arch/arm/kernel/entry-common.o
arch/arm/kernel/entry-common.S: Assembler messages:
arch/arm/kernel/entry-common.S:104: Error: __NR_syscalls is not equal to the size of the syscall table
make[1]: *** [arch/arm/kernel/entry-common.o] Error 1

遵循 Writing a new system call 中的建议,我添加了以下内容:

  • arch/arm/kernel/calls.S

    CALL(sys_helloworld)
  • arch/arm/include/uapi/asm/unistd.h

    #define __NR_helloworld                 (__NR_SYSCALL_BASE+380)
  • include/uapi/asm-generic/unistd.h

    #define __NR_helloworld 274
    __SYSCALL(__NR_helloworld, sys_helloworld)

    #define __NR_syscalls 275
  • arch/x86/syscalls/syscall_32.tbl

    351     i386    helloworld              sys_helloworld

我现在陷入了解决错误的困境。

当删除 calls.S 中的行时,内核编译正常;虽然我不能调用系统调用。添加上述行时,出现上述错误。

供引用:用于测试系统调用的客户端代码是:

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

int main (int argc, char* argv[])
{
int i=atoi(argv[1]);
int j=-1;
printf("invocing kernel function %i\n", i);
j=syscall(i); /* 350 is our system calls offset number */
printf("invoked. Return is %i. Bye.\n", j);

return 0;
}

所有其他系统调用(例如,1 == sys_exit)工作正常。

知道我遗漏了什么吗?例如,我不完全了解如何实现 rasens 答案。

最佳答案

_NR_syscallsarch/arm/include/asm/unistd.h 文件中定义,此值将始终为 __NR_last_syscall+1。因此,在您的情况下,_NR_syscalls 应修改为 381,但由于系统调用表中的填充,此更改也会产生相同的错误。因此将其定义为 384。这样可以解决编译错误。以下更改不是必需的:

include/uapi/asm-generic/unistd.h

#define __NR_helloworld 274
__SYSCALL(__NR_helloworld, sys_helloworld)

#define __NR_syscalls 275

arch/x86/syscalls/syscall_32.tbl

351 i386 helloworld sys_helloworld

关于linux - 为 Arm/Raspberry PI 扩展 Rasbian 内核(Linux 内核 3.10.28)——如何正确添加自己的系统调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21554267/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com