免费注册 查看新帖 |

Chinaunix

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

[进程管理] 关于sys_clone的疑问,求解答 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2014-03-17 21:30 |只看该作者 |倒序浏览
本帖最后由 我爱芒果叶 于 2014-03-17 21:50 编辑

arch/x86/kernel/process_32.c  
asmlinkage int sys_clone(struct pt_regs regs)  
{  
        unsigned long clone_flags;  
        unsigned long newsp;  
        int __user *parent_tidptr, *child_tidptr;  

        clone_flags = regs.ebx;  
        newsp = regs.ecx;  
        parent_tidptr = (int __user *)regs.edx;  
        child_tidptr = (int __user *)regs.edi;  
        if (!newsp)  
                newsp = regs.esp;  
        return do_fork(clone_flags, newsp, &regs, 0, parent_tidptr, child_tidptr);  
}

《深入Linux内核架构》一书中这样说:在生成线程时,可能需要这样做,线程可能与父进程共享地址空间,但线程自身的栈可能在另一个地址空间。
求解释,线程与父进程共享地址空间,而栈在另外一个地址空间。什么情况下会如此?当栈在另外一个地址空间时,ecx仅仅是个32位的寄存器而已,它的值就可以指明在哪个地址空间吗?

论坛徽章:
1
15-16赛季CBA联赛之北控
日期:2016-03-15 22:53:29
2 [报告]
发表于 2014-03-17 21:58 |只看该作者
回复,你看的是中文版本的? 英文版本的原文如下:
The clone flags are no longer permanently set but can be passed to the system call as parameters in
various registers. Thus, the first part of the function deals with extracting these parameters. Also, the
stack of the parent process is not copied; instead, a new address (newsp) can be specified for it. (This is
required to generate threads that share the address space with the parent process but use their own stack
in this address space.) Two pointers (parent_tidptr and child_tidptr) in userspace are also specified
for purposes of communication with thread libraries. Their meaning is discussed in Section 2.4.1.

论坛徽章:
0
3 [报告]
发表于 2014-03-17 22:12 |只看该作者
回复 2# yangPSO


忘记去翻英文版了,这中文翻译差得有点远啊,多谢多谢。

论坛徽章:
15
射手座
日期:2014-02-26 13:45:082015年迎新春徽章
日期:2015-03-04 09:54:452015年辞旧岁徽章
日期:2015-03-03 16:54:15羊年新春福章
日期:2015-02-26 08:47:552015年亚洲杯之卡塔尔
日期:2015-02-03 08:33:45射手座
日期:2014-12-31 08:36:51水瓶座
日期:2014-06-04 08:33:52天蝎座
日期:2014-05-14 14:30:41天秤座
日期:2014-04-21 08:37:08处女座
日期:2014-04-18 16:57:05戌狗
日期:2014-04-04 12:21:33技术图书徽章
日期:2014-03-25 09:00:29
4 [报告]
发表于 2014-03-18 08:36 |只看该作者
呵呵,中文版果真~,求真须看原版,但这个原版好像是德文的~~
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP