1 /* Wrapper around clone system call. PowerPC64 version.
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>
23 #define CLONE_VM 0x00000100
24 #define CLONE_THREAD 0x00010000
26 /* This is the only really unusual system call in PPC linux, but not
27 because of any weirdness in the system call itself; because of
28 all the freaky stuff we have to do to make the call useful. */
30 /* int [r3] clone(int (*fn)(void *arg) [r3], void *child_stack [r4],
31 int flags [r5], void *arg [r6], void *parent_tid [r7],
32 void *tls [r8], void *child_tid [r9]); */
37 /* Check for child_stack == NULL || fn == NULL. */
40 cror cr0*4+eq,cr1*4+eq,cr0*4+eq
43 /* Save some regs in the "red zone". */
55 /* Set up stack frame for child. */
58 stdu r0,-FRAME_MIN_SIZE_PARM(r4)
60 /* Save fn, args, stack across syscall. */
61 mr r30,r3 /* Function in r30. */
63 mr r29,r5 /* Flags in r29. */
65 mr r31,r6 /* Argument in r31. */
67 /* 'flags' argument is first parameter to clone syscall.
68 Second is the stack pointer, already in r4. */
70 /* Move the parent_tid, child_tid and tls arguments. */
75 /* End FDE now, because in the child the unwind info will be
80 DO_CALL(SYS_ify(clone))
82 /* Check for child process. */
84 crandc cr1*4+eq,cr1*4+eq,cr0*4+so
85 bne- cr1,L(parent) /* The '-' is to minimise the race. */
88 andis. r0,r29,CLONE_THREAD>>16
92 bne- cr0,L(nomoregetpid)
93 DO_CALL(SYS_ify(getpid))
100 std r2,FRAME_TOC_SAVE(r1)
101 /* Call procedure. */
102 PPC64_LOAD_FUNCPTR r30
105 ld r2,FRAME_TOC_SAVE(r1)
106 /* Call _exit with result from procedure. */
108 b JUMPTARGET(__GI__exit)
111 /* We won't ever get here but provide a nop so that the linker
112 will insert a toc adjusting stub if necessary. */
119 TAIL_CALL_SYSCALL_ERROR
122 /* Parent. Restore registers & return. */
142 weak_alias (__clone, clone)