blob: a95d2d60cfb12bdbcdd6f4bcb61ee4317083d7cf [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>
Kenny Root420878c2011-02-16 11:55:58 -080029#include <machine/asm.h>
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080030
Kenny Root420878c2011-02-16 11:55:58 -080031ENTRY(__pthread_clone)
David 'Digit' Turner97cf7f32010-01-22 18:59:05 -080032 @ insert the args onto the new stack
33 str r0, [r1, #-4]
34 str r3, [r1, #-8]
35
36 @ do the system call
37 @ get flags
38
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080039 mov r0, r2
David 'Digit' Turner97cf7f32010-01-22 18:59:05 -080040
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080041 @ new sp is already in r1
42
43#if __ARM_EABI__
44 stmfd sp!, {r4, r7}
45 ldr r7, =__NR_clone
David 'Digit' Turner97cf7f32010-01-22 18:59:05 -080046 swi #0
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080047#else
David 'Digit' Turner97cf7f32010-01-22 18:59:05 -080048 swi #__NR_clone
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080049#endif
50
David 'Digit' Turner97cf7f32010-01-22 18:59:05 -080051 movs r0, r0
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080052#if __ARM_EABI__
53 ldmnefd sp!, {r4, r7}
54#endif
David 'Digit' Turner97cf7f32010-01-22 18:59:05 -080055 blt __error
56 bxne lr
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080057
58
David 'Digit' Turner97cf7f32010-01-22 18:59:05 -080059 @ pick the function arg and call address off the stack and jump
60 @ to the C __thread_entry function which does some setup and then
61 @ calls the thread's start function
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080062
David 'Digit' Turner97cf7f32010-01-22 18:59:05 -080063 ldr r0, [sp, #-4]
64 ldr r1, [sp, #-8]
65 mov r2, sp @ __thread_entry needs the TLS pointer
66 b __thread_entry
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080067
68__error:
David 'Digit' Turner97cf7f32010-01-22 18:59:05 -080069 mov r0, #-1
70 bx lr
Kenny Root420878c2011-02-16 11:55:58 -080071END(__pthread_clone)
David 'Digit' Turner97cf7f32010-01-22 18:59:05 -080072
73
74 #
75 # This function is defined as:
76 #
77 # pid_t __bionic_clone( int flags, void *child_stack,
78 # pid_t *pid, void *tls, pid_t *ctid,
79 # int (*fn)(void *), void* arg );
80 #
81 # NOTE: This is not the same signature than the GLibc
82 # __clone function here !! Placing 'fn' and 'arg'
83 # at the end of the parameter list makes the
84 # implementation much simpler.
85 #
David 'Digit' Turner97cf7f32010-01-22 18:59:05 -080086
Kenny Root420878c2011-02-16 11:55:58 -080087ENTRY(__bionic_clone)
David 'Digit' Turner97cf7f32010-01-22 18:59:05 -080088 mov ip, sp
89 .save {r4, r5, r6, r7}
90
91 # save registers to parent stack
92 stmfd sp!, {r4, r5, r6, r7}
93
94 # load extra parameters
95 ldmfd ip, {r4, r5, r6}
96
97 # store 'fn' and 'arg' to the child stack
98 str r5, [r1, #-4]
99 str r6, [r1, #-8]
100
101 # system call
102 ldr r7, =__NR_clone
103 swi #0
104 movs r0, r0
105 beq 1f
106
107 # in parent, reload saved registers
108 # then either exit or error
109 #
110 ldmfd sp!, {r4, r5, r6, r7}
111 bxne lr
112 b __set_syscall_errno
113
1141: # in the child - pick arguments
115 ldr r0, [sp, #-4]
116 ldr r1, [sp, #-8]
117 b __bionic_clone_entry
Kenny Root420878c2011-02-16 11:55:58 -0800118END(__bionic_clone)