x64调用约定(堆栈)和varargs [英] x64 calling convention (stack) and varargs
问题描述
我已经阅读了 Microsoft的文档,但是该方案是如此尴尬的是,我想我会仔细检查以确保我正确理解...
I've read Microsoft's documentation, but the scheme is so awkward, I thought I'd double-check to make sure I'm understanding it correctly...
我的理解是传递参数的通用方法是这样的吗? :
My understanding is the generic method by which parameters are passed is this:
--- bottom of stack ---
(return address)
[shadow space for arg 1]
[shadow space for arg 2]
[shadow space for arg 3]
[shadow space for arg 4]
arg N
arg N - 1
arg N - 2
...
arg 6
arg 5
---- top of stack -----
在实现 va_arg
时似乎很尴尬,实际上是这样吗?
It seems so awkward when implementing va_arg
and such... is this actually correct?
推荐答案
正确的图是
--- Bottom of stack --- RSP + size (higher addresses)
arg N
arg N - 1
arg N - 2
...
arg 6
arg 5
[shadow space for arg 4]
[shadow space for arg 3]
[shadow space for arg 2]
[shadow space for arg 1]
(return address)
---- Top of stack ----- RSP (lower addresses)
[grows downward]
返回地址位于堆栈的顶部(最近被压入),其后是前四个参数的影子空间,后跟参数5和向前。
The return address is at the top of the stack (most recently pushed), followed by shadow space for the first four parameters, followed by parameters 5 and onward.
这些参数从右向左推:最后一个参数(N)首先被推,因此它最接近堆栈的底部。
The parameters are pushed right to left: The last parameter (N) is pushed first, so it is closest to the bottom of the stack.
这篇关于x64调用约定(堆栈)和varargs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!