linux - 系统调用如何知道包装函数将其参数放入何处?

标签 linux system-calls

我正在尝试在 Linux (RedHat Enterprise 8) 中实现一个系统调用,但我对它的工作方式有点困惑。据我所知,我在用户模式下实现了一个包装器,它将系统调用号放在 eax 中,将参数放在 ebx、ecx、edx 等中,然后调用调用适当系统调用的 int 0x80。我的问题是,由于系统调用的编写方式与常规 C 函数类似,它如何知道哪些寄存器包含哪些参数?它是一个约定,还是有一个机制,如果是的话,它在哪里以及如何做?

编辑:这是一项家庭作业。我知道有系统调用宏可以为我做这些事情。

最佳答案

来自Linux Journal文章,第 2 页底部

Since the system call interface is exclusively register-parametered, six parameters at most can be used with a single system call. %eax is the syscall number; %ebx, %ecx, %edx, %esi, %edi and %ebp are the six generic registers used as param0-5; and %esp cannot be used because it's overwritten by the kernel when it enters ring 0 (i.e., kernel mode).

您的 c 代码可能看起来像是在进行系统调用,但实际上它调用了 libc 中的函数。该函数确保所有参数都在正确的寄存器中,然后进行中断。

关于linux - 系统调用如何知道包装函数将其参数放入何处?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2495945/

相关文章:

regex - 退出值正则表达式bash问题

在 Makefile 中处理链接的正确方法?

linux - 为什么我执行的 sbrk 系统调用不起作用?

linux - 重定向密码提示警报

linux - 复制一个 1TB 的稀疏文件

networking - 关于 Hadoop 网络系统调用

linux - Supervisord 中的命令失败 'stdout_log and system command'

c - 如何忽略从标准输入读取的 C 中的箭头键?

你能帮我修改这段代码,让它在旧版本的 linux 中编译吗

linux - 如何在 Linux 中选择处理器?