1 /* Copyright (C) 2005, 2007 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
19 #include <sys/syscall.h>
21 #include <bits/signum.h>
24 /* Clone the calling process, but without copying the whole address space.
25 The calling process is suspended until the new process exits or is
26 replaced by a call to `execve'. Return -1 for errors, 0 to the new process,
27 and the process ID of the new process to the old process.
29 Note that it is important that we don't create a new stack frame for the
33 /* The following are defined in linux/sched.h, which unfortunately
34 is not safe for inclusion in an assembly file. */
35 #define CLONE_VM 0x00000100 /* set if VM shared between processes */
36 #define CLONE_VFORK 0x00004000 /* set if the parent wants the child to
37 wake it up on mm_release */
49 Implemented as __clone_syscall(CLONE_VFORK | CLONE_VM | SIGCHLD, 0) */
51 HIDDEN_ENTRY (__vfork)
54 extui a2, a0, 30, 2 /* call-size: call4/8/12 = 1/2/3 */
55 addx4 a4, a2, a6 /* find return address in jumptable */
60 xor a3, a0, a2 /* remove call-size from return addr */
61 extui a5, a4, 30, 2 /* get high bits of jump target */
63 or a3, a3, a5 /* stuff them into the return address */
64 xor a4, a4, a5 /* clear high bits of jump target */
65 or a0, a4, a2 /* create temporary return address */
66 retw /* "return" to .L4, .L8, or .L12 */
71 .word .L4 - .Ljumptable
72 .word .L8 - .Ljumptable
73 .word .L12 - .Ljumptable
75 /* a7: return address */
81 /* Use syscall 'clone'. Set new stack pointer to the same address. */
82 movi a2, SYS_ify (clone)
84 movi a6, CLONE_VM | CLONE_VFORK | SIGCHLD
97 1: call4 .Lerr /* returns to original caller */
100 /* a11: return address */
107 movi a2, SYS_ify (clone)
109 movi a6, CLONE_VM | CLONE_VFORK | SIGCHLD
123 1: call8 .Lerr /* returns to original caller */
126 /* a15: return address */
133 movi a2, SYS_ify (clone)
135 movi a6, CLONE_VM | CLONE_VFORK | SIGCHLD
150 1: call12 .Lerr /* returns to original caller */
156 /* Restore the return address. */
157 extui a4, a0, 30, 2 /* get the call-size bits */
159 slli a3, a3, 2 /* clear high bits of target address */
161 or a0, a3, a4 /* combine them */
167 weak_alias (__vfork, vfork)
168 libc_hidden_def(vfork)