为什么系统调用cloxber rcx和r11? [英] Why does a syscall clobber rcx and r11?

查看:85
本文介绍了为什么系统调用cloxber rcx和r11?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这本书 低级编程:C,汇编语言和程序执行英特尔®64架构

关于系统调用的参数:系统调用的参数与函数的参数存储在不同的寄存器集中.第四个参数存储在 r10 中,而函数在 rcx

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!

原因是 syscall 指令隐式使用 rcx .系统调用不能接受超过六个参数.

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

您可以在堆栈溢出帖子中看到该问题,

You can see this also mentioned in this Stack Overflow post,

通过syscall指令完成系统调用.此副本%rcx和%r11以及%rax,但保留了其他寄存器.

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

我了解破坏 rax 来存储返回码,但是为什么 rcx r11 却被破坏在 syscall ?是否存在破坏 rcx / r11 的特定系统调用的列表?是否有破坏的惯例?他们在任何系统调用中都被认为是安全的吗?

I understand clobbering rax to store the return code, but why is rcx, and r11 clobbered in syscall? Is there a list of the specific syscalls that clobber rcx/r11? Is there a convention for the clobbering? Are they assumed safe in any syscalls?

推荐答案

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

The syscall instruction uses rcx to store the address of the next instruction to return to, and r11 to save the value of the rflags register. These values will then be restored by the sysret instruction.

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

This is done by the CPU when executing the CPU instruction, so any OS-specific calling conventions need to avoid using these registers to pass arguments to syscalls.

这篇关于为什么系统调用cloxber rcx和r11?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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