5

我已经阅读了微软的文档,但是这个方案太尴尬了,我想我会仔细检查以确保我理解正确......

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

--- 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……这真的正确吗?

4

1 回答 1

7

正确的图是

--- 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)被最先压入,所以它最接近栈底。

于 2012-08-23T05:39:33.690 回答