[Devel] Re: updated x86_64 eclone() stub

Dave Hansen dave at linux.vnet.ibm.com
Fri Dec 4 08:05:13 PST 2009


On Fri, 2009-12-04 at 17:01 +0100, Louis Rilling wrote:
> On 04/12/09  7:29 -0800, Dave Hansen wrote:
> > This more closely resembles what glibc does.
> > 
> > The last version had a push/popq %ebp.  But, after looking at the glibc
> > code, I believe this to be unnecessary on 64-bit.  Suka also pointed out
> > that we were neglecting to pull the subthread's function argument off
> > the stack.
> > 
> > I also changed the register being used  for the subthread variable to be
> > rax.  This is just to more closely resemble the glibc code.  It doesn't
> > hurt to use it this way mostly because we overwrite it for the exit
> > syscall anyway.
> > 
> > int eclone(long flags_low, struct clone_args *clone_args, long args_size,
> >                  int *pids)
> > {
> >         long retval;
> > 
> >         __asm__  __volatile__(
> >                  "movq %5, %%r10\n\t"   /* pids in r10*/
> >                  "syscall\n\t"          /* Linux/x86_64 system call */
> >                  "testq %0,%0\n\t"      /* check return value */
> >                  "jne 1f\n\t"           /* jump if parent */
> >                  "popq %%rax\n\t"       /* get subthread function */
> >                  "popq %%rdi\n\t"       /* get the subthread function arg */
> >                  "call *%%rax\n\t"      /* start subthread function */
> >                  "movq %6,%0\n\t"
> >                  "syscall\n"            /* exit system call: exit subthread */
> >                  "1:\n\t"
> >                 :"=a" (retval)
> >                 :"0" (__NR_clone3),/* eax */
> >                  "D" (flags_low),  /* rdi */
> >                  "S" (clone_args), /* rsi */
> >                  "d" (args_size),  /* rdx */
> >                  "m" (pids),       /* gets moved to r10 */
> >                  "i" (__NR_exit)
> >                 :"rbx", "rcx", "r8", "r9", "r10"
> 
> Why is rbx in the clobber list? It's not used at all.

Because I forgot to take it out when I removed the popq into rbx. :)

> r8 and r9 can be removed from the clobber list, since they can only be clobbered
> when calling the subthread, and then exit() is called without returning to C.

OK, that makes sense.

> syscall also destroys r11, so it should be added to the clobber list.

Even though it is a ptregscall?

> Libc also adds "cc" to the clobber list. I'm not sure that this matters though.

I guess it can't hurt.  I'll add a comment about it.

-- Dave

_______________________________________________
Containers mailing list
Containers at lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/containers




More information about the Devel mailing list