博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
转载 linux内核 asmlinkage宏
阅读量:6995 次
发布时间:2019-06-27

本文共 1560 字,大约阅读时间需要 5 分钟。

转载

 

看一下/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 this simple function. This is a #define for some gcc magic that tells the compiler that the function should not expect to find any of its arguments in registers (a common optimization), but only on the CPU's stack. Recall our earlier assertion that system_call consumes its first argument, the system call number, and allows up to four more arguments that are passed along to the real system call. system_call achieves this feat simply by leaving its other arguments (which were passed to it in registers) on the stack. All system calls are marked with the asmlinkage tag, so they all look to the stack for arguments. Of course, in sys_ni_syscall's case, this doesn't make any difference, because sys_ni_syscall doesn't take any arguments, but it's an issue for most other system calls. And, because you'll be seeing asmlinkage in front of many other functions, I thought you should know what it was about.

转载于:https://www.cnblogs.com/pingandezhufu/p/4368598.html

你可能感兴趣的文章
30个高质量的免费jquery滑块PSD文件
查看>>
hdu1686(kmp)
查看>>
【web前端面试题整理05】做几道前端面试题休息休息吧
查看>>
SQL查询的几种方式
查看>>
悉尼农历节精彩贺岁活动准备就绪
查看>>
Facebook拟投资10亿美元在弗吉尼亚州打造数据中心
查看>>
图片基础知识梳理(1) ImageView 的 ScaleType 属性解析
查看>>
理解索引:MySQL执行计划详细介绍
查看>>
滑动冲突
查看>>
Ubuntu Linux 中虚拟主机的配置 - 搭配 Nginx
查看>>
1024程序员节最新福利之2018最全Android资料集合
查看>>
源码阅读:SDWebImage(七)——SDWebImageImageIOCoder
查看>>
App 启动优化 之 背景知识
查看>>
从0到1:打造移动端H5性能测试平台
查看>>
从零开始理解JAVA事件处理机制(1)
查看>>
AR+营销,推广只是第一步,和AR购物联姻才是未来
查看>>
JDBC实例代码
查看>>
MySQL 8.0窗口函数--row_number over..应用
查看>>
网上流行的各开源框架与技术
查看>>
聊一聊RPC
查看>>