]>
Commit | Line | Data |
---|---|---|
04277e02 | 1 | /* Copyright (C) 1996-2019 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 | |
17 | <http://www.gnu.org/licenses/>. */ | |
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) | |
389d1f1b SE |
36 | DELOUSE (0) |
37 | DELOUSE (1) | |
38 | DELOUSE (2) | |
39 | DELOUSE (3) | |
40 | DELOUSE (4) | |
41 | DELOUSE (5) | |
42 | DELOUSE (6) | |
111cc714 RH |
43 | /* Save args for the child. */ |
44 | mov x10, x0 | |
45 | mov x11, x2 | |
46 | mov x12, x3 | |
47 | ||
554066b8 | 48 | /* Sanity check args. */ |
111cc714 RH |
49 | mov x0, #-EINVAL |
50 | cbz x10, .Lsyscall_error | |
51 | cbz x1, .Lsyscall_error | |
554066b8 MS |
52 | |
53 | /* Do the system call. */ | |
111cc714 | 54 | /* X0:flags, x1:newsp, x2:parenttidptr, x3:newtls, x4:childtid. */ |
554066b8 | 55 | mov x0, x2 /* flags */ |
554066b8 MS |
56 | /* New sp is already in x1. */ |
57 | mov x2, x4 /* ptid */ | |
58 | mov x3, x5 /* tls */ | |
59 | mov x4, x6 /* ctid */ | |
554066b8 | 60 | mov x8, #SYS_ify(clone) |
554066b8 | 61 | svc 0x0 |
111cc714 | 62 | |
554066b8 | 63 | cmp x0, #0 |
111cc714 RH |
64 | beq thread_start |
65 | blt .Lsyscall_error | |
554066b8 | 66 | RET |
111cc714 | 67 | PSEUDO_END (__clone) |
554066b8 | 68 | |
111cc714 RH |
69 | .align 4 |
70 | .type thread_start, %function | |
71 | thread_start: | |
3a3acb6a TT |
72 | cfi_startproc |
73 | cfi_undefined (x30) | |
74 | mov x29, 0 | |
111cc714 | 75 | |
111cc714 RH |
76 | /* Pick the function arg and execute. */ |
77 | mov x0, x12 | |
78 | blr x10 | |
554066b8 MS |
79 | |
80 | /* We are done, pass the return value through x0. */ | |
3f823e87 AZ |
81 | mov x8, #SYS_ify(exit) |
82 | svc 0x0 | |
3a3acb6a | 83 | cfi_endproc |
111cc714 | 84 | .size thread_start, .-thread_start |
554066b8 | 85 | |
9ff72da4 | 86 | libc_hidden_def (__clone) |
554066b8 | 87 | weak_alias (__clone, clone) |