简体   繁体   中英

Windows calling conventions

Hi so a friend told me that:

calling conventions are c++ function specifiers that determine if the function that calls another function should clean the stack frame or that would be the job of the called function

is that true?

Also how would the cleaning part look in assembly with a syscall function calling another one?

Thanks in advance.

Historically, the Fortran and Pascal languages used a convention where the caller pushed its arguments on the stack (first parameter first in stack), and then called the callee function. The prologue code in the callee usually popped the return address and the parameters, and pushed again the return address ( this part is in fact an implementation detail). When the callee returns, the stack is clean.

The C language then came with the ability to call a function with a variable number of arguments. The convention was that the caller pushed the parameters in inverse order (last parameter first in stack) and then called the callee function. The callee then accessed the parameters in the stack without popping anything (the address of the first parameter is just near the return address). When the callee returns, the stack still contained the parameters and the caller should clean them.

This is still used in the Windows system, where most of the API function use the pascal convention ( winapi ) while by default C or C++ methods use by default the C ( cdecl ) convention.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM