]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/unix/sysv/linux/aarch64/clone.S
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / aarch64 / clone.S
CommitLineData
b168057a 1/* Copyright (C) 1996-2015 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
26#define CLONE_VM_BIT 8
27#define CLONE_VM (1 << CLONE_VM_BIT)
28
29#define CLONE_THREAD_BIT 16
30#define CLONE_THREAD (1 << CLONE_THREAD_BIT)
31
32/* int clone(int (*fn)(void *arg), x0
33 void *child_stack, x1
34 int flags, x2
35 void *arg, x3
36 pid_t *ptid, x4
37 struct user_desc *tls, x5
38 pid_t *ctid); x6
39 */
40 .text
41ENTRY(__clone)
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 66PSEUDO_END (__clone)
554066b8 67
111cc714
RH
68 .align 4
69 .type thread_start, %function
70thread_start:
3a3acb6a
TT
71 cfi_startproc
72 cfi_undefined (x30)
73 mov x29, 0
111cc714
RH
74
75 tbnz x11, #CLONE_THREAD_BIT, 3f
554066b8 76 mov x0, #-1
111cc714 77 tbnz x11, #CLONE_VM_BIT, 2f
554066b8
MS
78 mov x8, #SYS_ify(getpid)
79 svc 0x0
802:
81 mrs x1, tpidr_el0
82 sub x1, x1, #PTHREAD_SIZEOF
83 str w0, [x1, #PTHREAD_PID_OFFSET]
84 str w0, [x1, #PTHREAD_TID_OFFSET]
554066b8 853:
111cc714
RH
86
87 /* Pick the function arg and execute. */
88 mov x0, x12
89 blr x10
554066b8
MS
90
91 /* We are done, pass the return value through x0. */
92 b HIDDEN_JUMPTARGET(_exit)
3a3acb6a 93 cfi_endproc
111cc714 94 .size thread_start, .-thread_start
554066b8
MS
95
96weak_alias (__clone, clone)