+#if TARGET_OS_OSX
+ for (size_t i = 0; envp[i]; i++) {
+
+#if defined(__i386__) || defined(__x86_64__)
+ const char *VM_KERNEL_PAGE_SHIFT_ENV = "VM_KERNEL_PAGE_SIZE_4K=1";
+ if (vm_kernel_page_shift != 12 && strcmp(VM_KERNEL_PAGE_SHIFT_ENV, envp[i]) == 0) {
+ vm_kernel_page_shift = 12;
+ vm_kernel_page_size = 1 << vm_kernel_page_shift;
+ vm_kernel_page_mask = vm_kernel_page_size - 1;
+ }
+#endif /* defined(__i386__) || defined(__x86_64__) */
+ }
+#endif /* TARGET_OS_OSX */
+}
+
+void
+__libkernel_init_late(_libkernel_late_init_config_t config)
+{
+ if (config->version >= 1) {
+#if TARGET_OS_OSX && !defined(__i386__)
+ if (config->enable_system_version_compat) {
+ /* enable the version compatibility shim for this process (macOS only) */
+
+ /* first hook up the shims we reference from open{at}() */
+ system_version_compat_check_path_suffix = _system_version_compat_check_path_suffix;
+ system_version_compat_open_shim = _system_version_compat_open_shim;
+
+ system_version_compat_mode = SYSTEM_VERSION_COMPAT_MODE_MACOSX;
+
+ /*
+ * tell the kernel the shim is enabled for this process so it can shim any
+ * necessary sysctls
+ */
+ int enable = 1;
+ __sysctlbyname("kern.system_version_compat", strlen("kern.system_version_compat"),
+ NULL, NULL, &enable, sizeof(enable));
+ } else if ((config->version >= 2) && config->enable_ios_version_compat) {
+ /* enable the iOS ProductVersion compatibility shim for this process */
+
+ /* first hook up the shims we reference from open{at}() */
+ system_version_compat_check_path_suffix = _system_version_compat_check_path_suffix;
+ system_version_compat_open_shim = _system_version_compat_open_shim;
+
+ system_version_compat_mode = SYSTEM_VERSION_COMPAT_MODE_IOS;
+
+ /*
+ * We don't currently shim any sysctls for iOS apps running on macOS so we
+ * don't need to inform the kernel that this app has the SystemVersion shim enabled.
+ */
+ }
+#endif /* TARGET_OS_OSX && !defined(__i386__) */
+ }