简体   繁体   English

linux内核中的系统调用表在哪里?

[英]Where is the system call table in linux kernel?

I'm reading Linux Kernel Development by Robert Love and one of the exercises he does is to create a system call (page 106). 我正在阅读Robert Love的Linux内核开发,他所做的一项练习是创建一个系统调用(第106页)。 The problem is that I am unable to find the system call table file in v3.9 for the x86_32 architecture. 问题是我无法在v3.9中找到x86_32体系结构的系统调用表文件。 I know that he's using the version 2.6.xx but I don't know if that version will work with the distribution that I'm using as it is pretty old so I would rather prefer v3.9. 我知道他正在使用2.6.xx版本,但我不知道该版本是否适用于我正在使用的发行版,因为它很旧,所以我宁愿选择v3.9。

More information: The exercise of which I am speaking is the following: Add an entry to the end of the system call table.This needs to be done for each architecture that supports the system call (which, for most calls, is all the architectures).The position of the syscall in the table, starting at zero, is its system call number. 更多信息:我所说的练习如下:在系统调用表的末尾添加一个条目。这需要为每个支持系统调用的体系结构完成(对于大多数调用,这是所有体系结构)表中系统调用的位置,从零开始,是系统调用号。 For example, the tenth entry in the list is assigned syscall number nine. 例如,列表中的第十个条目被分配了系统调用号9。

Solved using the following approach: The system call table is located in arch/x86/syscalls/syscall_32.tbl for the x86 architecture. 使用以下方法解决:系统调用表位于x86体系结构的arch / x86 / syscalls / syscall_32.tbl中。 Thanks to Sudip Mukherjee for his help. 感谢Sudip Mukherjee的帮助。

Another approach is the following: http://lists.kernelnewbies.org/pipermail/kernelnewbies/2013-July/008598.html Thanks to Srinivas Ganji for his help too. 另一种方法如下: http //lists.kernelnewbies.org/pipermail/kernelnewbies/2013-July/008598.html感谢Srinivas Ganji的帮助。

From linux kernel 4.2, the system call table has been moved from arch/x86/syscalls/syscall_64.tbl to arch/x86/entry/syscalls/syscall_64.tbl 从linux内核4.2开始,系统调用表已从arch/x86/syscalls/syscall_64.tbl移至arch/x86/entry/syscalls/syscall_64.tbl

Here is the corresponding commit : 这是相应的提交

commit 1f57d5d85ba7f1f467173ff33f51d01a91f9aaf1
Author: Ingo Molnar <mingo@kernel.org>
Date:   Wed Jun 3 18:36:41 2015 +0200

    x86/asm/entry: Move the arch/x86/syscalls/ definitions to arch/x86/entry/syscalls/

    The build time generated syscall definitions are entry code related, move
    them into the arch/x86/entry/ directory.

Create a testing folder in src root: src/linux-3.4/testing/ , then put inside this folder: 在src root中创建一个测试文件夹: src/linux-3.4/testing/ ,然后放入这个文件夹:
- a file that contains syscall code: strcpy.c - 包含系统调用代码的文件: strcpy.c

#include <linux/linkage.h>
#include <linux/kernel.h>
asmlinkage long sys_strcpy(char *dest, char *src)
{
    int i=0;
    while(src[i]!='\0') {
        dest[i]=src[i++];
    }
    dest[i]='\0';
    printk(" Done it ");
    return 0;
}

and the Makefile that contains just the following line: 和包含以下行的Makefile:

obj-y:=strcpy.o

Add an entry to the syscall table and the prototype of the function: 在syscall表和函数原型中添加一个条目:
- edit the file src/linux-3.4/arch/x86/syscalls/syscall_32.tbl by adding this line to the entry 223 that is free - 通过将此行添加到免费的条目223来编辑文件src/linux-3.4/arch/x86/syscalls/syscall_32.tbl

 223        i386    strcpy          sys_strcpy

Edit the file src/linux-3.4/include/linux/syscalls.h by adding the prototype of the function 通过添加函数的原型来编辑文件src/linux-3.4/include/linux/syscalls.h

asmlinkage long sys_strcpy(char *dest, char *src);

Edit the main Makefile in the src root ( src/linux-3.4/Makefile ) by adding the testing folder created before, as follow: 通过添加之前创建的测试文件夹,编辑src根目录( src/linux-3.4/Makefile )中的主Makefile,如下所示:

core-y      += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ testing/

For systems where audit is enabled, a table of the syscalls may be easily retrieved with: 对于启用了审计的系统,可以使用以下方法轻松检索系统调用表:

ausyscall --dump

For example: 例如:

$ ausyscall --dump

Using x86_64 syscall table:
0   read
1   write
2   open
3   close
4   stat
5   fstat
6   lstat
7   poll
8   lseek
9   mmap
10  mprotect
...SNIP...

A similar question on SO where the OP seems to have solved it: 一个关于SO的类似问题OP似乎解决了它:

New syscall not found (linux kernel 3.0.0) where should I start looking? 未找到新的系统调用(linux内核3.0.0)我应该从哪里开始查找?

The file seems to be arch/x86/kernel/syscall_table_32.c . 该文件似乎是arch/x86/kernel/syscall_table_32.c

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM