]>
Commit | Line | Data |
---|---|---|
2b778ceb | 1 | /* Copyright (C) 1996-2021 Free Software Foundation, Inc. |
554066b8 MS |
2 | |
3 | This file is part of the GNU C Library. | |
4 | ||
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. | |
9 | ||
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. | |
14 | ||
15 | You should have received a copy of the GNU Lesser General Public | |
16 | License along with the GNU C Library; if not, see | |
5a82c748 | 17 | <https://www.gnu.org/licenses/>. */ |
554066b8 MS |
18 | |
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. */ | |
21 | ||
22 | #include <sysdep.h> | |
23 | #define _ERRNO_H 1 | |
24 | #include <bits/errno.h> | |
25 | ||
554066b8 MS |
26 | /* int clone(int (*fn)(void *arg), x0 |
27 | void *child_stack, x1 | |
28 | int flags, x2 | |
29 | void *arg, x3 | |
30 | pid_t *ptid, x4 | |
31 | struct user_desc *tls, x5 | |
32 | pid_t *ctid); x6 | |
33 | */ | |
34 | .text | |
35 | ENTRY(__clone) | |
45b1e17e SN |
36 | PTR_ARG (0) |
37 | PTR_ARG (1) | |
38 | PTR_ARG (3) | |
39 | PTR_ARG (4) | |
40 | PTR_ARG (5) | |
41 | PTR_ARG (6) | |
111cc714 RH |
42 | /* Save args for the child. */ |
43 | mov x10, x0 | |
44 | mov x11, x2 | |
45 | mov x12, x3 | |
46 | ||
554066b8 | 47 | /* Sanity check args. */ |
111cc714 RH |
48 | mov x0, #-EINVAL |
49 | cbz x10, .Lsyscall_error | |
50 | cbz x1, .Lsyscall_error | |
554066b8 MS |
51 | |
52 | /* Do the system call. */ | |
111cc714 | 53 | /* X0:flags, x1:newsp, x2:parenttidptr, x3:newtls, x4:childtid. */ |
554066b8 | 54 | mov x0, x2 /* flags */ |
554066b8 MS |
55 | /* New sp is already in x1. */ |
56 | mov x2, x4 /* ptid */ | |
57 | mov x3, x5 /* tls */ | |
58 | mov x4, x6 /* ctid */ | |
554066b8 | 59 | mov x8, #SYS_ify(clone) |
554066b8 | 60 | svc 0x0 |
111cc714 | 61 | |
554066b8 | 62 | cmp x0, #0 |
111cc714 RH |
63 | beq thread_start |
64 | blt .Lsyscall_error | |
554066b8 | 65 | RET |
111cc714 | 66 | PSEUDO_END (__clone) |
554066b8 | 67 | |
111cc714 RH |
68 | .align 4 |
69 | .type thread_start, %function | |
70 | thread_start: | |
3a3acb6a TT |
71 | cfi_startproc |
72 | cfi_undefined (x30) | |
73 | mov x29, 0 | |
111cc714 | 74 | |
111cc714 RH |
75 | /* Pick the function arg and execute. */ |
76 | mov x0, x12 | |
77 | blr x10 | |
554066b8 MS |
78 | |
79 | /* We are done, pass the return value through x0. */ | |
3f823e87 AZ |
80 | mov x8, #SYS_ify(exit) |
81 | svc 0x0 | |
3a3acb6a | 82 | cfi_endproc |
111cc714 | 83 | .size thread_start, .-thread_start |
554066b8 | 84 | |
9ff72da4 | 85 | libc_hidden_def (__clone) |
554066b8 | 86 | weak_alias (__clone, clone) |