2 * Copyright (c) 2010 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>
33 #include <mach/vm_page_size.h>
34 #include "_libkernel_init.h"
36 extern int mach_init(void);
40 #if !defined(__i386__)
42 #include "system-version-compat-support.h"
43 #include <sys/sysctl.h>
45 extern bool _system_version_compat_check_path_suffix(const char *orig_path
);
46 extern int _system_version_compat_open_shim(int opened_fd
, int openat_fd
, const char *orig_path
, int oflag
, mode_t mode
,
47 int (*close_syscall
)(int), int (*open_syscall
)(const char *, int, mode_t
),
48 int (*openat_syscall
)(int, const char *, int, mode_t
),
49 int (*fcntl_syscall
)(int, int, long));
51 extern bool (*system_version_compat_check_path_suffix
)(const char *orig_path
);
52 extern int (*system_version_compat_open_shim
)(int opened_fd
, int openat_fd
, const char *orig_path
, int oflag
, mode_t mode
,
53 int (*close_syscall
)(int), int (*open_syscall
)(const char *, int, mode_t
),
54 int (*openat_syscall
)(int, const char *, int, mode_t
),
55 int (*fcntl_syscall
)(int, int, long));
57 extern system_version_compat_mode_t system_version_compat_mode
;
59 int __sysctlbyname(const char *name
, size_t namelen
, void *oldp
, size_t *oldlenp
, void *newp
, size_t newlen
);
60 #endif /* !defined(__i386__) */
62 __attribute__((visibility("default")))
63 extern bool _os_xbs_chrooted
;
64 bool _os_xbs_chrooted
;
65 #endif /* TARGET_OS_OSX */
67 /* dlsym() funcptr is for legacy support in exc_catcher */
68 void* (*_dlsym
)(void*, const char*) __attribute__((visibility("hidden")));
70 __attribute__((visibility("hidden")))
71 _libkernel_functions_t _libkernel_functions
;
75 __libkernel_init(_libkernel_functions_t fns
,
76 const char *envp
[] __attribute__((unused
)),
77 const char *apple
[] __attribute__((unused
)),
78 const struct ProgramVars
*vars
__attribute__((unused
)))
80 _libkernel_functions
= fns
;
86 for (size_t i
= 0; envp
[i
]; i
++) {
88 #if defined(__i386__) || defined(__x86_64__)
89 const char *VM_KERNEL_PAGE_SHIFT_ENV
= "VM_KERNEL_PAGE_SIZE_4K=1";
90 if (vm_kernel_page_shift
!= 12 && strcmp(VM_KERNEL_PAGE_SHIFT_ENV
, envp
[i
]) == 0) {
91 vm_kernel_page_shift
= 12;
92 vm_kernel_page_size
= 1 << vm_kernel_page_shift
;
93 vm_kernel_page_mask
= vm_kernel_page_size
- 1;
95 #endif /* defined(__i386__) || defined(__x86_64__) */
97 #endif /* TARGET_OS_OSX */
101 __libkernel_init_late(_libkernel_late_init_config_t config
)
103 if (config
->version
>= 1) {
104 #if TARGET_OS_OSX && !defined(__i386__)
105 if (config
->enable_system_version_compat
) {
106 /* enable the version compatibility shim for this process (macOS only) */
108 /* first hook up the shims we reference from open{at}() */
109 system_version_compat_check_path_suffix
= _system_version_compat_check_path_suffix
;
110 system_version_compat_open_shim
= _system_version_compat_open_shim
;
112 system_version_compat_mode
= SYSTEM_VERSION_COMPAT_MODE_MACOSX
;
115 * tell the kernel the shim is enabled for this process so it can shim any
119 __sysctlbyname("kern.system_version_compat", strlen("kern.system_version_compat"),
120 NULL
, NULL
, &enable
, sizeof(enable
));
121 } else if ((config
->version
>= 2) && config
->enable_ios_version_compat
) {
122 /* enable the iOS ProductVersion compatibility shim for this process */
124 /* first hook up the shims we reference from open{at}() */
125 system_version_compat_check_path_suffix
= _system_version_compat_check_path_suffix
;
126 system_version_compat_open_shim
= _system_version_compat_open_shim
;
128 system_version_compat_mode
= SYSTEM_VERSION_COMPAT_MODE_IOS
;
131 * We don't currently shim any sysctls for iOS apps running on macOS so we
132 * don't need to inform the kernel that this app has the SystemVersion shim enabled.
135 #endif /* TARGET_OS_OSX && !defined(__i386__) */