X86 Calling Conventions - Callee Clean-up

Callee Clean-up

When the callee cleans the arguments from the stack it needs to be known at compile time how many bytes the stack needs to be adjusted. Therefore, these calling conventions are not compatible with variable argument lists, e.g. printf. They may be, however, more space efficient, as the code needed to unwind the stack does not need to be generated for each call.

Functions which utilize these conventions are easy to recognize in ASM code because they will unwind the stack prior to returning. The x86 ret instruction allows an optional 16-bit parameter that specifies the number of stack bytes to unwind before returning to the caller. Such code looks like this:

ret 12

Read more about this topic:  X86 Calling Conventions

Other related articles:

X86 Calling Conventions - Callee Clean-up - Safecall
... The safecall calling convention is the same as the stdcall calling convention, except that exceptions are passed back to the caller in EAX as a HResult (instead of in FS), while the function result is passed by reference on the stack as though it were a final "out" parameter ... When calling a Delphi function from Delphi this calling convention will appear just like any other calling convention, because although exceptions are passed back in EAX, they are automatically converted back to proper exceptions by the caller ...