__bionic_clone.S revision 851e68a2402fa414544e66650e09dfdaac813e51
1#include <private/bionic_asm.h> 2 3// pid_t __bionic_clone(int flags, void* child_stack, pid_t* parent_tid, void* tls, pid_t* child_tid, int (*fn)(void*), void* arg); 4ENTRY(__bionic_clone) 5 pushl %ebx 6 pushl %esi 7 pushl %edi 8 9 # Align child stack. 10 movl 20(%esp), %ecx 11 andl $~15, %ecx 12 13 # Copy 'fn' and 'arg' onto the child stack 14 movl 36(%esp), %eax # Read 'fn'. 15 movl %eax, -16(%ecx) # Write 'fn'. 16 movl 40(%esp), %eax # Read 'arg'. 17 movl %eax, -12(%ecx) # Write 'arg'. 18 subl $16, %ecx 19 20 # Make the system call. 21 movl $__NR_clone, %eax 22 movl 16(%esp), %ebx # flags 23 #movl %ecx, %ecx # child stack (already there) 24 movl 24(%esp), %edx # parent_tid 25 movl 28(%esp), %esi # tls 26 movl 32(%esp), %edi # child_tid 27 int $0x80 28 29 # Check result. 30 cmpl $0, %eax 31 je bc_child 32 jg bc_parent 33 34 # An error occurred, so set errno and return -1. 35 negl %eax 36 pushl %eax 37 call __set_errno 38 addl $4, %esp 39 orl $-1, %eax 40 jmp bc_return 41 42bc_child: 43 call __bionic_clone_entry 44 hlt 45 46bc_parent: 47 # we're the parent; nothing to do. 48bc_return: 49 popl %edi 50 popl %esi 51 popl %ebx 52 ret 53END(__bionic_clone) 54