我在哪里可以找到系统调用源代码?

时间:2022-04-29 15:08:51

In linux where can I find the source code for all system calls given that I have the source tree? Also if I were to want to look up the source code and assembly for a particular system call is there something that I can type in terminal like -my_system_call?

在Linux中我可以找到所有系统调用的源代码,因为我有源树吗?另外,如果我想要查找特定系统调用的源代码和程序集,那么我可以在终端中输入类似-my_system_call的内容吗?

3 个解决方案

#1


31  

You'll need the Linux kernel sources in order to see the actual source of the system calls. Manual pages, if installed on your local system, only contain the documentation of the calls and not their source itself.

您需要Linux内核源才能查看系统调用的实际来源。手动页面(如果安装在本地系统上)仅包含调用的文档,而不包含其源本身。

Unfortunately for you, system calls aren't stored in just one particular location in the whole kernel tree. This is because various system calls can refer to different parts of the system (process management, filesystem management, etc.) and therefore it would be infeasible to store them apart from the part of the tree related to that particular part of the system.

不幸的是,系统调用不会存储在整个内核树中的一个特定位置。这是因为各种系统调用可以引用系统的不同部分(进程管理,文件系统管理等),因此将它们存储在与系统的特定部分相关的树的部分之外是不可行的。

The best thing you can do is look for the SYSCALL_DEFINE[0-6] macro. It is used (obviously) to define the given block of code as a system call. For example, fs/ioctl.c has the following code :

你能做的最好的事情是寻找SYSCALL_DEFINE [0-6]宏。它(显然)用于将给定的代码块定义为系统调用。例如,fs / ioctl.c具有以下代码:

SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd, unsigned long, arg)
{
/* do freaky ioctl stuff */
}

Such a definition means that the ioctl syscall is declared and takes three arguments. The number next to the SYSCALL_DEFINE means the number of arguments. For example, in the case of getpid(void), declared in kernel/timer.c, we have the following code :

这样的定义意味着声明了ioctl系统调用并且接受了三个参数。 SYSCALL_DEFINE旁边的数字表示参数的数量。例如,在kernel / timer.c中声明的getpid(void)的情况下,我们有以下代码:

SYSCALL_DEFINE0(getpid)
{
        return task_tgid_vnr(current);
}

Hope that clears things up a little.

希望能把事情搞清楚一点。

#2


2  

From an application's point of view, a system call is an elementary and atomic operation done by the kernel.

从应用程序的角度来看,系统调用是内核完成的基本和原子操作。

The Assembly Howto explains what is happening, in terms of machine instruction.

大会如何根据机器指令解释正在发生的事情。

Of course, the kernel is doing a lot of things when handling a syscall.

当然,内核在处理系统调用时做了很多事情。

Actually, you almost could believe that the entire kernel code is devoted to handle all system calls (this is not entirely true, but almost; from applications' point of view, the kernel is only visible thru system calls). The other answer by Daniel Kamil Kozar is explaining what kernel function is starting the handling of some system call (but very often, many other parts of the kernel indirectly participate to system calls; for example, the scheduler participates indirectly into implementing fork because it manages the child process created by a successful fork syscall).

实际上,您几乎可以相信整个内核代码专门用于处理所有系统调用(这不完全正确,但几乎;从应用程序的角度来看,内核只能通过系统调用看到)。 Daniel Kamil Kozar的另一个答案是解释什么内核函数开始处理某些系统调用(但很多时候,内核的许多其他部分间接参与系统调用;例如,调度程序间接参与实现fork,因为它管理由一个成功的fork系统调用创建的子进程)。

#3


2  

I know it's old, but I was searching for the source for _system_call() too and found this tidbit

我知道它已经过时了,但我也在寻找_system_call()的来源,并发现这个花絮

Actual code for system_call entry point can be found in /usr/src/linux/kernel/sys_call.S Actual code for many of the system calls can be found in /usr/src/linux/kernel/sys.c, and the rest are found elsewhere. find is your friend.

system_call入口点的实际代码可以在/usr/src/linux/kernel/sys_call中找到。许多系统调用的实际代码可以在/usr/src/linux/kernel/sys.c中找到,其余的在其他地方找到。找到你的朋友。

I assume this is dated, because I don't even have that file. However, grep found ENTRY(system_call) in arch/x86/kernel/entry_64.S and seems to be the thing that calls the individual system calls. I'm not up on my intel-syntax x86 asm right now, so you'll have to look and see if this is what you wanted.

我认为这是过时的,因为我甚至没有那个文件。但是,grep在arch / x86 / kernel / entry_64.S中找到了ENTRY(system_call),似乎是调用单个系统调用的东西。我现在没有使用我的英特尔语法x86 asm,所以你必须查看这是否是你想要的。

#1


31  

You'll need the Linux kernel sources in order to see the actual source of the system calls. Manual pages, if installed on your local system, only contain the documentation of the calls and not their source itself.

您需要Linux内核源才能查看系统调用的实际来源。手动页面(如果安装在本地系统上)仅包含调用的文档,而不包含其源本身。

Unfortunately for you, system calls aren't stored in just one particular location in the whole kernel tree. This is because various system calls can refer to different parts of the system (process management, filesystem management, etc.) and therefore it would be infeasible to store them apart from the part of the tree related to that particular part of the system.

不幸的是,系统调用不会存储在整个内核树中的一个特定位置。这是因为各种系统调用可以引用系统的不同部分(进程管理,文件系统管理等),因此将它们存储在与系统的特定部分相关的树的部分之外是不可行的。

The best thing you can do is look for the SYSCALL_DEFINE[0-6] macro. It is used (obviously) to define the given block of code as a system call. For example, fs/ioctl.c has the following code :

你能做的最好的事情是寻找SYSCALL_DEFINE [0-6]宏。它(显然)用于将给定的代码块定义为系统调用。例如,fs / ioctl.c具有以下代码:

SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd, unsigned long, arg)
{
/* do freaky ioctl stuff */
}

Such a definition means that the ioctl syscall is declared and takes three arguments. The number next to the SYSCALL_DEFINE means the number of arguments. For example, in the case of getpid(void), declared in kernel/timer.c, we have the following code :

这样的定义意味着声明了ioctl系统调用并且接受了三个参数。 SYSCALL_DEFINE旁边的数字表示参数的数量。例如,在kernel / timer.c中声明的getpid(void)的情况下,我们有以下代码:

SYSCALL_DEFINE0(getpid)
{
        return task_tgid_vnr(current);
}

Hope that clears things up a little.

希望能把事情搞清楚一点。

#2


2  

From an application's point of view, a system call is an elementary and atomic operation done by the kernel.

从应用程序的角度来看,系统调用是内核完成的基本和原子操作。

The Assembly Howto explains what is happening, in terms of machine instruction.

大会如何根据机器指令解释正在发生的事情。

Of course, the kernel is doing a lot of things when handling a syscall.

当然,内核在处理系统调用时做了很多事情。

Actually, you almost could believe that the entire kernel code is devoted to handle all system calls (this is not entirely true, but almost; from applications' point of view, the kernel is only visible thru system calls). The other answer by Daniel Kamil Kozar is explaining what kernel function is starting the handling of some system call (but very often, many other parts of the kernel indirectly participate to system calls; for example, the scheduler participates indirectly into implementing fork because it manages the child process created by a successful fork syscall).

实际上,您几乎可以相信整个内核代码专门用于处理所有系统调用(这不完全正确,但几乎;从应用程序的角度来看,内核只能通过系统调用看到)。 Daniel Kamil Kozar的另一个答案是解释什么内核函数开始处理某些系统调用(但很多时候,内核的许多其他部分间接参与系统调用;例如,调度程序间接参与实现fork,因为它管理由一个成功的fork系统调用创建的子进程)。

#3


2  

I know it's old, but I was searching for the source for _system_call() too and found this tidbit

我知道它已经过时了,但我也在寻找_system_call()的来源,并发现这个花絮

Actual code for system_call entry point can be found in /usr/src/linux/kernel/sys_call.S Actual code for many of the system calls can be found in /usr/src/linux/kernel/sys.c, and the rest are found elsewhere. find is your friend.

system_call入口点的实际代码可以在/usr/src/linux/kernel/sys_call中找到。许多系统调用的实际代码可以在/usr/src/linux/kernel/sys.c中找到,其余的在其他地方找到。找到你的朋友。

I assume this is dated, because I don't even have that file. However, grep found ENTRY(system_call) in arch/x86/kernel/entry_64.S and seems to be the thing that calls the individual system calls. I'm not up on my intel-syntax x86 asm right now, so you'll have to look and see if this is what you wanted.

我认为这是过时的,因为我甚至没有那个文件。但是,grep在arch / x86 / kernel / entry_64.S中找到了ENTRY(system_call),似乎是调用单个系统调用的东西。我现在没有使用我的英特尔语法x86 asm,所以你必须查看这是否是你想要的。