Thursday, June 23, 2011

Windows Calling convention Summary

Default is __cdecl

  • caller pushes parms on stack
  • calls function
  • caller pops parms off stack
  • The decorated name in windows just has a leading underscore "_".
Alternative is __stdcal

  • also known as WINAPI and PASCAL
  • WIN32 uses this convention, hence WINAPI
  • callee pops parms off stack.  Results in smaller code since if a program calls a routine ten times the stack pop code is only once in the called function and not in each of the ten places it is used.
  • Routines with variable arguments are hard to clean up. ie. printf.
  • The decorated name has "_" prefix and a "@n" postfix.  "n" is a number saying how many bytes are used to encode the function parameters.
Other alternative is __fastcall

  • Uses some registers to pass parameters.
  • Time used to save registers cuts down on benefits.

No comments:

Post a Comment