windows - x64 调用约定(堆栈)和可变参数

标签 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 时看起来很尴尬...这真的是正确的吗?

最佳答案

正确的图是

--- 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) 先压入,因此它最靠近栈底。

关于windows - x64 调用约定(堆栈)和可变参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12083810/

相关文章:

C++ 如何在 MS VC++ 6.0 中编译 __thiscall

c++ - 简单明了,我们为什么要使用 _stdcall?

assembly - 调用 WinApi 函数后 RIP 损坏

windows - NLTK v3.2 : Unable to nltk. pos_tag()

c# - 使用 VS 2010 调试导入的 dll

macos - Cocoa:组件管理器未找到 64 位应用程序中的所有组件

windows - QtScript:在 64 位 Windows 上崩溃

.net - 如何从 .NET 锁定 Windows(如 "Windows + L")?

java - 使用 JAX-WS 的 EXCEPTION_STACK_OVERFLOW

android - 哪个 Eclipse 适用于 Android?