1 /* Copyright (C) 1996-2024 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library. If not, see
16 <https://www.gnu.org/licenses/>. */
18 /* clone() is even more special than fork() as it mucks with stacks
19 and invokes a function in the right context after its all over. */
23 #include <bits/errno.h>
26 /* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg,
27 void *parent_tidptr, void *tls, void *child_tidptr) */
32 /* Sanity check arguments. */
34 movel 4(%sp), %a0 /* no NULL function pointers */
36 jeq SYSCALL_ERROR_LABEL
37 movel 8(%sp), %a1 /* no NULL stack pointers */
39 jeq SYSCALL_ERROR_LABEL
41 /* Allocate space and copy the argument onto the new stack. */
44 /* Do the system call */
45 movel 12+0(%sp), %d1 /* get flags */
46 movel %d3, -(%a1) /* save %d3 and get parent_tidptr */
48 cfi_adjust_cfa_offset (4)
49 cfi_rel_offset (%d3, 0)
51 movel %d4, -(%a1) /* save %d4 and get child_tidptr */
53 cfi_adjust_cfa_offset (4)
54 cfi_rel_offset (%d4, 0)
56 movel %d5, -(%a1) /* save %d5 and get tls */
58 cfi_adjust_cfa_offset (4)
59 cfi_rel_offset (%d5, 0)
61 /* save %d2 and get stack pointer */
65 cfi_adjust_cfa_offset (4)
66 cfi_rel_offset (%d2, 0)
69 exg %d2, %a1 /* save %d2 and get stack pointer */
70 cfi_register (%d2, %a1)
72 movel #SYS_ify (clone), %d0
74 /* End FDE now, because in the child the unwind info will be
82 exg %d2, %a1 /* restore %d2 */
84 movel (%sp)+, %d5 /* restore %d5, %d4 and %d3 */
89 jmi SYSCALL_ERROR_LABEL
96 cfi_undefined (pc) /* Mark end of stack */
97 subl %fp, %fp /* terminate the stack frame */
100 movel #SYS_ify (exit), %d0
107 libc_hidden_def (__clone)
108 weak_alias (__clone, clone)