2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 /* Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
24 * File: libc/ppc/sys/vfork.s
27 * 23-Jun-1998 Umesh Vaishampayan (umeshv@apple.com)
33 #import <sys/syscall.h>
34 #import <architecture/ppc/asm_help.h>
35 #import <architecture/ppc/pseudo_inst.h>
36 #import <mach/ppc/syscall_sw.h>
38 /* We use 8 bytes for LOCAL_VAR(1) and LOCAL_VAR(2) */
39 NESTED(_vfork, 8, 0, 0, 0)
40 CALL_EXTERN(__cthread_fork_prepare)
41 #if defined(__DYNAMIC__)
44 .ascii "__dyld_fork_prepare\0"
51 addis r3,r3,ha16(LC1-1b)
52 addi r3,r3,lo16(LC1-1b)
53 addi r4,r1,LOCAL_VAR(1)
55 lwz r3,LOCAL_VAR(1)(r1)
61 b Lbotch // error return
64 beq Lparent // parent, since a1 == 0 in parent,
66 #if defined(__DYNAMIC__)
69 .ascii "__dyld_fork_child\0"
76 addis r3,r3,ha16(LC3-1b)
77 addi r3,r3,lo16(LC3-1b)
78 addi r4,r1,LOCAL_VAR(1)
80 lwz r3,LOCAL_VAR(1)(r1)
84 CALL_EXTERN(_fork_mach_init)
85 CALL_EXTERN(__cthread_fork_child)
86 #if defined(__DYNAMIC__)
89 .ascii "__dyld_fork_child_final\0"
96 addis r3,r3,ha16(LC4-1b)
97 addi r3,r3,lo16(LC4-1b)
98 addi r4,r1,LOCAL_VAR(1)
100 lwz r3,LOCAL_VAR(1)(r1)
109 #if defined(__DYNAMIC__)
110 stw r3,LOCAL_VAR(2)(r1) // save child pid
115 addis r3,r3,ha16(LC2-1b)
116 addi r3,r3,lo16(LC2-1b)
117 addi r4,r1,LOCAL_VAR(1)
118 bl __dyld_func_lookup
119 lwz r3,LOCAL_VAR(1)(r1)
123 CALL_EXTERN(__cthread_fork_parent)
124 #if defined(__DYNAMIC__)
125 lwz r3,LOCAL_VAR(2)(r1)
130 #if defined(__DYNAMIC__)
133 .ascii "__dyld_fork_parent\0"
136 stw r3,LOCAL_VAR(2)(r1) // save error value
141 addis r3,r3,ha16(LC2-1b)
142 addi r3,r3,lo16(LC2-1b)
143 addi r4,r1,LOCAL_VAR(1)
144 bl __dyld_func_lookup
145 lwz r3,LOCAL_VAR(1)(r1)
148 lwz r3,LOCAL_VAR(2)(r1) // restore error value for cerror
153 * We use cthread_fork_parent() to clean up after a fork error
154 * (unlock cthreads and mailloc packages) so the parent
155 * process can Malloc() after fork() errors without
158 CALL_EXTERN_AGAIN(__cthread_fork_parent)
159 li32 r3,-1 // error return
171 b Lbotch // error return
174 beqlr // parent, since a1 == 0 in parent,
178 BRANCH_EXTERN(cerror)