blob: eb9f5452450ddbe6db0a31bd30855d6528714049 [file] [log] [blame]
Elliott Hughes4cdde5f2013-03-21 22:48:18 -07001#include <asm/unistd.h>
Elliott Hughesbdff26d2013-02-11 17:08:16 -08002#include <machine/asm.h>
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08003
Elliott Hughes70b24b12013-11-15 11:51:07 -08004// pid_t __bionic_clone(int flags, void* child_stack, pid_t* parent_tid, void* tls, pid_t* child_tid, int (*fn)(void*), void* arg);
Elliott Hughesbdff26d2013-02-11 17:08:16 -08005ENTRY(__bionic_clone)
Jin Wei22d366c2012-08-08 15:15:16 +08006 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
Elliott Hughesb6032512013-02-12 23:02:33 -080023
24 # make system call
Jin Wei22d366c2012-08-08 15:15:16 +080025 movl $__NR_clone, %eax
26 int $0x80
Elliott Hughesb6032512013-02-12 23:02:33 -080027
28 cmpl $0, %eax
29 je bc_child
30 jg bc_parent
Jin Wei22d366c2012-08-08 15:15:16 +080031
32 # an error occurred, set errno and return -1
33 negl %eax
Elliott Hughesb6032512013-02-12 23:02:33 -080034 pushl %eax
Jin Wei22d366c2012-08-08 15:15:16 +080035 call __set_errno
Elliott Hughesb6032512013-02-12 23:02:33 -080036 addl $4, %esp
Jin Wei22d366c2012-08-08 15:15:16 +080037 orl $-1, %eax
Elliott Hughesb6032512013-02-12 23:02:33 -080038 jmp bc_return
Jin Wei22d366c2012-08-08 15:15:16 +080039
Elliott Hughesb6032512013-02-12 23:02:33 -080040bc_child:
Jin Wei22d366c2012-08-08 15:15:16 +080041 # 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
Elliott Hughesb6032512013-02-12 23:02:33 -080047bc_parent:
48 # we're the parent; nothing to do.
49bc_return:
Jin Wei22d366c2012-08-08 15:15:16 +080050 popl %edi
51 popl %esi
52 popl %ebx
53 ret
Elliott Hughesbdff26d2013-02-11 17:08:16 -080054END(__bionic_clone)