x64 calling convention (stack) and varargs

橙三吉。 提交于 2019-12-07 04:47:00

问题


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 -----

It seems so awkward when implementing va_arg and such... is this actually correct?


回答1:


The correct diagram is

--- 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]

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.

The parameters are pushed right to left: The last parameter (N) is pushed first, so it is closest to the bottom of the stack.



来源:https://stackoverflow.com/questions/12083810/x64-calling-convention-stack-and-varargs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!