]> git.saurik.com Git - apple/libc.git/blob - sys.subproj/ppc.subproj/vfork.s
14bc4f338dbf5f0a980765ae130fdfe526962699
[apple/libc.git] / sys.subproj / ppc.subproj / vfork.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) 1998 Apple Computer, Inc. All rights reserved.
23 *
24 * File: libc/ppc/sys/vfork.s
25 *
26 * HISTORY
27 * 23-Jun-1998 Umesh Vaishampayan (umeshv@apple.com)
28 * Created from fork.s
29 *
30 */
31
32 #if 0
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>
37
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__)
42 .cstring
43 LC1:
44 .ascii "__dyld_fork_prepare\0"
45 .text
46 .align 2
47 mflr r0
48 bl 1f
49 1: mflr r3
50 mtlr r0
51 addis r3,r3,ha16(LC1-1b)
52 addi r3,r3,lo16(LC1-1b)
53 addi r4,r1,LOCAL_VAR(1)
54 bl __dyld_func_lookup
55 lwz r3,LOCAL_VAR(1)(r1)
56 mtspr ctr,r3
57 bctrl
58 #endif
59 li r0,SYS_vfork
60 sc
61 b Lbotch // error return
62
63 cmpwi r4,0
64 beq Lparent // parent, since a1 == 0 in parent,
65 // 1 in child
66 #if defined(__DYNAMIC__)
67 .cstring
68 LC3:
69 .ascii "__dyld_fork_child\0"
70 .text
71 .align 2
72 mflr r0
73 bl 1f
74 1: mflr r3
75 mtlr r0
76 addis r3,r3,ha16(LC3-1b)
77 addi r3,r3,lo16(LC3-1b)
78 addi r4,r1,LOCAL_VAR(1)
79 bl __dyld_func_lookup
80 lwz r3,LOCAL_VAR(1)(r1)
81 mtspr ctr,r3
82 bctrl
83 #endif
84 CALL_EXTERN(_fork_mach_init)
85 CALL_EXTERN(__cthread_fork_child)
86 #if defined(__DYNAMIC__)
87 .cstring
88 LC4:
89 .ascii "__dyld_fork_child_final\0"
90 .text
91 .align 2
92 mflr r0
93 bl 1f
94 1: mflr r3
95 mtlr r0
96 addis r3,r3,ha16(LC4-1b)
97 addi r3,r3,lo16(LC4-1b)
98 addi r4,r1,LOCAL_VAR(1)
99 bl __dyld_func_lookup
100 lwz r3,LOCAL_VAR(1)(r1)
101 mtspr ctr,r3
102 bctrl
103 #endif
104
105 li r3,0
106 b Lreturn
107
108 Lparent:
109 #if defined(__DYNAMIC__)
110 stw r3,LOCAL_VAR(2)(r1) // save child pid
111 mflr r0
112 bl 1f
113 1: mflr r3
114 mtlr r0
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)
120 mtspr ctr,r3
121 bctrl
122 #endif
123 CALL_EXTERN(__cthread_fork_parent)
124 #if defined(__DYNAMIC__)
125 lwz r3,LOCAL_VAR(2)(r1)
126 #endif
127 b Lreturn
128
129 Lbotch:
130 #if defined(__DYNAMIC__)
131 .cstring
132 LC2:
133 .ascii "__dyld_fork_parent\0"
134 .text
135 .align 2
136 stw r3,LOCAL_VAR(2)(r1) // save error value
137 mflr r0
138 bl 1f
139 1: mflr r3
140 mtlr r0
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)
146 mtspr ctr,r3
147 bctrl
148 lwz r3,LOCAL_VAR(2)(r1) // restore error value for cerror
149
150 #endif
151 CALL_EXTERN(cerror)
152 /*
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
156 * deadlocking.
157 */
158 CALL_EXTERN_AGAIN(__cthread_fork_parent)
159 li32 r3,-1 // error return
160 Lreturn: RETURN
161 END(_vfork)
162 #else
163 #include "SYS.h"
164
165 .text
166 .align 2
167 .globl _vfork
168 _vfork:
169 li r0,SYS_vfork
170 sc
171 b Lbotch // error return
172
173 cmpwi r4,0
174 beqlr // parent, since a1 == 0 in parent,
175 li r3,0
176 blr
177 Lbotch:
178 BRANCH_EXTERN(cerror)
179 #endif
180