blob: 9c25053738eb1b157348b171d2c7e6bfdfc72290 [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001/*
David 'Digit' Turner97cf7f32010-01-22 18:59:05 -08002 * Copyright (C) 2008-2010 The Android Open Source Project
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08003 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
13 * distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28#include <sys/linux-syscalls.h>
29
David 'Digit' Turner97cf7f32010-01-22 18:59:05 -080030 .text
31 .type __pthread_clone, #function
32 .global __pthread_clone
33 .align 4
34 .fnstart
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080035
David 'Digit' Turner97cf7f32010-01-22 18:59:05 -080036__pthread_clone:
37 @ insert the args onto the new stack
38 str r0, [r1, #-4]
39 str r3, [r1, #-8]
40
41 @ do the system call
42 @ get flags
43
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080044 mov r0, r2
David 'Digit' Turner97cf7f32010-01-22 18:59:05 -080045
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080046 @ new sp is already in r1
47
48#if __ARM_EABI__
49 stmfd sp!, {r4, r7}
50 ldr r7, =__NR_clone
David 'Digit' Turner97cf7f32010-01-22 18:59:05 -080051 swi #0
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080052#else
David 'Digit' Turner97cf7f32010-01-22 18:59:05 -080053 swi #__NR_clone
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080054#endif
55
David 'Digit' Turner97cf7f32010-01-22 18:59:05 -080056 movs r0, r0
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080057#if __ARM_EABI__
58 ldmnefd sp!, {r4, r7}
59#endif
David 'Digit' Turner97cf7f32010-01-22 18:59:05 -080060 blt __error
61 bxne lr
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080062
63
David 'Digit' Turner97cf7f32010-01-22 18:59:05 -080064 @ pick the function arg and call address off the stack and jump
65 @ to the C __thread_entry function which does some setup and then
66 @ calls the thread's start function
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080067
David 'Digit' Turner97cf7f32010-01-22 18:59:05 -080068 ldr r0, [sp, #-4]
69 ldr r1, [sp, #-8]
70 mov r2, sp @ __thread_entry needs the TLS pointer
71 b __thread_entry
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080072
73__error:
David 'Digit' Turner97cf7f32010-01-22 18:59:05 -080074 mov r0, #-1
75 bx lr
76 .fnend
77
78
79 #
80 # This function is defined as:
81 #
82 # pid_t __bionic_clone( int flags, void *child_stack,
83 # pid_t *pid, void *tls, pid_t *ctid,
84 # int (*fn)(void *), void* arg );
85 #
86 # NOTE: This is not the same signature than the GLibc
87 # __clone function here !! Placing 'fn' and 'arg'
88 # at the end of the parameter list makes the
89 # implementation much simpler.
90 #
91 .type __bionic_clone, #function
92 .globl __bionic_clone
93 .align 4
94 .fnstart
95
96__bionic_clone:
97 mov ip, sp
98 .save {r4, r5, r6, r7}
99
100 # save registers to parent stack
101 stmfd sp!, {r4, r5, r6, r7}
102
103 # load extra parameters
104 ldmfd ip, {r4, r5, r6}
105
106 # store 'fn' and 'arg' to the child stack
107 str r5, [r1, #-4]
108 str r6, [r1, #-8]
109
110 # system call
111 ldr r7, =__NR_clone
112 swi #0
113 movs r0, r0
114 beq 1f
115
116 # in parent, reload saved registers
117 # then either exit or error
118 #
119 ldmfd sp!, {r4, r5, r6, r7}
120 bxne lr
121 b __set_syscall_errno
122
1231: # in the child - pick arguments
124 ldr r0, [sp, #-4]
125 ldr r1, [sp, #-8]
126 b __bionic_clone_entry
127
128 .fnend