2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 * 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_fork,%eax; // code for fork -> 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 fork 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 fork error so the parent process can
61 // dyld after fork() 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 fork we need to tell the dynamic linker that
93 // we have forked. 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
120 REG_TO_EXTERN(%eax, __current_pid)
121 CALL_EXTERN(__cthread_fork_child)
122 #if defined(__DYNAMIC__)
125 .ascii "__dyld_fork_child_final\0"
128 subl $4,%esp // allocate space for the address parameter
129 leal 0(%esp),%eax // get the address of the allocated space
130 pushl %eax // push the address of the allocated space
133 leal LC10-1b(%eax),%eax
134 pushl %eax // push the name of the function to look up
135 call __dyld_func_lookup
136 addl $8,%esp // remove parameters to __dyld_func_lookup
137 movl 0(%esp),%eax // move the value returned in address parameter
138 addl $4,%esp // deallocate the space for the address param
139 call *%eax // call __dyld_fork_child_final indirectly
141 xorl %eax,%eax // zero eax
146 push %eax // save pid
147 #if defined(__DYNAMIC__)
148 // __dyld_fork_parent() is called by the parent process after a fork syscall.
149 // This releases the dyld lock acquired by __dyld_fork_prepare().
150 subl $4,%esp // allocate space for the address parameter
151 leal 0(%esp),%eax // get the address of the allocated space
152 pushl %eax // push the address of the allocated space
155 leal LC2-1b(%eax),%eax
156 pushl %eax // push the name of the function to look up
157 call __dyld_func_lookup
158 addl $8,%esp // remove parameters to __dyld_func_lookup
159 movl 0(%esp),%eax // move the value returned in address parameter
160 addl $4,%esp // deallocate the space for the address param
161 call *%eax // call __dyld_fork_parent indirectly
163 CALL_EXTERN_AGAIN(__cthread_fork_parent)