1 /* Copyright (C) 1996-2014 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 /* clone() is even more special than fork() as it mucks with stacks
20 and invokes a function in the right context after its all over. */
24 #include <bits/errno.h>
26 #define CLONE_VM_BIT 8
27 #define CLONE_VM (1 << CLONE_VM_BIT)
29 #define CLONE_THREAD_BIT 16
30 #define CLONE_THREAD (1 << CLONE_THREAD_BIT)
32 /* int clone(int (*fn)(void *arg), x0
37 struct user_desc *tls, x5
42 /* Sanity check args. */
45 /* Insert the args onto the new stack. */
46 stp x0, x3, [x1, #-16]! /* Fn, arg. */
48 /* Do the system call. */
49 mov x0, x2 /* flags */
51 /* New sp is already in x1. */
57 /* We rely on the kernel preserving the argument regsiters across a
58 each system call so that we can inspect the flags against after
63 mov x8, #SYS_ify(clone)
64 /* X0:flags, x1:newsp, x2:parenttidptr, x3:newtls, x4:childtid. */
76 tbnz x5, #CLONE_THREAD_BIT, 3f
78 tbnz x5, #CLONE_VM_BIT, 2f
79 mov x8, #SYS_ify(getpid)
83 sub x1, x1, #PTHREAD_SIZEOF
84 str w0, [x1, #PTHREAD_PID_OFFSET]
85 str w0, [x1, #PTHREAD_TID_OFFSET]
89 /* Pick the function arg and call address from the stack and
94 /* We are done, pass the return value through x0. */
95 b HIDDEN_JUMPTARGET(_exit)
99 weak_alias (__clone, clone)