|
From: Nicholas N. <nj...@ca...> - 2004-07-28 17:34:36
|
Hi,
The x86 asm for VG_(clone) looks like this:
VG_(clone):
#define FSZ (4+4+4) /* frame size = retaddr+ebx+edi */
push %ebx
push %edi
/* set up child stack with function and arg */
movl 4+FSZ(%esp), %ecx /* child stack */
movl 12+FSZ(%esp), %ebx /* fn arg */
movl 0+FSZ(%esp), %eax /* fn */
lea -8(%ecx), %ecx /* make space on stack */
movl %ebx, 4(%ecx) /* fn arg */
movl %eax, 0(%ecx) /* fn */
/* get other args to clone */
movl 8+FSZ(%esp), %ebx /* flags */
movl 20+FSZ(%esp), %edx /* parent tid * */ ???
movl 16+FSZ(%esp), %edi /* child tid * */ ???
movl $__NR_clone, %eax
int $0x80
testl %eax, %eax
jnz 1f
/* CHILD - call thread function */
popl %eax
call *%eax
/* exit with result */
movl %eax, %ebx
movl $__NR_exit, %eax
int $0x80
/* Hm, exit returned */
ud2
1: /* PARENT or ERROR */
pop %edi
pop %ebx
ret
I understand it all except the two lines marked '???'. AIUI, the clone()
system call (as opposed to the library function) only takes two args,
'flags' and 'childstack', so %edx and %edi won't be used by it.
And those registers aren't used again later in the function. But if I
remove those two lines, some of the reg tests fail so they're obviously
doing something useful, possibly returning a value? Can someone explain
what they are doing?
Thanks.
N
|