Hi Dave, On 18/11/09 16:48 -0800, Dave Hansen wrote: > > This is still a bit rough, but I figured I'd post it for kicks. > > Most of the process.c stuff is copy-n-paste with i386 and needs > to get consolidated. I also need to give this the new name. > > I'd appreciate anybody that knows inline assembly well to make > sure that I'm not being a complete doofus with this call below. > This seems to work, but I'm not confident it is the best way. I'm not a total guru of inline assembly, but I have comments :) > > int clone_with_pids(long flags_low, struct clone_args *clone_args, long args_size, > int *pids) > { > long retval; > > __asm__ __volatile__( > "movq %3, %%r10\n\t" /* pids in r10*/ > "pushq %%rbp\n\t" /* save value of ebp */ > : > :"D" (flags_low), /* rdi */ > "S" (clone_args),/* rsi */ > "d" (args_size), /* rdx */ > "a" (pids) /* use rax, which gets moved to r10 */ > ); 1. The fourth C arg is not in rax, but in rcx. > > __asm__ __volatile__( > "syscall\n\t" /* Linux/x86_64 system call */ > "testq %0,%0\n\t" /* check return value */ > "jne 1f\n\t" /* jump if parent */ > "popq %%rbx\n\t" /* get subthread function */ > "call *%%rbx\n\t" /* start subthread function */ > "movq %2,%0\n\t" > "syscall\n" /* exit system call: exit subthread */ > "1:\n\t" > "popq %%rbp\t" /* restore parent's ebp */ > :"=a" (retval) > :"0" (__NR_clone3), "i" (__NR_exit) > :"ebx", "ecx", "edx" > ); 2. You should probably not separate this into two asm statements. In particular, the compiler has no way to know that r10 should be preserved between the two statements, and may be confused by the change of rsp. 3. r10 and r11 should be listed as clobbered. 4. I fail to see the magic that puts the subthread function pointer in the stack. 5. Maybe rdi should contain the subthread argument before calling the subthread? 6. rdi, rsi, rdx, rcx, r8 and r9 should be added to the clobber list because of the call to the subthread function. 7. rsi could be used in place of rbx to hold the function pointer, which would allow you to remove ebx from the clobber list. 8. I don't see why rbp should be saved. The ABI says it must be saved by the callee. 9. Before calling exit(), maybe put some exit code in rdi? > > if (retval < 0) { > errno = -retval; > retval = -1; > } > return retval; > } Thanks, Louis [...] -- 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
Attachment:
signature.asc
Description: Digital signature
_______________________________________________ Containers mailing list Containers@xxxxxxxxxxxxxxxxxxxxxxxxxx https://lists.linux-foundation.org/mailman/listinfo/containers