1 /* Wrapper around clone system call.
2 Copyright (C) 1997-2014 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>
22 #include <kernel-features.h>
24 #define CLONE_VM 0x00000100
25 #define CLONE_THREAD 0x00010000
28 /* This is the only really unusual system call in PPC linux, but not
29 because of any weirdness in the system call itself; because of
30 all the freaky stuff we have to do to make the call useful. */
32 /* int [r3] clone(int (*fn)(void *arg) [r3], void *child_stack [r4],
33 int flags [r5], void *arg [r6], void *parent_tid [r7],
34 void *tls [r8], void *child_tid [r9]); */
38 /* Check for child_stack == NULL || fn == NULL. */
41 cror cr0*4+eq,cr1*4+eq,cr0*4+eq
44 /* Set up stack frame for parent. */
46 cfi_adjust_cfa_offset (32)
53 /* Set up stack frame for child. */
58 /* Save fn, args, stack across syscall. */
59 mr r30,r3 /* Function in r30. */
63 mr r31,r6 /* Argument in r31. */
65 /* 'flags' argument is first parameter to clone syscall. (The other
66 argument is the stack pointer, already in r4.) */
69 /* Move the parent_tid, child_tid and tls arguments. */
74 /* End FDE now, because in the child the unwind info will be
79 DO_CALL(SYS_ify(clone))
81 /* Check for child process. */
83 crandc cr1*4+eq,cr1*4+eq,cr0*4+so
84 bne- cr1,L(parent) /* The '-' is to minimise the race. */
87 andis. r0,r28,CLONE_THREAD>>16
91 bne- r0,L(nomoregetpid)
92 DO_CALL(SYS_ify(getpid))
103 /* Call _exit with result from procedure. */
104 b HIDDEN_JUMPTARGET(_exit)
107 /* Parent. Restore registers & return. */
115 b __syscall_error@local
119 b __syscall_error@local
124 weak_alias (__clone, clone)