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

use*_*939 2 linux kernel arm system-calls raspberry-pi

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

要添加系统调用,我基本上遵循以下git repo中的内核源代码的大纲(http://elinux.org/RPi_Kernel_Compilation):

混帐://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;
}
Run Code Online (Sandbox Code Playgroud)

helloworld.h:

#ifndef HELLO_WORLD_H
#define HELLO_WORLD_H
asmlinkage long sys_helloworld(void);
#endif
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

按照编写新系统调用的建议,我添加了以下内容:

我现在坚持解决错误.

删除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;
}
Run Code Online (Sandbox Code Playgroud)

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

我缺少什么想法?例如,我没有完全了解如何实施rasens的答案.

小智 5

_NR_syscallsarch/arm/include/asm/unistd.h文件中定义此值始终为__NR_last_syscall+1.因此,在您的情况下_NR_syscalls应修改为381,但由于syscall表中的填充,此更改也会产生相同的错误.因此将其定义为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
Run Code Online (Sandbox Code Playgroud)