blob: 3823ecc1786b6ed9f97e23952ec6736e362b692b [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
Elliott Hughes99c393d2013-11-26 16:20:50 -080010 # Align child stack.
Jin Wei22d366c2012-08-08 15:15:16 +080011 movl 20(%esp), %ecx
12 andl $~15, %ecx
Jin Wei22d366c2012-08-08 15:15:16 +080013
Elliott Hughes99c393d2013-11-26 16:20:50 -080014 # 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'.
Jin Wei22d366c2012-08-08 15:15:16 +080019 subl $16, %ecx
Elliott Hughesb6032512013-02-12 23:02:33 -080020
Elliott Hughes99c393d2013-11-26 16:20:50 -080021 # Make the system call.
Jin Wei22d366c2012-08-08 15:15:16 +080022 movl $__NR_clone, %eax
Elliott Hughes99c393d2013-11-26 16:20:50 -080023 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
Jin Wei22d366c2012-08-08 15:15:16 +080028 int $0x80
Elliott Hughesb6032512013-02-12 23:02:33 -080029
Elliott Hughes99c393d2013-11-26 16:20:50 -080030 # Check result.
Elliott Hughesb6032512013-02-12 23:02:33 -080031 cmpl $0, %eax
32 je bc_child
33 jg bc_parent
Jin Wei22d366c2012-08-08 15:15:16 +080034
Elliott Hughes99c393d2013-11-26 16:20:50 -080035 # An error occurred, so set errno and return -1.
Jin Wei22d366c2012-08-08 15:15:16 +080036 negl %eax
Elliott Hughesb6032512013-02-12 23:02:33 -080037 pushl %eax
Jin Wei22d366c2012-08-08 15:15:16 +080038 call __set_errno
Elliott Hughesb6032512013-02-12 23:02:33 -080039 addl $4, %esp
Jin Wei22d366c2012-08-08 15:15:16 +080040 orl $-1, %eax
Elliott Hughesb6032512013-02-12 23:02:33 -080041 jmp bc_return
Jin Wei22d366c2012-08-08 15:15:16 +080042
Elliott Hughesb6032512013-02-12 23:02:33 -080043bc_child:
Jin Wei22d366c2012-08-08 15:15:16 +080044 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)