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
28 CALL_EXTERN(__cthread_fork_prepare)
29 #if defined(__DYNAMIC__)
30 // Just like __cthread_fork_prepare we need to prevent threads on the child's
31 // side from doing a mach call in the dynamic linker until __dyld_fork_child
32 // is run (see below). So we call __dyld_fork_prepare which takes out the dyld
33 // lock to prevent all other threads but this one from entering dyld.
36 .ascii "__dyld_fork_prepare\0"
38 subl $4,%esp // allocate space for the address parameter
39 leal 0(%esp),%eax // get the address of the allocated space
40 pushl %eax // push the address of the allocated space
43 leal LC1-1b(%eax),%eax
44 pushl %eax // push the name of the function to look up
45 call __dyld_func_lookup
46 addl $8,%esp // remove parameters to __dyld_func_lookup
47 movl 0(%esp),%eax // move the value returned in address parameter
48 addl $4,%esp // deallocate the space for the address param
49 call *%eax // call __dyld_fork_prepare indirectly
52 movl $SYS_fork,%eax; // code for fork -> eax
53 UNIX_SYSCALL_TRAP; // do the system call
54 jnc L1 // jump if CF==0
56 #if defined(__DYNAMIC__)
57 // __dyld_fork_parent() is called by the parent process after a fork syscall.
58 // This releases the dyld lock acquired by __dyld_fork_prepare(). In this case
59 // we just use it to clean up after a fork error so the parent process can
60 // dyld after fork() errors without deadlocking.
63 .ascii "__dyld_fork_parent\0"
65 pushl %eax // save the return value (errno)
66 subl $4,%esp // allocate space for the address parameter
67 leal 0(%esp),%eax // get the address of the allocated space
68 pushl %eax // push the address of the allocated space
71 leal LC2-1b(%eax),%eax
72 pushl %eax // push the name of the function to look up
73 call __dyld_func_lookup
74 addl $8,%esp // remove parameters to __dyld_func_lookup
75 movl 0(%esp),%eax // move the value returned in address parameter
76 addl $4,%esp // deallocate the space for the address param
77 call *%eax // call __dyld_fork_parent indirectly
78 popl %eax // restore the return value (errno)
81 CALL_EXTERN(__cthread_fork_parent)
86 orl %edx,%edx // CF=OF=0, ZF set if zero result
87 jz L2 // parent, since r1 == 0 in parent, 1 in child
90 #if defined(__DYNAMIC__)
91 // Here on the child side of the fork we need to tell the dynamic linker that
92 // we have forked. To do this we call __dyld_fork_child in the dyanmic
93 // linker. But since we can't dynamicly bind anything until this is done we
94 // do this by using the private extern __dyld_func_lookup() function to get the
95 // address of __dyld_fork_child (the 'C' code equivlent):
97 // _dyld_func_lookup("__dyld_fork_child", &address);
102 .ascii "__dyld_fork_child\0"
105 subl $4,%esp // allocate space for the address parameter
106 leal 0(%esp),%eax // get the address of the allocated space
107 pushl %eax // push the address of the allocated space
110 leal LC0-1b(%eax),%eax
111 pushl %eax // push the name of the function to look up
112 call __dyld_func_lookup
113 addl $8,%esp // remove parameters to __dyld_func_lookup
114 movl 0(%esp),%eax // move the value returned in address parameter
115 addl $4,%esp // deallocate the space for the address param
116 call *%eax // call __dyld_fork_child indirectly
118 CALL_EXTERN(_fork_mach_init)
119 CALL_EXTERN(__cthread_fork_child)
120 #if defined(__DYNAMIC__)
123 .ascii "__dyld_fork_child_final\0"
126 subl $4,%esp // allocate space for the address parameter
127 leal 0(%esp),%eax // get the address of the allocated space
128 pushl %eax // push the address of the allocated space
131 leal LC10-1b(%eax),%eax
132 pushl %eax // push the name of the function to look up
133 call __dyld_func_lookup
134 addl $8,%esp // remove parameters to __dyld_func_lookup
135 movl 0(%esp),%eax // move the value returned in address parameter
136 addl $4,%esp // deallocate the space for the address param
137 call *%eax // call __dyld_fork_child_final indirectly
139 xorl %eax,%eax // zero eax
144 push %eax // save pid
145 #if defined(__DYNAMIC__)
146 // __dyld_fork_parent() is called by the parent process after a fork syscall.
147 // This releases the dyld lock acquired by __dyld_fork_prepare().
148 subl $4,%esp // allocate space for the address parameter
149 leal 0(%esp),%eax // get the address of the allocated space
150 pushl %eax // push the address of the allocated space
153 leal LC2-1b(%eax),%eax
154 pushl %eax // push the name of the function to look up
155 call __dyld_func_lookup
156 addl $8,%esp // remove parameters to __dyld_func_lookup
157 movl 0(%esp),%eax // move the value returned in address parameter
158 addl $4,%esp // deallocate the space for the address param
159 call *%eax // call __dyld_fork_parent indirectly
161 CALL_EXTERN_AGAIN(__cthread_fork_parent)