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 subl $28, %esp // Align the stack, with 16 bytes of extra padding that we'll need
30 CALL_EXTERN(__cthread_fork_prepare)
31 #if defined(__DYNAMIC__)
32 // Just like __cthread_fork_prepare we need to prevent threads on the child's
33 // side from doing a mach call in the dynamic linker until __dyld_fork_child
34 // is run (see below). So we call __dyld_fork_prepare which takes out the dyld
35 // lock to prevent all other threads but this one from entering dyld.
38 .ascii "__dyld_fork_prepare\0"
40 // Put a pointer to 8(%esp) in 4(%esp) for _dyld_func_lookup to fill in.
41 leal 0x8(%esp),%eax // get the address where we're going to store the pointer
42 movl %eax, 0x4(%esp) // copy the address of the pointer
45 leal LC1-1b(%eax),%eax
46 movl %eax, 0x0(%esp) // copy the name of the function to look up
47 call __dyld_func_lookup
48 movl 0x8(%esp),%eax // move the value returned in address parameter
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 movl %eax, 0xc(%esp) // save the return value (errno)
66 leal 0x8(%esp),%eax // get the address where we're going to store the pointer
67 movl %eax, 0x4(%esp) // copy the address of the pointer
70 leal LC2-1b(%eax),%eax
71 movl %eax, 0x0(%esp) // copy the name of the function to look up
72 call __dyld_func_lookup
73 movl 0x8(%esp),%eax // move the value returned in address parameter
74 call *%eax // call __dyld_fork_parent indirectly
75 movl 0xc(%esp), %eax // restore the return value (errno)
78 CALL_EXTERN(__cthread_fork_parent)
80 addl $28, %esp // restore the stack
84 orl %edx,%edx // CF=OF=0, ZF set if zero result
85 jz L2 // parent, since r1 == 0 in parent, 1 in child
88 #if defined(__DYNAMIC__)
89 // Here on the child side of the fork we need to tell the dynamic linker that
90 // we have forked. To do this we call __dyld_fork_child in the dyanmic
91 // linker. But since we can't dynamically bind anything until this is done we
92 // do this by using the private extern __dyld_func_lookup() function to get the
93 // address of __dyld_fork_child (the 'C' code equivlent):
95 // _dyld_func_lookup("__dyld_fork_child", &address);
100 .ascii "__dyld_fork_child\0"
103 leal 0x8(%esp),%eax // get the address where we're going to store the pointer
104 movl %eax, 0x4(%esp) // copy the address of the pointer
107 leal LC0-1b(%eax),%eax
108 movl %eax, 0x0(%esp) // copy the name of the function to look up
109 call __dyld_func_lookup
110 movl 0x8(%esp),%eax // move the value returned in address parameter
111 call *%eax // call __dyld_fork_child indirectly
114 REG_TO_EXTERN(%eax, __current_pid)
115 CALL_EXTERN(__cthread_fork_child)
116 #if defined(__DYNAMIC__)
119 .ascii "__dyld_fork_child_final\0"
122 leal 0x8(%esp),%eax // get the address where we're going to store the pointer
123 movl %eax, 0x4(%esp) // copy the address of the pointer
126 leal LC10-1b(%eax),%eax
127 movl %eax, 0x0(%esp) // copy the name of the function to look up
128 call __dyld_func_lookup
129 movl 0x8(%esp),%eax // move the value returned in address parameter
130 call *%eax // call __dyld_fork_child_final indirectly
132 xorl %eax,%eax // zero eax
133 addl $28, %esp // restore the stack
138 movl %eax, 0xc(%esp) // save pid
139 #if defined(__DYNAMIC__)
140 // __dyld_fork_parent() is called by the parent process after a fork syscall.
141 // This releases the dyld lock acquired by __dyld_fork_prepare().
142 leal 0x8(%esp),%eax // get the address where we're going to store the pointer
143 movl %eax, 0x4(%esp) // copy the address of the allocated space
146 leal LC2-1b(%eax),%eax
147 movl %eax, 0x0(%esp) // copy the name of the function to look up
148 call __dyld_func_lookup
149 movl 0x8(%esp),%eax // move the value returned in address parameter
150 call *%eax // call __dyld_fork_parent indirectly
152 CALL_EXTERN_AGAIN(__cthread_fork_parent)
153 movl 0xc(%esp), %eax // return pid
154 addl $28, %esp // restore the stack