Add missing export of fallocate64 on 32-bit platforms.
[glibc.git] / sysdeps / unix / sysv / linux / powerpc / powerpc32 / clone.S
blob37b777799c7db1a1240a4c759b432cca7f9666ed
1 /* Wrapper around clone system call.
2    Copyright (C) 1997,98,99,2000,02,04,2006 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, write to the Free
17    Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA
18    02110-1301 USA.  */
20 #include <sysdep.h>
21 #define _ERRNO_H        1
22 #include <bits/errno.h>
23 #include <kernel-features.h>
24 #include <bp-sym.h>
25 #include <bp-asm.h>
27 #define CLONE_VM        0x00000100
28 #define CLONE_THREAD    0x00010000
31 /* This is the only really unusual system call in PPC linux, but not
32    because of any weirdness in the system call itself; because of
33    all the freaky stuff we have to do to make the call useful.  */
35 /* int [r3] clone(int (*fn)(void *arg) [r3], void *child_stack [r4],
36                   int flags [r5], void *arg [r6], void *parent_tid [r7],
37                   void *tls [r8], void *child_tid [r9]); */
39 ENTRY (BP_SYM (__clone))
40         /* GKM FIXME: add bounds checks, where sensible.  */
41         DISCARD_BOUNDS (r4)
42         DISCARD_BOUNDS (r6)
44         /* Check for child_stack == NULL || fn == NULL.  */
45         cmpwi   cr0,r4,0
46         cmpwi   cr1,r3,0
47         cror    cr0*4+eq,cr1*4+eq,cr0*4+eq
48         beq-    cr0,L(badargs)
50         /* Set up stack frame for parent.  */
51         stwu    r1,-32(r1)
52         cfi_adjust_cfa_offset (32)
53 #ifdef RESET_PID
54         stmw    r28,16(r1)
55 #else
56 # ifndef __ASSUME_FIXED_CLONE_SYSCALL
57         stmw    r29,16(r1)
58 # else
59         stmw    r30,16(r1)
60 # endif
61 #endif
63         /* Set up stack frame for child.  */
64         clrrwi  r4,r4,4
65         li      r0,0
66         stwu    r0,-16(r4)
68         /* Save fn, args, stack across syscall.  */
69         mr      r30,r3                  /* Function in r30.  */
70 #ifndef __ASSUME_FIXED_CLONE_SYSCALL
71         mr      r29,r4                  /* Stack pointer in r29.  */
72 #endif
73 #ifdef RESET_PID
74         mr      r28,r5
75 #endif
76         mr      r31,r6                  /* Argument in r31.  */
78         /* 'flags' argument is first parameter to clone syscall. (The other
79            argument is the stack pointer, already in r4.)  */
80         mr      r3,r5
82         /* Move the parent_tid, child_tid and tls arguments. */
83         mr      r5,r7
84         mr      r6,r8
85         mr      r7,r9
87         /* End FDE now, because in the child the unwind info will be
88            wrong.  */
89         cfi_endproc
91         /* Do the call.  */
92         DO_CALL(SYS_ify(clone))
94         /* Check for child process.  */
95         cmpwi   cr1,r3,0
96         crandc  cr1*4+eq,cr1*4+eq,cr0*4+so
97         bne-    cr1,L(parent)           /* The '-' is to minimise the race.  */
99 #ifndef __ASSUME_FIXED_CLONE_SYSCALL
100         /* On at least mklinux DR3a5, clone() doesn't actually change
101            the stack pointer.  I'm pretty sure this is a bug, because
102            it adds a race condition if a signal is sent to a thread
103            just after it is created (in the previous three instructions).  */
104         mr      r1,r29
105 #endif
107 #ifdef RESET_PID
108         andis.  r0,r28,CLONE_THREAD>>16
109         bne+    r0,L(oldpid)
110         andi.   r0,r28,CLONE_VM
111         li      r3,-1
112         bne-    r0,L(nomoregetpid)
113         DO_CALL(SYS_ify(getpid))
114 L(nomoregetpid):
115         stw     r3,TID(r2)
116         stw     r3,PID(r2)
117 L(oldpid):
118 #endif
120         /* Call procedure.  */
121         mtctr   r30
122         mr      r3,r31
123         bctrl
124         /* Call _exit with result from procedure.  */
125         b       HIDDEN_JUMPTARGET(_exit)
127 L(parent):
128         /* Parent.  Restore registers & return.  */
129 #ifdef RESET_PID
130         lmw     r28,16(r1)
131 #else
132 # ifndef __ASSUME_FIXED_CLONE_SYSCALL
133         lmw     r29,16(r1)
134 # else
135         lmw     r30,16(r1)
136 # endif
137 #endif
138         addi    r1,r1,32
139         bnslr+
140         b       __syscall_error@local
142 L(badargs):
143         li      r3,EINVAL
144         b       __syscall_error@local
146         cfi_startproc
147 END (BP_SYM (__clone))
149 weak_alias (BP_SYM (__clone), BP_SYM (clone))