扩展Rasbian内核(Linux内核28年3月10日)于ARM /覆盆子PI - 如何正确地添加自己的系统调用? [英] Extending the Rasbian Kernel (Linux Kernel 3.10.28) for Arm / Raspberry PI - How to correctly add own system calls?

查看:668
本文介绍了扩展Rasbian内核(Linux内核28年3月10日)于ARM /覆盆子PI - 如何正确地添加自己的系统调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个自己的系统调用添加到Raspbian Linux内核。现在我坚持寻找2天左右找到解决的办法了。

I need to add an own system call to the Raspbian Linux Kernel. Now I am stuck after searching for about 2 days to find a solution.

要增加一个系统调用,我基本上遵循大纲
http://elinux.org/RPi_Kernel_Compilation )使用内核源代码从以下混帐回购协议:

To add a system call, I am basically following the general outline (http://elinux.org/RPi_Kernel_Compilation) using the kernel sources from the following git repo:

混帐://github.com/raspberrypi/tool​​s.git

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

我已经安装使用的crosstool-ng的一个交叉编译环境( HTTP:// WWW .kitware.com /博客/家庭/后/ 426 )。

I have installed a cross-compile environment using crosstool-ng (http://www.kitware.com/blog/home/post/426).

所有上述这些作品。我能够编译和部署一个新的内核。我还能够交叉编译的Raspbian。

All these above works. I am able to compile and deploy a new kernel. I am furthermore able to cross-compile for the Raspbian.

我想添加一个世界你好系统调用。该功能驻留在自己实现文件和实施(内核/的HelloWorld?):

I am trying to add a 'hello world' system call. The function resides in its own implementation files (kernel/helloworld.?) and are implemented as:

helloworld.c:

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:

helloworld.h:

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

Makefile是相应延长。

The Makefile is extended accordingly.

我现在被困在错误信息

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

建议编写新的系统调用,我添加了以下


  • 弓/ ARM /内核/ calls.S

  • arch/arm/kernel/calls.S

CALL(sys_helloworld)


  • 弓/ ARM /有/ uapi / ASM / unistd.h中

  • arch/arm/include/uapi/asm/unistd.h

    #define __NR_helloworld                 (__NR_SYSCALL_BASE+380)
    


  • 在include / uapi / ASM-通用/ unistd.h中

  • include/uapi/asm-generic/unistd.h

    #define __NR_helloworld 274
    __SYSCALL(__NR_helloworld, sys_helloworld)
    
    #define __NR_syscalls 275
    


  • 在arch / 86 /系统调用/ syscall_32.tbl

  • arch/x86/syscalls/syscall_32.tbl

    351     i386    helloworld              sys_helloworld
    


  • 我现在被困在解决错误。

    I am now stuck in solving the error.

    当去除calls.S行,内核编译罚款;虽然我不能调用系统调用。当添加行如上所述,我收到提到的错误。

    When removing the line in calls.S, the kernel compiles fine; though I can't invoke the system call. When adding the line stated above, I am getting the mentioned error.

    有关参考:本客户端 - code测试的系统调用是:

    For reference: The client-code for testing the system call is:

    #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)做工精细。

    All other system calls (e.g., 1 == sys_exit) work fine.

    任何想法,我缺少什么?例如,我不完全得到如何实现rasens答案。

    Any ideas what I am missing? E.g., I don't fully get how to implement rasens answer.

    推荐答案

    在arch / ARM定义_NR_syscalls /有/ ASM / unistd.h中的文件,该值将始终__NR_last_syscall + 1。因此,在你的情况_NR_syscalls应体改到381,但这种变化也将给因为系统调用表填充了同样的错误。因此,它定义了384。这解决售后服务的编译错误。以下变化并不neccessary,

    _NR_syscalls defined in arch/arm/include/asm/unistd.h file this value will always be __NR_last_syscall+1 . Hence in your case _NR_syscalls should be modifed to 381, but this change will also give the same error because of padding in syscall table. Hence define it to 384 . This slove the compilation error. Below changes are not neccessary,

    在include / uapi / ASM-通用/ unistd.h中

    include/uapi/asm-generic/unistd.h

    __ SYSCALL(__ NR_helloworld,sys_helloworld)

    __SYSCALL(__NR_helloworld, sys_helloworld)

    在arch / 86 /系统调用/ syscall_32.tbl

    arch/x86/syscalls/syscall_32.tbl

    351 I386的HelloWorld sys_helloworld

    351 i386 helloworld sys_helloworld

    干杯

    这篇关于扩展Rasbian内核(Linux内核28年3月10日)于ARM /覆盆子PI - 如何正确地添加自己的系统调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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