1 /* Wrapper around clone system call.
2 Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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/>. */
21 #include <bits/errno.h>
24 #define CLONE_VM 0x00000100
25 #define CLONE_THREAD 0x00010000
27 /* This is the only really unusual system call in PPC linux, but not
28 because of any weirdness in the system call itself; because of
29 all the freaky stuff we have to do to make the call useful. */
31 /* int [r3] clone(int (*fn)(void *arg) [r3], void *child_stack [r4],
32 int flags [r5], void *arg [r6], void *parent_tid [r7],
33 void *tls [r8], void *child_tid [r9]); */
37 .type __clone,@function
41 /* Check for child_stack == NULL || fn == NULL. */
44 cror cr0*4+eq,cr1*4+eq,cr0*4+eq
47 /* Set up stack frame for parent. */
49 cfi_adjust_cfa_offset (32)
53 # ifndef __ASSUME_FIXED_CLONE_SYSCALL
60 /* Set up stack frame for child. */
65 /* Save fn, args, stack across syscall. */
66 mr r30,r3 /* Function in r30. */
67 #ifndef __ASSUME_FIXED_CLONE_SYSCALL
68 mr r29,r4 /* Stack pointer in r29. */
73 mr r31,r6 /* Argument in r31. */
75 /* 'flags' argument is first parameter to clone syscall. (The other
76 argument is the stack pointer, already in r4.) */
79 /* Move the parent_tid, child_tid and tls arguments. */
84 /* End FDE now, because in the child the unwind info will be wrong. */
91 /* Check for child process. */
93 crandc cr1*4+eq,cr1*4+eq,cr0*4+so
94 bne- cr1,.Lparent /* The '-' is to minimise the race. */
96 #ifndef __ASSUME_FIXED_CLONE_SYSCALL
97 /* On at least mklinux DR3a5, clone() doesn't actually change
98 the stack pointer. I'm pretty sure this is a bug, because
99 it adds a race condition if a signal is sent to a thread
100 just after it is created (in the previous three instructions). */
105 andis. r0,r28,CLONE_THREAD>>16
107 andi. r0,r28,CLONE_VM
109 bne- r0,.Lnomoregetpid
115 /* Call procedure. */
119 /* Call _exit with result from procedure. */
120 b HIDDEN_JUMPTARGET(_exit)
123 /* Parent. Restore registers & return. */
127 # ifndef __ASSUME_FIXED_CLONE_SYSCALL
142 .size __clone,.-__clone
143 weak_alias(__clone, clone)