1 /* Wrapper around clone system call. C-SKY ABIV2 version.
2 Copyright (C) 2018-2022 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 <https://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 /* int clone (int (*fn) (void *arg), void *child_stack, int flags, void *arg,
27 pid_t *ptid, struct user_desc *tls, pid_t *ctid) */
31 /* Sanity check arguments. */
32 cmpnei a0, 0 /* No NULL function pointers. */
34 cmpnei a1, 0 /* No NULL stack pointers. */
38 stw a0, (a1, 0) /* Insert the function into the new stack. */
39 stw a3, (a1, 4) /* Insert the args into the new stack. */
41 mov t1, r7 /* Save r7. */
42 mov t2, r4 /* Save r4. */
44 /* The syscall expects the args to be in different slots. */
52 mov r7, t1 /* Restore r7. */
53 mov r4, t2 /* Restore r4. */
54 btsti a0, 31 /* Check if return is less than zero. */
72 lrw t0, __syscall_error@PLT
73 ldr.w t0, (gb, t0 << 0)
84 ENTRY (__thread_start)
87 ldw a0, (sp, 4) /* Restore args from new sp. */
88 ldw a1, (sp, 0) /* Restore function from new sp. */
97 libc_hidden_def (__clone)
98 weak_alias (__clone, clone)