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 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宏相关推荐

  1. 转载 linux内核 asmlinkage宏

    转载http://blog.chinaunix.net/uid-7390305-id-2057287.html 看一下/usr/include/asm/linkage.h里面的定义: #define ...

  2. Linux内核第一宏:container_of

    static void device_release(struct device *dev) {struct device *rd = to_device(dev);devm_kfree(dev, r ...

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

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

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

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

  5. linux内核current宏介绍

    1.概述 本文主要介绍linux current宏在arm和arm64上的实现 内核版本:Linux 5.3 2.current在arm和arm64上的实现 在linux 内核中,有一个current ...

  6. 【Linux 内核】宏内核与微内核架构 ( 操作系统需要满足的要素 | 宏内核 | 微内核 | Linux 内核动态加载机制 )

    文章目录 一.操作系统需要满足的要素 二.宏内核 三.微内核 四.Linux 内核动态加载机制 一.操作系统需要满足的要素 电脑上运行的 操作系统 , 是一个 软件 ; 设备管理 : 操作系统需要 为 ...

  7. Linux内核--各种宏定义

    1. asmlinkage宏 [cpp] view plaincopy #define asmlinkage __attribute__((regparm(0))). 解释:gcc编译器在汇编过程中调 ...

  8. 【GCC系列】深入理解Linux内核 -- __no_sanitize_address宏定义

    本文使用的Linux源码内核版本:Linux 5.10.0 __no_sanitize_address宏定义: 在Linux的内核源码里,尤其是一些关键的内核函数,会包含__no_sanitize_a ...

  9. linux内核系统调用宏SYSCALL_DEFINE

    注:源码来自内核版本3.13 在Linux的系统中,系统调用在内核的入口函数都是以 sys_xxx 命名的(如:sys_read) ,但是如果在内核源码去搜索相关函数时,很遗憾,搜索不到 sys_xx ...

最新文章

  1. TCP的三次握手和四次分手
  2. linux下时间问题---date
  3. (转载)机器学习知识点(十二)坐标下降法(Coordinate descent)
  4. 技巧分享:如何利用CSS属性修改图片颜色?
  5. P1003 铺地毯(模拟)
  6. Java操作MySQL
  7. [Ext JS 4] 拖放[drag and drop]
  8. python执行过程_Python threading模块condition原理及运行流程详解
  9. spring配置线程池
  10. Android 网络请求(OKHttp框架)
  11. eclipse 配色方案
  12. Python 函数的定义与调用
  13. 来自北京大学NOIP金牌选手yxc的常用代码模板1——基础算法
  14. python发邮件附件_python 发送带附件的邮件
  15. 计算机域名(domain name)
  16. mouseover和mouseenter的异同
  17. 读《经济学通识》薛兆丰
  18. python哈姆雷特词频统计_Python练习题15:文本词频统计:英文版哈姆雷特
  19. 汽车芯片短缺潮“拐点”已至?下一波“网络安全”升级战悄然开始
  20. All Eyes on Docs! 练就火眼金睛,就来StarRocks 极客营

热门文章

  1. 再说TCP神奇的40ms
  2. 了解一些多线程相关的知识
  3. Android博客文章整理
  4. 纪念:2006年我在51CTO的第一帖
  5. asp.net mvc 简易上传功能
  6. 向 Internet Explorer 添加 Google 搜索
  7. 讨论SELinux对系统安全的影响(转)
  8. Kubuntu 9.10设置支持文件分级的方法
  9. pluto实现分析(7)
  10. asp.net基础复习(二)——母版页