#include <pthread.h>
#include <pthread/private.h>
#include <dlfcn.h>
+#include <fcntl.h>
#include <errno.h>
#include <_libkernel_init.h> // Must be after voucher_private.h
extern void _libsecinit_initializer(void); // from libsecinit.dylib
extern void _libtrace_init(void); // from libsystem_trace.dylib
extern void _container_init(const char *apple[]); // from libsystem_containermanager.dylib
+extern void __libdarwin_init(void); // from libsystem_darwin.dylib
// signal malloc stack logging that initialisation has finished
extern char *_dirhelper(int, char *, size_t);
#endif
-#if TARGET_OS_EMBEDDED && !TARGET_OS_WATCH && !__LP64__
-extern void _vminterpose_init(void);
-#endif
-
// advance decls for below;
void libSystem_atfork_prepare(void);
void libSystem_atfork_parent(void);
void libSystem_atfork_child(void);
+#if CURRENT_VARIANT_asan
+const char *__asan_default_options(void);
+#endif
+
// libsyscall_initializer() initializes all of libSystem.dylib
// <rdar://problem/4892197>
__attribute__((constructor))
// TODO: Move __malloc_init before __libc_init after breaking malloc's upward link to Libc
__malloc_init(apple);
-#if !TARGET_OS_SIMULATOR && !TARGET_OS_TV && !TARGET_OS_WATCH
+#if TARGET_OS_OSX
/* <rdar://problem/9664631> */
__keymgr_initializer();
#endif
+ // No ASan interceptors are invoked before this point. ASan is normally initialized via the malloc interceptor:
+ // _dyld_initializer() -> tlv_load_notification -> wrap_malloc -> ASanInitInternal
+
_dyld_initializer();
libdispatch_init();
_libxpc_initializer();
+#if CURRENT_VARIANT_asan
+ setenv("DT_BYPASS_LEAKS_CHECK", "1", 1);
+#endif
+
// must be initialized after dispatch
_libtrace_init();
_libsecinit_initializer();
#endif
-#if TARGET_OS_EMBEDDED
+#if defined(HAVE_SYSTEM_CONTAINERMANAGER)
_container_init(apple);
#endif
- __stack_logging_early_finished();
+ __libdarwin_init();
-#if TARGET_OS_EMBEDDED && !TARGET_OS_WATCH && !__LP64__
- _vminterpose_init();
-#endif
+ __stack_logging_early_finished();
#if !TARGET_OS_IPHONE
/* <rdar://problem/22139800> - Preserve the old behavior of apple[] for
_pthread_atfork_child_handlers();
}
+#if CURRENT_VARIANT_asan
+char dynamic_asan_opts[1024] = {0};
+const char *__asan_default_options(void) {
+ int fd = open("/System/Library/Preferences/com.apple.asan.options", O_RDONLY);
+ if (fd != -1) {
+ ssize_t remaining_size = sizeof(dynamic_asan_opts) - 1;
+ char *p = dynamic_asan_opts;
+ ssize_t read_bytes = 0;
+ do {
+ read_bytes = read(fd, p, remaining_size);
+ remaining_size -= read_bytes;
+ } while (read_bytes > 0);
+ close(fd);
+
+ if (dynamic_asan_opts[0]) {
+ return dynamic_asan_opts;
+ }
+ }
+
+ return "color=never:handle_segv=0:handle_sigbus=0:handle_sigill=0:handle_sigfpe=0";
+}
+#endif
+
/*
* Old crt1.o glue used to call through mach_init_routine which was used to initialize libSystem.
* LibSystem now auto-initializes but mach_init_routine is left for binary compatibility.