]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/aarch64/clone.S
Prefer https to http for gnu.org and fsf.org URLs
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / aarch64 / clone.S
1 /* Copyright (C) 1996-2019 Free Software Foundation, Inc.
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 <https://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
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)
36 DELOUSE (0)
37 DELOUSE (1)
38 DELOUSE (2)
39 DELOUSE (3)
40 DELOUSE (4)
41 DELOUSE (5)
42 DELOUSE (6)
43 /* Save args for the child. */
44 mov x10, x0
45 mov x11, x2
46 mov x12, x3
47
48 /* Sanity check args. */
49 mov x0, #-EINVAL
50 cbz x10, .Lsyscall_error
51 cbz x1, .Lsyscall_error
52
53 /* Do the system call. */
54 /* X0:flags, x1:newsp, x2:parenttidptr, x3:newtls, x4:childtid. */
55 mov x0, x2 /* flags */
56 /* New sp is already in x1. */
57 mov x2, x4 /* ptid */
58 mov x3, x5 /* tls */
59 mov x4, x6 /* ctid */
60 mov x8, #SYS_ify(clone)
61 svc 0x0
62
63 cmp x0, #0
64 beq thread_start
65 blt .Lsyscall_error
66 RET
67 PSEUDO_END (__clone)
68
69 .align 4
70 .type thread_start, %function
71 thread_start:
72 cfi_startproc
73 cfi_undefined (x30)
74 mov x29, 0
75
76 /* Pick the function arg and execute. */
77 mov x0, x12
78 blr x10
79
80 /* We are done, pass the return value through x0. */
81 mov x8, #SYS_ify(exit)
82 svc 0x0
83 cfi_endproc
84 .size thread_start, .-thread_start
85
86 libc_hidden_def (__clone)
87 weak_alias (__clone, clone)