X64 calling convention (stack) and varargs

I read the Microsoft documentation , but the circuit is so inconvenient that I decided to double check to make sure that I understood it correctly ...

My understanding is the general method by which the parameters are passed:

--- 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 inconvenient to implement va_argand such ... is this really correct?

+5
source share
1 answer

Correct diagram

--- 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 (last pushed), followed by a shadow space for the first four parameters, followed by parameters 5 and beyond.

: (N) , .

+6

All Articles