x64 调用约定(堆栈)和可变参数 [英] x64 calling convention (stack) and varargs

查看:25
本文介绍了x64 调用约定(堆栈)和可变参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了 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 调用约定(堆栈)和可变参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆