blob: 9266f8453d7f85c75f4e3bcc56a73778cf03ee90 [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001#include <sys/linux-syscalls.h>
2
3.text
4
Elliott Hughes5e3fc432013-02-11 16:36:48 -08005// int __pthread_clone(int (*fn)(void*), void* tls, int flags, void* arg);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08006.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 Rencb082042012-03-21 17:48:13 +080013
14 # save tls
15 movl %ecx, %ebx
16 # 16-byte alignment on child stack
17 andl $~15, %ecx
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080018
19 # insert arguments onto the child stack
20 movl 12(%esp), %eax
Jack Rencb082042012-03-21 17:48:13 +080021 movl %eax, -16(%ecx)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080022 movl 24(%esp), %eax
Jack Rencb082042012-03-21 17:48:13 +080023 movl %eax, -12(%ecx)
24 movl %ebx, -8(%ecx)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080025
Jack Rene480fc82011-09-21 12:44:11 +020026 subl $16, %ecx
Jack Rencb082042012-03-21 17:48:13 +080027 movl 20(%esp), %ebx
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080028 movl $__NR_clone, %eax
29 int $0x80
30 test %eax, %eax
31 jns 1f
32
Jin Wei22d366c2012-08-08 15:15:16 +080033 # an error occurred, set errno and return -1
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080034 negl %eax
35 call __set_errno
36 orl $-1, %eax
37 jmp 2f
38
391:
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 Rencb082042012-03-21 17:48:13 +080045 call __thread_entry
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080046 hlt
47
482:
49 popl %ecx
50 popl %ebx
51 ret
David 'Digit' Turner97cf7f32010-01-22 18:59:05 -080052
Jin Wei22d366c2012-08-08 15:15:16 +080053
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 Beare16984422010-06-25 09:02:10 -070062 */
Jin Wei22d366c2012-08-08 15:15:16 +080063.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
961:
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
1052:
106 popl %edi
107 popl %esi
108 popl %ebx
109 ret