2 * Copyright (c) 2010 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@
23 #include <sys/types.h>
27 extern pid_t
__fork(void);
28 extern void _cthread_fork_prepare();
29 extern void _cthread_fork_parent();
30 extern void _cthread_fork_child();
32 static void (*_libSystem_atfork_prepare
)(void) = 0;
33 static void (*_libSystem_atfork_parent
)(void) = 0;
34 static void (*_libSystem_atfork_child
)(void) = 0;
36 __private_extern__
void _libc_fork_init(void (*prepare
)(void), void (*parent
)(void), void (*child
)(void))
38 _libSystem_atfork_prepare
= prepare
;
39 _libSystem_atfork_parent
= parent
;
40 _libSystem_atfork_child
= child
;
51 _libSystem_atfork_prepare();
52 // Reader beware: this __fork() call is yet another wrapper around the actual syscall
53 // and lives inside libsyscall. The fork syscall needs some cuddling by asm before it's
54 // allowed to see the big wide C world.
58 // __fork already set errno for us
59 _libSystem_atfork_parent();
65 // We're the child in this part.
66 _libSystem_atfork_child();
70 _libSystem_atfork_parent();