2 * Copyright (c) 2007, 2008 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_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. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
30 #include <TargetConditionals.h> // for TARGET_OS_EMBEDDED
32 #include <_libkernel_init.h>
35 struct ProgramVars
; /* forward reference */
37 // system library initialisers
38 extern void bootstrap_init(void); // from liblaunch.dylib
39 extern void mach_init(void); // from libsystem_mach.dylib
40 extern void pthread_init(void); // from libc.a
41 extern void __libc_init(const struct ProgramVars
*vars
, void (*atfork_prepare
)(void), void (*atfork_parent
)(void), void (*atfork_child
)(void), const char *apple
[]); // from libc.a
42 extern void __keymgr_initializer(void); // from libkeymgr.a
43 extern void _dyld_initializer(void); // from libdyld.a
44 extern void libdispatch_init(void); // from libdispatch.a
45 extern void _libxpc_initializer(void); // from libxpc
47 // system library atfork handlers
48 extern void _cthread_fork_prepare();
49 extern void _cthread_fork_parent();
50 extern void _cthread_fork_child();
51 extern void _cthread_fork_child_postinit();
53 extern void _mach_fork_child();
54 extern void _cproc_fork_child();
55 extern void _libc_fork_child();
56 extern void _notify_fork_child();
57 extern void _dyld_fork_child();
58 extern void xpc_atfork_prepare();
59 extern void xpc_atfork_parent();
60 extern void xpc_atfork_child();
62 // advance decls for below;
63 void libSystem_atfork_prepare();
64 void libSystem_atfork_parent();
65 void libSystem_atfork_child();
67 // from mig_support.c in libc
68 mach_port_t
_mig_get_reply_port();
69 void _mig_set_reply_port(mach_port_t
);
71 void cthread_set_errno_self(int);
75 * libsyscall_initializer() initializes all of libSystem.dylib <rdar://problem/4892197>
77 static __attribute__((constructor
))
78 void libSystem_initializer(int argc
, const char* argv
[], const char* envp
[], const char* apple
[], const struct ProgramVars
* vars
)
80 _libkernel_functions_t libkernel_funcs
= {
81 .get_reply_port
= _mig_get_reply_port
,
82 .set_reply_port
= _mig_set_reply_port
,
84 .set_errno
= cthread_set_errno_self
,
88 _libkernel_init(libkernel_funcs
);
93 __libc_init(vars
, libSystem_atfork_prepare
, libSystem_atfork_parent
, libSystem_atfork_child
, apple
);
94 __keymgr_initializer();
97 #if !TARGET_OS_EMBEDDED || __IPHONE_OS_VERSION_MAX_ALLOWED >= 50000 // __IPHONE_5_0
98 _libxpc_initializer();
103 * libSystem_atfork_{prepare,parent,child}() are called by libc when we fork, then we deal with running fork handlers
106 void libSystem_atfork_prepare()
108 #if !TARGET_OS_EMBEDDED || __IPHONE_OS_VERSION_MAX_ALLOWED >= 50000 // __IPHONE_5_0
109 xpc_atfork_prepare();
111 _cthread_fork_prepare();
114 void libSystem_atfork_parent()
116 _cthread_fork_parent();
117 #if !TARGET_OS_EMBEDDED || __IPHONE_OS_VERSION_MAX_ALLOWED >= 50000 // __IPHONE_5_0
122 void libSystem_atfork_child()
125 _cthread_fork_child();
131 _notify_fork_child();
132 #if !TARGET_OS_EMBEDDED || __IPHONE_OS_VERSION_MAX_ALLOWED >= 50000 // __IPHONE_5_0
136 _cthread_fork_child_postinit();
140 * Old crt1.o glue used to call through mach_init_routine which was used to initialize libSystem.
141 * LibSystem now auto-initializes but mach_init_routine is left for binary compatibility.
143 static void mach_init_old() {}
144 void (*mach_init_routine
)(void) = &mach_init_old
;
147 * This __crashreporter_info__ symbol is for all non-dylib parts of libSystem.
149 const char *__crashreporter_info__
;
150 asm (".desc __crashreporter_info__, 0x10");
152 #endif /* __DYNAMIC__ */