]>
Commit | Line | Data |
---|---|---|
04277e02 | 1 | /* Copyright (C) 1996-2019 Free Software Foundation, Inc. |
3c7b2587 UD |
2 | This file is part of the GNU C Library. |
3 | Contributed by Richard Henderson <rth@tamu.edu>, 1996. | |
3b0174d0 | 4 | |
3c7b2587 | 5 | The GNU C Library is free software; you can redistribute it and/or |
3214b89b AJ |
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. | |
3b0174d0 | 9 | |
3c7b2587 UD |
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 | |
3214b89b | 13 | Lesser General Public License for more details. |
3b0174d0 | 14 | |
3214b89b | 15 | You should have received a copy of the GNU Lesser General Public |
ab84e3ff PE |
16 | License along with the GNU C Library. If not, see |
17 | <http://www.gnu.org/licenses/>. */ | |
3b0174d0 UD |
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> | |
81e25b60 | 23 | #define _ERRNO_H 1 |
405916ef | 24 | #include <bits/errno.h> |
3b0174d0 | 25 | |
4feb1bb5 RH |
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. */ | |
3b0174d0 UD |
33 | |
34 | .text | |
c18b7473 RH |
35 | .align 4 |
36 | .globl __clone | |
37 | .ent __clone | |
38 | .usepv __clone, USEPV_PROF | |
39 | ||
40 | cfi_startproc | |
41 | __clone: | |
dd4b8913 | 42 | #ifdef PROF |
054b72cc | 43 | .set noat |
18a702a8 | 44 | ldgp gp,0(pv) |
dd4b8913 UD |
45 | lda AT, _mcount |
46 | jsr AT, (AT), _mcount | |
054b72cc | 47 | .set at |
18a702a8 | 48 | #endif |
3b0174d0 UD |
49 | |
50 | /* Sanity check arguments. */ | |
c18b7473 RH |
51 | ldiq v0, EINVAL |
52 | beq a0, SYSCALL_ERROR_LABEL /* no NULL function pointers */ | |
53 | beq a1, SYSCALL_ERROR_LABEL /* no NULL stack pointers */ | |
3b0174d0 | 54 | |
0f85544d | 55 | /* Save the fn ptr and arg on the new stack. */ |
c18b7473 RH |
56 | subq a1, 32, a1 |
57 | stq a0, 0(a1) | |
58 | stq a3, 8(a1) | |
c18b7473 | 59 | stq a2, 16(a1) |
0f85544d | 60 | |
4feb1bb5 RH |
61 | /* The syscall is of the form clone(flags, usp, ptid, ctid, tls). |
62 | Shift the flags, ptid, ctid, tls arguments into place; the | |
e8b06fdf | 63 | child_stack argument is already correct. */ |
c18b7473 RH |
64 | mov a2, a0 |
65 | mov a4, a2 | |
66 | ldq a3, 0(sp) | |
67 | mov a5, a4 | |
e8b06fdf RM |
68 | |
69 | /* Do the system call. */ | |
c18b7473 | 70 | ldiq v0, __NR_clone |
3b0174d0 UD |
71 | call_pal PAL_callsys |
72 | ||
c18b7473 RH |
73 | bne a3, SYSCALL_ERROR_LABEL |
74 | beq v0, thread_start | |
3b0174d0 | 75 | |
e8b06fdf | 76 | /* Successful return from the parent. */ |
3b0174d0 UD |
77 | ret |
78 | ||
c18b7473 RH |
79 | PSEUDO_END(__clone) |
80 | cfi_endproc | |
3b0174d0 UD |
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 | |
b5ce64ef | 84 | debug info. */ |
3b0174d0 | 85 | |
279b24e2 | 86 | .align 4 |
3b0174d0 | 87 | .ent thread_start |
c18b7473 | 88 | cfi_startproc |
3b0174d0 | 89 | thread_start: |
13e579e4 | 90 | mov 0, fp |
c18b7473 RH |
91 | cfi_def_cfa_register(fp) |
92 | cfi_undefined(ra) | |
3b0174d0 | 93 | |
0f85544d | 94 | /* Load up the arguments. */ |
c18b7473 RH |
95 | ldq pv, 0(sp) |
96 | ldq a0, 8(sp) | |
97 | addq sp, 32, sp | |
0f85544d | 98 | |
e8b06fdf | 99 | /* Call the user's function. */ |
c18b7473 RH |
100 | jsr ra, (pv) |
101 | ldgp gp, 0(ra) | |
3b0174d0 | 102 | |
d500130f | 103 | mov v0, a0 |
3f823e87 AZ |
104 | ldiq v0, __NR_exit |
105 | call_pal PAL_callsys | |
3b0174d0 | 106 | |
b5ce64ef | 107 | /* Die horribly. */ |
279b24e2 | 108 | .align 4 |
b5ce64ef UD |
109 | halt |
110 | ||
279b24e2 | 111 | .align 4 |
c18b7473 | 112 | cfi_endproc |
3b0174d0 UD |
113 | .end thread_start |
114 | ||
9ff72da4 | 115 | libc_hidden_def (__clone) |
8796ce21 | 116 | weak_alias (__clone, clone) |