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@
23 * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
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.
37 .ascii "__dyld_fork_prepare\0"
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
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
53 movl $SYS_vfork,%eax; // code for vfork -> eax
54 UNIX_SYSCALL_TRAP; // do the system call
55 jnc L1 // jump if CF==0
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.
64 .ascii "__dyld_fork_parent\0"
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
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)
82 CALL_EXTERN(__cthread_fork_parent)
87 orl %edx,%edx // CF=OF=0, ZF set if zero result
88 jz L2 // parent, since r1 == 0 in parent, 1 in child
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):
98 // _dyld_func_lookup("__dyld_fork_child", &address);
103 .ascii "__dyld_fork_child\0"
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
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
119 CALL_EXTERN(_fork_mach_init)
120 CALL_EXTERN(__cthread_fork_child)
121 #if defined(__DYNAMIC__)
124 .ascii "__dyld_fork_child_final\0"
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
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
140 xorl %eax,%eax // zero eax
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
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
162 CALL_EXTERN_AGAIN(__cthread_fork_parent)
169 movl $SYS_vfork,%eax; // code for vfork -> eax
170 UNIX_SYSCALL_TRAP; // do the system call
171 jnb L1 // jump if CF==0
173 BRANCH_EXTERN(cerror)
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