]>
Commit | Line | Data |
---|---|---|
2b778ceb | 1 | /* Copyright (C) 1997-2021 Free Software Foundation, Inc. |
41bdb6e2 | 2 | This file is part of the GNU C Library. |
5ae3e846 UD |
3 | Contributed by Richard Henderson (rth@tamu.edu). |
4 | ||
5 | The GNU C Library is free software; you can redistribute it and/or | |
41bdb6e2 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. | |
5ae3e846 UD |
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 | |
41bdb6e2 | 13 | Lesser General Public License for more details. |
5ae3e846 | 14 | |
41bdb6e2 | 15 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 | 16 | License along with the GNU C Library; if not, see |
5a82c748 | 17 | <https://www.gnu.org/licenses/>. */ |
5ae3e846 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 <asm/errno.h> | |
edac0e8f | 23 | #include <tcb-offsets.h> |
043cee37 | 24 | #include <sysdep.h> |
5ae3e846 | 25 | |
edac0e8f UD |
26 | /* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg, |
27 | pid_t *ptid, void *tls, pid_t *ctid); */ | |
28 | ||
29 | .register %g2,#scratch | |
30 | .register %g3,#scratch | |
5ae3e846 UD |
31 | |
32 | .text | |
5ae3e846 | 33 | |
043cee37 | 34 | ENTRY (__clone) |
9c4c0024 | 35 | save %sp, -192, %sp |
043cee37 RM |
36 | cfi_def_cfa_register(%fp) |
37 | cfi_window_save | |
38 | cfi_register(%o7, %i7) | |
5ae3e846 UD |
39 | |
40 | /* sanity check arguments */ | |
edac0e8f UD |
41 | brz,pn %i0, 99f /* fn non-NULL? */ |
42 | mov %i0, %g2 | |
43 | brz,pn %i1, 99f /* child_stack non-NULL? */ | |
44 | mov %i2, %o0 /* clone flags */ | |
45 | ||
46 | /* The child_stack is the top of the stack, allocate one | |
47 | whole stack frame from that as this is what the kernel | |
48 | expects. Also, subtract STACK_BIAS. */ | |
49 | sub %i1, 192 + 0x7ff, %o1 | |
50 | mov %i3, %g3 | |
edac0e8f UD |
51 | |
52 | mov %i4,%o2 /* PTID */ | |
53 | mov %i5,%o3 /* TLS */ | |
54 | ldx [%fp+0x7ff+176],%o4 /* CTID */ | |
5ae3e846 UD |
55 | |
56 | /* Do the system call */ | |
5ae3e846 | 57 | set __NR_clone, %g1 |
9c4c0024 | 58 | ta 0x6d |
91ddd9c4 | 59 | bcs,pn %xcc, 98f |
5ae3e846 | 60 | nop |
09bf6406 | 61 | brnz,pn %o1, __thread_start |
edac0e8f | 62 | nop |
043cee37 | 63 | jmpl %i7 + 8, %g0 |
edac0e8f | 64 | restore %o0, %g0, %o0 |
91ddd9c4 JJ |
65 | 99: mov EINVAL, %o0 |
66 | 98: call HIDDEN_JUMPTARGET(__errno_location) | |
67 | mov %o0, %i0 | |
5ae3e846 | 68 | st %i0, [%o0] |
043cee37 | 69 | jmpl %i7 + 8, %g0 |
09bf6406 | 70 | restore %g0,-1,%o0 |
043cee37 | 71 | END(__clone) |
5ae3e846 UD |
72 | |
73 | .type __thread_start,@function | |
74 | __thread_start: | |
75 | mov %g0, %fp /* terminate backtrace */ | |
edac0e8f UD |
76 | call %g2 |
77 | mov %g3,%o0 | |
3f823e87 AZ |
78 | set __NR_exit, %g1 |
79 | ta 0x6d | |
5ae3e846 | 80 | nop |
043cee37 RM |
81 | |
82 | .size __thread_start, .-__thread_start | |
4194bc66 | 83 | |
9ff72da4 | 84 | libc_hidden_def (__clone) |
1ab18a5b | 85 | weak_alias (__clone, clone) |