]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/alpha/clone.S
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / alpha / clone.S
1 /* Copyright (C) 1996-2019 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Richard Henderson <rth@tamu.edu>, 1996.
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 /* int clone(int (*fn)(void *arg), void *child_stack, int flags,
27 void *arg, pid_t *ptid, void *tls, pid_t *ctid);
28
29 Note that everything past ARG is technically optional, based
30 on FLAGS, and that CTID is arg 7, and thus is on the stack.
31 However, since a load from top-of-stack better be legal always,
32 we don't bother checking FLAGS. */
33
34 .text
35 .align 4
36 .globl __clone
37 .ent __clone
38 .usepv __clone, USEPV_PROF
39
40 cfi_startproc
41 __clone:
42 #ifdef PROF
43 .set noat
44 ldgp gp,0(pv)
45 lda AT, _mcount
46 jsr AT, (AT), _mcount
47 .set at
48 #endif
49
50 /* Sanity check arguments. */
51 ldiq v0, EINVAL
52 beq a0, SYSCALL_ERROR_LABEL /* no NULL function pointers */
53 beq a1, SYSCALL_ERROR_LABEL /* no NULL stack pointers */
54
55 /* Save the fn ptr and arg on the new stack. */
56 subq a1, 32, a1
57 stq a0, 0(a1)
58 stq a3, 8(a1)
59 stq a2, 16(a1)
60
61 /* The syscall is of the form clone(flags, usp, ptid, ctid, tls).
62 Shift the flags, ptid, ctid, tls arguments into place; the
63 child_stack argument is already correct. */
64 mov a2, a0
65 mov a4, a2
66 ldq a3, 0(sp)
67 mov a5, a4
68
69 /* Do the system call. */
70 ldiq v0, __NR_clone
71 call_pal PAL_callsys
72
73 bne a3, SYSCALL_ERROR_LABEL
74 beq v0, thread_start
75
76 /* Successful return from the parent. */
77 ret
78
79 PSEUDO_END(__clone)
80 cfi_endproc
81
82 /* Load up the arguments to the function. Put this block of code in
83 its own function so that we can terminate the stack trace with our
84 debug info. */
85
86 .align 4
87 .ent thread_start
88 cfi_startproc
89 thread_start:
90 mov 0, fp
91 cfi_def_cfa_register(fp)
92 cfi_undefined(ra)
93
94 /* Load up the arguments. */
95 ldq pv, 0(sp)
96 ldq a0, 8(sp)
97 addq sp, 32, sp
98
99 /* Call the user's function. */
100 jsr ra, (pv)
101 ldgp gp, 0(ra)
102
103 mov v0, a0
104 ldiq v0, __NR_exit
105 call_pal PAL_callsys
106
107 /* Die horribly. */
108 .align 4
109 halt
110
111 .align 4
112 cfi_endproc
113 .end thread_start
114
115 libc_hidden_def (__clone)
116 weak_alias (__clone, clone)