2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
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
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.
23 * @APPLE_LICENSE_HEADER_END@
25 /* Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
27 * File: libc/ppc/sys/vfork.s
30 * 23-Jun-1998 Umesh Vaishampayan (umeshv@apple.com)
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>
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__)
46 .ascii "__dyld_fork_prepare\0"
53 addis r3,r3,ha16(LC1-1b)
54 addi r3,r3,lo16(LC1-1b)
55 addi r4,r1,LOCAL_VAR(1)
57 lwz r3,LOCAL_VAR(1)(r1)
63 b Lbotch // error return
66 beq Lparent // parent, since a1 == 0 in parent,
68 #if defined(__DYNAMIC__)
71 .ascii "__dyld_fork_child\0"
78 addis r3,r3,ha16(LC3-1b)
79 addi r3,r3,lo16(LC3-1b)
80 addi r4,r1,LOCAL_VAR(1)
82 lwz r3,LOCAL_VAR(1)(r1)
87 REG_TO_EXTERN(r3, EXT(_current_pid))
88 CALL_EXTERN(_fork_mach_init)
89 CALL_EXTERN(__cthread_fork_child)
90 #if defined(__DYNAMIC__)
93 .ascii "__dyld_fork_child_final\0"
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)
113 #if defined(__DYNAMIC__)
114 stw r3,LOCAL_VAR(2)(r1) // save child pid
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)
127 CALL_EXTERN(__cthread_fork_parent)
128 #if defined(__DYNAMIC__)
129 lwz r3,LOCAL_VAR(2)(r1)
134 #if defined(__DYNAMIC__)
137 .ascii "__dyld_fork_parent\0"
140 stw r3,LOCAL_VAR(2)(r1) // save error value
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)
152 lwz r3,LOCAL_VAR(2)(r1) // restore error value for cerror
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
162 CALL_EXTERN_AGAIN(__cthread_fork_parent)
163 li32 r3,-1 // error return
170 #if defined(__DYNAMIC__)
171 PICIFY(__current_pid)
173 NON_LAZY_STUB(__current_pid)
175 lis r5,ha16(__current_pid)
176 ori r5,r5,lo16(__current_pid)
179 lwarx r6,0,r5 // dont cache pid across vfork
181 ble- 3f // is another vfork in progress
182 li r6,0 // if not, erase the stored pid
184 addi r6,r6,-1 // count the parallel vforks in
185 stwcx. r6,0,r5 // negative cached pid values
190 b Lbotch // error return
193 beq Lparent // parent, since a1 == 0 in parent,
199 lwarx r6,0,r5 // were back, decrement vfork count
206 lwarx r6,0,r5 // never went, decrement vfork count
211 BRANCH_EXTERN(cerror)