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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17652555/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 00:15:53  来源:igfitidea点击:

Where is the system call table in linux kernel?

linuxkernel

提问by Iker

I'm reading Linux Kernel Development by Robert Love and one of the exercises he does is to create a system call (page 106). The problem is that I am unable to find the system call table file in v3.9 for the x86_32 architecture. 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.

我正在阅读 Robert Love 的 Linux Kernel Development,他所做的练习之一是创建系统调用(第 106 页)。问题是我在 v3.9 中找不到 x86_32 架构的系统调用表文件。我知道他使用的是 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. Thanks to Sudip Mukherjee for his help.

使用以下方法解决:x86 架构的系统调用表位于 arch/x86/syscalls/syscall_32.tbl。感谢 Sudip Mukherjee 的帮助。

Another approach is the following:http://lists.kernelnewbies.org/pipermail/kernelnewbies/2013-July/008598.htmlThanks to Srinivas Ganji for his help too.

另一种方法如下:http://lists.kernelnewbies.org/pipermail/kernelnewbies/2013-July/008598.html 也感谢 Srinivas Ganji 的帮助。

回答by Mandeep Sandhu

A similar question on SO where the OP seems to have solved it:

OP似乎已经解决了SO上的一个类似问题:

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.

回答by Roshan Mehta

Create a testing folder in src root: src/linux-3.4/testing/, then put inside this folder:
- a file that contains syscall code: strcpy.c

在 src root: 中创建一个 testing 文件夹src/linux-3.4/testing/,然后放入这个文件夹中:
- 一个包含系统调用代码的文件:strcpy.c

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

and the Makefile that contains just the following line:

以及仅包含以下行的 Makefile:

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

Add an entry to the syscall table and the prototype of the function:
- edit the file src/linux-3.4/arch/x86/syscalls/syscall_32.tblby adding this line to the entry 223 that is free

向系统调用表和函数原型添加一个条目:
-src/linux-3.4/arch/x86/syscalls/syscall_32.tbl通过将此行添加到空闲的条目 223 来编辑文件

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

Edit the file src/linux-3.4/include/linux/syscalls.hby adding the prototype of the function

src/linux-3.4/include/linux/syscalls.h通过添加函数原型来编辑文件

commit 1f57d5d85ba7f1f467173ff33f51d01a91f9aaf1
Author: Ingo Molnar <[email protected]>
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.

Edit the main Makefile in the src root (src/linux-3.4/Makefile) by adding the testing folder created before, as follow:

src/linux-3.4/Makefile通过添加之前创建的 testing 文件夹来编辑 src root ( ) 中的主 Makefile ,如下所示:

ausyscall --dump

回答by Ortomala Lokni

From linux kernel 4.2, the system call table has been moved from arch/x86/syscalls/syscall_64.tblto arch/x86/entry/syscalls/syscall_64.tbl

从Linux内核4.2,系统调用表已经从移动arch/x86/syscalls/syscall_64.tblarch/x86/entry/syscalls/syscall_64.tbl

Here is the corresponding commit:

这是相应的提交

$ 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...

回答by RaddKatt

For systems where audit is enabled, a table of the syscalls may be easily retrieved with:

对于启用了审计的系统,可以通过以下方式轻松检索系统调用表:

##代码##

For example:

例如:

##代码##