x86_64 Linux syscall参数 [英] x86_64 Linux syscall arguments
问题描述
我正在Linux上学习x86_64程序集,遇到了一些我希望可以清除的冲突信息.一方面,我已经阅读了有关syscall参数的信息,您将按rdi,rsi,rdx等顺序使用寄存器.但是另一方面,我读到您使用了寄存器rbx,rcx,rdx等.有人告诉我,这样做的原因是因为ABI,但我并不完全理解那是什么意思.
I'm learning x86_64 assembly on Linux and I've run into some conflicting information that I was hoping could get cleared up. On one hand, I've read that for syscall arguments, you would use registers in the order of rdi, rsi, rdx, and so on. But on the other hand I've read that you use the registers rbx, rcx, rdx, and so on. One person told me that the reasoning for this is because of ABI, but I'm not totally understanding what that exactly means.
为什么要使用两种格式,哪种才是正确的格式?
Why are there two formats for this and which would be the proper one to use?
推荐答案
根据此Wikibooks页面,这取决于您用于执行系统调用的指令.
According to this Wikibooks page, it depends on which instruction you are using to perform the syscall.
-
如果使用的是
int $0x80
(呼叫号码为asm/unistd_32.h
的32位ABI),则应使用eax
作为系统调用号码,并使用ebx
,ecx
,edx
,esi
,edi
和ebp
作为参数(按此顺序).
If you are using
int $0x80
(the 32-bit ABI with call numbers fromasm/unistd_32.h
), then you should useeax
for the syscall number, andebx
,ecx
,edx
,esi
,edi
, andebp
for the parameters (in that order).
如果使用的是syscall
指令(具有来自asm/unistd.h
的本地调用号的64位ABI),则应将rax
用作系统调用号,并将rdi
,rsi
, rdx
,r10
,r8
和r9
作为参数.
If you are using the syscall
instruction (the 64-bit ABI with native call numbers from asm/unistd.h
), you should use rax
for the syscall number and rdi
, rsi
, rdx
, r10
, r8
, and r9
for the parameters.
UNIX&的调用约定是什么? Linux系统在i386和x86-64上调用
在64位模式下,首选syscall
,因为它速度更快,可在所有x86-64 Linux内核上使用,并且支持64位指针和整数.例如,int 0x80
ABI实际上是在ecx
中而不是在rcx
中接受输入的,因此对于64位代码的堆栈中的缓冲区的write
或read
而言,它是不可使用的.
如果您以64位代码使用32位int 0x80 Linux ABI,会发生什么情况?.
In 64-bit mode syscall
is preferred because it's faster, available on all x86-64 Linux kernels, and supports 64-bit pointers and integers. The int 0x80
ABI truly takes input in ecx
, not rcx
, for example, making it unusable for write
or read
of a buffer on the stack in 64-bit code.
What happens if you use the 32-bit int 0x80 Linux ABI in 64-bit code?.
这篇关于x86_64 Linux syscall参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!