[Devel] Re: updated x86_64 eclone() stub

Louis Rilling Louis.Rilling at kerlabs.com
Fri Dec 4 09:24:16 PST 2009


On 04/12/09  8:21 -0800, Dave Hansen wrote:
> On Fri, 2009-12-04 at 17:08 +0100, Louis Rilling wrote:
> > On 04/12/09  8:05 -0800, Dave Hansen wrote:
> > > > syscall also destroys r11, so it should be added to the clobber list.
> > > 
> > > Even though it is a ptregscall?
> > 
> > The assembly instruction itself destroys r11 (same for rcx).
> 
> Thanks again for the help, Louis.  How does this look?

Looks ok :)

Thanks,

Louis

> 
> int clone_with_pids(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)
>                 :"rcx", "r10", "r11", "cc" 
>         );
>         /*
>          * glibc lists 'cc' as clobbered, so we might as
> 	 * well do it too.  'r11' and 'rcx' are clobbered
> 	 * by the 'syscall' instruction itself.  'r8' and
> 	 * 'r9' are clobbered by the clone, but that
> 	 * thread will exit before getting back out to C.
>          */
> 
>         if (retval < 0) {
>                 errno = -retval;
>                 retval = -1;
>         }
>         return retval;
> }
> 
> 
> 
> > Thanks,
> > 
> > Louis
> > 
> -- Dave
> 

-- 
Dr Louis Rilling			Kerlabs
Skype: louis.rilling			Batiment Germanium
Phone: (+33|0) 6 80 89 08 23		80 avenue des Buttes de Coesmes
http://www.kerlabs.com/			35700 Rennes
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: Digital signature
URL: <http://lists.openvz.org/pipermail/devel/attachments/20091204/b5975002/attachment-0001.sig>
-------------- next part --------------
_______________________________________________
Containers mailing list
Containers at lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/containers


More information about the Devel mailing list