]> git.saurik.com Git - apple/libc.git/blob - ppc/sys/vfork.s
Libc-320.tar.gz
[apple/libc.git] / ppc / sys / vfork.s
1 /*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /* Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
26 *
27 * File: libc/ppc/sys/vfork.s
28 *
29 * HISTORY
30 * 23-Jun-1998 Umesh Vaishampayan (umeshv@apple.com)
31 * Created from fork.s
32 *
33 */
34 #if 0
35 #import <sys/syscall.h>
36 #import <architecture/ppc/asm_help.h>
37 #import <architecture/ppc/pseudo_inst.h>
38 #import <mach/ppc/syscall_sw.h>
39
40 /* We use 8 bytes for LOCAL_VAR(1) and LOCAL_VAR(2) */
41 NESTED(_vfork, 8, 0, 0, 0)
42 CALL_EXTERN(__cthread_fork_prepare)
43 #if defined(__DYNAMIC__)
44 .cstring
45 LC1:
46 .ascii "__dyld_fork_prepare\0"
47 .text
48 .align 2
49 mflr r0
50 bl 1f
51 1: mflr r3
52 mtlr r0
53 addis r3,r3,ha16(LC1-1b)
54 addi r3,r3,lo16(LC1-1b)
55 addi r4,r1,LOCAL_VAR(1)
56 bl __dyld_func_lookup
57 lwz r3,LOCAL_VAR(1)(r1)
58 mtspr ctr,r3
59 bctrl
60 #endif
61 li r0,SYS_vfork
62 sc
63 b Lbotch // error return
64
65 cmpwi r4,0
66 beq Lparent // parent, since a1 == 0 in parent,
67 // 1 in child
68 #if defined(__DYNAMIC__)
69 .cstring
70 LC3:
71 .ascii "__dyld_fork_child\0"
72 .text
73 .align 2
74 mflr r0
75 bl 1f
76 1: mflr r3
77 mtlr r0
78 addis r3,r3,ha16(LC3-1b)
79 addi r3,r3,lo16(LC3-1b)
80 addi r4,r1,LOCAL_VAR(1)
81 bl __dyld_func_lookup
82 lwz r3,LOCAL_VAR(1)(r1)
83 mtspr ctr,r3
84 bctrl
85 #endif
86 li r3,0
87 REG_TO_EXTERN(r3, EXT(_current_pid))
88 CALL_EXTERN(_fork_mach_init)
89 CALL_EXTERN(__cthread_fork_child)
90 #if defined(__DYNAMIC__)
91 .cstring
92 LC4:
93 .ascii "__dyld_fork_child_final\0"
94 .text
95 .align 2
96 mflr r0
97 bl 1f
98 1: mflr r3
99 mtlr r0
100 addis r3,r3,ha16(LC4-1b)
101 addi r3,r3,lo16(LC4-1b)
102 addi r4,r1,LOCAL_VAR(1)
103 bl __dyld_func_lookup
104 lwz r3,LOCAL_VAR(1)(r1)
105 mtspr ctr,r3
106 bctrl
107 #endif
108
109 li r3,0
110 b Lreturn
111
112 Lparent:
113 #if defined(__DYNAMIC__)
114 stw r3,LOCAL_VAR(2)(r1) // save child pid
115 mflr r0
116 bl 1f
117 1: mflr r3
118 mtlr r0
119 addis r3,r3,ha16(LC2-1b)
120 addi r3,r3,lo16(LC2-1b)
121 addi r4,r1,LOCAL_VAR(1)
122 bl __dyld_func_lookup
123 lwz r3,LOCAL_VAR(1)(r1)
124 mtspr ctr,r3
125 bctrl
126 #endif
127 CALL_EXTERN(__cthread_fork_parent)
128 #if defined(__DYNAMIC__)
129 lwz r3,LOCAL_VAR(2)(r1)
130 #endif
131 b Lreturn
132
133 Lbotch:
134 #if defined(__DYNAMIC__)
135 .cstring
136 LC2:
137 .ascii "__dyld_fork_parent\0"
138 .text
139 .align 2
140 stw r3,LOCAL_VAR(2)(r1) // save error value
141 mflr r0
142 bl 1f
143 1: mflr r3
144 mtlr r0
145 addis r3,r3,ha16(LC2-1b)
146 addi r3,r3,lo16(LC2-1b)
147 addi r4,r1,LOCAL_VAR(1)
148 bl __dyld_func_lookup
149 lwz r3,LOCAL_VAR(1)(r1)
150 mtspr ctr,r3
151 bctrl
152 lwz r3,LOCAL_VAR(2)(r1) // restore error value for cerror
153
154 #endif
155 CALL_EXTERN(cerror)
156 /*
157 * We use cthread_fork_parent() to clean up after a fork error
158 * (unlock cthreads and mailloc packages) so the parent
159 * process can Malloc() after fork() errors without
160 * deadlocking.
161 */
162 CALL_EXTERN_AGAIN(__cthread_fork_parent)
163 li32 r3,-1 // error return
164 Lreturn: RETURN
165 END(_vfork)
166 #else
167 #include "SYS.h"
168
169 LEAF(_vfork)
170 #if defined(__DYNAMIC__)
171 PICIFY(__current_pid)
172 mr r5,PICIFY_REG
173 NON_LAZY_STUB(__current_pid)
174 #else
175 lis r5,ha16(__current_pid)
176 ori r5,r5,lo16(__current_pid)
177 #endif
178 2:
179 lwarx r6,0,r5 // dont cache pid across vfork
180 cmpwi r6,0
181 ble- 3f // is another vfork in progress
182 li r6,0 // if not, erase the stored pid
183 3:
184 addi r6,r6,-1 // count the parallel vforks in
185 stwcx. r6,0,r5 // negative cached pid values
186 bne- 2b
187
188 li r0,SYS_vfork
189 sc
190 b Lbotch // error return
191
192 cmpwi r4,0
193 beq Lparent // parent, since a1 == 0 in parent,
194
195 li r3,0 // child
196 blr
197
198 Lparent:
199 lwarx r6,0,r5 // were back, decrement vfork count
200 addi r6,r6,1
201 stwcx. r6,0,r5
202 bne- Lparent
203 blr
204
205 Lbotch:
206 lwarx r6,0,r5 // never went, decrement vfork count
207 addi r6,r6,1
208 stwcx. r6,0,r5
209 bne- Lbotch
210
211 BRANCH_EXTERN(cerror)
212 END(_vfork)
213 #endif
214