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