/src/vulkan-loader/loader/vk_loader_platform.h
Line | Count | Source |
1 | | /* |
2 | | * |
3 | | * Copyright (c) 2015-2022 The Khronos Group Inc. |
4 | | * Copyright (c) 2015-2022 Valve Corporation |
5 | | * Copyright (c) 2015-2022 LunarG, Inc. |
6 | | * Copyright (c) 2021-2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
7 | | * Copyright (c) 2023-2023 RasterGrid Kft. |
8 | | * |
9 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
10 | | * you may not use this file except in compliance with the License. |
11 | | * You may obtain a copy of the License at |
12 | | * |
13 | | * http://www.apache.org/licenses/LICENSE-2.0 |
14 | | * |
15 | | * Unless required by applicable law or agreed to in writing, software |
16 | | * distributed under the License is distributed on an "AS IS" BASIS, |
17 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
18 | | * See the License for the specific language governing permissions and |
19 | | * limitations under the License. |
20 | | * |
21 | | * Author: Ian Elliot <ian@lunarg.com> |
22 | | * Author: Jon Ashburn <jon@lunarg.com> |
23 | | * Author: Lenny Komow <lenny@lunarg.com> |
24 | | * Author: Charles Giessen <charles@lunarg.com> |
25 | | * |
26 | | */ |
27 | | #pragma once |
28 | | |
29 | | #if defined(__FreeBSD__) || defined(__OpenBSD__) |
30 | | #include <sys/types.h> |
31 | | #include <sys/select.h> |
32 | | #endif |
33 | | |
34 | | #include <assert.h> |
35 | | #include <float.h> |
36 | | #include <stdbool.h> |
37 | | #include <stdint.h> |
38 | | #include <stdio.h> |
39 | | #include <string.h> |
40 | | |
41 | | #if defined(__Fuchsia__) |
42 | | #include "dlopen_fuchsia.h" |
43 | | #endif // defined(__Fuchsia__) |
44 | | |
45 | | // Set of platforms with a common set of functionality which is queried throughout the program |
46 | | #if defined(__linux__) || defined(__APPLE__) || defined(__Fuchsia__) || defined(__QNX__) || defined(__FreeBSD__) || \ |
47 | | defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__GNU__) || defined(__CYGWIN__) |
48 | | #define COMMON_UNIX_PLATFORMS 1 |
49 | | #else |
50 | | #define COMMON_UNIX_PLATFORMS 0 |
51 | | #endif |
52 | | |
53 | | #if COMMON_UNIX_PLATFORMS |
54 | | #include <unistd.h> |
55 | | // Note: The following file is for dynamic loading: |
56 | | #include <dlfcn.h> |
57 | | #include <pthread.h> |
58 | | #include <stdlib.h> |
59 | | #include <libgen.h> |
60 | | |
61 | | #elif defined(_WIN32) |
62 | | // WinBase.h defines CreateSemaphore and synchapi.h defines CreateEvent |
63 | | // undefine them to avoid conflicts with VkLayerDispatchTable struct members. |
64 | | #if defined(CreateSemaphore) |
65 | | #undef CreateSemaphore |
66 | | #endif |
67 | | #if defined(CreateEvent) |
68 | | #undef CreateEvent |
69 | | #endif |
70 | | #include <stdio.h> |
71 | | #include <io.h> |
72 | | #include <shlwapi.h> |
73 | | #include <direct.h> |
74 | | |
75 | | #include "stack_allocation.h" |
76 | | #endif // defined(_WIN32) |
77 | | |
78 | | #if defined(APPLE_STATIC_LOADER) && !defined(__APPLE__) |
79 | | #error "APPLE_STATIC_LOADER can only be defined on Apple platforms!" |
80 | | #endif |
81 | | |
82 | | #if defined(APPLE_STATIC_LOADER) |
83 | | #define LOADER_EXPORT |
84 | | #elif defined(__GNUC__) && __GNUC__ >= 4 |
85 | | #define LOADER_EXPORT __attribute__((visibility("default"))) |
86 | | #elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590) |
87 | | #define LOADER_EXPORT __attribute__((visibility("default"))) |
88 | | #else |
89 | | #define LOADER_EXPORT |
90 | | #endif |
91 | | |
92 | | // For testing purposes, we want to expose some functions not normally callable on the library |
93 | | #if defined(SHOULD_EXPORT_TEST_FUNCTIONS) |
94 | | #if defined(_WIN32) |
95 | | #define TEST_FUNCTION_EXPORT __declspec(dllexport) |
96 | | #else |
97 | | #define TEST_FUNCTION_EXPORT LOADER_EXPORT |
98 | | #endif |
99 | | #else |
100 | | #define TEST_FUNCTION_EXPORT |
101 | | #endif |
102 | | |
103 | | #define MAX_STRING_SIZE 1024 |
104 | | |
105 | | // This is defined in vk_layer.h, but if there's problems we need to create the define |
106 | | // here. |
107 | | #if !defined(MAX_NUM_UNKNOWN_EXTS) |
108 | | #define MAX_NUM_UNKNOWN_EXTS 250 |
109 | | #endif |
110 | | |
111 | | // Environment Variable information |
112 | 1.20k | #define VK_ICD_FILENAMES_ENV_VAR "VK_ICD_FILENAMES" // Deprecated in v1.3.207 loader |
113 | 1.20k | #define VK_DRIVER_FILES_ENV_VAR "VK_DRIVER_FILES" |
114 | 24.3k | #define VK_EXPLICIT_LAYER_PATH_ENV_VAR "VK_LAYER_PATH" |
115 | | // Support added in v1.3.207 loader |
116 | 1.20k | #define VK_ADDITIONAL_DRIVER_FILES_ENV_VAR "VK_ADD_DRIVER_FILES" |
117 | 24.3k | #define VK_ADDITIONAL_EXPLICIT_LAYER_PATH_ENV_VAR "VK_ADD_LAYER_PATH" |
118 | | // Support added in v1.3.234 loader |
119 | 35.6k | #define VK_LAYERS_ENABLE_ENV_VAR "VK_LOADER_LAYERS_ENABLE" |
120 | 35.2k | #define VK_LAYERS_DISABLE_ENV_VAR "VK_LOADER_LAYERS_DISABLE" |
121 | 35.2k | #define VK_LAYERS_ALLOW_ENV_VAR "VK_LOADER_LAYERS_ALLOW" |
122 | 1.20k | #define VK_DRIVERS_SELECT_ENV_VAR "VK_LOADER_DRIVERS_SELECT" |
123 | 1.20k | #define VK_DRIVERS_DISABLE_ENV_VAR "VK_LOADER_DRIVERS_DISABLE" |
124 | 0 | #define VK_LOADER_DISABLE_ALL_LAYERS_VAR_1 "~all~" |
125 | 0 | #define VK_LOADER_DISABLE_ALL_LAYERS_VAR_2 "*" |
126 | 0 | #define VK_LOADER_DISABLE_ALL_LAYERS_VAR_3 "**" |
127 | 0 | #define VK_LOADER_DISABLE_IMPLICIT_LAYERS_VAR "~implicit~" |
128 | 0 | #define VK_LOADER_DISABLE_EXPLICIT_LAYERS_VAR "~explicit~" |
129 | | // Support added in v1.3.295 loader |
130 | 32.8k | #define VK_IMPLICIT_LAYER_PATH_ENV_VAR "VK_IMPLICIT_LAYER_PATH" |
131 | 32.8k | #define VK_ADDITIONAL_IMPLICIT_LAYER_PATH_ENV_VAR "VK_ADD_IMPLICIT_LAYER_PATH" |
132 | | |
133 | 0 | #define VK_DEVICE_ID_FILTER_ENV_VAR "VK_LOADER_DEVICE_ID_FILTER" |
134 | 0 | #define VK_VENDOR_ID_FILTER_ENV_VAR "VK_LOADER_VENDOR_ID_FILTER" |
135 | 0 | #define VK_DRIVER_ID_FILTER_ENV_VAR "VK_LOADER_DRIVER_ID_FILTER" |
136 | | |
137 | | // Override layer information |
138 | 3.53M | #define VK_OVERRIDE_LAYER_NAME "VK_LAYER_LUNARG_override" |
139 | | |
140 | | // Loader Settings filename |
141 | 150k | #define VK_LOADER_SETTINGS_FILENAME "vk_loader_settings.json" |
142 | | |
143 | | #define LAYERS_PATH_ENV "VK_LAYER_PATH" |
144 | 0 | #define ENABLED_LAYERS_ENV "VK_INSTANCE_LAYERS" |
145 | | |
146 | | #if COMMON_UNIX_PLATFORMS |
147 | | /* Linux-specific common code: */ |
148 | | |
149 | | // VK Library Filenames, Paths, etc.: |
150 | 682M | #define PATH_SEPARATOR ':' |
151 | 567M | #define DIRECTORY_SYMBOL '/' |
152 | | |
153 | 58.3k | #define VULKAN_DIR "vulkan/" |
154 | 1.20k | #define VULKAN_ICDCONF_DIR "icd.d" |
155 | | #define VULKAN_ICD_DIR "icd" |
156 | | #define VULKAN_SETTINGSCONF_DIR "settings.d" |
157 | 24.3k | #define VULKAN_ELAYERCONF_DIR "explicit_layer.d" |
158 | 32.8k | #define VULKAN_ILAYERCONF_DIR "implicit_layer.d" |
159 | | #define VULKAN_LAYER_DIR "layer" |
160 | | |
161 | 1.20k | #define VK_DRIVERS_INFO_RELATIVE_DIR VULKAN_DIR VULKAN_ICDCONF_DIR |
162 | | #define VK_SETTINGS_INFO_RELATIVE_DIR VULKAN_DIR VULKAN_SETTINGSCONF_DIR |
163 | 24.3k | #define VK_ELAYERS_INFO_RELATIVE_DIR VULKAN_DIR VULKAN_ELAYERCONF_DIR |
164 | 32.8k | #define VK_ILAYERS_INFO_RELATIVE_DIR VULKAN_DIR VULKAN_ILAYERCONF_DIR |
165 | | |
166 | | #define VK_DRIVERS_INFO_REGISTRY_LOC "" |
167 | | #define VK_ELAYERS_INFO_REGISTRY_LOC "" |
168 | | #define VK_ILAYERS_INFO_REGISTRY_LOC "" |
169 | | #define VK_SETTINGS_INFO_REGISTRY_LOC "" |
170 | | |
171 | | #if defined(__QNX__) |
172 | | #ifndef SYSCONFDIR |
173 | | #define SYSCONFDIR "/etc" |
174 | | #endif |
175 | | #endif |
176 | | |
177 | | // C99: |
178 | | #define PRINTF_SIZE_T_SPECIFIER "%zu" |
179 | | |
180 | | // Dynamic Loading of libraries: |
181 | | typedef void *loader_platform_dl_handle; |
182 | | |
183 | | // Threads: |
184 | | typedef pthread_t loader_platform_thread; |
185 | | |
186 | | // Thread IDs: |
187 | | typedef pthread_t loader_platform_thread_id; |
188 | | |
189 | | // Thread mutex: |
190 | | typedef pthread_mutex_t loader_platform_thread_mutex; |
191 | | |
192 | | typedef pthread_cond_t loader_platform_thread_cond; |
193 | | |
194 | | #elif defined(_WIN32) |
195 | | /* Windows-specific common code: */ |
196 | | // VK Library Filenames, Paths, etc.: |
197 | | #define PATH_SEPARATOR ';' |
198 | | #define DIRECTORY_SYMBOL '\\' |
199 | | #define DEFAULT_VK_REGISTRY_HIVE HKEY_LOCAL_MACHINE |
200 | | #define DEFAULT_VK_REGISTRY_HIVE_STR "HKEY_LOCAL_MACHINE" |
201 | | #define SECONDARY_VK_REGISTRY_HIVE HKEY_CURRENT_USER |
202 | | #define SECONDARY_VK_REGISTRY_HIVE_STR "HKEY_CURRENT_USER" |
203 | | |
204 | | #define VK_DRIVERS_INFO_RELATIVE_DIR "" |
205 | | #define VK_SETTINGS_INFO_RELATIVE_DIR "" |
206 | | #define VK_ELAYERS_INFO_RELATIVE_DIR "" |
207 | | #define VK_ILAYERS_INFO_RELATIVE_DIR "" |
208 | | |
209 | | #define VK_VARIANT_REG_STR "" |
210 | | #define VK_VARIANT_REG_STR_W L"" |
211 | | |
212 | | #define VK_DRIVERS_INFO_REGISTRY_LOC "SOFTWARE\\Khronos\\Vulkan" VK_VARIANT_REG_STR "\\Drivers" |
213 | | #define VK_ELAYERS_INFO_REGISTRY_LOC "SOFTWARE\\Khronos\\Vulkan" VK_VARIANT_REG_STR "\\ExplicitLayers" |
214 | | #define VK_ILAYERS_INFO_REGISTRY_LOC "SOFTWARE\\Khronos\\Vulkan" VK_VARIANT_REG_STR "\\ImplicitLayers" |
215 | | #define VK_SETTINGS_INFO_REGISTRY_LOC "SOFTWARE\\Khronos\\Vulkan" VK_VARIANT_REG_STR "\\LoaderSettings" |
216 | | |
217 | | #define PRINTF_SIZE_T_SPECIFIER "%Iu" |
218 | | |
219 | | // Dynamic Loading: |
220 | | typedef HMODULE loader_platform_dl_handle; |
221 | | |
222 | | // Threads: |
223 | | typedef HANDLE loader_platform_thread; |
224 | | |
225 | | // Thread IDs: |
226 | | typedef DWORD loader_platform_thread_id; |
227 | | |
228 | | // Thread mutex: |
229 | | typedef CRITICAL_SECTION loader_platform_thread_mutex; |
230 | | |
231 | | typedef CONDITION_VARIABLE loader_platform_thread_cond; |
232 | | |
233 | | #else |
234 | | |
235 | | #warning The "vk_loader_platform.h" file must be modified for this OS. |
236 | | |
237 | | // NOTE: In order to support another OS, an #elif needs to be added (above the |
238 | | // "#else // defined(_WIN32)") for that OS, and OS-specific versions of the |
239 | | // contents of this file must be created, or extend one of the existing OS specific |
240 | | // sections with the necessary changes. |
241 | | |
242 | | #endif |
243 | | |
244 | | // controls whether loader_platform_close_library() closes the libraries or not - controlled by an environment variables |
245 | | extern bool loader_disable_dynamic_library_unloading; |
246 | | |
247 | | // Returns true if the DIRECTORY_SYMBOL is contained within path |
248 | 130k | static inline bool loader_platform_is_path(const char *path) { return strchr(path, DIRECTORY_SYMBOL) != NULL; }Unexecuted instantiation: instance_enumerate_fuzzer.c:loader_platform_is_path Unexecuted instantiation: trampoline.c:loader_platform_is_path Unexecuted instantiation: allocation.c:loader_platform_is_path Unexecuted instantiation: debug_utils.c:loader_platform_is_path Unexecuted instantiation: gpa_helper.c:loader_platform_is_path loader.c:loader_platform_is_path Line | Count | Source | 248 | 130k | static inline bool loader_platform_is_path(const char *path) { return strchr(path, DIRECTORY_SYMBOL) != NULL; } |
Unexecuted instantiation: loader_environment.c:loader_platform_is_path Unexecuted instantiation: loader_json.c:loader_platform_is_path Unexecuted instantiation: loader_linux.c:loader_platform_is_path Unexecuted instantiation: log.c:loader_platform_is_path Unexecuted instantiation: settings.c:loader_platform_is_path Unexecuted instantiation: terminator.c:loader_platform_is_path Unexecuted instantiation: unknown_function_handling.c:loader_platform_is_path Unexecuted instantiation: wsi.c:loader_platform_is_path Unexecuted instantiation: cJSON.c:loader_platform_is_path Unexecuted instantiation: extension_manual.c:loader_platform_is_path Unexecuted instantiation: json_load_fuzzer.c:loader_platform_is_path Unexecuted instantiation: settings_fuzzer.c:loader_platform_is_path Unexecuted instantiation: instance_create_advanced_fuzzer.c:loader_platform_is_path Unexecuted instantiation: instance_create_fuzzer.c:loader_platform_is_path |
249 | | |
250 | | // The loader has various initialization tasks which it must do before user code can run. This includes initializing synchronization |
251 | | // objects, determining the log level, writing the version of the loader to the log, and loading dll's (on windows). On linux, the |
252 | | // solution is simply running the initialization code in __attribute__((constructor)), which MacOS uses when the loader is |
253 | | // dynamically linked. When statically linking on MacOS, the setup code instead uses pthread_once to run the logic a single time |
254 | | // regardless of which API function the application calls first. On Windows, the equivalent way to run code at dll load time is |
255 | | // DllMain which has many limitations placed upon it. Instead, the Windows code follows MacOS and does initialization in the first |
256 | | // API call made, using InitOnceExecuteOnce, except for initialization primitives which must be done in DllMain. This is because |
257 | | // there is no way to clean up the resources allocated by anything allocated by once init. |
258 | | |
259 | | #if defined(APPLE_STATIC_LOADER) |
260 | | static inline void loader_platform_thread_once_fn(pthread_once_t *ctl, void (*func)(void)) { |
261 | | assert(func != NULL); |
262 | | assert(ctl != NULL); |
263 | | pthread_once(ctl, func); |
264 | | } |
265 | | #define LOADER_PLATFORM_THREAD_ONCE_DECLARATION(var) pthread_once_t var = PTHREAD_ONCE_INIT; |
266 | | #define LOADER_PLATFORM_THREAD_ONCE_EXTERN_DEFINITION(var) extern pthread_once_t var; |
267 | | #define LOADER_PLATFORM_THREAD_ONCE(ctl, func) loader_platform_thread_once_fn(ctl, func); |
268 | | #elif defined(WIN32) |
269 | | static inline void loader_platform_thread_win32_once_fn(INIT_ONCE *ctl, PINIT_ONCE_FN func) { |
270 | | InitOnceExecuteOnce(ctl, func, NULL, NULL); |
271 | | } |
272 | | #define LOADER_PLATFORM_THREAD_ONCE_DECLARATION(var) INIT_ONCE var = INIT_ONCE_STATIC_INIT; |
273 | | #define LOADER_PLATFORM_THREAD_ONCE_EXTERN_DEFINITION(var) extern INIT_ONCE var; |
274 | | #define LOADER_PLATFORM_THREAD_ONCE(ctl, func) loader_platform_thread_win32_once_fn(ctl, func); |
275 | | #else |
276 | | #define LOADER_PLATFORM_THREAD_ONCE_DECLARATION(var) |
277 | | #define LOADER_PLATFORM_THREAD_ONCE_EXTERN_DEFINITION(var) |
278 | | #define LOADER_PLATFORM_THREAD_ONCE(ctl, func) |
279 | | |
280 | | #endif |
281 | | |
282 | | #if COMMON_UNIX_PLATFORMS |
283 | | |
284 | | // File IO |
285 | 215k | static inline bool loader_platform_file_exists(const char *path) { |
286 | 215k | if (access(path, F_OK)) |
287 | 56.3k | return false; |
288 | 159k | else |
289 | 159k | return true; |
290 | 215k | } Unexecuted instantiation: instance_enumerate_fuzzer.c:loader_platform_file_exists Unexecuted instantiation: trampoline.c:loader_platform_file_exists Unexecuted instantiation: allocation.c:loader_platform_file_exists Unexecuted instantiation: debug_utils.c:loader_platform_file_exists Unexecuted instantiation: gpa_helper.c:loader_platform_file_exists loader.c:loader_platform_file_exists Line | Count | Source | 285 | 130k | static inline bool loader_platform_file_exists(const char *path) { | 286 | 130k | if (access(path, F_OK)) | 287 | 1.68k | return false; | 288 | 128k | else | 289 | 128k | return true; | 290 | 130k | } |
Unexecuted instantiation: loader_environment.c:loader_platform_file_exists Unexecuted instantiation: loader_json.c:loader_platform_file_exists Unexecuted instantiation: loader_linux.c:loader_platform_file_exists Unexecuted instantiation: log.c:loader_platform_file_exists settings.c:loader_platform_file_exists Line | Count | Source | 285 | 85.3k | static inline bool loader_platform_file_exists(const char *path) { | 286 | 85.3k | if (access(path, F_OK)) | 287 | 54.6k | return false; | 288 | 30.6k | else | 289 | 30.6k | return true; | 290 | 85.3k | } |
Unexecuted instantiation: terminator.c:loader_platform_file_exists Unexecuted instantiation: unknown_function_handling.c:loader_platform_file_exists Unexecuted instantiation: wsi.c:loader_platform_file_exists Unexecuted instantiation: cJSON.c:loader_platform_file_exists Unexecuted instantiation: extension_manual.c:loader_platform_file_exists Unexecuted instantiation: json_load_fuzzer.c:loader_platform_file_exists Unexecuted instantiation: settings_fuzzer.c:loader_platform_file_exists Unexecuted instantiation: instance_create_advanced_fuzzer.c:loader_platform_file_exists Unexecuted instantiation: instance_create_fuzzer.c:loader_platform_file_exists |
291 | | |
292 | | // Returns true if the given string appears to be a relative or absolute |
293 | | // path, as opposed to a bare filename. |
294 | 28.2k | static inline bool loader_platform_is_path_absolute(const char *path) { |
295 | 28.2k | if (path[0] == '/') |
296 | 2.50k | return true; |
297 | 25.7k | else |
298 | 25.7k | return false; |
299 | 28.2k | } Unexecuted instantiation: instance_enumerate_fuzzer.c:loader_platform_is_path_absolute Unexecuted instantiation: trampoline.c:loader_platform_is_path_absolute Unexecuted instantiation: allocation.c:loader_platform_is_path_absolute Unexecuted instantiation: debug_utils.c:loader_platform_is_path_absolute Unexecuted instantiation: gpa_helper.c:loader_platform_is_path_absolute loader.c:loader_platform_is_path_absolute Line | Count | Source | 294 | 28.2k | static inline bool loader_platform_is_path_absolute(const char *path) { | 295 | 28.2k | if (path[0] == '/') | 296 | 2.50k | return true; | 297 | 25.7k | else | 298 | 25.7k | return false; | 299 | 28.2k | } |
Unexecuted instantiation: loader_environment.c:loader_platform_is_path_absolute Unexecuted instantiation: loader_json.c:loader_platform_is_path_absolute Unexecuted instantiation: loader_linux.c:loader_platform_is_path_absolute Unexecuted instantiation: log.c:loader_platform_is_path_absolute Unexecuted instantiation: settings.c:loader_platform_is_path_absolute Unexecuted instantiation: terminator.c:loader_platform_is_path_absolute Unexecuted instantiation: unknown_function_handling.c:loader_platform_is_path_absolute Unexecuted instantiation: wsi.c:loader_platform_is_path_absolute Unexecuted instantiation: cJSON.c:loader_platform_is_path_absolute Unexecuted instantiation: extension_manual.c:loader_platform_is_path_absolute Unexecuted instantiation: json_load_fuzzer.c:loader_platform_is_path_absolute Unexecuted instantiation: settings_fuzzer.c:loader_platform_is_path_absolute Unexecuted instantiation: instance_create_advanced_fuzzer.c:loader_platform_is_path_absolute Unexecuted instantiation: instance_create_fuzzer.c:loader_platform_is_path_absolute |
300 | | |
301 | 0 | static inline char *loader_platform_dirname(char *path) { return dirname(path); }Unexecuted instantiation: instance_enumerate_fuzzer.c:loader_platform_dirname Unexecuted instantiation: trampoline.c:loader_platform_dirname Unexecuted instantiation: allocation.c:loader_platform_dirname Unexecuted instantiation: debug_utils.c:loader_platform_dirname Unexecuted instantiation: gpa_helper.c:loader_platform_dirname Unexecuted instantiation: loader.c:loader_platform_dirname Unexecuted instantiation: loader_environment.c:loader_platform_dirname Unexecuted instantiation: loader_json.c:loader_platform_dirname Unexecuted instantiation: loader_linux.c:loader_platform_dirname Unexecuted instantiation: log.c:loader_platform_dirname Unexecuted instantiation: settings.c:loader_platform_dirname Unexecuted instantiation: terminator.c:loader_platform_dirname Unexecuted instantiation: unknown_function_handling.c:loader_platform_dirname Unexecuted instantiation: wsi.c:loader_platform_dirname Unexecuted instantiation: cJSON.c:loader_platform_dirname Unexecuted instantiation: extension_manual.c:loader_platform_dirname Unexecuted instantiation: json_load_fuzzer.c:loader_platform_dirname Unexecuted instantiation: settings_fuzzer.c:loader_platform_dirname Unexecuted instantiation: instance_create_advanced_fuzzer.c:loader_platform_dirname Unexecuted instantiation: instance_create_fuzzer.c:loader_platform_dirname |
302 | | |
303 | | // loader_platform_executable_path finds application path + name. |
304 | | // Path cannot be longer than 1024, returns NULL if it is greater than that. |
305 | | #if defined(__linux__) || defined(__GNU__) || defined(__CYGWIN__) |
306 | 51.9k | static inline char *loader_platform_executable_path(char *buffer, size_t size) { |
307 | 51.9k | ssize_t count = readlink("/proc/self/exe", buffer, size); |
308 | 51.9k | if (count == -1) return NULL; |
309 | 51.9k | if (count == 0) return NULL; |
310 | 51.9k | buffer[count] = '\0'; |
311 | 51.9k | return buffer; |
312 | 51.9k | } Unexecuted instantiation: instance_enumerate_fuzzer.c:loader_platform_executable_path Unexecuted instantiation: trampoline.c:loader_platform_executable_path Unexecuted instantiation: allocation.c:loader_platform_executable_path Unexecuted instantiation: debug_utils.c:loader_platform_executable_path Unexecuted instantiation: gpa_helper.c:loader_platform_executable_path loader.c:loader_platform_executable_path Line | Count | Source | 306 | 32.8k | static inline char *loader_platform_executable_path(char *buffer, size_t size) { | 307 | 32.8k | ssize_t count = readlink("/proc/self/exe", buffer, size); | 308 | 32.8k | if (count == -1) return NULL; | 309 | 32.8k | if (count == 0) return NULL; | 310 | 32.8k | buffer[count] = '\0'; | 311 | 32.8k | return buffer; | 312 | 32.8k | } |
Unexecuted instantiation: loader_environment.c:loader_platform_executable_path Unexecuted instantiation: loader_json.c:loader_platform_executable_path Unexecuted instantiation: loader_linux.c:loader_platform_executable_path Unexecuted instantiation: log.c:loader_platform_executable_path settings.c:loader_platform_executable_path Line | Count | Source | 306 | 19.1k | static inline char *loader_platform_executable_path(char *buffer, size_t size) { | 307 | 19.1k | ssize_t count = readlink("/proc/self/exe", buffer, size); | 308 | 19.1k | if (count == -1) return NULL; | 309 | 19.1k | if (count == 0) return NULL; | 310 | 19.1k | buffer[count] = '\0'; | 311 | 19.1k | return buffer; | 312 | 19.1k | } |
Unexecuted instantiation: terminator.c:loader_platform_executable_path Unexecuted instantiation: unknown_function_handling.c:loader_platform_executable_path Unexecuted instantiation: wsi.c:loader_platform_executable_path Unexecuted instantiation: cJSON.c:loader_platform_executable_path Unexecuted instantiation: extension_manual.c:loader_platform_executable_path Unexecuted instantiation: json_load_fuzzer.c:loader_platform_executable_path Unexecuted instantiation: settings_fuzzer.c:loader_platform_executable_path Unexecuted instantiation: instance_create_advanced_fuzzer.c:loader_platform_executable_path Unexecuted instantiation: instance_create_fuzzer.c:loader_platform_executable_path |
313 | | #elif defined(__APPLE__) |
314 | | #include <TargetConditionals.h> |
315 | | // TARGET_OS_IPHONE isn't just iOS it's also iOS/tvOS/watchOS. See TargetConditionals.h documentation. |
316 | | #if TARGET_OS_IPHONE |
317 | | static inline char *loader_platform_executable_path(char *buffer, size_t size) { |
318 | | (void)size; |
319 | | buffer[0] = '\0'; |
320 | | return buffer; |
321 | | } |
322 | | #endif |
323 | | #if TARGET_OS_OSX |
324 | | #include <libproc.h> |
325 | | static inline char *loader_platform_executable_path(char *buffer, size_t size) { |
326 | | // proc_pidpath takes a uint32_t for the buffer size |
327 | | if (size > UINT32_MAX) { |
328 | | return NULL; |
329 | | } |
330 | | pid_t pid = getpid(); |
331 | | int ret = proc_pidpath(pid, buffer, (uint32_t)size); |
332 | | if (ret <= 0) { |
333 | | return NULL; |
334 | | } |
335 | | buffer[ret] = '\0'; |
336 | | return buffer; |
337 | | } |
338 | | #endif |
339 | | #elif defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) |
340 | | #include <sys/sysctl.h> |
341 | | static inline char *loader_platform_executable_path(char *buffer, size_t size) { |
342 | | int mib[] = { |
343 | | CTL_KERN, |
344 | | #if defined(__NetBSD__) |
345 | | KERN_PROC_ARGS, |
346 | | -1, |
347 | | KERN_PROC_PATHNAME, |
348 | | #else |
349 | | KERN_PROC, |
350 | | KERN_PROC_PATHNAME, |
351 | | -1, |
352 | | #endif |
353 | | }; |
354 | | if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), buffer, &size, NULL, 0) < 0) { |
355 | | return NULL; |
356 | | } |
357 | | |
358 | | return buffer; |
359 | | } |
360 | | #elif defined(__Fuchsia__) || defined(__OpenBSD__) |
361 | | static inline char *loader_platform_executable_path(char *buffer, size_t size) { return NULL; } |
362 | | #elif defined(__QNX__) |
363 | | |
364 | | #ifndef SYSCONFDIR |
365 | | #define SYSCONFDIR "/etc" |
366 | | #endif |
367 | | |
368 | | #include <fcntl.h> |
369 | | #include <sys/stat.h> |
370 | | |
371 | | static inline char *loader_platform_executable_path(char *buffer, size_t size) { |
372 | | int fd = open("/proc/self/exefile", O_RDONLY); |
373 | | size_t rdsize; |
374 | | |
375 | | if (fd == -1) { |
376 | | return NULL; |
377 | | } |
378 | | |
379 | | rdsize = read(fd, buffer, size); |
380 | | if (rdsize == size) { |
381 | | return NULL; |
382 | | } |
383 | | buffer[rdsize] = 0x00; |
384 | | close(fd); |
385 | | |
386 | | return buffer; |
387 | | } |
388 | | #endif // defined (__QNX__) |
389 | | |
390 | | // Compatibility with compilers that don't support __has_feature |
391 | | #if !defined(__has_feature) |
392 | | #define __has_feature(x) 0 |
393 | | #endif |
394 | | |
395 | | #if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__) |
396 | | #define LOADER_ADDRESS_SANITIZER_ACTIVE // TODO: Add proper build flag for ASAN support |
397 | | #endif |
398 | | |
399 | | // When loading the library, we use RTLD_LAZY so that not all symbols have to be |
400 | | // resolved at this time (which improves performance). Note that if not all symbols |
401 | | // can be resolved, this could cause crashes later. Use the LD_BIND_NOW environment |
402 | | // variable to force all symbols to be resolved here. |
403 | 76 | #define LOADER_DLOPEN_MODE (RTLD_LAZY | RTLD_LOCAL) |
404 | | |
405 | | #if defined(__Fuchsia__) |
406 | | static inline loader_platform_dl_handle loader_platform_open_driver(const char *libPath) { |
407 | | return dlopen_fuchsia(libPath, LOADER_DLOPEN_MODE, true); |
408 | | } |
409 | | static inline loader_platform_dl_handle loader_platform_open_library(const char *libPath) { |
410 | | return dlopen_fuchsia(libPath, LOADER_DLOPEN_MODE, false); |
411 | | } |
412 | | #else |
413 | 76 | static inline loader_platform_dl_handle loader_platform_open_library(const char *libPath) { |
414 | 76 | return dlopen(libPath, LOADER_DLOPEN_MODE); |
415 | 76 | } Unexecuted instantiation: instance_enumerate_fuzzer.c:loader_platform_open_library Unexecuted instantiation: trampoline.c:loader_platform_open_library Unexecuted instantiation: allocation.c:loader_platform_open_library Unexecuted instantiation: debug_utils.c:loader_platform_open_library Unexecuted instantiation: gpa_helper.c:loader_platform_open_library loader.c:loader_platform_open_library Line | Count | Source | 413 | 76 | static inline loader_platform_dl_handle loader_platform_open_library(const char *libPath) { | 414 | | return dlopen(libPath, LOADER_DLOPEN_MODE); | 415 | 76 | } |
Unexecuted instantiation: loader_environment.c:loader_platform_open_library Unexecuted instantiation: loader_json.c:loader_platform_open_library Unexecuted instantiation: loader_linux.c:loader_platform_open_library Unexecuted instantiation: log.c:loader_platform_open_library Unexecuted instantiation: settings.c:loader_platform_open_library Unexecuted instantiation: terminator.c:loader_platform_open_library Unexecuted instantiation: unknown_function_handling.c:loader_platform_open_library Unexecuted instantiation: wsi.c:loader_platform_open_library Unexecuted instantiation: cJSON.c:loader_platform_open_library Unexecuted instantiation: extension_manual.c:loader_platform_open_library Unexecuted instantiation: json_load_fuzzer.c:loader_platform_open_library Unexecuted instantiation: settings_fuzzer.c:loader_platform_open_library Unexecuted instantiation: instance_create_advanced_fuzzer.c:loader_platform_open_library Unexecuted instantiation: instance_create_fuzzer.c:loader_platform_open_library |
416 | | #endif |
417 | | |
418 | 76 | static inline const char *loader_platform_open_library_error(const char *libPath) { |
419 | 76 | (void)libPath; |
420 | | #if defined(__Fuchsia__) |
421 | | return dlerror_fuchsia(); |
422 | | #else |
423 | 76 | return dlerror(); |
424 | 76 | #endif |
425 | 76 | } Unexecuted instantiation: instance_enumerate_fuzzer.c:loader_platform_open_library_error Unexecuted instantiation: trampoline.c:loader_platform_open_library_error Unexecuted instantiation: allocation.c:loader_platform_open_library_error Unexecuted instantiation: debug_utils.c:loader_platform_open_library_error Unexecuted instantiation: gpa_helper.c:loader_platform_open_library_error loader.c:loader_platform_open_library_error Line | Count | Source | 418 | 76 | static inline const char *loader_platform_open_library_error(const char *libPath) { | 419 | 76 | (void)libPath; | 420 | | #if defined(__Fuchsia__) | 421 | | return dlerror_fuchsia(); | 422 | | #else | 423 | 76 | return dlerror(); | 424 | 76 | #endif | 425 | 76 | } |
Unexecuted instantiation: loader_environment.c:loader_platform_open_library_error Unexecuted instantiation: loader_json.c:loader_platform_open_library_error Unexecuted instantiation: loader_linux.c:loader_platform_open_library_error Unexecuted instantiation: log.c:loader_platform_open_library_error Unexecuted instantiation: settings.c:loader_platform_open_library_error Unexecuted instantiation: terminator.c:loader_platform_open_library_error Unexecuted instantiation: unknown_function_handling.c:loader_platform_open_library_error Unexecuted instantiation: wsi.c:loader_platform_open_library_error Unexecuted instantiation: cJSON.c:loader_platform_open_library_error Unexecuted instantiation: extension_manual.c:loader_platform_open_library_error Unexecuted instantiation: json_load_fuzzer.c:loader_platform_open_library_error Unexecuted instantiation: settings_fuzzer.c:loader_platform_open_library_error Unexecuted instantiation: instance_create_advanced_fuzzer.c:loader_platform_open_library_error Unexecuted instantiation: instance_create_fuzzer.c:loader_platform_open_library_error |
426 | 0 | static inline void loader_platform_close_library(loader_platform_dl_handle library) { |
427 | 0 | if (!loader_disable_dynamic_library_unloading) { |
428 | 0 | dlclose(library); |
429 | 0 | } else { |
430 | 0 | (void)library; |
431 | 0 | } |
432 | 0 | } Unexecuted instantiation: instance_enumerate_fuzzer.c:loader_platform_close_library Unexecuted instantiation: trampoline.c:loader_platform_close_library Unexecuted instantiation: allocation.c:loader_platform_close_library Unexecuted instantiation: debug_utils.c:loader_platform_close_library Unexecuted instantiation: gpa_helper.c:loader_platform_close_library Unexecuted instantiation: loader.c:loader_platform_close_library Unexecuted instantiation: loader_environment.c:loader_platform_close_library Unexecuted instantiation: loader_json.c:loader_platform_close_library Unexecuted instantiation: loader_linux.c:loader_platform_close_library Unexecuted instantiation: log.c:loader_platform_close_library Unexecuted instantiation: settings.c:loader_platform_close_library Unexecuted instantiation: terminator.c:loader_platform_close_library Unexecuted instantiation: unknown_function_handling.c:loader_platform_close_library Unexecuted instantiation: wsi.c:loader_platform_close_library Unexecuted instantiation: cJSON.c:loader_platform_close_library Unexecuted instantiation: extension_manual.c:loader_platform_close_library Unexecuted instantiation: json_load_fuzzer.c:loader_platform_close_library Unexecuted instantiation: settings_fuzzer.c:loader_platform_close_library Unexecuted instantiation: instance_create_advanced_fuzzer.c:loader_platform_close_library Unexecuted instantiation: instance_create_fuzzer.c:loader_platform_close_library |
433 | 0 | static inline void *loader_platform_get_proc_address(loader_platform_dl_handle library, const char *name) { |
434 | 0 | assert(library); |
435 | 0 | assert(name); |
436 | 0 | return dlsym(library, name); |
437 | 0 | } Unexecuted instantiation: instance_enumerate_fuzzer.c:loader_platform_get_proc_address Unexecuted instantiation: trampoline.c:loader_platform_get_proc_address Unexecuted instantiation: allocation.c:loader_platform_get_proc_address Unexecuted instantiation: debug_utils.c:loader_platform_get_proc_address Unexecuted instantiation: gpa_helper.c:loader_platform_get_proc_address Unexecuted instantiation: loader.c:loader_platform_get_proc_address Unexecuted instantiation: loader_environment.c:loader_platform_get_proc_address Unexecuted instantiation: loader_json.c:loader_platform_get_proc_address Unexecuted instantiation: loader_linux.c:loader_platform_get_proc_address Unexecuted instantiation: log.c:loader_platform_get_proc_address Unexecuted instantiation: settings.c:loader_platform_get_proc_address Unexecuted instantiation: terminator.c:loader_platform_get_proc_address Unexecuted instantiation: unknown_function_handling.c:loader_platform_get_proc_address Unexecuted instantiation: wsi.c:loader_platform_get_proc_address Unexecuted instantiation: cJSON.c:loader_platform_get_proc_address Unexecuted instantiation: extension_manual.c:loader_platform_get_proc_address Unexecuted instantiation: json_load_fuzzer.c:loader_platform_get_proc_address Unexecuted instantiation: settings_fuzzer.c:loader_platform_get_proc_address Unexecuted instantiation: instance_create_advanced_fuzzer.c:loader_platform_get_proc_address Unexecuted instantiation: instance_create_fuzzer.c:loader_platform_get_proc_address |
438 | 0 | static inline const char *loader_platform_get_proc_address_error(const char *name) { |
439 | 0 | (void)name; |
440 | 0 | return dlerror(); |
441 | 0 | } Unexecuted instantiation: instance_enumerate_fuzzer.c:loader_platform_get_proc_address_error Unexecuted instantiation: trampoline.c:loader_platform_get_proc_address_error Unexecuted instantiation: allocation.c:loader_platform_get_proc_address_error Unexecuted instantiation: debug_utils.c:loader_platform_get_proc_address_error Unexecuted instantiation: gpa_helper.c:loader_platform_get_proc_address_error Unexecuted instantiation: loader.c:loader_platform_get_proc_address_error Unexecuted instantiation: loader_environment.c:loader_platform_get_proc_address_error Unexecuted instantiation: loader_json.c:loader_platform_get_proc_address_error Unexecuted instantiation: loader_linux.c:loader_platform_get_proc_address_error Unexecuted instantiation: log.c:loader_platform_get_proc_address_error Unexecuted instantiation: settings.c:loader_platform_get_proc_address_error Unexecuted instantiation: terminator.c:loader_platform_get_proc_address_error Unexecuted instantiation: unknown_function_handling.c:loader_platform_get_proc_address_error Unexecuted instantiation: wsi.c:loader_platform_get_proc_address_error Unexecuted instantiation: cJSON.c:loader_platform_get_proc_address_error Unexecuted instantiation: extension_manual.c:loader_platform_get_proc_address_error Unexecuted instantiation: json_load_fuzzer.c:loader_platform_get_proc_address_error Unexecuted instantiation: settings_fuzzer.c:loader_platform_get_proc_address_error Unexecuted instantiation: instance_create_advanced_fuzzer.c:loader_platform_get_proc_address_error Unexecuted instantiation: instance_create_fuzzer.c:loader_platform_get_proc_address_error |
442 | | |
443 | | // Thread mutex: |
444 | 48 | static inline void loader_platform_thread_create_mutex(loader_platform_thread_mutex *pMutex) { pthread_mutex_init(pMutex, NULL); }Unexecuted instantiation: instance_enumerate_fuzzer.c:loader_platform_thread_create_mutex Unexecuted instantiation: trampoline.c:loader_platform_thread_create_mutex Unexecuted instantiation: allocation.c:loader_platform_thread_create_mutex Unexecuted instantiation: debug_utils.c:loader_platform_thread_create_mutex Unexecuted instantiation: gpa_helper.c:loader_platform_thread_create_mutex loader.c:loader_platform_thread_create_mutex Line | Count | Source | 444 | 36 | static inline void loader_platform_thread_create_mutex(loader_platform_thread_mutex *pMutex) { pthread_mutex_init(pMutex, NULL); } |
Unexecuted instantiation: loader_environment.c:loader_platform_thread_create_mutex Unexecuted instantiation: loader_json.c:loader_platform_thread_create_mutex Unexecuted instantiation: loader_linux.c:loader_platform_thread_create_mutex Unexecuted instantiation: log.c:loader_platform_thread_create_mutex settings.c:loader_platform_thread_create_mutex Line | Count | Source | 444 | 12 | static inline void loader_platform_thread_create_mutex(loader_platform_thread_mutex *pMutex) { pthread_mutex_init(pMutex, NULL); } |
Unexecuted instantiation: terminator.c:loader_platform_thread_create_mutex Unexecuted instantiation: unknown_function_handling.c:loader_platform_thread_create_mutex Unexecuted instantiation: wsi.c:loader_platform_thread_create_mutex Unexecuted instantiation: cJSON.c:loader_platform_thread_create_mutex Unexecuted instantiation: extension_manual.c:loader_platform_thread_create_mutex Unexecuted instantiation: json_load_fuzzer.c:loader_platform_thread_create_mutex Unexecuted instantiation: settings_fuzzer.c:loader_platform_thread_create_mutex Unexecuted instantiation: instance_create_advanced_fuzzer.c:loader_platform_thread_create_mutex Unexecuted instantiation: instance_create_fuzzer.c:loader_platform_thread_create_mutex |
445 | 78.8k | static inline void loader_platform_thread_lock_mutex(loader_platform_thread_mutex *pMutex) { pthread_mutex_lock(pMutex); }Unexecuted instantiation: instance_enumerate_fuzzer.c:loader_platform_thread_lock_mutex trampoline.c:loader_platform_thread_lock_mutex Line | Count | Source | 445 | 28.0k | static inline void loader_platform_thread_lock_mutex(loader_platform_thread_mutex *pMutex) { pthread_mutex_lock(pMutex); } |
Unexecuted instantiation: allocation.c:loader_platform_thread_lock_mutex Unexecuted instantiation: debug_utils.c:loader_platform_thread_lock_mutex Unexecuted instantiation: gpa_helper.c:loader_platform_thread_lock_mutex Unexecuted instantiation: loader.c:loader_platform_thread_lock_mutex Unexecuted instantiation: loader_environment.c:loader_platform_thread_lock_mutex Unexecuted instantiation: loader_json.c:loader_platform_thread_lock_mutex Unexecuted instantiation: loader_linux.c:loader_platform_thread_lock_mutex Unexecuted instantiation: log.c:loader_platform_thread_lock_mutex settings.c:loader_platform_thread_lock_mutex Line | Count | Source | 445 | 50.8k | static inline void loader_platform_thread_lock_mutex(loader_platform_thread_mutex *pMutex) { pthread_mutex_lock(pMutex); } |
Unexecuted instantiation: terminator.c:loader_platform_thread_lock_mutex Unexecuted instantiation: unknown_function_handling.c:loader_platform_thread_lock_mutex Unexecuted instantiation: wsi.c:loader_platform_thread_lock_mutex Unexecuted instantiation: cJSON.c:loader_platform_thread_lock_mutex Unexecuted instantiation: extension_manual.c:loader_platform_thread_lock_mutex Unexecuted instantiation: json_load_fuzzer.c:loader_platform_thread_lock_mutex Unexecuted instantiation: settings_fuzzer.c:loader_platform_thread_lock_mutex Unexecuted instantiation: instance_create_advanced_fuzzer.c:loader_platform_thread_lock_mutex Unexecuted instantiation: instance_create_fuzzer.c:loader_platform_thread_lock_mutex |
446 | 78.8k | static inline void loader_platform_thread_unlock_mutex(loader_platform_thread_mutex *pMutex) { pthread_mutex_unlock(pMutex); }Unexecuted instantiation: instance_enumerate_fuzzer.c:loader_platform_thread_unlock_mutex trampoline.c:loader_platform_thread_unlock_mutex Line | Count | Source | 446 | 28.0k | static inline void loader_platform_thread_unlock_mutex(loader_platform_thread_mutex *pMutex) { pthread_mutex_unlock(pMutex); } |
Unexecuted instantiation: allocation.c:loader_platform_thread_unlock_mutex Unexecuted instantiation: debug_utils.c:loader_platform_thread_unlock_mutex Unexecuted instantiation: gpa_helper.c:loader_platform_thread_unlock_mutex Unexecuted instantiation: loader.c:loader_platform_thread_unlock_mutex Unexecuted instantiation: loader_environment.c:loader_platform_thread_unlock_mutex Unexecuted instantiation: loader_json.c:loader_platform_thread_unlock_mutex Unexecuted instantiation: loader_linux.c:loader_platform_thread_unlock_mutex Unexecuted instantiation: log.c:loader_platform_thread_unlock_mutex settings.c:loader_platform_thread_unlock_mutex Line | Count | Source | 446 | 50.8k | static inline void loader_platform_thread_unlock_mutex(loader_platform_thread_mutex *pMutex) { pthread_mutex_unlock(pMutex); } |
Unexecuted instantiation: terminator.c:loader_platform_thread_unlock_mutex Unexecuted instantiation: unknown_function_handling.c:loader_platform_thread_unlock_mutex Unexecuted instantiation: wsi.c:loader_platform_thread_unlock_mutex Unexecuted instantiation: cJSON.c:loader_platform_thread_unlock_mutex Unexecuted instantiation: extension_manual.c:loader_platform_thread_unlock_mutex Unexecuted instantiation: json_load_fuzzer.c:loader_platform_thread_unlock_mutex Unexecuted instantiation: settings_fuzzer.c:loader_platform_thread_unlock_mutex Unexecuted instantiation: instance_create_advanced_fuzzer.c:loader_platform_thread_unlock_mutex Unexecuted instantiation: instance_create_fuzzer.c:loader_platform_thread_unlock_mutex |
447 | 3.15k | static inline void loader_platform_thread_delete_mutex(loader_platform_thread_mutex *pMutex) { pthread_mutex_destroy(pMutex); }Unexecuted instantiation: instance_enumerate_fuzzer.c:loader_platform_thread_delete_mutex Unexecuted instantiation: trampoline.c:loader_platform_thread_delete_mutex Unexecuted instantiation: allocation.c:loader_platform_thread_delete_mutex Unexecuted instantiation: debug_utils.c:loader_platform_thread_delete_mutex Unexecuted instantiation: gpa_helper.c:loader_platform_thread_delete_mutex Unexecuted instantiation: loader.c:loader_platform_thread_delete_mutex Unexecuted instantiation: loader_environment.c:loader_platform_thread_delete_mutex Unexecuted instantiation: loader_json.c:loader_platform_thread_delete_mutex Unexecuted instantiation: loader_linux.c:loader_platform_thread_delete_mutex Unexecuted instantiation: log.c:loader_platform_thread_delete_mutex settings.c:loader_platform_thread_delete_mutex Line | Count | Source | 447 | 3.15k | static inline void loader_platform_thread_delete_mutex(loader_platform_thread_mutex *pMutex) { pthread_mutex_destroy(pMutex); } |
Unexecuted instantiation: terminator.c:loader_platform_thread_delete_mutex Unexecuted instantiation: unknown_function_handling.c:loader_platform_thread_delete_mutex Unexecuted instantiation: wsi.c:loader_platform_thread_delete_mutex Unexecuted instantiation: cJSON.c:loader_platform_thread_delete_mutex Unexecuted instantiation: extension_manual.c:loader_platform_thread_delete_mutex Unexecuted instantiation: json_load_fuzzer.c:loader_platform_thread_delete_mutex Unexecuted instantiation: settings_fuzzer.c:loader_platform_thread_delete_mutex Unexecuted instantiation: instance_create_advanced_fuzzer.c:loader_platform_thread_delete_mutex Unexecuted instantiation: instance_create_fuzzer.c:loader_platform_thread_delete_mutex |
448 | | |
449 | 350k | static inline void *thread_safe_strtok(char *str, const char *delim, char **saveptr) { return strtok_r(str, delim, saveptr); }Unexecuted instantiation: instance_enumerate_fuzzer.c:thread_safe_strtok Unexecuted instantiation: trampoline.c:thread_safe_strtok Unexecuted instantiation: allocation.c:thread_safe_strtok Unexecuted instantiation: debug_utils.c:thread_safe_strtok Unexecuted instantiation: gpa_helper.c:thread_safe_strtok loader.c:thread_safe_strtok Line | Count | Source | 449 | 279k | static inline void *thread_safe_strtok(char *str, const char *delim, char **saveptr) { return strtok_r(str, delim, saveptr); } |
loader_environment.c:thread_safe_strtok Line | Count | Source | 449 | 70.5k | static inline void *thread_safe_strtok(char *str, const char *delim, char **saveptr) { return strtok_r(str, delim, saveptr); } |
Unexecuted instantiation: loader_json.c:thread_safe_strtok Unexecuted instantiation: loader_linux.c:thread_safe_strtok Unexecuted instantiation: log.c:thread_safe_strtok Unexecuted instantiation: settings.c:thread_safe_strtok Unexecuted instantiation: terminator.c:thread_safe_strtok Unexecuted instantiation: unknown_function_handling.c:thread_safe_strtok Unexecuted instantiation: wsi.c:thread_safe_strtok Unexecuted instantiation: cJSON.c:thread_safe_strtok Unexecuted instantiation: extension_manual.c:thread_safe_strtok Unexecuted instantiation: json_load_fuzzer.c:thread_safe_strtok Unexecuted instantiation: settings_fuzzer.c:thread_safe_strtok Unexecuted instantiation: instance_create_advanced_fuzzer.c:thread_safe_strtok Unexecuted instantiation: instance_create_fuzzer.c:thread_safe_strtok |
450 | | |
451 | 0 | static inline FILE *loader_fopen(const char *fileName, const char *mode) { return fopen(fileName, mode); }Unexecuted instantiation: instance_enumerate_fuzzer.c:loader_fopen Unexecuted instantiation: trampoline.c:loader_fopen Unexecuted instantiation: allocation.c:loader_fopen Unexecuted instantiation: debug_utils.c:loader_fopen Unexecuted instantiation: gpa_helper.c:loader_fopen Unexecuted instantiation: loader.c:loader_fopen Unexecuted instantiation: loader_environment.c:loader_fopen Unexecuted instantiation: loader_json.c:loader_fopen Unexecuted instantiation: loader_linux.c:loader_fopen Unexecuted instantiation: log.c:loader_fopen Unexecuted instantiation: settings.c:loader_fopen Unexecuted instantiation: terminator.c:loader_fopen Unexecuted instantiation: unknown_function_handling.c:loader_fopen Unexecuted instantiation: wsi.c:loader_fopen Unexecuted instantiation: cJSON.c:loader_fopen Unexecuted instantiation: extension_manual.c:loader_fopen Unexecuted instantiation: json_load_fuzzer.c:loader_fopen Unexecuted instantiation: settings_fuzzer.c:loader_fopen Unexecuted instantiation: instance_create_advanced_fuzzer.c:loader_fopen Unexecuted instantiation: instance_create_fuzzer.c:loader_fopen |
452 | 6.04M | static inline char *loader_strncat(char *dest, size_t dest_sz, const char *src, size_t count) { |
453 | 6.04M | (void)dest_sz; |
454 | 6.04M | return strncat(dest, src, count); |
455 | 6.04M | } Unexecuted instantiation: instance_enumerate_fuzzer.c:loader_strncat Unexecuted instantiation: trampoline.c:loader_strncat Unexecuted instantiation: allocation.c:loader_strncat Unexecuted instantiation: debug_utils.c:loader_strncat Unexecuted instantiation: gpa_helper.c:loader_strncat Unexecuted instantiation: loader.c:loader_strncat Unexecuted instantiation: loader_environment.c:loader_strncat Unexecuted instantiation: loader_json.c:loader_strncat Unexecuted instantiation: loader_linux.c:loader_strncat Line | Count | Source | 452 | 5.95M | static inline char *loader_strncat(char *dest, size_t dest_sz, const char *src, size_t count) { | 453 | 5.95M | (void)dest_sz; | 454 | 5.95M | return strncat(dest, src, count); | 455 | 5.95M | } |
settings.c:loader_strncat Line | Count | Source | 452 | 85.3k | static inline char *loader_strncat(char *dest, size_t dest_sz, const char *src, size_t count) { | 453 | 85.3k | (void)dest_sz; | 454 | 85.3k | return strncat(dest, src, count); | 455 | 85.3k | } |
Unexecuted instantiation: terminator.c:loader_strncat Unexecuted instantiation: unknown_function_handling.c:loader_strncat Unexecuted instantiation: wsi.c:loader_strncat Unexecuted instantiation: cJSON.c:loader_strncat Unexecuted instantiation: extension_manual.c:loader_strncat Unexecuted instantiation: json_load_fuzzer.c:loader_strncat Unexecuted instantiation: settings_fuzzer.c:loader_strncat Unexecuted instantiation: instance_create_advanced_fuzzer.c:loader_strncat Unexecuted instantiation: instance_create_fuzzer.c:loader_strncat |
456 | 2.56M | static inline char *loader_strncpy(char *dest, size_t dest_sz, const char *src, size_t count) { |
457 | 2.56M | (void)dest_sz; |
458 | 2.56M | return strncpy(dest, src, count); |
459 | 2.56M | } Unexecuted instantiation: instance_enumerate_fuzzer.c:loader_strncpy Unexecuted instantiation: trampoline.c:loader_strncpy Unexecuted instantiation: allocation.c:loader_strncpy Unexecuted instantiation: debug_utils.c:loader_strncpy Unexecuted instantiation: gpa_helper.c:loader_strncpy Line | Count | Source | 456 | 2.39M | static inline char *loader_strncpy(char *dest, size_t dest_sz, const char *src, size_t count) { | 457 | 2.39M | (void)dest_sz; | 458 | 2.39M | return strncpy(dest, src, count); | 459 | 2.39M | } |
loader_environment.c:loader_strncpy Line | Count | Source | 456 | 35.2k | static inline char *loader_strncpy(char *dest, size_t dest_sz, const char *src, size_t count) { | 457 | 35.2k | (void)dest_sz; | 458 | 35.2k | return strncpy(dest, src, count); | 459 | 35.2k | } |
Unexecuted instantiation: loader_json.c:loader_strncpy Unexecuted instantiation: loader_linux.c:loader_strncpy Unexecuted instantiation: log.c:loader_strncpy settings.c:loader_strncpy Line | Count | Source | 456 | 137k | static inline char *loader_strncpy(char *dest, size_t dest_sz, const char *src, size_t count) { | 457 | 137k | (void)dest_sz; | 458 | 137k | return strncpy(dest, src, count); | 459 | 137k | } |
Unexecuted instantiation: terminator.c:loader_strncpy Unexecuted instantiation: unknown_function_handling.c:loader_strncpy Unexecuted instantiation: wsi.c:loader_strncpy Unexecuted instantiation: cJSON.c:loader_strncpy Unexecuted instantiation: extension_manual.c:loader_strncpy Unexecuted instantiation: json_load_fuzzer.c:loader_strncpy Unexecuted instantiation: settings_fuzzer.c:loader_strncpy Unexecuted instantiation: instance_create_advanced_fuzzer.c:loader_strncpy Unexecuted instantiation: instance_create_fuzzer.c:loader_strncpy |
460 | | |
461 | | #elif defined(_WIN32) |
462 | | |
463 | | // Get the key for the plug n play driver registry |
464 | | // The string returned by this function should NOT be freed |
465 | | static inline const char *LoaderPnpDriverRegistry() { |
466 | | BOOL is_wow; |
467 | | IsWow64Process(GetCurrentProcess(), &is_wow); |
468 | | return is_wow ? "Vulkan" VK_VARIANT_REG_STR "DriverNameWow" : "Vulkan" VK_VARIANT_REG_STR "DriverName"; |
469 | | } |
470 | | static inline const wchar_t *LoaderPnpDriverRegistryWide() { |
471 | | BOOL is_wow; |
472 | | IsWow64Process(GetCurrentProcess(), &is_wow); |
473 | | return is_wow ? L"Vulkan" VK_VARIANT_REG_STR_W L"DriverNameWow" : L"Vulkan" VK_VARIANT_REG_STR_W L"DriverName"; |
474 | | } |
475 | | |
476 | | // Get the key for the plug 'n play explicit layer registry |
477 | | // The string returned by this function should NOT be freed |
478 | | static inline const char *LoaderPnpELayerRegistry() { |
479 | | BOOL is_wow; |
480 | | IsWow64Process(GetCurrentProcess(), &is_wow); |
481 | | return is_wow ? "Vulkan" VK_VARIANT_REG_STR "ExplicitLayersWow" : "Vulkan" VK_VARIANT_REG_STR "ExplicitLayers"; |
482 | | } |
483 | | static inline const wchar_t *LoaderPnpELayerRegistryWide() { |
484 | | BOOL is_wow; |
485 | | IsWow64Process(GetCurrentProcess(), &is_wow); |
486 | | return is_wow ? L"Vulkan" VK_VARIANT_REG_STR_W L"ExplicitLayersWow" : L"Vulkan" VK_VARIANT_REG_STR_W L"ExplicitLayers"; |
487 | | } |
488 | | |
489 | | // Get the key for the plug 'n play implicit layer registry |
490 | | // The string returned by this function should NOT be freed |
491 | | static inline const char *LoaderPnpILayerRegistry() { |
492 | | BOOL is_wow; |
493 | | IsWow64Process(GetCurrentProcess(), &is_wow); |
494 | | return is_wow ? "Vulkan" VK_VARIANT_REG_STR "ImplicitLayersWow" : "Vulkan" VK_VARIANT_REG_STR "ImplicitLayers"; |
495 | | } |
496 | | static inline const wchar_t *LoaderPnpILayerRegistryWide() { |
497 | | BOOL is_wow; |
498 | | IsWow64Process(GetCurrentProcess(), &is_wow); |
499 | | return is_wow ? L"Vulkan" VK_VARIANT_REG_STR_W L"ImplicitLayersWow" : L"Vulkan" VK_VARIANT_REG_STR_W L"ImplicitLayers"; |
500 | | } |
501 | | |
502 | | // File IO |
503 | | static inline bool loader_platform_file_exists(const char *path) { |
504 | | int path_utf16_size = MultiByteToWideChar(CP_UTF8, 0, path, -1, NULL, 0); |
505 | | if (path_utf16_size <= 0) { |
506 | | return false; |
507 | | } |
508 | | wchar_t *path_utf16 = (wchar_t *)loader_stack_alloc(path_utf16_size * sizeof(wchar_t)); |
509 | | if (MultiByteToWideChar(CP_UTF8, 0, path, -1, path_utf16, path_utf16_size) != path_utf16_size) { |
510 | | return false; |
511 | | } |
512 | | if (_waccess(path_utf16, 0) == -1) |
513 | | return false; |
514 | | else |
515 | | return true; |
516 | | } |
517 | | |
518 | | // Returns true if the given string appears to be a relative or absolute |
519 | | // path, as opposed to a bare filename. |
520 | | static inline bool loader_platform_is_path_absolute(const char *path) { |
521 | | if (!path || !*path) { |
522 | | return false; |
523 | | } |
524 | | if (*path == DIRECTORY_SYMBOL || path[1] == ':') { |
525 | | return true; |
526 | | } |
527 | | return false; |
528 | | } |
529 | | |
530 | | // WIN32 runtime doesn't have dirname(). |
531 | | static inline char *loader_platform_dirname(char *path) { |
532 | | char *current, *next; |
533 | | |
534 | | // TODO/TBD: Do we need to deal with the Windows's ":" character? |
535 | | |
536 | | for (current = path; *current != '\0'; current = next) { |
537 | | next = strchr(current, DIRECTORY_SYMBOL); |
538 | | if (next == NULL) { |
539 | | if (current != path) *(current - 1) = '\0'; |
540 | | return path; |
541 | | } else { |
542 | | // Point one character past the DIRECTORY_SYMBOL: |
543 | | next++; |
544 | | } |
545 | | } |
546 | | return path; |
547 | | } |
548 | | |
549 | | static inline char *loader_platform_executable_path(char *buffer, size_t size) { |
550 | | wchar_t *buffer_utf16 = (wchar_t *)loader_stack_alloc(size * sizeof(wchar_t)); |
551 | | DWORD ret = GetModuleFileNameW(NULL, buffer_utf16, (DWORD)size); |
552 | | if (ret == 0) { |
553 | | return NULL; |
554 | | } |
555 | | if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { |
556 | | return NULL; |
557 | | } |
558 | | int buffer_utf8_size = WideCharToMultiByte(CP_UTF8, 0, buffer_utf16, -1, NULL, 0, NULL, NULL); |
559 | | if (buffer_utf8_size <= 0 || (size_t)buffer_utf8_size > size) { |
560 | | return NULL; |
561 | | } |
562 | | if (WideCharToMultiByte(CP_UTF8, 0, buffer_utf16, -1, buffer, buffer_utf8_size, NULL, NULL) != buffer_utf8_size) { |
563 | | return NULL; |
564 | | } |
565 | | return buffer; |
566 | | } |
567 | | |
568 | | // Dynamic Loading: |
569 | | static inline loader_platform_dl_handle loader_platform_open_library(const char *lib_path) { |
570 | | int lib_path_utf16_size = MultiByteToWideChar(CP_UTF8, 0, lib_path, -1, NULL, 0); |
571 | | if (lib_path_utf16_size <= 0) { |
572 | | return NULL; |
573 | | } |
574 | | wchar_t *lib_path_utf16 = (wchar_t *)loader_stack_alloc(lib_path_utf16_size * sizeof(wchar_t)); |
575 | | if (MultiByteToWideChar(CP_UTF8, 0, lib_path, -1, lib_path_utf16, lib_path_utf16_size) != lib_path_utf16_size) { |
576 | | return NULL; |
577 | | } |
578 | | // Try loading the library the original way first. |
579 | | loader_platform_dl_handle lib_handle = LoadLibraryW(lib_path_utf16); |
580 | | if (lib_handle == NULL && GetLastError() == ERROR_MOD_NOT_FOUND) { |
581 | | // If that failed, then try loading it with broader search folders. |
582 | | lib_handle = LoadLibraryExW(lib_path_utf16, NULL, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR); |
583 | | } |
584 | | return lib_handle; |
585 | | } |
586 | | static inline const char *loader_platform_open_library_error(const char *libPath) { |
587 | | static char errorMsg[512]; |
588 | | (void)snprintf(errorMsg, 511, "Failed to open dynamic library \"%s\" with error %lu", libPath, GetLastError()); |
589 | | return errorMsg; |
590 | | } |
591 | | static inline void loader_platform_close_library(loader_platform_dl_handle library) { |
592 | | if (!loader_disable_dynamic_library_unloading) { |
593 | | FreeLibrary(library); |
594 | | } else { |
595 | | (void)library; |
596 | | } |
597 | | } |
598 | | static inline void *loader_platform_get_proc_address(loader_platform_dl_handle library, const char *name) { |
599 | | assert(library); |
600 | | assert(name); |
601 | | return (void *)GetProcAddress(library, name); |
602 | | } |
603 | | static inline const char *loader_platform_get_proc_address_error(const char *name) { |
604 | | static char errorMsg[120]; |
605 | | (void)snprintf(errorMsg, 119, "Failed to find function \"%s\" in dynamic library", name); |
606 | | return errorMsg; |
607 | | } |
608 | | |
609 | | // Thread mutex: |
610 | | static inline void loader_platform_thread_create_mutex(loader_platform_thread_mutex *pMutex) { InitializeCriticalSection(pMutex); } |
611 | | static inline void loader_platform_thread_lock_mutex(loader_platform_thread_mutex *pMutex) { EnterCriticalSection(pMutex); } |
612 | | static inline void loader_platform_thread_unlock_mutex(loader_platform_thread_mutex *pMutex) { LeaveCriticalSection(pMutex); } |
613 | | static inline void loader_platform_thread_delete_mutex(loader_platform_thread_mutex *pMutex) { DeleteCriticalSection(pMutex); } |
614 | | |
615 | | static inline void *thread_safe_strtok(char *str, const char *delimiters, char **context) { |
616 | | return strtok_s(str, delimiters, context); |
617 | | } |
618 | | |
619 | | static inline FILE *loader_fopen(const char *fileName, const char *mode) { |
620 | | FILE *file = NULL; |
621 | | errno_t err = fopen_s(&file, fileName, mode); |
622 | | if (err != 0) return NULL; |
623 | | return file; |
624 | | } |
625 | | |
626 | | static inline char *loader_strncat(char *dest, size_t dest_sz, const char *src, size_t count) { |
627 | | errno_t err = strncat_s(dest, dest_sz, src, count); |
628 | | if (err != 0) return NULL; |
629 | | return dest; |
630 | | } |
631 | | |
632 | | static inline char *loader_strncpy(char *dest, size_t dest_sz, const char *src, size_t count) { |
633 | | errno_t err = strncpy_s(dest, dest_sz, src, count); |
634 | | if (err != 0) return NULL; |
635 | | return dest; |
636 | | } |
637 | | |
638 | | #else // defined(_WIN32) |
639 | | |
640 | | #warning The "vk_loader_platform.h" file must be modified for this OS. |
641 | | |
642 | | // NOTE: In order to support another OS, an #elif needs to be added (above the |
643 | | // "#else // defined(_WIN32)") for that OS, and OS-specific versions of the |
644 | | // contents of this file must be created. |
645 | | |
646 | | // NOTE: Other OS-specific changes are also needed for this OS. Search for |
647 | | // files with "WIN32" in it, as a quick way to find files that must be changed. |
648 | | |
649 | | #endif // defined(_WIN32) |