免费注册 查看新帖 |

Chinaunix

广告
  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1886 | 回复: 0
打印 上一主题 下一主题

在gcc里嵌入_asm里的"g"表示什么意思? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-07-20 12:19 |只看该作者 |倒序浏览
在查看代码的时候,在fs/open.c里的
SYSCALL_DEFINE3(open, const char __user *, filename, int, flags, int, mode)
{
    long ret;

    if (force_o_largefile())
        flags |= O_LARGEFILE;

    ret = do_sys_open(AT_FDCWD, filename, flags, mode);
    /* avoid REGPARM breakage on x86: */
    asmlinkage_protect(3, ret, filename, flags, mode);
    return ret;
}


的asmlinkage_protect(3, ret, filename, flags, mode);是什么意思,它展开后应该是这样的
__asm__ __volatile__ ("" : "=r" (ret) : "0" (ret), "g" (filename), "g" (flags), "g" (mode));

然后看了这个代码上有一个注释如下
/*
* Make sure the compiler doesn't do anything stupid with the
* arguments on the stack - they are owned by the *caller*, not
* the callee. This just fools gcc into not spilling into them,
* and keeps it from doing tailcall recursion and/or using the
* stack slots for temporaries, since they are live and "used"
* all the way to the end of the function.
*
* NOTE! On x86-64, all the arguments are in registers, so this
* only matters on a 32-bit kernel.
*/
/*
为了防止编译器操作栈上的参数 -它是属于调用函数的,而不是被调用函数的,
所以这些参数在调用者里都是有效的,并且一直被使用,因而这只是为了告诉
gcc不要影响它们(这些参数),并且不能用其(这些参数)做递归调用或者
用作临时变量。

注意:因为只有在x86-64上,这些参数都是在寄存器里的,所以在32位的内核上不
存在这个问题。
*/

请大虾指教,为什么会存在这样的问题,在__asm里的"g"表示什么意思?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP