asmlinkage
转自:http://www.cnblogs.com/china_blue/archive/2010/01/15/1648523.html
声明,仅为了便于自己记忆和查询,非原创,摘自:http://blog.csdn.net/skywalkzf/archive/2009/12/24/5068966.aspx
什么是 "asmlinkage"?
相信大家在看linux的source code的时候,都会注意到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.
看一下/usr/include/asm/linkage.h里面的定义:
#define asmlinkage CPP_ASMLINKAGE __attribute__((regparm(0)))
__attribute__是关键字,是gcc的C语言扩展,regparm(0)表示不从寄存器传递参数
如果是__attribute__((regparm(3))),那么调用函数的时候参数不是通过栈传递,而是直接放到寄存器里,被调用函数直接从寄存器取参数
还有一种是:
#define fastcall __attribute__((regparm(3)))
#define asmlinkage __attribute__((regparm(0)))
函数定义前加宏asmlinkage ,表示这些函数通过堆栈而不是通过寄存器传递参数。
gcc编译器在汇编过程中调用c语言函数时传递参数有两种方法:一种是通过堆栈,另一种是通过寄存器。缺省时采用寄存器,假如你要在你的汇编过程中调用c语言函数,并且想通过堆栈传递参数,你定义的c函数时要在函数前加上宏asmlinkage
asmlinkage long sys_nice(int increment)
"asmlinkage" 是在 i386 system call 实作中相当重要的一个 gcc 标签(tag)。
当 system call handler 要调用相对应的 system call routine 时,便将一般用途缓存器的值 push 到 stack 里,因此 system call routine 就要由 stack 来读取 system call handler 传递的
参数。这就是 asmlinkage 标签的用意。
system call handler 是 assembly code,system call routine(例如:sys_nice)是 C code,当 assembly code 调用 C function,并且是以 stack 方式传参数(parameter)时,在 C
function 的 prototype 前面就要加上 "asmlinkage"。
加上 "asmlinkage" 后,C function 就会由 stack 取参数,而不是从 register 取参数(可能发生在程序代码最佳化后)。
更进一步的说明...
80x86 的 assembly 有 2 种传递参数的方法:
1. register method
2. stack method
Register method 大多使用一般用途(general-purpose)缓存器来传递参数,这种方法的好处是简单且快速。另外一种传递参数的做法是使用 stack(堆栈),assembly code 的模式如下:
push number1
push number2
push number3
call sum
在 'sum' procedure 里取值的方法,最简单的做法是:
pop ax
pop ax
pop bx
pop cx
Stack Top 是放 IP,我们传给 sum procedure 的参数由 stack 的后一个 entry 开始读取。
其它有关 asmlinkage
1. asmlinkage 是一个定义
2. "asmlinkage" 被定义在 /usr/include/linux/linkage.h
3. 如果您看了 linkage.h,会发现 "__attribute__" 这个语法,这是 gcc 用来定义 function attribute 的语法
asmlinkage的更多相关文章
- 转载 linux内核 asmlinkage宏
转载http://blog.chinaunix.net/uid-7390305-id-2057287.html 看一下/usr/include/asm/linkage.h里面的定义:#define a ...
- Linux内核中的fastcall和asmlinkage宏
代码中看见:#define _fastcall 所以了解下fastcall -------------------------------------------------------------- ...
- asmlinkage的作用
本文转载自:http://blog.chinaunix.net/uid-24945116-id-83893.html 学习啦! asmlinkage是个宏,使用它是为了保持参数在stack中.因为从汇 ...
- asmlinkage的用法
转自:https://www.cnblogs.com/china_blue/archive/2010/01/15/1648523.html https://blog.csdn.net/liujiaoy ...
- linux内核 asmlinkage宏
http://blog.chinaunix.net/uid-7390305-id-2057287.html
- linux内核调试技术之修改内核定时器来定位系统僵死问题
1.简介 在内核调试中,会经常出现内核僵死的问题,也就是发生死循环,内核不能产生调度.导致内核失去响应.这种情况下我们可以采用修改系统内核中的系统时钟的中断来定位发生僵死的进程和函数名称.因为内核系统 ...
- Linux内核启动过程概述
版权声明:本文原创,转载需声明作者ID和原文链接地址. Hi!大家好,我是CrazyCatJack.今天给大家带来的是Linux内核启动过程概述.希望能够帮助大家更好的理解Linux内核的启动,并且创 ...
- Android/Linux下CGroup框架分析及其使用
1 cgroup介绍 CGroup是control group的简称,它为Linux kernel提供一种任务聚集和划分的机制,可以限制.记录.隔离进程组(process groups)所使用的资源( ...
- 第4天--linux内核学习
驱动使用方式1.编译到内核中 * make uImage进入到系统后mknod /dev/led c 500 0 创建设备节点 2.编译为模块 M make module进入到系统后 mknod /d ...
随机推荐
- Vijos P1769 网络的关键边
Description 一个连通的无向图,有些点有A属性,有些点有B属性,可以同时具有.删掉某条边后,如果使得连通块中一些点不具有A,B属性的点,求这些边. Sol Tarjan求割边. 首先这些边一 ...
- Python自动化之sqlalchemy关联查询
外键关联 from sqlalchemy import ForeignKey from sqlalchemy.orm import relationship class Address(Base): ...
- Linux nohup 程序后台运行
&方式: Unix/Linux下一般想让某个程序在后台运行,很多都是使用 & 在程序结尾来让程序自动运行.比如我们要运行mysql在后台: /usr/local/my ...
- AJAX 页面数据传递
$.ajax({ //一个Ajax过程 type: "post", //以post方式与后台沟通 url: "personstockajax.php", //与 ...
- Zigzag Iterator
Given two 1d vectors, implement an iterator to return their elements alternately. For example, given ...
- POJ 1917
http://poj.org/problem?id=1917 poj的字符串的一道水题. 题意么无关紧要, 反正输出的第一行就是把那个<>去掉,s1<s2>s3<s4&g ...
- jQuery获取循环中的选中单选按钮radio的值
1.<input type="radio" name="testradio" value="jquery获取radio的值" /> ...
- docker -v挂载数据卷网络异常的问题
docker 删除容器并重新运行容器时报如下异常: docker: Error response from daemon: failed to create endpoint tomcat001 on ...
- MongoDB 副本集的相关概念【转】
一.副本集基本概念 副本集(replica set) MongoDB的replica set是一个mongod进程实例簇,数据在这个簇中相互复制,并自动进行故障切换. MongoDB的数据库复制增加了 ...
- Java for LeetCode 228 Summary Ranges
Given a sorted integer array without duplicates, return the summary of its ranges. For example, give ...