fa.netbsd.tech.kern
[Top] [All Lists]

Re: clone()

Subject: Re: clone()
From: Emmanuel Dreyfus
Date: Sun, 16 Sep 2007 04:30:15 UTC
Newsgroups: fa.netbsd.tech.kern

Andrew Doran <ad@xxxxxxxxxx> wrote:

> Are there any other potential problems with this?

I see one problem: On Linux, clone() really produces processes, and this
is what we reproduce. NPTL is implemented in the Linux kernel as a layer
on the top of existing kernel code. Kernel PID are shown to userland as
TID, and the PID of the parent process of the thread group is presented
to userland as the PID.

Here are example taken from Linux code. As, in linux/kernel/timer.c:
asmlinkage long sys_gettid(void)
{
        return current->pid;    
}
(...)
asmlinkage long sys_getpid(void)
{
        return current->tgid; 
}

If you grep through the sources, you'll see that tgid is the PID of the
parent process. Example in linux/kernel/fork.c:copy_process()
        p->tgid = p->pid;        
        if (clone_flags & CLONE_THREAD)
                p->tgid = current->tgid;

p is the process structure for the newly created process, current is the
parent. 

Changing clone() to produce LWP will actually cause the emulated
behaviour to drift away from what Linux does. I'm affraid this will open
a large can of worms. You will have to rewrite our NPTL emulation, and
of course check that no regression occured. I would not want to be in
your shoes :-)

> How would it affect Irix emulation?

I have trouble to tell, I don't remember the odd details of IRIX
threading. However, a quick look to the code shows that COMPAT_IRIX uses
fork1() and not clone().

-- 
Emmanuel Dreyfus
http://hcpnet.free.fr/pubz
manu@xxxxxxxxxx

<Prev in Thread] Current Thread [Next in Thread>
  • clone(), Andrew Doran
    • Message not available
    • Message not available
    • Message not available
      • Re: clone(), Emmanuel Dreyfus <=
    • Message not available