在哪里可以找到系统调用源代码? [英] Where can I find system call source code?

查看:42
本文介绍了在哪里可以找到系统调用源代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Linux 中,如果我有源代码树,我在哪里可以找到所有系统调用的源代码?另外,如果我想查找特定系统调用的源代码和程序集,是否可以在终端中输入诸如 my_system_call 之类的内容?

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 内核源代码才能查看系统调用的实际来源.手册页(如果安装在您的本地系统上)仅包含调用的文档,而不包含其来源本身.

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.

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

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.

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

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_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd, unsigned long, arg)
{
/* do freaky ioctl stuff */
}

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

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 :

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

希望能稍微澄清一下.

这篇关于在哪里可以找到系统调用源代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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