linux-gcc下asmlinkage是什么意思
2010-03-02 16:07
393 查看
它是GCC对C程序的一种扩展, #define asmlinkage __attribute__((regparm(0)))
表示用0个寄存器传递函数参数,这样,所有的函数参数强迫从栈中提取。
这个asmlinkage大都用在系统调用中,系统调用需要在entry.s文件中用汇编语言调用,所以必须要保证它符合C语言的参数传递规则,才能用汇编语言正确调用它。
这也是为何使用asmlinkage的原因吧!这是我的理解。
仔细看一下有asmlinkage的地方通常是系统调用的函数,因为在系统调用中,寄存器从用户空间传过来后SAVE_ALL压入堆栈,接着调用相应的系统调用函数,这样系统调用函数一定要保证是通过堆栈传递参数的
转贴一段:
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.
具体可以研究一下arch/i386/kernel/entry.S
是不是为了保护寄存器内容不受更改 才用堆栈传递参数 以便以后能RESTORE--ALL?
系统调用把参数存放在寄存器中然后进入内核空间,其实就和正常的函数调用一样,在内核中通过SAVE_ALL构造一个函数调用的栈帧环境,然后调用相应的系统调用函数而已
这里使用的堆栈就是原来SAVE--ALL的寄存器的内容吧??
对的
ENTRY(system_call)
pushl %eax # save orig_eax
SAVE_ALL
GET_THREAD_INFO(%ebp)
# system call tracing in operation
/* Note, _TIF_SECCOMP is bit number 8, and so it needs testw and not testb */
testw $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SECCOMP),TI_flags(%ebp)
jnz syscall_trace_entry
cmpl $(nr_syscalls), %eax
jae syscall_badsys
syscall_call:
call *sys_call_table(,%eax,4)
movl %eax,EAX(%esp) # store the return value
表示用0个寄存器传递函数参数,这样,所有的函数参数强迫从栈中提取。
这个asmlinkage大都用在系统调用中,系统调用需要在entry.s文件中用汇编语言调用,所以必须要保证它符合C语言的参数传递规则,才能用汇编语言正确调用它。
这也是为何使用asmlinkage的原因吧!这是我的理解。
仔细看一下有asmlinkage的地方通常是系统调用的函数,因为在系统调用中,寄存器从用户空间传过来后SAVE_ALL压入堆栈,接着调用相应的系统调用函数,这样系统调用函数一定要保证是通过堆栈传递参数的
转贴一段:
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.
具体可以研究一下arch/i386/kernel/entry.S
是不是为了保护寄存器内容不受更改 才用堆栈传递参数 以便以后能RESTORE--ALL?
系统调用把参数存放在寄存器中然后进入内核空间,其实就和正常的函数调用一样,在内核中通过SAVE_ALL构造一个函数调用的栈帧环境,然后调用相应的系统调用函数而已
这里使用的堆栈就是原来SAVE--ALL的寄存器的内容吧??
对的
ENTRY(system_call)
pushl %eax # save orig_eax
SAVE_ALL
GET_THREAD_INFO(%ebp)
# system call tracing in operation
/* Note, _TIF_SECCOMP is bit number 8, and so it needs testw and not testb */
testw $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SECCOMP),TI_flags(%ebp)
jnz syscall_trace_entry
cmpl $(nr_syscalls), %eax
jae syscall_badsys
syscall_call:
call *sys_call_table(,%eax,4)
movl %eax,EAX(%esp) # store the return value
相关文章推荐
- linux所说的挂载是什么意思
- linux 中i386 i686 i486 I586….等等是什么意思(转)
- 在UNIX或Linux中TTY是什么意思[转]
- linux 下shell中的“-e,-d,-f”什么意思
- linux下的rpm是什么意思
- Linux开发工具(gcc,gdb,make,shell)——三级优化分别做了什么(一)
- 什么是 "asmlinkage"?
- 编程基础-----c++与c调用so文件/C和C++之间so库的互相调用/GCC -lm 是什么意思
- Linux开发工具(gcc,gdb,make,shell)——三级优化分别做了什么
- linux 里命令ls -l 后,文件类型权限后面的数字什么意思
- Linux执行top命令后看到的参数都是什么意思
- Linux部分命令解释(命令缩写代表什么意思)
- 什么是 "asmlinkage"?
- Linux IO 多路复用是什么意思,一直没弄明白?
- linux 中rc是什么意思
- Linux#Shell#if [ $# -ne 1 ];then 是什么意思?
- makefile中的gcc -o $@ $^是什么意思?
- easonjim Code, code and more code. Linux脚本开头#!/bin/bash和#!/bin/sh是什么意思以及区别 一、意思 #!/bin/sh是指此脚本使用/b
- linux中.bashrc 等文件中的rc是什么意思
- linux中 ~是什么意思。 cd ~ - ./ ../的区别