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