Several commonly used calling convention

Three kinds of function calling convention

Disclaimer: This article is a blogger original article, reproduced, please attach the original source link and this statement. 2019-10-02,22: 48: 24.
By ----- drowning heart of the ups and downs ---- blog Park

Overview

  The convention is that some call a function when the function call rules, including:

  Yazhan order function parameters,

  1. By the caller or the callee parameters popped,
  2. And a method of producing a modified function name.
  3. Push function parameters is the order, the caller needs a function to be called when a function of several parameters (the definition of a function), transmission parameters is performed by the stack. The caller will be in a certain sequence parameters were pushed onto the stack for use by the calling function. you or the caller is calling this the parameters popped, who refers to the management stack space, calls the process is complete: callers to connect your stack base (EBP) onto the stack, then the current top of the stack (ESP) assignment to the bottom of the stack as the new EBP, and then open up a new piece of stack space based on the new bottom of the stack as the stack space used by the called function. What is the caller or the called this upon returning to empty this pushed up (use of already finished) parameter stack space. Way function to produce a modified name refers to the compilation, call a function this function generates a string description of the format string convention will be different depending on the call.

Summary of all types of calling convention

  The main summarize __cdecl, __ stdcall, __ fastcall, __ nakedcall, __ thiscall, __ pascal calling convention of several principles. (Naked on the blog post)

      

  •   __cdecl

  C and C ++ is the default calling convention (whether you write and not write, are __cdecl):

  1.   Right-to-left will push the parameters
  2.   The caller maintenance parameters memory stack
  3.   Decorated name format is an underscore in front of the original function name, such as _function  

      

  •   __stdcall

  C and C ++ standard way to call a function in the Win32 API generally call this way:

  1.   Right-to-left will push the parameters
  2.   This is called the stack memory management parameters, namely empty stack before the function to return to their
  3.   Decorated name format is an underscore in front of the original function name, the original name of the function plus an @, as _function @

     

  •   __fastcall

  fastcall is fast calling convention passes parameters in registers, compared to the read parameters to the stack memory, faster fastcall:

  1.   DWORD before transmission using two or less ECX and EDX registers parameters, other parameters sequentially from right to left Drawing
  2.   Called function is responsible for managing memory stack parameters
  3.   Each applied modification is a Name Format @ before the original function name and the rear, and the number of bytes followed function parameters, such as the @ function @ 16

     

      

  •   __thiscall

  C ++ class member function default calling convention in C ++, because the class members have a particularity of this pointer, thiscall need special treatment:

  1.   Parameters onto the stack from right to left
  2.   Indeterminate number of arguments calling is responsible for managing memory stack by the caller, the caller or by the memory management stack; if the number of parameters determined, this pointer by ecx register passed to the called function, otherwise after all parameters onto the stack, this pointer the stack is passed to the caller
  •   __nakedcall

  Rarely use this calling convention, in nakedcall calling convention, the compiler will not increase the initialization and cleanup code to this function, more special is that you can not return the return value return, can only be inserted into the compilation of results are returned.

  •   __pascal

  pascal calling convention and above several different:

  1.   From left to right the pushing of the parameters
  2.   Callee stack management parameters

Guess you like

Origin www.cnblogs.com/Reverse-xiaoyu/p/11618739.html