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) 1992 NeXT Computer, Inc. All rights reserved.
27 * File: libc/ppc/sys/fork.s
30 * 18-Nov-92 Ben Fathi (benf@next.com)
31 * Created from M88K sources
33 * 11-Jan-92 Peter King (king@next.com)
34 * Created from M68K sources
37 #import <sys/syscall.h>
38 #import <architecture/ppc/asm_help.h>
39 #import <architecture/ppc/pseudo_inst.h>
40 #import <mach/ppc/syscall_sw.h>
42 /* We use 8 bytes for LOCAL_VAR(1) and LOCAL_VAR(2) */
43 NESTED(_fork, 8, 0, 0, 0)
44 CALL_EXTERN(__cthread_fork_prepare)
45 #if defined(__DYNAMIC__)
48 .ascii "__dyld_fork_prepare\0"
55 addis r3,r3,ha16(LC1-1b)
56 addi r3,r3,lo16(LC1-1b)
57 addi r4,r1,LOCAL_VAR(1)
59 lwz r3,LOCAL_VAR(1)(r1)
65 b Lbotch // error return
68 beq Lparent // parent, since a1 == 0 in parent,
70 #if defined(__DYNAMIC__)
73 .ascii "__dyld_fork_child\0"
80 addis r3,r3,ha16(LC3-1b)
81 addi r3,r3,lo16(LC3-1b)
82 addi r4,r1,LOCAL_VAR(1)
84 lwz r3,LOCAL_VAR(1)(r1)
88 li r3,0x0 // clear cached pid in child
89 REG_TO_EXTERN(r3,__current_pid)
90 CALL_EXTERN(_fork_mach_init)
91 CALL_EXTERN(__cthread_fork_child)
92 #if defined(__DYNAMIC__)
95 .ascii "__dyld_fork_child_final\0"
102 addis r3,r3,ha16(LC4-1b)
103 addi r3,r3,lo16(LC4-1b)
104 addi r4,r1,LOCAL_VAR(1)
105 bl __dyld_func_lookup
106 lwz r3,LOCAL_VAR(1)(r1)
115 #if defined(__DYNAMIC__)
116 stw r3,LOCAL_VAR(2)(r1) // save child pid
121 addis r3,r3,ha16(LC2-1b)
122 addi r3,r3,lo16(LC2-1b)
123 addi r4,r1,LOCAL_VAR(1)
124 bl __dyld_func_lookup
125 lwz r3,LOCAL_VAR(1)(r1)
129 CALL_EXTERN(__cthread_fork_parent)
130 #if defined(__DYNAMIC__)
131 lwz r3,LOCAL_VAR(2)(r1)
136 #if defined(__DYNAMIC__)
139 .ascii "__dyld_fork_parent\0"
142 stw r3,LOCAL_VAR(2)(r1) // save error value
147 addis r3,r3,ha16(LC2-1b)
148 addi r3,r3,lo16(LC2-1b)
149 addi r4,r1,LOCAL_VAR(1)
150 bl __dyld_func_lookup
151 lwz r3,LOCAL_VAR(1)(r1)
154 lwz r3,LOCAL_VAR(2)(r1) // restore error value for cerror
159 * We use cthread_fork_parent() to clean up after a fork error
160 * (unlock cthreads and mailloc packages) so the parent
161 * process can Malloc() after fork() errors without
164 CALL_EXTERN_AGAIN(__cthread_fork_parent)
165 li32 r3,-1 // error return