linux - 为什么系统调用会破坏 rcx 和 r11?

标签 linux assembly x86-64 system-calls

<分区>

在书中Low-Level Programming: C, Assembly, and Program Execution on Intel® 64 Architecture它说,

On system call arguments The arguments for system calls are stored in a different set of registers than those for functions. The fourth argument is stored in r10 , while a function accepts the fourth argument in rcx!

The reason is that syscall instruction implicitly uses rcx. System calls cannot accept more than six arguments.

你可以看到这个Stack Overflow post里面也提到了这个,

A system-call is done via the syscall instruction. This clobbers %rcx and %r11, as well as %rax, but other registers are preserved.

我理解破坏 rax 来存储返回码,但为什么 rcxr11syscall 中被破坏>?是否有破坏 rcx/r11 的特定系统调用的列表?有破坏的约定吗?它们在任何系统调用中都被认为是安全的吗?

最佳答案

syscall指令使用rcx 存储下一条要返回的指令的地址,使用r11 保存rflags 寄存器的值。然后这些值将由 sysret 指令恢复。

这是由 CPU 在执行 CPU 指令时完成的,因此任何特定于操作系统的调用约定都需要避免使用这些寄存器将参数传递给系统调用。

关于linux - 为什么系统调用会破坏 rcx 和 r11?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50571275/

相关文章:

javascript - 如何通过 sudo 命令使用 forever-node?

linux - linux 中的 ipc_namespace.h 在哪里

c - 汇编跳转指令地址计算

c - 使用指定初始值设定项时不同的 gcc 程序集

FXSAVE 能否在 FXRSTOR 之前执行两次?

x86 - 将 _mm_shuffle_epi32 转换为 C 表达式以进行排列?

linux - 如何获取远程服务器的sftp版本?

linux - nginx 设置为反向代理的目录重定向问题

c++ - Visual C++ 内联汇编程序和定义字符串?

multithreading - 使用 HT 在一个 Core 上执行的线程之间的数据交换将使用什么?