]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
6d2010ae | 2 | * Copyright (c) 2010 Apple Inc. All rights reserved. |
5d5c5d0d | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
0a7de745 | 5 | * |
2d21ac55 A |
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. | |
0a7de745 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
0a7de745 | 17 | * |
2d21ac55 A |
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 | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
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. | |
0a7de745 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b | 27 | */ |
1c79356b | 28 | |
5ba3f43e A |
29 | #include <TargetConditionals.h> |
30 | #include <stdbool.h> | |
31 | #include <strings.h> | |
32 | #include <unistd.h> | |
6d2010ae | 33 | #include "_libkernel_init.h" |
1c79356b | 34 | |
39236c6e | 35 | extern int mach_init(void); |
1c79356b | 36 | |
5ba3f43e | 37 | #if TARGET_OS_OSX |
f427ee49 A |
38 | |
39 | #if !defined(__i386__) | |
40 | ||
41 | #include "system-version-compat-support.h" | |
42 | #include <sys/sysctl.h> | |
43 | ||
44 | extern bool _system_version_compat_check_path_suffix(const char *orig_path); | |
45 | extern int _system_version_compat_open_shim(int opened_fd, int openat_fd, const char *orig_path, int oflag, mode_t mode, | |
46 | int (*close_syscall)(int), int (*open_syscall)(const char *, int, mode_t), | |
47 | int (*openat_syscall)(int, const char *, int, mode_t), | |
48 | int (*fcntl_syscall)(int, int, long)); | |
49 | ||
50 | extern bool (*system_version_compat_check_path_suffix)(const char *orig_path); | |
51 | extern int (*system_version_compat_open_shim)(int opened_fd, int openat_fd, const char *orig_path, int oflag, mode_t mode, | |
52 | int (*close_syscall)(int), int (*open_syscall)(const char *, int, mode_t), | |
53 | int (*openat_syscall)(int, const char *, int, mode_t), | |
54 | int (*fcntl_syscall)(int, int, long)); | |
55 | ||
56 | extern system_version_compat_mode_t system_version_compat_mode; | |
57 | ||
58 | int __sysctlbyname(const char *name, size_t namelen, void *oldp, size_t *oldlenp, void *newp, size_t newlen); | |
59 | #endif /* !defined(__i386__) */ | |
60 | ||
5ba3f43e A |
61 | __attribute__((visibility("default"))) |
62 | extern bool _os_xbs_chrooted; | |
63 | bool _os_xbs_chrooted; | |
f427ee49 | 64 | #endif /* TARGET_OS_OSX */ |
5ba3f43e | 65 | |
6d2010ae A |
66 | /* dlsym() funcptr is for legacy support in exc_catcher */ |
67 | void* (*_dlsym)(void*, const char*) __attribute__((visibility("hidden"))); | |
91447636 | 68 | |
39236c6e A |
69 | __attribute__((visibility("hidden"))) |
70 | _libkernel_functions_t _libkernel_functions; | |
71 | ||
d9a64523 | 72 | |
6d2010ae | 73 | void |
39236c6e | 74 | __libkernel_init(_libkernel_functions_t fns, |
0a7de745 A |
75 | const char *envp[] __attribute__((unused)), |
76 | const char *apple[] __attribute__((unused)), | |
77 | const struct ProgramVars *vars __attribute__((unused))) | |
1c79356b | 78 | { |
39236c6e A |
79 | _libkernel_functions = fns; |
80 | if (fns->dlsym) { | |
81 | _dlsym = fns->dlsym; | |
82 | } | |
83 | mach_init(); | |
1c79356b | 84 | } |
f427ee49 A |
85 | |
86 | void | |
87 | __libkernel_init_late(_libkernel_late_init_config_t config) | |
88 | { | |
89 | if (config->version >= 1) { | |
90 | #if TARGET_OS_OSX && !defined(__i386__) | |
91 | if (config->enable_system_version_compat) { | |
92 | /* enable the version compatibility shim for this process (macOS only) */ | |
93 | ||
94 | /* first hook up the shims we reference from open{at}() */ | |
95 | system_version_compat_check_path_suffix = _system_version_compat_check_path_suffix; | |
96 | system_version_compat_open_shim = _system_version_compat_open_shim; | |
97 | ||
98 | system_version_compat_mode = SYSTEM_VERSION_COMPAT_MODE_MACOSX; | |
99 | ||
100 | /* | |
101 | * tell the kernel the shim is enabled for this process so it can shim any | |
102 | * necessary sysctls | |
103 | */ | |
104 | int enable = 1; | |
105 | __sysctlbyname("kern.system_version_compat", strlen("kern.system_version_compat"), | |
106 | NULL, NULL, &enable, sizeof(enable)); | |
107 | } else if ((config->version >= 2) && config->enable_ios_version_compat) { | |
108 | /* enable the iOS ProductVersion compatibility shim for this process */ | |
109 | ||
110 | /* first hook up the shims we reference from open{at}() */ | |
111 | system_version_compat_check_path_suffix = _system_version_compat_check_path_suffix; | |
112 | system_version_compat_open_shim = _system_version_compat_open_shim; | |
113 | ||
114 | system_version_compat_mode = SYSTEM_VERSION_COMPAT_MODE_IOS; | |
115 | ||
116 | /* | |
117 | * We don't currently shim any sysctls for iOS apps running on macOS so we | |
118 | * don't need to inform the kernel that this app has the SystemVersion shim enabled. | |
119 | */ | |
120 | } | |
121 | #endif /* TARGET_OS_OSX && !defined(__i386__) */ | |
122 | } | |
123 | } |