]> git.saurik.com Git - apple/libc.git/blob - sys.subproj/ppc.subproj/fork.s
6df807e0a31273382a2dd7f45b2883a37dd42139
[apple/libc.git] / sys.subproj / ppc.subproj / fork.s
1 /*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
11 *
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
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved.
23 *
24 * File: libc/ppc/sys/fork.s
25 *
26 * HISTORY
27 * 18-Nov-92 Ben Fathi (benf@next.com)
28 * Created from M88K sources
29 *
30 * 11-Jan-92 Peter King (king@next.com)
31 * Created from M68K sources
32 */
33
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>
38
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__)
43 .cstring
44 LC1:
45 .ascii "__dyld_fork_prepare\0"
46 .text
47 .align 2
48 mflr r0
49 bl 1f
50 1: mflr r3
51 mtlr r0
52 addis r3,r3,ha16(LC1-1b)
53 addi r3,r3,lo16(LC1-1b)
54 addi r4,r1,LOCAL_VAR(1)
55 bl __dyld_func_lookup
56 lwz r3,LOCAL_VAR(1)(r1)
57 mtspr ctr,r3
58 bctrl
59 #endif
60 li r0,SYS_fork
61 sc
62 b Lbotch // error return
63
64 cmpwi r4,0
65 beq Lparent // parent, since a1 == 0 in parent,
66 // 1 in child
67 #if defined(__DYNAMIC__)
68 .cstring
69 LC3:
70 .ascii "__dyld_fork_child\0"
71 .text
72 .align 2
73 mflr r0
74 bl 1f
75 1: mflr r3
76 mtlr r0
77 addis r3,r3,ha16(LC3-1b)
78 addi r3,r3,lo16(LC3-1b)
79 addi r4,r1,LOCAL_VAR(1)
80 bl __dyld_func_lookup
81 lwz r3,LOCAL_VAR(1)(r1)
82 mtspr ctr,r3
83 bctrl
84 #endif
85 CALL_EXTERN(_fork_mach_init)
86 CALL_EXTERN(__cthread_fork_child)
87 #if defined(__DYNAMIC__)
88 .cstring
89 LC4:
90 .ascii "__dyld_fork_child_final\0"
91 .text
92 .align 2
93 mflr r0
94 bl 1f
95 1: mflr r3
96 mtlr r0
97 addis r3,r3,ha16(LC4-1b)
98 addi r3,r3,lo16(LC4-1b)
99 addi r4,r1,LOCAL_VAR(1)
100 bl __dyld_func_lookup
101 lwz r3,LOCAL_VAR(1)(r1)
102 mtspr ctr,r3
103 bctrl
104 #endif
105
106 li r3,0
107 b Lreturn
108
109 Lparent:
110 #if defined(__DYNAMIC__)
111 stw r3,LOCAL_VAR(2)(r1) // save child pid
112 mflr r0
113 bl 1f
114 1: mflr r3
115 mtlr r0
116 addis r3,r3,ha16(LC2-1b)
117 addi r3,r3,lo16(LC2-1b)
118 addi r4,r1,LOCAL_VAR(1)
119 bl __dyld_func_lookup
120 lwz r3,LOCAL_VAR(1)(r1)
121 mtspr ctr,r3
122 bctrl
123 #endif
124 CALL_EXTERN(__cthread_fork_parent)
125 #if defined(__DYNAMIC__)
126 lwz r3,LOCAL_VAR(2)(r1)
127 #endif
128 b Lreturn
129
130 Lbotch:
131 #if defined(__DYNAMIC__)
132 .cstring
133 LC2:
134 .ascii "__dyld_fork_parent\0"
135 .text
136 .align 2
137 stw r3,LOCAL_VAR(2)(r1) // save error value
138 mflr r0
139 bl 1f
140 1: mflr r3
141 mtlr r0
142 addis r3,r3,ha16(LC2-1b)
143 addi r3,r3,lo16(LC2-1b)
144 addi r4,r1,LOCAL_VAR(1)
145 bl __dyld_func_lookup
146 lwz r3,LOCAL_VAR(1)(r1)
147 mtspr ctr,r3
148 bctrl
149 lwz r3,LOCAL_VAR(2)(r1) // restore error value for cerror
150
151 #endif
152 CALL_EXTERN(cerror)
153 /*
154 * We use cthread_fork_parent() to clean up after a fork error
155 * (unlock cthreads and mailloc packages) so the parent
156 * process can Malloc() after fork() errors without
157 * deadlocking.
158 */
159 CALL_EXTERN_AGAIN(__cthread_fork_parent)
160 li32 r3,-1 // error return
161 Lreturn: RETURN
162 END(_fork)
163