__bionic_clone.S revision 99c393dff33e0a5d3838c16dc7878f32ac3da971
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        # Align child stack.
11        movl    20(%esp), %ecx
12        andl    $~15, %ecx
13
14        # Copy 'fn' and 'arg' onto the child stack
15        movl    36(%esp), %eax   # Read 'fn'.
16        movl    %eax, -16(%ecx)  # Write 'fn'.
17        movl    40(%esp), %eax   # Read 'arg'.
18        movl    %eax, -12(%ecx)  # Write 'arg'.
19        subl    $16, %ecx
20
21        # Make the system call.
22        movl    $__NR_clone, %eax
23        movl    16(%esp), %ebx  # flags
24        #movl   %ecx, %ecx      # child stack (already there)
25        movl    24(%esp), %edx  # parent_tid
26        movl    28(%esp), %esi  # tls
27        movl    32(%esp), %edi  # child_tid
28        int     $0x80
29
30        # Check result.
31        cmpl    $0, %eax
32        je      bc_child
33        jg      bc_parent
34
35        # An error occurred, so set errno and return -1.
36        negl    %eax
37        pushl   %eax
38        call    __set_errno
39        addl    $4, %esp
40        orl     $-1, %eax
41        jmp     bc_return
42
43bc_child:
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