blob: e6ddaaad459b96e3c4e84987d0b28c42ba9e18f5 [file] [log] [blame]
Elliott Hughes851e68a2014-02-19 16:53:20 -08001#include <private/bionic_asm.h>
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08002
Elliott Hughes70b24b12013-11-15 11:51:07 -08003// 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 -08004ENTRY(__bionic_clone)
Jin Wei22d366c2012-08-08 15:15:16 +08005 pushl %ebx
6 pushl %esi
7 pushl %edi
8
Elliott Hughes99c393d2013-11-26 16:20:50 -08009 # Align child stack.
Jin Wei22d366c2012-08-08 15:15:16 +080010 movl 20(%esp), %ecx
11 andl $~15, %ecx
Jin Wei22d366c2012-08-08 15:15:16 +080012
Elliott Hughes99c393d2013-11-26 16:20:50 -080013 # 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'.
Jin Wei22d366c2012-08-08 15:15:16 +080018 subl $16, %ecx
Elliott Hughesb6032512013-02-12 23:02:33 -080019
Elliott Hughes99c393d2013-11-26 16:20:50 -080020 # Make the system call.
Jin Wei22d366c2012-08-08 15:15:16 +080021 movl $__NR_clone, %eax
Elliott Hughes99c393d2013-11-26 16:20:50 -080022 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
Jin Wei22d366c2012-08-08 15:15:16 +080027 int $0x80
Elliott Hughesb6032512013-02-12 23:02:33 -080028
Elliott Hughes99c393d2013-11-26 16:20:50 -080029 # Check result.
Elliott Hughesb6032512013-02-12 23:02:33 -080030 cmpl $0, %eax
31 je bc_child
32 jg bc_parent
Jin Wei22d366c2012-08-08 15:15:16 +080033
Elliott Hughes99c393d2013-11-26 16:20:50 -080034 # An error occurred, so set errno and return -1.
Jin Wei22d366c2012-08-08 15:15:16 +080035 negl %eax
Elliott Hughesb6032512013-02-12 23:02:33 -080036 pushl %eax
Jin Wei22d366c2012-08-08 15:15:16 +080037 call __set_errno
Elliott Hughesb6032512013-02-12 23:02:33 -080038 addl $4, %esp
Jin Wei22d366c2012-08-08 15:15:16 +080039 orl $-1, %eax
Elliott Hughesb6032512013-02-12 23:02:33 -080040 jmp bc_return
Jin Wei22d366c2012-08-08 15:15:16 +080041
Elliott Hughesb6032512013-02-12 23:02:33 -080042bc_child:
Jin Wei22d366c2012-08-08 15:15:16 +080043 call __bionic_clone_entry
44 hlt
45
Elliott Hughesb6032512013-02-12 23:02:33 -080046bc_parent:
47 # we're the parent; nothing to do.
48bc_return:
Jin Wei22d366c2012-08-08 15:15:16 +080049 popl %edi
50 popl %esi
51 popl %ebx
52 ret
Elliott Hughesbdff26d2013-02-11 17:08:16 -080053END(__bionic_clone)