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) 1992 NeXT Computer, Inc. All rights reserved.
24 * File: libc/ppc/sys/fork.s
27 * 18-Nov-92 Ben Fathi (benf@next.com)
28 * Created from M88K sources
30 * 11-Jan-92 Peter King (king@next.com)
31 * Created from M68K sources
34 #import <sys/syscall.h>
35 #import <architecture/ppc/asm_help.h>
36 #import <architecture/ppc/pseudo_inst.h>
37 #import <mach/ppc/syscall_sw.h>
39 /* We use 8 bytes for LOCAL_VAR(1) and LOCAL_VAR(2) */
40 NESTED(_fork, 8, 0, 0, 0)
41 CALL_EXTERN(__cthread_fork_prepare)
42 #if defined(__DYNAMIC__)
45 .ascii "__dyld_fork_prepare\0"
52 addis r3,r3,ha16(LC1-1b)
53 addi r3,r3,lo16(LC1-1b)
54 addi r4,r1,LOCAL_VAR(1)
56 lwz r3,LOCAL_VAR(1)(r1)
62 b Lbotch // error return
65 beq Lparent // parent, since a1 == 0 in parent,
67 #if defined(__DYNAMIC__)
70 .ascii "__dyld_fork_child\0"
77 addis r3,r3,ha16(LC3-1b)
78 addi r3,r3,lo16(LC3-1b)
79 addi r4,r1,LOCAL_VAR(1)
81 lwz r3,LOCAL_VAR(1)(r1)
85 li r3,0x0 // clear cached pid in child
86 REG_TO_EXTERN(r3,__current_pid)
87 CALL_EXTERN(_fork_mach_init)
88 CALL_EXTERN(__cthread_fork_child)
89 #if defined(__DYNAMIC__)
92 .ascii "__dyld_fork_child_final\0"
99 addis r3,r3,ha16(LC4-1b)
100 addi r3,r3,lo16(LC4-1b)
101 addi r4,r1,LOCAL_VAR(1)
102 bl __dyld_func_lookup
103 lwz r3,LOCAL_VAR(1)(r1)
112 #if defined(__DYNAMIC__)
113 stw r3,LOCAL_VAR(2)(r1) // save child pid
118 addis r3,r3,ha16(LC2-1b)
119 addi r3,r3,lo16(LC2-1b)
120 addi r4,r1,LOCAL_VAR(1)
121 bl __dyld_func_lookup
122 lwz r3,LOCAL_VAR(1)(r1)
126 CALL_EXTERN(__cthread_fork_parent)
127 #if defined(__DYNAMIC__)
128 lwz r3,LOCAL_VAR(2)(r1)
133 #if defined(__DYNAMIC__)
136 .ascii "__dyld_fork_parent\0"
139 stw r3,LOCAL_VAR(2)(r1) // save error value
144 addis r3,r3,ha16(LC2-1b)
145 addi r3,r3,lo16(LC2-1b)
146 addi r4,r1,LOCAL_VAR(1)
147 bl __dyld_func_lookup
148 lwz r3,LOCAL_VAR(1)(r1)
151 lwz r3,LOCAL_VAR(2)(r1) // restore error value for cerror
156 * We use cthread_fork_parent() to clean up after a fork error
157 * (unlock cthreads and mailloc packages) so the parent
158 * process can Malloc() after fork() errors without
161 CALL_EXTERN_AGAIN(__cthread_fork_parent)
162 li32 r3,-1 // error return