转载http://blog.chinaunix.net/uid-7390305-id-2057287.html

看一下/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.
linux内核 asmlinkage宏

转载 linux内核 asmlinkage宏的更多相关文章

  1. linux内核 asmlinkage宏

    http://blog.chinaunix.net/uid-7390305-id-2057287.html

  2. 嵌入式C语言自我修养 04:Linux 内核第一宏:container_of

    4.1 typeof 关键字 ANSI C 定义了 sizeof 关键字,用来获取一个变量或数据类型在内存中所占的存储字节数.GNU C 扩展了一个关键字 typeof,用来获取一个变量或表达式的类型 ...

  3. Linux 内核常见宏定义

    我们在阅读Linux内核是,常见到这些宏 __init, __initdata, __initfunc(), asmlinkage, ENTRY(), FASTCALL()等等.它们定义在 /incl ...

  4. [转载]Linux内核编译

    原文地址:https://blog.csdn.net/qq_34247099/article/details/50949720 写在前面的话: 本人大二,东南大学一个软工狗,正在修一门名为<操作 ...

  5. [转载]linux内核中的HZ介绍

    时钟中断由系统定时硬件以周期性的间隔产生,这个间隔由内核根据 HZ 值来设定,HZ 是一个体系依赖的值,在 <Linux/param.h>中定义或该文件包含的某个子平台相关文件中.作为通用 ...

  6. [转载]Linux 内核list_head 学习(一)

    在Linux内核中,提供了一个用来创建双向循环链表的结构 list_head.虽然linux内核是用C语言写的,但是list_head的引入,使得内核数据结构也可以拥有面向对象的特性,通过使用操作li ...

  7. linux内核第一宏 container_of

    内核第一宏 list_entry()有着内核第一宏的美称,它被设计用来通过结构体成员的指针来返回结构体的指针.现在就让我们通过一步步的分析,来揭开它的神秘面纱,感受内核第一宏设计的精妙之处. 整理分析 ...

  8. [转载]Linux内核list_head学习(二)

    前一篇文章讨论了list_head 结构的基本结构和实现原理,本文主要介绍一下实例代码. 自己如果想在应用程序中使用list_head 的相应操作(当然应该没人使用了,C++ STL提供了list 用 ...

  9. 转载-linux内核长什么样

    来源:Linux中国 今天,我来为大家解读一幅来自 TurnOff.us 的漫画 "InSide The Linux Kernel" . TurnOff.us是一个极客漫画网站,作 ...

随机推荐

  1. ios swift 2 新的OptionSetType使用方法

    http://www.rockhoppertech.com/blog/swift-2-optionsettype/?utm_source=tuicool 主要使用方法如下 components([NS ...

  2. 在wpf中使用winrt的Toast弹框效果

    源码地址:https://code.msdn.microsoft.com/windowsdesktop/Sending-toast-notifications-71e230a2/sourcecode? ...

  3. Git-windows安装包

    下载地址 http://192.168.168.230/sw-search-sp/soft/4e/30195/Git-2.7.2-32-bit_setup.1457942412.exe 来自为知笔记( ...

  4. Match:Cyclic Nacklace(KMP的next数组的高级应用)(HDU 3746)

    串珠子 题目大意:给定一个字串,要你找到如果要使之成为循环串,在末尾需要的最小的字数(只能添加字符,不能删减字符) 首先联动一下之前做过的动态规划问题POJ 3280,当然了3280这一题是用的LD, ...

  5. QT Creator调用动态链接库实例

    #include<iostream> #include <QLibrary> using namespace std; int main() { cout<<&qu ...

  6. HTML认识

    1.1 认识什么是纯文本文件 txt window自带有一个软件,叫做记事本,记事本保存的格式TXT,就是英文text的缩写,术语上称呼为"纯文本文件" TXT文件,只能保存文本内 ...

  7. osgearth 配置mapNode TerrainOptions

    设置瓦片PagedLOD节点最小可视距离因子,默认是6.0 minTileRangeFactor() Map *map = new Map();WWOptions wwImgGlobe;map-> ...

  8. 点击按钮对两个div的隐藏与显示进行切换

    HTML: <button type="button"  id="showHidden">点击切换div的隐藏与显示</button> ...

  9. strlen与sizeof

    strlen计算不包括终止符null字节的字符串长度,而sizeof则计算包括终止null字节的长度.另一个差别,strlen需要一次函数调用,而sizeof在编译时计算缓冲区长度.

  10. iOS - 定制多样式二维码

    二维码/条形码是按照某种特定的几何图形按一定规律在平台(一维/二维方向上)分布的黑白相间的图形纪录符号信息.使用若干个与二进制对应的几何形体来表示文字数值信息.   最常见的二维码功能包括信息获取.网 ...