Update copyright dates with scripts/update-copyrights.
[glibc.git] / sysdeps / unix / sysv / linux / powerpc / powerpc32 / clone.S
blobc5d663451519008ca78ce51d55452b8fd1a58427
1 /* Wrapper around clone system call.
2    Copyright (C) 1997-2015 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/>.  */
19 #include <sysdep.h>
20 #define _ERRNO_H        1
21 #include <bits/errno.h>
23 #define CLONE_VM        0x00000100
24 #define CLONE_THREAD    0x00010000
27 /* This is the only really unusual system call in PPC linux, but not
28    because of any weirdness in the system call itself; because of
29    all the freaky stuff we have to do to make the call useful.  */
31 /* int [r3] clone(int (*fn)(void *arg) [r3], void *child_stack [r4],
32                   int flags [r5], void *arg [r6], void *parent_tid [r7],
33                   void *tls [r8], void *child_tid [r9]); */
35 ENTRY (__clone)
37         /* Check for child_stack == NULL || fn == NULL.  */
38         cmpwi   cr0,r4,0
39         cmpwi   cr1,r3,0
40         cror    cr0*4+eq,cr1*4+eq,cr0*4+eq
41         beq-    cr0,L(badargs)
43         /* Set up stack frame for parent.  */
44         stwu    r1,-32(r1)
45         cfi_adjust_cfa_offset (32)
46         stmw    r28,16(r1)
48         /* Set up stack frame for child.  */
49         clrrwi  r4,r4,4
50         li      r0,0
51         stwu    r0,-16(r4)
53         /* Save fn, args, stack across syscall.  */
54         mr      r30,r3                  /* Function in r30.  */
55         mr      r28,r5
56         mr      r31,r6                  /* Argument in r31.  */
58         /* 'flags' argument is first parameter to clone syscall. (The other
59            argument is the stack pointer, already in r4.)  */
60         mr      r3,r5
62         /* Move the parent_tid, child_tid and tls arguments. */
63         mr      r5,r7
64         mr      r6,r8
65         mr      r7,r9
67         /* End FDE now, because in the child the unwind info will be
68            wrong.  */
69         cfi_endproc
71         /* Do the call.  */
72         DO_CALL(SYS_ify(clone))
74         /* Check for child process.  */
75         cmpwi   cr1,r3,0
76         crandc  cr1*4+eq,cr1*4+eq,cr0*4+so
77         bne-    cr1,L(parent)           /* The '-' is to minimise the race.  */
79         andis.  r0,r28,CLONE_THREAD>>16
80         bne+    r0,L(oldpid)
81         andi.   r0,r28,CLONE_VM
82         li      r3,-1
83         bne-    r0,L(nomoregetpid)
84         DO_CALL(SYS_ify(getpid))
85 L(nomoregetpid):
86         stw     r3,TID(r2)
87         stw     r3,PID(r2)
88 L(oldpid):
90         /* Call procedure.  */
91         mtctr   r30
92         mr      r3,r31
93         bctrl
94         /* Call _exit with result from procedure.  */
95         b       HIDDEN_JUMPTARGET(_exit)
97 L(parent):
98         /* Parent.  Restore registers & return.  */
99         lmw     r28,16(r1)
100         addi    r1,r1,32
101         bnslr+
102         b       __syscall_error@local
104 L(badargs):
105         li      r3,EINVAL
106         b       __syscall_error@local
108         cfi_startproc
109 END (__clone)
111 weak_alias (__clone, clone)