Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3902670
  • 博文数量: 534
  • 博客积分: 10470
  • 博客等级: 上将
  • 技术积分: 4800
  • 用 户 组: 普通用户
  • 注册时间: 2006-05-26 14:08
文章分类

全部博文(534)

文章存档

2021年(1)

2019年(1)

2017年(1)

2016年(2)

2013年(2)

2012年(10)

2011年(43)

2010年(10)

2009年(17)

2008年(121)

2007年(253)

2006年(73)

分类:

2007-04-12 10:46:57

fastcall是在include/asm-i386/linkage.h中定义的宏,它指导GCC连接时把fastcall修饰的函数的前三个参数用寄存器传递。

asmlinkage则告诉GCC不要用寄存器传递参数.

asmlinkage和fastcall不能共存

__user 宏简单告诉编译器(通过 noderef)不应该解除这个指针的引用(因为在当前地址空间中它是没有意义的)。 不明白什么意义? 有些网友说是为用户空间的, 我自己用了, 用的不是用户空间一样没什么问题.

我查了内核源码是这样定义的:
./include/linux/compiler.h:# define __user __attribute__((noderef, address_space(1)))

希望将来可以真正明白Why......
============================================
2008-3-21添加下面的内容:
 
asmlinkage long sys_diffjiffies( long ujiffies )
{
  return (long)get_jiffies_64() - ujiffies;
}
注意 asmlinkage 修饰符的使用。这个宏(在 linux/include/asm-i386/linkage.h 中定义)告诉编译器将传递栈中的所有函数参数.
 
"传递栈中的所有函数参数"==> 可以理解为不使用寄存器传递参数吗?现在好长时间没怎么看kernel部分的东西了,快忘了.
 
============================================
修改于: 2008-03-22
 
来源:
 
The asmlinkage tag tells gcc that that the function should not expect to find any of its arguments in registers (a common optimization), but only on the CPU's stack. Many kernel functions use the fact, that system_call consumes its first argument, the system call number, and leaves 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.
 
"asmlinkage" 告诉gcc不要从寄存器中传参数,从CPU栈中读函数参数.
 
=============================================
 
 
阅读(4639) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2008-03-28 14:11:24

以前我没见过asmlinkage的时候,就一直认为C语言中的函数经过编译后都会有从堆栈里取参数的指令。好像就是规定了。 看内核后,接触到asmlinkage,上网搜了搜,看了之后就糊涂了。