blob: af6ef19071a39e0a76841bddabff705bfc85123a [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 Hughesb6032512013-02-12 23:02:33 -080028 cmpl $0, %eax
Elliott Hughesfff3c0f2014-05-09 12:16:20 -070029 je .L_bc_child
30 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
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 Hughesfff3c0f2014-05-09 12:16:20 -070038 jmp .L_bc_return
Jin Wei22d366c2012-08-08 15:15:16 +080039
Elliott Hughesfff3c0f2014-05-09 12:16:20 -070040.L_bc_child:
Jin Wei22d366c2012-08-08 15:15:16 +080041 call __bionic_clone_entry
42 hlt
43
Elliott Hughesfff3c0f2014-05-09 12:16:20 -070044.L_bc_parent:
Elliott Hughesb6032512013-02-12 23:02:33 -080045 # we're the parent; nothing to do.
Elliott Hughesfff3c0f2014-05-09 12:16:20 -070046.L_bc_return:
Jin Wei22d366c2012-08-08 15:15:16 +080047 popl %edi
48 popl %esi
49 popl %ebx
50 ret
Elliott Hughesbdff26d2013-02-11 17:08:16 -080051END(__bionic_clone)
Elliott Hughes954cf0d2014-05-08 19:00:23 -070052.hidden __bionic_clone