2 * Copyright (c) 2007, 2008, 2011 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@
29 #include <TargetConditionals.h> // for TARGET_OS_EMBEDDED
31 #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 // signal malloc stack logging that initialisation has finished
48 extern void __stack_logging_early_finished(void); // form libsystem_c.dylib
50 // system library atfork handlers
51 extern void _cthread_fork_prepare(void);
52 extern void _cthread_fork_parent(void);
53 extern void _cthread_fork_child(void);
54 extern void _cthread_fork_child_postinit(void);
56 extern void _mach_fork_child(void);
57 extern void _cproc_fork_child(void);
58 extern void _libc_fork_child(void);
59 extern void _notify_fork_child(void);
60 extern void _dyld_fork_child(void);
61 extern void xpc_atfork_prepare(void);
62 extern void xpc_atfork_parent(void);
63 extern void xpc_atfork_child(void);
65 // advance decls for below;
66 void libSystem_atfork_prepare(void);
67 void libSystem_atfork_parent(void);
68 void libSystem_atfork_child(void);
70 // from mig_support.c in libc
71 mach_port_t
_mig_get_reply_port(void);
72 void _mig_set_reply_port(mach_port_t
);
74 void cthread_set_errno_self(int);
77 * libsyscall_initializer() initializes all of libSystem.dylib <rdar://problem/4892197>
79 static __attribute__((constructor
))
80 void libSystem_initializer(int argc
, const char* argv
[], const char* envp
[], const char* apple
[], const struct ProgramVars
* vars
)
82 _libkernel_functions_t libkernel_funcs
= {
83 .get_reply_port
= _mig_get_reply_port
,
84 .set_reply_port
= _mig_set_reply_port
,
86 .set_errno
= cthread_set_errno_self
,
90 _libkernel_init(libkernel_funcs
);
95 __libc_init(vars
, libSystem_atfork_prepare
, libSystem_atfork_parent
, libSystem_atfork_child
, apple
);
96 __keymgr_initializer();
99 _libxpc_initializer();
101 __stack_logging_early_finished();
103 /* <rdar://problem/11588042>
104 * C99 standard has the following in section 7.5(3):
105 * "The value of errno is zero at program startup, but is never set
106 * to zero by any library function."
112 * libSystem_atfork_{prepare,parent,child}() are called by libc when we fork, then we deal with running fork handlers
115 void libSystem_atfork_prepare(void)
117 xpc_atfork_prepare();
118 _cthread_fork_prepare();
121 void libSystem_atfork_parent(void)
123 _cthread_fork_parent();
127 void libSystem_atfork_child(void)
130 _cthread_fork_child();
136 _notify_fork_child();
139 _cthread_fork_child_postinit();
143 * Old crt1.o glue used to call through mach_init_routine which was used to initialize libSystem.
144 * LibSystem now auto-initializes but mach_init_routine is left for binary compatibility.
146 static void mach_init_old(void) {}
147 void (*mach_init_routine
)(void) = &mach_init_old
;
150 * This __crashreporter_info__ symbol is for all non-dylib parts of libSystem.
152 const char *__crashreporter_info__
;
153 asm (".desc __crashreporter_info__, 0x10");