* elf/tst-tls8.c (do_test): Use $ORIGIN in module names.
[glibc.git] / sysdeps / unix / sysv / linux / powerpc / powerpc32 / clone.S
blobf4c92ad7c74be084710bed8e7c01bf2fdb828b22
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         /* Do the call.  */
88         DO_CALL(SYS_ify(clone))
90         /* Check for child process.  */
91         cmpwi   cr1,r3,0
92         crandc  cr1*4+eq,cr1*4+eq,cr0*4+so
93         bne-    cr1,L(parent)           /* The '-' is to minimise the race.  */
95 #ifndef __ASSUME_FIXED_CLONE_SYSCALL
96         /* On at least mklinux DR3a5, clone() doesn't actually change
97            the stack pointer.  I'm pretty sure this is a bug, because
98            it adds a race condition if a signal is sent to a thread
99            just after it is created (in the previous three instructions).  */
100         mr      r1,r29
101 #endif
103 #ifdef RESET_PID
104         andis.  r0,r28,CLONE_THREAD>>16
105         bne+    r0,L(oldpid)
106         andi.   r0,r28,CLONE_VM
107         li      r3,-1
108         bne-    r0,L(nomoregetpid)
109         DO_CALL(SYS_ify(getpid))
110 L(nomoregetpid):
111         stw     r3,TID(r2)
112         stw     r3,PID(r2)
113 L(oldpid):
114 #endif
116         /* Call procedure.  */
117         mtctr   r30
118         mr      r3,r31
119         bctrl
120         /* Call _exit with result from procedure.  */
121         b       HIDDEN_JUMPTARGET(_exit)
123 L(parent):
124         /* Parent.  Restore registers & return.  */
125 #ifdef RESET_PID
126         lmw     r28,16(r1)
127 #else
128 # ifndef __ASSUME_FIXED_CLONE_SYSCALL
129         lmw     r29,16(r1)
130 # else
131         lmw     r30,16(r1)
132 # endif
133 #endif
134         addi    r1,r1,32
135         bnslr+
136         b       __syscall_error@local
138 L(badargs):
139         li      r3,EINVAL
140         b       __syscall_error@local
141 END (BP_SYM (__clone))
143 weak_alias (BP_SYM (__clone), BP_SYM (clone))