1 /* Wrapper around clone system call. PowerPC64 version.
2 Copyright (C) 1997,98,99,2000,02,04, 2006 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, write to the Free
17 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA
22 #include <bits/errno.h>
26 #define CLONE_VM 0x00000100
27 #define CLONE_THREAD 0x00010000
29 /* This is the only really unusual system call in PPC linux, but not
30 because of any weirdness in the system call itself; because of
31 all the freaky stuff we have to do to make the call useful. */
33 /* int [r3] clone(int (*fn)(void *arg) [r3], void *child_stack [r4],
34 int flags [r5], void *arg [r6], void *parent_tid [r7],
35 void *tls [r8], void *child_tid [r9]); */
37 ENTRY (BP_SYM (__clone))
39 /* GKM FIXME: add bounds checks, where sensible. */
43 /* Check for child_stack == NULL || fn == NULL. */
46 cror cr0*4+eq,cr1*4+eq,cr0*4+eq
49 /* Set up stack frame for parent. */
51 cfi_adjust_cfa_offset (80)
59 /* Set up stack frame for child. */
62 stdu r0,-48(r4) /* min stack frame is 48 bytes per ABI */
64 /* Save fn, args, stack across syscall. */
65 mr r29,r3 /* Function in r29. */
66 mr r30,r4 /* Stack pointer in r30. */
68 mr r28,r5 /* Flags in r28. */
70 mr r31,r6 /* Argument in r31. */
72 /* 'flags' argument is first parameter to clone syscall. (The other
73 argument is the stack pointer, already in r4.) */
75 /* Move the parent_tid, child_tid and tls arguments. */
81 DO_CALL(SYS_ify(clone))
83 /* Check for child process. */
85 crandc cr1*4+eq,cr1*4+eq,cr0*4+so
86 bne- cr1,L(parent) /* The '-' is to minimise the race. */
89 andis. r0,r28,CLONE_THREAD>>16
93 bne- cr0,L(nomoregetpid)
94 DO_CALL(SYS_ify(getpid))
102 /* Call procedure. */
109 /* Call _exit with result from procedure. */
111 b JUMPTARGET(__GI__exit)
117 /* Parent. Restore registers & return. */
126 b JUMPTARGET(__syscall_error)
130 b JUMPTARGET(__syscall_error)
131 END (BP_SYM (__clone))
133 weak_alias (BP_SYM (__clone), BP_SYM (clone))