2014-02-20 00:53:20 +00:00
|
|
|
#include <private/bionic_asm.h>
|
2009-03-04 03:28:35 +00:00
|
|
|
|
2013-11-15 19:51:07 +00:00
|
|
|
// pid_t __bionic_clone(int flags, void* child_stack, pid_t* parent_tid, void* tls, pid_t* child_tid, int (*fn)(void*), void* arg);
|
2013-02-12 01:08:16 +00:00
|
|
|
ENTRY(__bionic_clone)
|
2012-08-08 07:15:16 +00:00
|
|
|
pushl %ebx
|
|
|
|
pushl %esi
|
|
|
|
pushl %edi
|
|
|
|
|
2014-05-09 21:42:16 +00:00
|
|
|
# Load system call arguments into registers.
|
|
|
|
movl 16(%esp), %ebx # flags
|
|
|
|
movl 20(%esp), %ecx # child_stack
|
|
|
|
movl 24(%esp), %edx # parent_tid
|
|
|
|
movl 28(%esp), %esi # tls
|
|
|
|
movl 32(%esp), %edi # child_tid
|
2012-08-08 07:15:16 +00:00
|
|
|
|
2013-11-27 00:20:50 +00:00
|
|
|
# Copy 'fn' and 'arg' onto the child stack
|
|
|
|
movl 36(%esp), %eax # Read 'fn'.
|
|
|
|
movl %eax, -16(%ecx) # Write 'fn'.
|
|
|
|
movl 40(%esp), %eax # Read 'arg'.
|
|
|
|
movl %eax, -12(%ecx) # Write 'arg'.
|
2012-08-08 07:15:16 +00:00
|
|
|
subl $16, %ecx
|
2013-02-13 07:02:33 +00:00
|
|
|
|
2013-11-27 00:20:50 +00:00
|
|
|
# Make the system call.
|
2012-08-08 07:15:16 +00:00
|
|
|
movl $__NR_clone, %eax
|
|
|
|
int $0x80
|
2013-02-13 07:02:33 +00:00
|
|
|
|
2013-11-27 00:20:50 +00:00
|
|
|
# Check result.
|
2014-06-05 19:28:14 +00:00
|
|
|
testl %eax, %eax
|
|
|
|
jz .L_bc_child
|
2014-05-09 19:16:20 +00:00
|
|
|
jg .L_bc_parent
|
2012-08-08 07:15:16 +00:00
|
|
|
|
2013-11-27 00:20:50 +00:00
|
|
|
# An error occurred, so set errno and return -1.
|
2012-08-08 07:15:16 +00:00
|
|
|
negl %eax
|
2013-02-13 07:02:33 +00:00
|
|
|
pushl %eax
|
2012-08-08 07:15:16 +00:00
|
|
|
call __set_errno
|
2013-02-13 07:02:33 +00:00
|
|
|
addl $4, %esp
|
2014-05-09 19:16:20 +00:00
|
|
|
jmp .L_bc_return
|
2012-08-08 07:15:16 +00:00
|
|
|
|
2014-05-09 19:16:20 +00:00
|
|
|
.L_bc_child:
|
2014-05-30 18:15:32 +00:00
|
|
|
# We don't want anyone to unwind past this point.
|
|
|
|
.cfi_undefined %eip
|
2014-06-06 22:18:54 +00:00
|
|
|
call __start_thread
|
2012-08-08 07:15:16 +00:00
|
|
|
hlt
|
|
|
|
|
2014-05-09 19:16:20 +00:00
|
|
|
.L_bc_parent:
|
2014-06-05 19:28:14 +00:00
|
|
|
# We're the parent; nothing to do.
|
2014-05-09 19:16:20 +00:00
|
|
|
.L_bc_return:
|
2012-08-08 07:15:16 +00:00
|
|
|
popl %edi
|
|
|
|
popl %esi
|
|
|
|
popl %ebx
|
|
|
|
ret
|
2013-02-12 01:08:16 +00:00
|
|
|
END(__bionic_clone)
|
2014-05-09 02:00:23 +00:00
|
|
|
.hidden __bionic_clone
|