]> git.saurik.com Git - apple/libsystem.git/blobdiff - init.c
Libsystem-1292.50.1.tar.gz
[apple/libsystem.git] / init.c
diff --git a/init.c b/init.c
index 9d604e0c529bf115d3622809748fe5510fa4c957..cdc51303dcc0436fbdb0e4e2d51379457a696388 100644 (file)
--- a/init.c
+++ b/init.c
@@ -225,6 +225,7 @@ libSystem_initializer(int argc,
        _libSystem_ktrace_init_func(LIBC);
 
        // TODO: Move __malloc_init before __libc_init after breaking malloc's upward link to Libc
+       // Note that __malloc_init() will also initialize ASAN when it is present
        __malloc_init(apple);
        _libSystem_ktrace_init_func(MALLOC);
 
@@ -234,9 +235,6 @@ libSystem_initializer(int argc,
        _libSystem_ktrace_init_func(KEYMGR);
 #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();
        _libSystem_ktrace_init_func(DYLD);
 
@@ -285,6 +283,37 @@ libSystem_initializer(int argc,
        }
 #endif
 
+#if TARGET_OS_OSX && !defined(__i386__)
+       bool enable_system_version_compat = false;
+       bool enable_ios_version_compat = false;
+       char *system_version_compat_override = getenv("SYSTEM_VERSION_COMPAT");
+       if (system_version_compat_override != NULL) {
+               long override = strtol(system_version_compat_override, NULL, 0);
+               if (override == 1) {
+                       enable_system_version_compat = true;
+               } else if (override == 2) {
+                       enable_ios_version_compat = true;
+               }
+       } else if (dyld_get_active_platform() == PLATFORM_MACCATALYST) {
+               if (!dyld_program_sdk_at_least(dyld_platform_version_iOS_14_0)) {
+                       enable_system_version_compat = true;
+               }
+       } else if (dyld_get_active_platform() == PLATFORM_IOS) {
+               enable_ios_version_compat = true;
+       } else if (!dyld_program_sdk_at_least(dyld_platform_version_macOS_10_16)) {
+               enable_system_version_compat = true;
+       }
+
+       if (enable_system_version_compat || enable_ios_version_compat) {
+               struct _libkernel_late_init_config config = {
+                       .version = 2,
+                       .enable_system_version_compat = enable_system_version_compat,
+                       .enable_ios_version_compat = enable_ios_version_compat,
+               };
+               __libkernel_init_late(&config);
+       }
+#endif // TARGET_OS_OSX && !defined(__i386__)
+
        _libSystem_ktrace0(ARIADNE_LIFECYCLE_libsystem_init | DBG_FUNC_END);
 
        /* <rdar://problem/11588042>