1 /* Copyright (C) 2011-2014 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
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/>. */
20 #define __ASSEMBLY__ /* for kernel headers */
21 #include <linux/sched.h>
22 #include <asm/signal.h>
23 #include <tcb-offsets.h>
25 /* Clone the calling process, but without copying the whole address space.
26 The calling process is suspended until the new process exits or is
27 replaced by a call to `execve'. Return -1 for errors, 0 to the new process,
28 and the process ID of the new process to the old process. */
33 addli r11, tp, PID_OFFSET /* Point at PID. */
37 LD4U r12, r11 /* Load the saved PID. */
38 shli r13, r13, 31 /* Build 0x80000000. */
40 sub r12, zero, r12 /* Negate it. */
42 CMOVEQZ r12, r12, r13 /* Replace zero pids. */
44 ST4 r11, r12 /* Store the temporary PID. */
47 moveli r0, CLONE_VFORK | CLONE_VM | SIGCHLD
54 moveli TREG_SYSCALL_NR_NAME, __NR_clone
57 BEQZ r0, 1f /* If we are the parent... */
59 addli r11, tp, PID_OFFSET /* Point at PID. */
63 LD4U r12, r11 /* Load the saved PID. */
64 shli r13, r13, 31 /* Build 0x80000000. */
67 CMPEQ r13, r12, r12 /* Test for that value. */
68 sub r12, zero, r12 /* Re-negate it. */
71 CMOVNEZ r12, r13, zero /* Replace zero pids. */
73 ST4 r11, r12 /* Restore the PID. */
78 libc_hidden_def (__vfork)
80 weak_alias (__vfork, vfork)