Elliott Hughes | bdff26d | 2013-02-11 17:08:16 -0800 | [diff] [blame^] | 1 | #include <machine/asm.h> |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 2 | #include <sys/linux-syscalls.h> |
| 3 | |
Elliott Hughes | 5e3fc43 | 2013-02-11 16:36:48 -0800 | [diff] [blame] | 4 | // int __pthread_clone(int (*fn)(void*), void* tls, int flags, void* arg); |
Elliott Hughes | bdff26d | 2013-02-11 17:08:16 -0800 | [diff] [blame^] | 5 | ENTRY(__pthread_clone) |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 6 | pushl %ebx |
| 7 | pushl %ecx |
| 8 | movl 16(%esp), %ecx |
Jack Ren | cb08204 | 2012-03-21 17:48:13 +0800 | [diff] [blame] | 9 | |
| 10 | # save tls |
| 11 | movl %ecx, %ebx |
| 12 | # 16-byte alignment on child stack |
| 13 | andl $~15, %ecx |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 14 | |
| 15 | # insert arguments onto the child stack |
| 16 | movl 12(%esp), %eax |
Jack Ren | cb08204 | 2012-03-21 17:48:13 +0800 | [diff] [blame] | 17 | movl %eax, -16(%ecx) |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 18 | movl 24(%esp), %eax |
Jack Ren | cb08204 | 2012-03-21 17:48:13 +0800 | [diff] [blame] | 19 | movl %eax, -12(%ecx) |
| 20 | movl %ebx, -8(%ecx) |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 21 | |
Jack Ren | e480fc8 | 2011-09-21 12:44:11 +0200 | [diff] [blame] | 22 | subl $16, %ecx |
Jack Ren | cb08204 | 2012-03-21 17:48:13 +0800 | [diff] [blame] | 23 | movl 20(%esp), %ebx |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 24 | movl $__NR_clone, %eax |
| 25 | int $0x80 |
| 26 | test %eax, %eax |
| 27 | jns 1f |
| 28 | |
Jin Wei | 22d366c | 2012-08-08 15:15:16 +0800 | [diff] [blame] | 29 | # an error occurred, set errno and return -1 |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 30 | negl %eax |
| 31 | call __set_errno |
| 32 | orl $-1, %eax |
| 33 | jmp 2f |
| 34 | |
| 35 | 1: |
| 36 | jnz 2f |
| 37 | |
| 38 | # we're in the child thread now, call __thread_entry |
| 39 | # with the appropriate arguments on the child stack |
| 40 | # we already placed most of them |
Jack Ren | cb08204 | 2012-03-21 17:48:13 +0800 | [diff] [blame] | 41 | call __thread_entry |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 42 | hlt |
| 43 | |
| 44 | 2: |
| 45 | popl %ecx |
| 46 | popl %ebx |
| 47 | ret |
Elliott Hughes | bdff26d | 2013-02-11 17:08:16 -0800 | [diff] [blame^] | 48 | END(__pthread_clone) |
David 'Digit' Turner | 97cf7f3 | 2010-01-22 18:59:05 -0800 | [diff] [blame] | 49 | |
Jin Wei | 22d366c | 2012-08-08 15:15:16 +0800 | [diff] [blame] | 50 | |
| 51 | /* |
| 52 | * int __bionic_clone(unsigned long clone_flags, |
| 53 | * void* newsp, |
| 54 | * int *parent_tidptr, |
| 55 | * void *new_tls, |
| 56 | * int *child_tidptr, |
| 57 | * int (*fn)(void *), |
| 58 | * void *arg); |
Bruce Beare | 1698442 | 2010-06-25 09:02:10 -0700 | [diff] [blame] | 59 | */ |
Elliott Hughes | bdff26d | 2013-02-11 17:08:16 -0800 | [diff] [blame^] | 60 | ENTRY(__bionic_clone) |
Jin Wei | 22d366c | 2012-08-08 15:15:16 +0800 | [diff] [blame] | 61 | pushl %ebx |
| 62 | pushl %esi |
| 63 | pushl %edi |
| 64 | |
| 65 | # insert arguments onto the child stack |
| 66 | movl 20(%esp), %ecx |
| 67 | andl $~15, %ecx |
| 68 | movl 36(%esp), %eax |
| 69 | movl %eax, -16(%ecx) |
| 70 | movl 40(%esp), %eax |
| 71 | movl %eax, -12(%ecx) |
| 72 | |
| 73 | subl $16, %ecx |
| 74 | movl 16(%esp), %ebx |
| 75 | movl 24(%esp), %edx |
| 76 | movl 32(%esp), %esi |
| 77 | movl 28(%esp), %edi |
| 78 | movl $__NR_clone, %eax |
| 79 | int $0x80 |
| 80 | test %eax, %eax |
| 81 | jns 1f |
| 82 | |
| 83 | # an error occurred, set errno and return -1 |
| 84 | negl %eax |
| 85 | call __set_errno |
| 86 | orl $-1, %eax |
| 87 | jmp 2f |
| 88 | |
| 89 | 1: |
| 90 | jnz 2f |
| 91 | |
| 92 | # we're in the child now, call __bionic_clone_entry |
| 93 | # with the appropriate arguments on the child stack |
| 94 | # we already placed most of them |
| 95 | call __bionic_clone_entry |
| 96 | hlt |
| 97 | |
| 98 | 2: |
| 99 | popl %edi |
| 100 | popl %esi |
| 101 | popl %ebx |
| 102 | ret |
Elliott Hughes | bdff26d | 2013-02-11 17:08:16 -0800 | [diff] [blame^] | 103 | END(__bionic_clone) |