2014-02-20 01:53:20 +01:00
|
|
|
#include <private/bionic_asm.h>
|
2009-03-04 04:28:35 +01:00
|
|
|
|
2013-11-15 20:51:07 +01: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 02:08:16 +01:00
|
|
|
ENTRY(__bionic_clone)
|
2012-08-08 09:15:16 +02:00
|
|
|
pushl %ebx
|
2015-04-13 23:20:11 +02:00
|
|
|
.cfi_adjust_cfa_offset 4
|
|
|
|
.cfi_rel_offset ebx, 0
|
2012-08-08 09:15:16 +02:00
|
|
|
pushl %esi
|
2015-04-13 23:20:11 +02:00
|
|
|
.cfi_adjust_cfa_offset 4
|
|
|
|
.cfi_rel_offset esi, 0
|
2012-08-08 09:15:16 +02:00
|
|
|
pushl %edi
|
2015-04-13 23:20:11 +02:00
|
|
|
.cfi_adjust_cfa_offset 4
|
|
|
|
.cfi_rel_offset edi, 0
|
2012-08-08 09:15:16 +02:00
|
|
|
|
2014-05-09 23:42:16 +02: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 09:15:16 +02:00
|
|
|
|
2013-11-27 01:20:50 +01: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 09:15:16 +02:00
|
|
|
subl $16, %ecx
|
2013-02-13 08:02:33 +01:00
|
|
|
|
2013-11-27 01:20:50 +01:00
|
|
|
# Make the system call.
|
2012-08-08 09:15:16 +02:00
|
|
|
movl $__NR_clone, %eax
|
|
|
|
int $0x80
|
2013-02-13 08:02:33 +01:00
|
|
|
|
2013-11-27 01:20:50 +01:00
|
|
|
# Check result.
|
2014-06-05 21:28:14 +02:00
|
|
|
testl %eax, %eax
|
|
|
|
jz .L_bc_child
|
2014-05-09 21:16:20 +02:00
|
|
|
jg .L_bc_parent
|
2012-08-08 09:15:16 +02:00
|
|
|
|
2013-11-27 01:20:50 +01:00
|
|
|
# An error occurred, so set errno and return -1.
|
2012-08-08 09:15:16 +02:00
|
|
|
negl %eax
|
2013-02-13 08:02:33 +01:00
|
|
|
pushl %eax
|
2014-09-09 00:25:01 +02:00
|
|
|
call __set_errno_internal
|
2013-02-13 08:02:33 +01:00
|
|
|
addl $4, %esp
|
2014-05-09 21:16:20 +02:00
|
|
|
jmp .L_bc_return
|
2012-08-08 09:15:16 +02:00
|
|
|
|
2014-05-09 21:16:20 +02:00
|
|
|
.L_bc_child:
|
2014-05-30 20:15:32 +02:00
|
|
|
# We don't want anyone to unwind past this point.
|
|
|
|
.cfi_undefined %eip
|
2014-06-07 00:18:54 +02:00
|
|
|
call __start_thread
|
2012-08-08 09:15:16 +02:00
|
|
|
hlt
|
|
|
|
|
2014-05-09 21:16:20 +02:00
|
|
|
.L_bc_parent:
|
2014-06-05 21:28:14 +02:00
|
|
|
# We're the parent; nothing to do.
|
2014-05-09 21:16:20 +02:00
|
|
|
.L_bc_return:
|
2012-08-08 09:15:16 +02:00
|
|
|
popl %edi
|
2015-04-13 23:20:11 +02:00
|
|
|
.cfi_adjust_cfa_offset -4
|
|
|
|
.cfi_restore edi
|
2012-08-08 09:15:16 +02:00
|
|
|
popl %esi
|
2015-04-13 23:20:11 +02:00
|
|
|
.cfi_adjust_cfa_offset -4
|
|
|
|
.cfi_restore esi
|
2012-08-08 09:15:16 +02:00
|
|
|
popl %ebx
|
2015-04-13 23:20:11 +02:00
|
|
|
.cfi_adjust_cfa_offset -4
|
|
|
|
.cfi_restore ebx
|
2012-08-08 09:15:16 +02:00
|
|
|
ret
|
2013-02-12 02:08:16 +01:00
|
|
|
END(__bionic_clone)
|
2014-05-09 04:00:23 +02:00
|
|
|
.hidden __bionic_clone
|