Update copyright dates with scripts/update-copyrights.
[glibc.git] / sysdeps / unix / sysv / linux / tile / vfork.S
blobc2fb753929cc5d38746d8d7a3b7ee8ebcfb9a16d
1 /* Copyright (C) 2011-2015 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/>.  */
19 #include <sysdep.h>
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.  */
30         .text
31 ENTRY (__vfork)
32         {
33          addli r11, tp, PID_OFFSET      /* Point at PID. */
34          movei r13, 1
35         }
36         {
37          LD4U r12, r11                  /* Load the saved PID.  */
38          shli r13, r13, 31              /* Build 0x80000000. */
39         }
40         sub r12, zero, r12              /* Negate it.  */
41         CMOVEQZ r12, r12, r13           /* Replace zero pids.  */
42         ST4 r11, r12                    /* Store the temporary PID.  */
44         {
45          moveli r0, CLONE_VFORK | CLONE_VM | SIGCHLD
46          move r1, zero
47         }
48         {
49          move r2, zero
50          move r3, zero
51         }
52         moveli TREG_SYSCALL_NR_NAME, __NR_clone
53         swint1
55         BEQZ r0, 1f                     /* If we are the parent... */
56         {
57          addli r11, tp, PID_OFFSET      /* Point at PID. */
58          movei r13, 1
59         }
60         {
61          LD4U r12, r11                  /* Load the saved PID.  */
62          shli r13, r13, 31              /* Build 0x80000000. */
63         }
64         {
65          CMPEQ r13, r12, r12            /* Test for that value. */
66          sub r12, zero, r12             /* Re-negate it.  */
67         }
68         CMOVNEZ r12, r13, zero          /* Replace zero pids.  */
69         ST4 r11, r12                    /* Restore the PID.  */
71         BNEZ r1, 0f
72         jrp lr
73 PSEUDO_END (__vfork)
74 libc_hidden_def (__vfork)
76 weak_alias (__vfork, vfork)
77 strong_alias (__vfork, __libc_vfork)