x64调用约定(堆栈)和varargs

时间:2012-08-23 02:06:34

标签: windows 64-bit calling-convention win64

我读过Microsoft's documentation,但这个计划太尴尬了,我想我会仔细检查以确保我正确理解它...

我的理解是传递参数的通用方法是:

--- 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时似乎很尴尬,这样......这实际上是否正确?

1 个答案:

答案 0 :(得分:6)

正确的图表是

--- 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及以后。

参数从右向左推:最后一个参数(N)被推动,因此它最接近堆栈的底部。