Linux 系统调用和 INT 80 软件中断之间的巨大差异

发布于 2024-12-21 01:05:20 字数 103 浏览 1 评论 0原文

从目前正在发生的情况来看,有人可以更多地阐述 Linux 系统调用(如 read() 和 write() 等)之间的区别,并使用 x86 INT 操作码将它们写入汇编中并进行设置指定的寄存器?

From a not so far removed picture of what is going on, could someone expound more on what is the difference between Linux's system calls like read() and write() etc. and writing them in assembly using the x86 INT opcode along with setting up the specified registers?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

橘亓 2024-12-28 01:05:20

实际的函数 read() 是所谓“系统调用门”的 C 库包装器。 C 库包装器主要负责诸如在失败时设置 errno 之类的事情,以及用户空间中使用的结构与低级系统调用使用的结构之间的映射。

反过来,系统调用门实际上是从用户模式切换到内核模式的。这取决于 CPU 架构 - 在 x86 上,您有两种选择 - 一种是在使用系统调用号和参数设置寄存器后使用 INT 080h;另一种是使用 INT 080h 来设置寄存器。另一种方法是使用相同的寄存器设置调用映射到每个可执行文件地址空间的库提供的符号。然后,该库在用户->内核转换的几个潜在选项之间进行选择,包括 SYSENTER、SYSCALL 或回退到 INT 080h。其他架构使用不同的方法。无论如何,CPU 都会转移到内核空间,其中系统调用号用于在大表中查找适当的处理程序。

The actual function read() is a C library wrapper over what is called the 'system call gate' . The C library wrapper is primarily responsible for things like setting errno on failure, as well as mapping between structures used in userspace and those used by the low-level syscall.

The system call gate, in turn, is what actually switches from usermode to kernel mode. This depends on the CPU architecture - on x86, you have two options - one is to use INT 080h after setting up registers with the syscall number and arguments; another is to call into a symbol provided by a library mapped into every executable's address space, with the same register setup. This library then picks between several potential options for user->kernel transitions, including SYSENTER, SYSCALL, or a fallback to INT 080h. Other architectures use yet different methods. In any case, the CPU shifts into kernelspace, where the syscall number is used to lookup the appropriate handler in a big table.

冷…雨湿花 2024-12-28 01:05:20

中断不是调用系统调用的唯一方法,您可以使用特殊指令,如 sysenter、syscall 或在保护模式下简单跳转到特定地址。

interrupt is not the only way to invoke system call, you use special instructs like sysenter, syscall or simple jump to specific address in protected mode.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文