linux中asmlinkage宏的使用
来源:互联网 发布:电视剧网站源码 编辑:程序博客网 时间:2024/05/20 17:59
asmlinkage是个宏,使用它是为了保持参数在stack中。
看一下/usr/include/asm/linkage.h里面的定义:
#define asmlinkage CPP_ASMLINKAGE __attribute__((regparm(0)))
其中 __attribute__是关键字,是gcc的C语言扩展。
__attribute__机制是GNU C的一大特色,它可以设置函数属性、变量属性和类型属性等。可以通过它们向编译器提供更多数据,帮助编译器执行优化等。
__attribute__((regparm(0))):告诉gcc编译器该函数不需要通过任何寄存器来传递参数,参数只是通过堆栈来传递。
__attribute__((regparm(3))):告诉gcc编译器这个函数可以通过寄存器传递多达3个的参数,这3个寄存器依次为EAX、EDX 和 ECX。更多的参数才通过堆栈传递。这样可以减少一些入栈出栈操作,因此调用比较快。
asmlinkage大都用在系统调用中。有一些情况下是需要明确的告诉编译器,我们是使用stack来传递参数的,比如X86中的系统调用,是先将参数压入stack以后调用sys_*函数的,所以所有的sys_*函数都有asmlinkage来告诉编译器不要使用寄存器来编译,
The asmlinkage tag is one other thing that we should observe about thissimple function. This is a #define for some gcc magic that tells thecompiler that the function should not expect to find any of itsarguments in registers (a common optimization), but only on the CPU'sstack. Recall our earlier assertion that system_call consumes its firstargument, the system call number, and allows up to four more argumentsthat are passed along to the real system call. system_call achievesthis feat simply by leaving its other arguments (which were passed toit in registers) on the stack. All system calls are marked with theasmlinkage tag, so they all look to the stack for arguments. Of course,in sys_ni_syscall's case, this doesn't make any difference, becausesys_ni_syscall doesn't take any arguments, but it's an issue for mostother system calls. And, because you'll be seeing asmlinkage in frontof many other functions, I thought you should know what it was about.
#define asmlinkage CPP_ASMLINKAGE __attribute__((regparm(0)))
其中 __attribute__是关键字,是gcc的C语言扩展。
__attribute__机制是GNU C的一大特色,它可以设置函数属性、变量属性和类型属性等。可以通过它们向编译器提供更多数据,帮助编译器执行优化等。
__attribute__((regparm(0))):告诉gcc编译器该函数不需要通过任何寄存器来传递参数,参数只是通过堆栈来传递。
__attribute__((regparm(3))):告诉gcc编译器这个函数可以通过寄存器传递多达3个的参数,这3个寄存器依次为EAX、EDX 和 ECX。更多的参数才通过堆栈传递。这样可以减少一些入栈出栈操作,因此调用比较快。
asmlinkage大都用在系统调用中。有一些情况下是需要明确的告诉编译器,我们是使用stack来传递参数的,比如X86中的系统调用,是先将参数压入stack以后调用sys_*函数的,所以所有的sys_*函数都有asmlinkage来告诉编译器不要使用寄存器来编译,
The asmlinkage tag is one other thing that we should observe about thissimple function. This is a #define for some gcc magic that tells thecompiler that the function should not expect to find any of itsarguments in registers (a common optimization), but only on the CPU'sstack. Recall our earlier assertion that system_call consumes its firstargument, the system call number, and allows up to four more argumentsthat are passed along to the real system call. system_call achievesthis feat simply by leaving its other arguments (which were passed toit in registers) on the stack. All system calls are marked with theasmlinkage tag, so they all look to the stack for arguments. Of course,in sys_ni_syscall's case, this doesn't make any difference, becausesys_ni_syscall doesn't take any arguments, but it's an issue for mostother system calls. And, because you'll be seeing asmlinkage in frontof many other functions, I thought you should know what it was about.
阅读全文
0 0
- linux中asmlinkage宏的使用
- linux中asmlinkage宏的解析
- linux源码中asmlinkage的作用
- linux内核中asmlinkage的含义
- linux内核 asmlinkage宏
- linux内核 asmlinkage宏
- linux内核 asmlinkage宏
- linux内核 asmlinkage宏
- linux内核 asmlinkage宏
- linux内核 asmlinkage宏
- linux内核 asmlinkage宏
- linux内核中的fastcall和asmlinkage宏
- linux内核中的fastcall和asmlinkage宏
- Linux内核中的fastcall和asmlinkage宏
- linux内核中的fastcall和asmlinkage宏
- asmlinkage宏
- asmlinkage宏
- asmlinkage宏
- 数组排序
- eoLinker AMS 识别代码注释生成文档功能教程
- c#获取当前登录用户的所有进程,而不是所有用户的进程
- DeepLearning与Local minima
- centeros6.5安装 rrdtool
- linux中asmlinkage宏的使用
- Android WebView 回退到原生goback() 遭遇重定向
- cocos creator项目添加其他的库后用Android studio打包apk时出现couldn't find "cocos2djs.so"
- 从Handler.post(Runnable r)再一次梳理Android的消息机制(以及handler的内存泄露)
- ARM常用汇编指令
- nginx 自启动代码-官网
- 动态添加碎片的正确姿势,防止碎片的重新创建,用add取代replace
- HDU-1561 The more, The Better (树上背包)
- Java程序员职业生涯规划完整版:从程序员到CTO