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
|
|
|
|
pushl %esi
|
|
|
|
pushl %edi
|
|
|
|
|
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.
|
2013-02-13 08:02:33 +01:00
|
|
|
cmpl $0, %eax
|
2014-05-09 21:16:20 +02:00
|
|
|
je .L_bc_child
|
|
|
|
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
|
2012-08-08 09:15:16 +02:00
|
|
|
call __set_errno
|
2013-02-13 08:02:33 +01:00
|
|
|
addl $4, %esp
|
2012-08-08 09:15:16 +02:00
|
|
|
orl $-1, %eax
|
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:
|
2012-08-08 09:15:16 +02:00
|
|
|
call __bionic_clone_entry
|
|
|
|
hlt
|
|
|
|
|
2014-05-09 21:16:20 +02:00
|
|
|
.L_bc_parent:
|
2013-02-13 08:02:33 +01: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
|
|
|
|
popl %esi
|
|
|
|
popl %ebx
|
|
|
|
ret
|
2013-02-12 02:08:16 +01:00
|
|
|
END(__bionic_clone)
|
2014-05-09 04:00:23 +02:00
|
|
|
.hidden __bionic_clone
|