1 | /* The clone3 syscall wrapper. Linux/aarch64 version. |
2 | Copyright (C) 2023-2024 Free Software Foundation, Inc. |
3 | |
4 | This file is part of the GNU C Library. |
5 | |
6 | The GNU C Library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Lesser General Public |
8 | License as published by the Free Software Foundation; either |
9 | version 2.1 of the License, or (at your option) any later version. |
10 | |
11 | The GNU C Library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Lesser General Public License for more details. |
15 | |
16 | You should have received a copy of the GNU Lesser General Public |
17 | License along with the GNU C Library; if not, see |
18 | <https://www.gnu.org/licenses/>. */ |
19 | |
20 | #include <sysdep.h> |
21 | #define _ERRNO_H 1 |
22 | #include <bits/errno.h> |
23 | |
24 | /* The userland implementation is: |
25 | int clone3 (struct clone_args *cl_args, size_t size, |
26 | int (*func)(void *arg), void *arg); |
27 | |
28 | the kernel entry is: |
29 | int clone3 (struct clone_args *cl_args, size_t size); |
30 | |
31 | The parameters are passed in registers from userland: |
32 | x0: cl_args |
33 | x1: size |
34 | x2: func |
35 | x3: arg */ |
36 | |
37 | .text |
38 | ENTRY(__clone3) |
39 | PTR_ARG (0) |
40 | PTR_ARG (1) |
41 | PTR_ARG (3) |
42 | PTR_ARG (4) |
43 | /* Save args for the child. */ |
44 | mov x10, x0 /* cl_args */ |
45 | mov x11, x2 /* func */ |
46 | mov x12, x3 /* args */ |
47 | |
48 | /* Sanity check args. */ |
49 | mov x0, #-EINVAL |
50 | cbz x10, .Lsyscall_error /* No NULL cl_args pointer. */ |
51 | cbz x2, .Lsyscall_error /* No NULL function pointer. */ |
52 | |
53 | /* Do the system call, the kernel expects: |
54 | x8: system call number |
55 | x0: cl_args |
56 | x1: size */ |
57 | mov x0, x10 |
58 | mov x8, #SYS_ify(clone3) |
59 | svc 0x0 |
60 | |
61 | cmp x0, #0 |
62 | beq thread_start |
63 | blt .Lsyscall_error |
64 | RET |
65 | PSEUDO_END (__clone3) |
66 | |
67 | .align 4 |
68 | .type thread_start, %function |
69 | thread_start: |
70 | cfi_startproc |
71 | cfi_undefined (x30) |
72 | mov x29, 0 |
73 | |
74 | /* Pick the function arg and execute. */ |
75 | mov x0, x12 |
76 | blr x11 |
77 | |
78 | /* We are done, pass the return value through x0. */ |
79 | mov x8, #SYS_ify(exit) |
80 | svc 0x0 |
81 | cfi_endproc |
82 | .size thread_start, .-thread_start |
83 | |
84 | libc_hidden_def (__clone3) |
85 | weak_alias (__clone3, clone3) |
86 | |