Windows x64 function call Convention posted on December 28,200 9 by openwares
Using the PC processor architecture to transition from x86 to x64, Ms cleans up the function call conventions on Windows x64 platform, from the original several types including stdcall, thiscall, fastcall, cdecl, Pascal, etc, unified as a new fastcall call method. This call method is benefited from the increase in the number of registers on the x64 platform.
The main features of the fastcall call Convention on Windows x64 are as follows:
- The first four integer or pointer type parameters are passed in sequence by RCX, RDX, R8, and R9, and the first four floating point type parameters are passed in sequence by xmm0, xmm1, xmm2, and xmm3.
- The called function retains the corresponding space on the call stack for the first four parameters, called Shadow space or spill slot. Even if the called party has no or less than four parameters, the called function retains so much stack space, which helps simplify the call conventions in some special circumstances.
- Any other parameter except the first four parameters is passed through the stack, from right to left.
- The call function is responsible for clearing the call stack.
- The return values of integer or pointer type smaller than or equal to 64 bits are transmitted by Rax.
- The floating point return value is transmitted by xmm0.
- For larger return values (such as struct), the caller allocates space on the stack, and rcX holds the pointer to the space and passes it to the called function, therefore, the registers used by Integer Parameters are shifted one by one to the right. In fact, only three registers can be used, and other parameters are included in the stack. After the function is called, Rax returns the pointer to the space.
- In addition to rcX, RDX, R8, and R9, rax, R10, R11, xmm4, and xmm5 are also volatile registers.
- The RBx, RBP, RDI, RSI, R12, R14, R14, and r15 registers must be protected during use.
- In registers, all parameters are right aligned. Parameters smaller than 64 bits are not highly zero-scaling, that is, high levels are unpredictable junk data.
X64 call conventions