]>
Commit | Line | Data |
---|---|---|
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 | /* | |
23 | * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved | |
24 | */ | |
25 | #include "SYS.h" | |
26 | ||
27 | #if 0 | |
28 | LEAF(_vfork, 0) | |
29 | CALL_EXTERN(__cthread_fork_prepare) | |
30 | #if defined(__DYNAMIC__) | |
31 | // Just like __cthread_fork_prepare we need to prevent threads on the child's | |
32 | // side from doing a mach call in the dynamic linker until __dyld_fork_child | |
33 | // is run (see below). So we call __dyld_fork_prepare which takes out the dyld | |
34 | // lock to prevent all other threads but this one from entering dyld. | |
35 | .cstring | |
36 | LC1: | |
37 | .ascii "__dyld_fork_prepare\0" | |
38 | .text | |
39 | subl $4,%esp // allocate space for the address parameter | |
40 | leal 0(%esp),%eax // get the address of the allocated space | |
41 | pushl %eax // push the address of the allocated space | |
42 | call 1f | |
43 | 1: popl %eax | |
44 | leal LC1-1b(%eax),%eax | |
45 | pushl %eax // push the name of the function to look up | |
46 | call __dyld_func_lookup | |
47 | addl $8,%esp // remove parameters to __dyld_func_lookup | |
48 | movl 0(%esp),%eax // move the value returned in address parameter | |
49 | addl $4,%esp // deallocate the space for the address param | |
50 | call *%eax // call __dyld_fork_prepare indirectly | |
51 | #endif | |
52 | ||
53 | movl $SYS_vfork,%eax; // code for vfork -> eax | |
54 | UNIX_SYSCALL_TRAP; // do the system call | |
55 | jnc L1 // jump if CF==0 | |
56 | ||
57 | #if defined(__DYNAMIC__) | |
58 | // __dyld_fork_parent() is called by the parent process after a vfork syscall. | |
59 | // This releases the dyld lock acquired by __dyld_fork_prepare(). In this case | |
60 | // we just use it to clean up after a vfork error so the parent process can | |
61 | // dyld after vfork() errors without deadlocking. | |
62 | .cstring | |
63 | LC2: | |
64 | .ascii "__dyld_fork_parent\0" | |
65 | .text | |
66 | pushl %eax // save the return value (errno) | |
67 | subl $4,%esp // allocate space for the address parameter | |
68 | leal 0(%esp),%eax // get the address of the allocated space | |
69 | pushl %eax // push the address of the allocated space | |
70 | call 1f | |
71 | 1: popl %eax | |
72 | leal LC2-1b(%eax),%eax | |
73 | pushl %eax // push the name of the function to look up | |
74 | call __dyld_func_lookup | |
75 | addl $8,%esp // remove parameters to __dyld_func_lookup | |
76 | movl 0(%esp),%eax // move the value returned in address parameter | |
77 | addl $4,%esp // deallocate the space for the address param | |
78 | call *%eax // call __dyld_fork_parent indirectly | |
79 | popl %eax // restore the return value (errno) | |
80 | #endif | |
81 | CALL_EXTERN(cerror) | |
82 | CALL_EXTERN(__cthread_fork_parent) | |
83 | movl $-1,%eax | |
84 | ret | |
85 | ||
86 | L1: | |
87 | orl %edx,%edx // CF=OF=0, ZF set if zero result | |
88 | jz L2 // parent, since r1 == 0 in parent, 1 in child | |
89 | ||
90 | //child here... | |
91 | #if defined(__DYNAMIC__) | |
92 | // Here on the child side of the vfork we need to tell the dynamic linker that | |
93 | // we have vforked. To do this we call __dyld_fork_child in the dyanmic | |
94 | // linker. But since we can't dynamicly bind anything until this is done we | |
95 | // do this by using the private extern __dyld_func_lookup() function to get the | |
96 | // address of __dyld_fork_child (the 'C' code equivlent): | |
97 | // | |
98 | // _dyld_func_lookup("__dyld_fork_child", &address); | |
99 | // address(); | |
100 | // | |
101 | .cstring | |
102 | LC0: | |
103 | .ascii "__dyld_fork_child\0" | |
104 | ||
105 | .text | |
106 | subl $4,%esp // allocate space for the address parameter | |
107 | leal 0(%esp),%eax // get the address of the allocated space | |
108 | pushl %eax // push the address of the allocated space | |
109 | call 1f | |
110 | 1: popl %eax | |
111 | leal LC0-1b(%eax),%eax | |
112 | pushl %eax // push the name of the function to look up | |
113 | call __dyld_func_lookup | |
114 | addl $8,%esp // remove parameters to __dyld_func_lookup | |
115 | movl 0(%esp),%eax // move the value returned in address parameter | |
116 | addl $4,%esp // deallocate the space for the address param | |
117 | call *%eax // call __dyld_fork_child indirectly | |
118 | #endif | |
119 | CALL_EXTERN(_fork_mach_init) | |
120 | CALL_EXTERN(__cthread_fork_child) | |
121 | #if defined(__DYNAMIC__) | |
122 | .cstring | |
123 | LC10: | |
124 | .ascii "__dyld_fork_child_final\0" | |
125 | ||
126 | .text | |
127 | subl $4,%esp // allocate space for the address parameter | |
128 | leal 0(%esp),%eax // get the address of the allocated space | |
129 | pushl %eax // push the address of the allocated space | |
130 | call 1f | |
131 | 1: popl %eax | |
132 | leal LC10-1b(%eax),%eax | |
133 | pushl %eax // push the name of the function to look up | |
134 | call __dyld_func_lookup | |
135 | addl $8,%esp // remove parameters to __dyld_func_lookup | |
136 | movl 0(%esp),%eax // move the value returned in address parameter | |
137 | addl $4,%esp // deallocate the space for the address param | |
138 | call *%eax // call __dyld_fork_child_final indirectly | |
139 | #endif | |
140 | xorl %eax,%eax // zero eax | |
141 | ret | |
142 | ||
143 | //parent here... | |
144 | L2: | |
145 | push %eax // save pid | |
146 | #if defined(__DYNAMIC__) | |
147 | // __dyld_fork_parent() is called by the parent process after a vfork syscall. | |
148 | // This releases the dyld lock acquired by __dyld_fork_prepare(). | |
149 | subl $4,%esp // allocate space for the address parameter | |
150 | leal 0(%esp),%eax // get the address of the allocated space | |
151 | pushl %eax // push the address of the allocated space | |
152 | call 1f | |
153 | 1: popl %eax | |
154 | leal LC2-1b(%eax),%eax | |
155 | pushl %eax // push the name of the function to look up | |
156 | call __dyld_func_lookup | |
157 | addl $8,%esp // remove parameters to __dyld_func_lookup | |
158 | movl 0(%esp),%eax // move the value returned in address parameter | |
159 | addl $4,%esp // deallocate the space for the address param | |
160 | call *%eax // call __dyld_fork_parent indirectly | |
161 | #endif | |
162 | CALL_EXTERN_AGAIN(__cthread_fork_parent) | |
163 | pop %eax | |
164 | ret | |
165 | #else | |
166 | ||
167 | LEAF(_vfork, 0) | |
168 | popl %ecx | |
169 | movl $SYS_vfork,%eax; // code for vfork -> eax | |
170 | UNIX_SYSCALL_TRAP; // do the system call | |
171 | jnb L1 // jump if CF==0 | |
172 | pushl %ecx | |
173 | BRANCH_EXTERN(cerror) | |
174 | ||
175 | L1: | |
176 | orl %edx,%edx // CF=OF=0, ZF set if zero result | |
177 | jz L2 // parent, since r1 == 0 in parent, 1 in child | |
178 | xorl %eax,%eax // zero eax | |
179 | jmp *%ecx | |
180 | ||
181 | L2: | |
182 | jmp *%ecx | |
183 | ||
184 | #endif | |
185 |