2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
26 * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
31 CALL_EXTERN(__cthread_fork_prepare)
32 #if defined(__DYNAMIC__)
33 // Just like __cthread_fork_prepare we need to prevent threads on the child's
34 // side from doing a mach call in the dynamic linker until __dyld_fork_child
35 // is run (see below). So we call __dyld_fork_prepare which takes out the dyld
36 // lock to prevent all other threads but this one from entering dyld.
39 .ascii "__dyld_fork_prepare\0"
41 subl $4,%esp // allocate space for the address parameter
42 leal 0(%esp),%eax // get the address of the allocated space
43 pushl %eax // push the address of the allocated space
46 leal LC1-1b(%eax),%eax
47 pushl %eax // push the name of the function to look up
48 call __dyld_func_lookup
49 addl $8,%esp // remove parameters to __dyld_func_lookup
50 movl 0(%esp),%eax // move the value returned in address parameter
51 addl $4,%esp // deallocate the space for the address param
52 call *%eax // call __dyld_fork_prepare indirectly
55 movl $ SYS_fork,%eax; // code for fork -> eax
56 UNIX_SYSCALL_TRAP; // do the system call
57 jnc L1 // jump if CF==0
59 #if defined(__DYNAMIC__)
60 // __dyld_fork_parent() is called by the parent process after a fork syscall.
61 // This releases the dyld lock acquired by __dyld_fork_prepare(). In this case
62 // we just use it to clean up after a fork error so the parent process can
63 // dyld after fork() errors without deadlocking.
66 .ascii "__dyld_fork_parent\0"
68 pushl %eax // save the return value (errno)
69 subl $4,%esp // allocate space for the address parameter
70 leal 0(%esp),%eax // get the address of the allocated space
71 pushl %eax // push the address of the allocated space
74 leal LC2-1b(%eax),%eax
75 pushl %eax // push the name of the function to look up
76 call __dyld_func_lookup
77 addl $8,%esp // remove parameters to __dyld_func_lookup
78 movl 0(%esp),%eax // move the value returned in address parameter
79 addl $4,%esp // deallocate the space for the address param
80 call *%eax // call __dyld_fork_parent indirectly
81 popl %eax // restore the return value (errno)
84 CALL_EXTERN(__cthread_fork_parent)
89 orl %edx,%edx // CF=OF=0, ZF set if zero result
90 jz L2 // parent, since r1 == 0 in parent, 1 in child
93 #if defined(__DYNAMIC__)
94 // Here on the child side of the fork we need to tell the dynamic linker that
95 // we have forked. To do this we call __dyld_fork_child in the dyanmic
96 // linker. But since we can't dynamicly bind anything until this is done we
97 // do this by using the private extern __dyld_func_lookup() function to get the
98 // address of __dyld_fork_child (the 'C' code equivlent):
100 // _dyld_func_lookup("__dyld_fork_child", &address);
105 .ascii "__dyld_fork_child\0"
108 subl $4,%esp // allocate space for the address parameter
109 leal 0(%esp),%eax // get the address of the allocated space
110 pushl %eax // push the address of the allocated space
113 leal LC0-1b(%eax),%eax
114 pushl %eax // push the name of the function to look up
115 call __dyld_func_lookup
116 addl $8,%esp // remove parameters to __dyld_func_lookup
117 movl 0(%esp),%eax // move the value returned in address parameter
118 addl $4,%esp // deallocate the space for the address param
119 call *%eax // call __dyld_fork_child indirectly
122 REG_TO_EXTERN(%eax, __current_pid)
123 CALL_EXTERN(__cthread_fork_child)
124 #if defined(__DYNAMIC__)
127 .ascii "__dyld_fork_child_final\0"
130 subl $4,%esp // allocate space for the address parameter
131 leal 0(%esp),%eax // get the address of the allocated space
132 pushl %eax // push the address of the allocated space
135 leal LC10-1b(%eax),%eax
136 pushl %eax // push the name of the function to look up
137 call __dyld_func_lookup
138 addl $8,%esp // remove parameters to __dyld_func_lookup
139 movl 0(%esp),%eax // move the value returned in address parameter
140 addl $4,%esp // deallocate the space for the address param
141 call *%eax // call __dyld_fork_child_final indirectly
143 xorl %eax,%eax // zero eax
148 push %eax // save pid
149 #if defined(__DYNAMIC__)
150 // __dyld_fork_parent() is called by the parent process after a fork syscall.
151 // This releases the dyld lock acquired by __dyld_fork_prepare().
152 subl $4,%esp // allocate space for the address parameter
153 leal 0(%esp),%eax // get the address of the allocated space
154 pushl %eax // push the address of the allocated space
157 leal LC2-1b(%eax),%eax
158 pushl %eax // push the name of the function to look up
159 call __dyld_func_lookup
160 addl $8,%esp // remove parameters to __dyld_func_lookup
161 movl 0(%esp),%eax // move the value returned in address parameter
162 addl $4,%esp // deallocate the space for the address param
163 call *%eax // call __dyld_fork_parent indirectly
165 CALL_EXTERN_AGAIN(__cthread_fork_parent)