2013-03-22 05:48:18 +00:00
|
|
|
#include <asm/unistd.h>
|
2013-02-12 01:08:16 +00:00
|
|
|
#include <machine/asm.h>
|
2009-03-04 03:28:35 +00:00
|
|
|
|
2013-02-15 02:59:37 +00:00
|
|
|
// int __pthread_clone(void* (*fn)(void*), void* tls, int flags, void* arg);
|
2013-02-12 01:08:16 +00:00
|
|
|
ENTRY(__pthread_clone)
|
2009-03-04 03:28:35 +00:00
|
|
|
pushl %ebx
|
|
|
|
pushl %ecx
|
|
|
|
movl 16(%esp), %ecx
|
2012-03-21 09:48:13 +00:00
|
|
|
|
|
|
|
# save tls
|
|
|
|
movl %ecx, %ebx
|
|
|
|
# 16-byte alignment on child stack
|
|
|
|
andl $~15, %ecx
|
2009-03-04 03:28:35 +00:00
|
|
|
|
|
|
|
# insert arguments onto the child stack
|
|
|
|
movl 12(%esp), %eax
|
2012-03-21 09:48:13 +00:00
|
|
|
movl %eax, -16(%ecx)
|
2009-03-04 03:28:35 +00:00
|
|
|
movl 24(%esp), %eax
|
2012-03-21 09:48:13 +00:00
|
|
|
movl %eax, -12(%ecx)
|
|
|
|
movl %ebx, -8(%ecx)
|
2009-03-04 03:28:35 +00:00
|
|
|
|
2011-09-21 10:44:11 +00:00
|
|
|
subl $16, %ecx
|
2012-03-21 09:48:13 +00:00
|
|
|
movl 20(%esp), %ebx
|
2013-02-13 07:02:33 +00:00
|
|
|
|
|
|
|
# make system call
|
2009-03-04 03:28:35 +00:00
|
|
|
movl $__NR_clone, %eax
|
|
|
|
int $0x80
|
2013-02-13 07:02:33 +00:00
|
|
|
|
|
|
|
cmpl $0, %eax
|
|
|
|
je pc_child
|
|
|
|
jg pc_parent
|
2009-03-04 03:28:35 +00:00
|
|
|
|
2012-08-08 07:15:16 +00:00
|
|
|
# an error occurred, set errno and return -1
|
2009-03-04 03:28:35 +00:00
|
|
|
negl %eax
|
2013-02-13 07:02:33 +00:00
|
|
|
pushl %eax
|
2009-03-04 03:28:35 +00:00
|
|
|
call __set_errno
|
2013-02-13 07:02:33 +00:00
|
|
|
addl $4, %esp
|
2009-03-04 03:28:35 +00:00
|
|
|
orl $-1, %eax
|
2013-02-13 07:02:33 +00:00
|
|
|
jmp pc_return
|
2009-03-04 03:28:35 +00:00
|
|
|
|
2013-02-13 07:02:33 +00:00
|
|
|
pc_child:
|
2009-03-04 03:28:35 +00:00
|
|
|
# we're in the child thread now, call __thread_entry
|
|
|
|
# with the appropriate arguments on the child stack
|
|
|
|
# we already placed most of them
|
2012-03-21 09:48:13 +00:00
|
|
|
call __thread_entry
|
2009-03-04 03:28:35 +00:00
|
|
|
hlt
|
|
|
|
|
2013-02-13 07:02:33 +00:00
|
|
|
pc_parent:
|
|
|
|
# we're the parent; nothing to do.
|
|
|
|
pc_return:
|
2009-03-04 03:28:35 +00:00
|
|
|
popl %ecx
|
|
|
|
popl %ebx
|
|
|
|
ret
|
2013-02-12 01:08:16 +00:00
|
|
|
END(__pthread_clone)
|
2010-01-23 02:59:05 +00:00
|
|
|
|
2012-08-08 07:15:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* int __bionic_clone(unsigned long clone_flags,
|
|
|
|
* void* newsp,
|
|
|
|
* int *parent_tidptr,
|
|
|
|
* void *new_tls,
|
|
|
|
* int *child_tidptr,
|
|
|
|
* int (*fn)(void *),
|
|
|
|
* void *arg);
|
2010-06-25 16:02:10 +00:00
|
|
|
*/
|
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
|
|
|
|
|
|
|
|
# insert arguments onto the child stack
|
|
|
|
movl 20(%esp), %ecx
|
|
|
|
andl $~15, %ecx
|
|
|
|
movl 36(%esp), %eax
|
|
|
|
movl %eax, -16(%ecx)
|
|
|
|
movl 40(%esp), %eax
|
|
|
|
movl %eax, -12(%ecx)
|
|
|
|
|
|
|
|
subl $16, %ecx
|
|
|
|
movl 16(%esp), %ebx
|
|
|
|
movl 24(%esp), %edx
|
|
|
|
movl 32(%esp), %esi
|
|
|
|
movl 28(%esp), %edi
|
2013-02-13 07:02:33 +00:00
|
|
|
|
|
|
|
# make system call
|
2012-08-08 07:15:16 +00:00
|
|
|
movl $__NR_clone, %eax
|
|
|
|
int $0x80
|
2013-02-13 07:02:33 +00:00
|
|
|
|
|
|
|
cmpl $0, %eax
|
|
|
|
je bc_child
|
|
|
|
jg bc_parent
|
2012-08-08 07:15:16 +00:00
|
|
|
|
|
|
|
# an error occurred, set errno and return -1
|
|
|
|
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
|
2012-08-08 07:15:16 +00:00
|
|
|
orl $-1, %eax
|
2013-02-13 07:02:33 +00:00
|
|
|
jmp bc_return
|
2012-08-08 07:15:16 +00:00
|
|
|
|
2013-02-13 07:02:33 +00:00
|
|
|
bc_child:
|
2012-08-08 07:15:16 +00:00
|
|
|
# we're in the child now, call __bionic_clone_entry
|
|
|
|
# with the appropriate arguments on the child stack
|
|
|
|
# we already placed most of them
|
|
|
|
call __bionic_clone_entry
|
|
|
|
hlt
|
|
|
|
|
2013-02-13 07:02:33 +00:00
|
|
|
bc_parent:
|
|
|
|
# we're the parent; nothing to do.
|
|
|
|
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)
|