stdcall
Function arguments are passed (pushed) from right to left. Stack is cleaned up by callee.
Stdcall is almost the same as cdecl with the exception that the callee resets
ESP
to the initial state with
ret x
(instead of
ret
?).
x
= number of arguments *
sizeof(int)
.
push arg3
push arg2
push arg1
call f
f:
; … do this , do that …
ret 12
cdecl
The default (native) calling convention for
C and C++ programs. cdecl is short for
c declaration.
Caller pushes arguments on stack and cleans up stack.
Cleaning up the stack causes larger programs than those with stdcall.
cdecl is required for variadic function arguments (vararg).
push arg3 ; rightmost argument
push arg2
push arg1 ; leftmost argument
call f
add esp, 12 ; 12 = 3 arguments each being 4 bytes
When entering the function (just after call f
and before add esp, 12
), the stack is:
| | Notation in IDA |
ESP | return address | |
ESP+4 | arg1 | arg_0 |
ESP+8 | arg2 | arg_1 |
ESP+12 | arg3 | arg_2 |
fastcall
Some values passed via registers
The 64-bit WinAPI is similar to the 32-bit WinAPI fastcall. The first four parameters are passed in rcx
, rdx
, r8
and r9
(from right to left). Additional parameters are stored on the stack.