1.在include\linux\Syscalls.h 中有很多系统调用的函数原型
形式为:asmlinkage reutrn_type (*sys_call)(type_argv argv)
2.在include\asm-i386\Linkage.h 中有asmlinkage这个宏的定义
但不是每个体系都支持这个宏好像,很多asm-arch\Linkage.h 没有这个宏的定义。
#define asmlinkage CPP_ASMLINKAGE __attribute__((regparm(0)))
3.在这个帖子里面有人有解答,
此外在http://www.jollen.org/blog/2006/10/_asmlinkage.html里面有一篇博文
已经被到处转载乱大街了。
4.摘抄过来
asmlinkage是个宏,使用它是为了保持参数在stack中。因为从汇编语言到C语言代码参数
的传递是通过stack的,它也可能从stack中得到一些不需要的参数。Asmlinkage将要
解析那些参数。
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)))
原文地址:
阅读(892) | 评论(0) | 转发(0) |