linux 系统调用实现

linux system call implementation

在哪里可以找到一些系统调用的源代码?例如,我正在寻找 fstat 的实现,如 here.

所述

一个system call is mostly implemented inside the Linux kernel, with a tiny glue code in the C standard library. But see also vdso(7).

从用户态的角度来看,系统调用(它们在 syscalls(2)...) is a single machine instruction (often SYSENTER) with some calling conventions 中列出(例如定义哪个机器寄存器保存系统调用号 - 例如 __NR_stat 来自 /usr/include/asm/unistd_64.h ....-,以及哪些其他寄存器包含系统调用的参数)。

使用strace(1)了解给定程序或进程完成了哪些系统调用。

C 标准库有一个微型包装函数(调用内核,在 ABI 之后,并处理错误报告和 errno)。

对于stat(2), the C wrapping function is e.g. in stat/stat.c for musl-libc

kernel code, most of the work happens in fs/stat.c 内(例如在第 207 行之后)。

另请参阅 & that 个答案