Calling convention-调用约定
In computer science, a calling convention is an implementation-level (low-level) scheme for how subroutines receive parameters from their caller and how they return a result. Differences in various implementations include where parameters, return values, return addresses and scope links are placed, and how the tasks of preparing for a function call and restoring the environment afterward are divided between the caller and the callee.
Calling conventions may be related to a particular programming language's evaluation strategy but most often are not considered part of it (or vice versa), as the evaluation strategy is usually defined on a higher abstraction level and seen as a part of the language rather than as a low-level implementation detail of a particular language's compiler.
Variations[edit]
Calling conventions may differ in:
- Where parameters, return values and return addresses are placed (in registers, on the call stack, a mix of both, or in other memory structures)
- The order in which actual arguments for formal parameters are passed (or the parts of a large or complex argument)
- How a (possibly long or complex) return value is delivered from the callee back to the caller (on the stack, in a register, or within the heap)
- How the task of setting up for and cleaning up after a function call is divided between the caller and the callee
- Whether and how metadata describing the arguments is passed
- Where the previous value of the frame pointer is stored, which is used to restore the frame pointer when the routine ends (in the stack frame, or in some register)
- Where any static scope links for the routine's non-local data access are placed (typically at one or more positions in the stack frame, but sometimes in a general register, or, for some architectures, in special-purpose registers)
- How local variables are allocated can sometimes also be part of the calling convention (when the caller allocates for the callee)
In some cases, differences also include the following:
- Conventions on which registers may be directly used by the callee, without being preserved (otherwise regarded as an ABI detail)
- Which registers are considered to be volatile and, if volatile, need not be restored by the callee (often regarded as an ABI detail)
Language variation[edit]
Threaded code[edit]
Threaded code places all the responsibility for setting up for and cleaning up after a function call on the called code. The calling code does nothing but list the subroutines to be called. This puts all the function setup and cleanup code in one place—the prolog and epilog of the function—rather than in the many places that function is called. This makes threaded code the most compact calling convention.
Threaded code passes all arguments on the stack. All return values are returned on the stack. This makes naive implementations slower than calling conventions that keep more values in registers. However, threaded code implementations that cache several of the top stack values in registers—in particular, the return address—are usually faster than subroutine calling conventions that always push and pop the return address to the stack.[1][2][3]
https://en.wikipedia.org/wiki/Calling_convention
Calling convention-调用约定的更多相关文章
- C/C++/动态链接库DLL中函数的调用约定与名称修饰
参见:http://blog.twofei.com/cc/impl/calling-convension.html 调用约定(Calling Convention)是指在程序设计语言中为了实现函数调用 ...
- X86调用约定 calling convention
http://zh.wikipedia.org/wiki/X86%E8%B0%83%E7%94%A8%E7%BA%A6%E5%AE%9A 这里描述了在x86芯片架构上的调用约定(calling con ...
- C/C++:函数的调用约定(Calling Convention)和名称修饰(Decorated Name)以及两者不匹配引起的问题
转自:http://blog.csdn.net/zskof/article/details/3475182 注:C++有着与C不同的名称修饰,主要是为了解决重载(overload):调用约定则影响函数 ...
- C++调用约定和名字约定
C++调用约定和名字约定 转自http://www.cppblog.com/mzty/archive/2007/04/20/22349.html 调用约定:__cdecl __fastcall与 __ ...
- DLL中调用约定和名称修饰(一)
DLL中调用约定和名称修饰(一) 调用约定(Calling Convention)是指在程序设计语言中为了实现函数调用而建立的一种协议.这种协议规定了该语言的函数中的参数传送方式.参数是否可变和由谁来 ...
- Delphi调用约定
Register Calling Convention Ojbect Pascal的默认调用约定为register,寄存器调用约定会将前三个参数依次放入eax,edx,ecx,返回值是eax(根据类型 ...
- VC内存溢出一例 –- 调用约定不一致 (_CRT_DEBUGGER_HOOK(_CRT_DEBUGGER_GSFAILURE)
VC (_CRT_DEBUGGER_HOOK(_CRT_DEBUGGER_GSFAILURE) 问题记录 VC内存溢出一例 –- 调用约定不一致 (_CRT_DEBUGGER_HOOK(_CRT_DE ...
- 从栈不平衡问题 理解 calling convention
最近在开发的过程中遇到了几个很诡异的问题,造成了栈不平衡从而导致程序崩溃. 经过几经排查发现是和调用规约(calling convention)相关的问题,特此分享出来. 首先,讲一下什么是调用规约. ...
- 调用约定__cdecl __fastcall与__stdcall
__cdecl __fastcall与__stdcall,三者都是调用约定(Calling convention),它决定以下内容:1)函数参数的压栈顺序,2)由调用者还是被调用者把参数弹出栈,3)以 ...
- C&C++ Calling Convention
tkorays(tkorays@hotmail.com) 调用约定(Calling Convention) 是计算机编程中一个比较底层的设计,它主要涉及: 函数参数通过寄存器传递还是栈? 函数参数从左 ...
随机推荐
- javascript中封装获取样式属性值的兼容方法
function getStyle(obj, attr) { if (window.getComputedStyle) { return window.getComputedStyle(obj, nu ...
- Linux apache tomcat
[root@node1 ~]# mv jdk-7u79-linux-x64.tar.gz /usr/local/[root@node1 ~]# cd /usr/local/[root@node1 lo ...
- UWP Control Toolkit Collections 求UWP工作
1. it is like wechat wait-sliderdeleteitem in iOS 看起来比较像微信删掉项 now support listview and gridview in C ...
- 洛谷P2915 [USACO08NOV]奶牛混合起来Mixed Up Cows 状压动归
考场上空间开大了一倍就爆0了QAQ- Code: #include<cstdio> #include<algorithm> #include<cmath> usin ...
- Pyhton学习——Day10
#################################################################################################### ...
- Web API Filter
在Web Api中,有三种Filter Filter类型 实现的接口 描述 Authorization IAuthorizationFilter 最先运行的Filter,被用作请求权限校验 Actio ...
- HDU 2303 The Embarrassed Cryptographer
The Embarrassed Cryptographer 题意 给一个两个素数乘积(1e100)K, 给以个数L(1e6), 判断K的两个素数是不是都大于L 题解 对于这么大的范围,素数肯定是要打表 ...
- 【WPF】这可能是全网最全的拖拽实现方法的总结
原文地址 https://www.cnblogs.com/younShieh/p/10811456.html 前文 本文只对笔者学习掌握的一般的拖动问题的实现方法进行整理和讨论,包括窗口.控件等内容的 ...
- BZOJ 1030 [JSOI2007]文本生成器 (Trie图+DP)
题目大意:给你一堆字符串,一个串不合法的条件是这些字符串中任意一个是这个串的子串,求合法的串的数量 其实这道题比 [HNOI2008]GT考试 那道题好写一些,但道理是一样的 只不过这道题的答案可以转 ...
- MySQL主从宕机的解决方法
测试系统:centos6.5系统 测试环境IP地址划分: master: 192.168.80.130 slave:192.168.80.143 slave:192.168.80.146 首先模拟(M ...