blob: 917dc6883b47646ccd483bd820a02e22e72682fd [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 Hughes0d236aa2014-05-09 14:42:16 -07009 # Load system call arguments into registers.
10 movl 16(%esp), %ebx # flags
11 movl 20(%esp), %ecx # child_stack
12 movl 24(%esp), %edx # parent_tid
13 movl 28(%esp), %esi # tls
14 movl 32(%esp), %edi # child_tid
Jin Wei22d366c2012-08-08 15:15:16 +080015
Elliott Hughes99c393d2013-11-26 16:20:50 -080016 # Copy 'fn' and 'arg' onto the child stack
17 movl 36(%esp), %eax # Read 'fn'.
18 movl %eax, -16(%ecx) # Write 'fn'.
19 movl 40(%esp), %eax # Read 'arg'.
20 movl %eax, -12(%ecx) # Write 'arg'.
Jin Wei22d366c2012-08-08 15:15:16 +080021 subl $16, %ecx
Elliott Hughesb6032512013-02-12 23:02:33 -080022
Elliott Hughes99c393d2013-11-26 16:20:50 -080023 # Make the system call.
Jin Wei22d366c2012-08-08 15:15:16 +080024 movl $__NR_clone, %eax
25 int $0x80
Elliott Hughesb6032512013-02-12 23:02:33 -080026
Elliott Hughes99c393d2013-11-26 16:20:50 -080027 # Check result.
Elliott Hughesaeb30162014-06-05 12:28:14 -070028 testl %eax, %eax
29 jz .L_bc_child
Elliott Hughesfff3c0f2014-05-09 12:16:20 -070030 jg .L_bc_parent
Jin Wei22d366c2012-08-08 15:15:16 +080031
Elliott Hughes99c393d2013-11-26 16:20:50 -080032 # An error occurred, so set errno and return -1.
Jin Wei22d366c2012-08-08 15:15:16 +080033 negl %eax
Elliott Hughesb6032512013-02-12 23:02:33 -080034 pushl %eax
Dan Albert3726f9c2014-08-08 15:15:29 -070035 call __set_errno
Elliott Hughesb6032512013-02-12 23:02:33 -080036 addl $4, %esp
Elliott Hughesfff3c0f2014-05-09 12:16:20 -070037 jmp .L_bc_return
Jin Wei22d366c2012-08-08 15:15:16 +080038
Elliott Hughesfff3c0f2014-05-09 12:16:20 -070039.L_bc_child:
Elliott Hughesee9d5bd2014-05-30 11:15:32 -070040 # We don't want anyone to unwind past this point.
41 .cfi_undefined %eip
Elliott Hughesebc8cd12014-06-06 15:18:54 -070042 call __start_thread
Jin Wei22d366c2012-08-08 15:15:16 +080043 hlt
44
Elliott Hughesfff3c0f2014-05-09 12:16:20 -070045.L_bc_parent:
Elliott Hughesaeb30162014-06-05 12:28:14 -070046 # We're the parent; nothing to do.
Elliott Hughesfff3c0f2014-05-09 12:16:20 -070047.L_bc_return:
Jin Wei22d366c2012-08-08 15:15:16 +080048 popl %edi
49 popl %esi
50 popl %ebx
51 ret
Elliott Hughesbdff26d2013-02-11 17:08:16 -080052END(__bionic_clone)
Elliott Hughes954cf0d2014-05-08 19:00:23 -070053.hidden __bionic_clone