Coverage Report

Created: 2025-07-18 06:36

/src/vulkan-loader/loader/vk_loader_platform.h
Line
Count
Source (jump to first uncovered line)
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__)
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.12k
#define VK_ICD_FILENAMES_ENV_VAR "VK_ICD_FILENAMES"  // Deprecated in v1.3.207 loader
113
1.12k
#define VK_DRIVER_FILES_ENV_VAR "VK_DRIVER_FILES"
114
23.7k
#define VK_EXPLICIT_LAYER_PATH_ENV_VAR "VK_LAYER_PATH"
115
// Support added in v1.3.207 loader
116
1.12k
#define VK_ADDITIONAL_DRIVER_FILES_ENV_VAR "VK_ADD_DRIVER_FILES"
117
23.7k
#define VK_ADDITIONAL_EXPLICIT_LAYER_PATH_ENV_VAR "VK_ADD_LAYER_PATH"
118
// Support added in v1.3.234 loader
119
33.6k
#define VK_LAYERS_ENABLE_ENV_VAR "VK_LOADER_LAYERS_ENABLE"
120
32.8k
#define VK_LAYERS_DISABLE_ENV_VAR "VK_LOADER_LAYERS_DISABLE"
121
32.8k
#define VK_LAYERS_ALLOW_ENV_VAR "VK_LOADER_LAYERS_ALLOW"
122
1.12k
#define VK_DRIVERS_SELECT_ENV_VAR "VK_LOADER_DRIVERS_SELECT"
123
1.12k
#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
31.0k
#define VK_IMPLICIT_LAYER_PATH_ENV_VAR "VK_IMPLICIT_LAYER_PATH"
131
31.0k
#define VK_ADDITIONAL_IMPLICIT_LAYER_PATH_ENV_VAR "VK_ADD_IMPLICIT_LAYER_PATH"
132
133
// Override layer information
134
4.50M
#define VK_OVERRIDE_LAYER_NAME "VK_LAYER_LUNARG_override"
135
136
// Loader Settings filename
137
37.0k
#define VK_LOADER_SETTINGS_FILENAME "vk_loader_settings.json"
138
139
#define LAYERS_PATH_ENV "VK_LAYER_PATH"
140
0
#define ENABLED_LAYERS_ENV "VK_INSTANCE_LAYERS"
141
142
#if COMMON_UNIX_PLATFORMS
143
/* Linux-specific common code: */
144
145
// VK Library Filenames, Paths, etc.:
146
275M
#define PATH_SEPARATOR ':'
147
2.57G
#define DIRECTORY_SYMBOL '/'
148
149
55.9k
#define VULKAN_DIR "vulkan/"
150
1.12k
#define VULKAN_ICDCONF_DIR "icd.d"
151
#define VULKAN_ICD_DIR "icd"
152
#define VULKAN_SETTINGSCONF_DIR "settings.d"
153
23.7k
#define VULKAN_ELAYERCONF_DIR "explicit_layer.d"
154
31.0k
#define VULKAN_ILAYERCONF_DIR "implicit_layer.d"
155
#define VULKAN_LAYER_DIR "layer"
156
157
1.12k
#define VK_DRIVERS_INFO_RELATIVE_DIR VULKAN_DIR VULKAN_ICDCONF_DIR
158
#define VK_SETTINGS_INFO_RELATIVE_DIR VULKAN_DIR VULKAN_SETTINGSCONF_DIR
159
23.7k
#define VK_ELAYERS_INFO_RELATIVE_DIR VULKAN_DIR VULKAN_ELAYERCONF_DIR
160
31.0k
#define VK_ILAYERS_INFO_RELATIVE_DIR VULKAN_DIR VULKAN_ILAYERCONF_DIR
161
162
#define VK_DRIVERS_INFO_REGISTRY_LOC ""
163
#define VK_ELAYERS_INFO_REGISTRY_LOC ""
164
#define VK_ILAYERS_INFO_REGISTRY_LOC ""
165
#define VK_SETTINGS_INFO_REGISTRY_LOC ""
166
167
#if defined(__QNX__)
168
#ifndef SYSCONFDIR
169
#define SYSCONFDIR "/etc"
170
#endif
171
#endif
172
173
// C99:
174
#define PRINTF_SIZE_T_SPECIFIER "%zu"
175
176
// Dynamic Loading of libraries:
177
typedef void *loader_platform_dl_handle;
178
179
// Threads:
180
typedef pthread_t loader_platform_thread;
181
182
// Thread IDs:
183
typedef pthread_t loader_platform_thread_id;
184
185
// Thread mutex:
186
typedef pthread_mutex_t loader_platform_thread_mutex;
187
188
typedef pthread_cond_t loader_platform_thread_cond;
189
190
#elif defined(_WIN32)
191
/* Windows-specific common code: */
192
// VK Library Filenames, Paths, etc.:
193
#define PATH_SEPARATOR ';'
194
#define DIRECTORY_SYMBOL '\\'
195
#define DEFAULT_VK_REGISTRY_HIVE HKEY_LOCAL_MACHINE
196
#define DEFAULT_VK_REGISTRY_HIVE_STR "HKEY_LOCAL_MACHINE"
197
#define SECONDARY_VK_REGISTRY_HIVE HKEY_CURRENT_USER
198
#define SECONDARY_VK_REGISTRY_HIVE_STR "HKEY_CURRENT_USER"
199
200
#define VK_DRIVERS_INFO_RELATIVE_DIR ""
201
#define VK_SETTINGS_INFO_RELATIVE_DIR ""
202
#define VK_ELAYERS_INFO_RELATIVE_DIR ""
203
#define VK_ILAYERS_INFO_RELATIVE_DIR ""
204
205
#define VK_VARIANT_REG_STR ""
206
#define VK_VARIANT_REG_STR_W L""
207
208
#define VK_DRIVERS_INFO_REGISTRY_LOC "SOFTWARE\\Khronos\\Vulkan" VK_VARIANT_REG_STR "\\Drivers"
209
#define VK_ELAYERS_INFO_REGISTRY_LOC "SOFTWARE\\Khronos\\Vulkan" VK_VARIANT_REG_STR "\\ExplicitLayers"
210
#define VK_ILAYERS_INFO_REGISTRY_LOC "SOFTWARE\\Khronos\\Vulkan" VK_VARIANT_REG_STR "\\ImplicitLayers"
211
#define VK_SETTINGS_INFO_REGISTRY_LOC "SOFTWARE\\Khronos\\Vulkan" VK_VARIANT_REG_STR "\\LoaderSettings"
212
213
#define PRINTF_SIZE_T_SPECIFIER "%Iu"
214
215
// Dynamic Loading:
216
typedef HMODULE loader_platform_dl_handle;
217
218
// Threads:
219
typedef HANDLE loader_platform_thread;
220
221
// Thread IDs:
222
typedef DWORD loader_platform_thread_id;
223
224
// Thread mutex:
225
typedef CRITICAL_SECTION loader_platform_thread_mutex;
226
227
typedef CONDITION_VARIABLE loader_platform_thread_cond;
228
229
#else
230
231
#warning The "vk_loader_platform.h" file must be modified for this OS.
232
233
// NOTE: In order to support another OS, an #elif needs to be added (above the
234
// "#else // defined(_WIN32)") for that OS, and OS-specific versions of the
235
// contents of this file must be created, or extend one of the existing OS specific
236
// sections with the necessary changes.
237
238
#endif
239
240
// controls whether loader_platform_close_library() closes the libraries or not - controlled by an environment variables
241
extern bool loader_disable_dynamic_library_unloading;
242
243
// Returns true if the DIRECTORY_SYMBOL is contained within path
244
156k
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
244
156k
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
245
246
// The loader has various initialization tasks which it must do before user code can run. This includes initializing synchronization
247
// objects, determining the log level, writing the version of the loader to the log, and loading dll's (on windows). On linux, the
248
// solution is simply running the initialization code in  __attribute__((constructor)), which MacOS uses when the loader is
249
// dynamically linked. When statically linking on MacOS, the setup code instead uses pthread_once to run the logic a single time
250
// regardless of which API function the application calls first. On Windows, the equivalent way to run code at dll load time is
251
// DllMain which has many limitations placed upon it. Instead, the Windows code follows MacOS and does initialization in the first
252
// API call made, using InitOnceExecuteOnce, except for initialization primitives which must be done in DllMain. This is because
253
// there is no way to clean up the resources allocated by anything allocated by once init.
254
255
#if defined(APPLE_STATIC_LOADER)
256
static inline void loader_platform_thread_once_fn(pthread_once_t *ctl, void (*func)(void)) {
257
    assert(func != NULL);
258
    assert(ctl != NULL);
259
    pthread_once(ctl, func);
260
}
261
#define LOADER_PLATFORM_THREAD_ONCE_DECLARATION(var) pthread_once_t var = PTHREAD_ONCE_INIT;
262
#define LOADER_PLATFORM_THREAD_ONCE_EXTERN_DEFINITION(var) extern pthread_once_t var;
263
#define LOADER_PLATFORM_THREAD_ONCE(ctl, func) loader_platform_thread_once_fn(ctl, func);
264
#elif defined(WIN32)
265
static inline void loader_platform_thread_win32_once_fn(INIT_ONCE *ctl, PINIT_ONCE_FN func) {
266
    InitOnceExecuteOnce(ctl, func, NULL, NULL);
267
}
268
#define LOADER_PLATFORM_THREAD_ONCE_DECLARATION(var) INIT_ONCE var = INIT_ONCE_STATIC_INIT;
269
#define LOADER_PLATFORM_THREAD_ONCE_EXTERN_DEFINITION(var) extern INIT_ONCE var;
270
#define LOADER_PLATFORM_THREAD_ONCE(ctl, func) loader_platform_thread_win32_once_fn(ctl, func);
271
#else
272
#define LOADER_PLATFORM_THREAD_ONCE_DECLARATION(var)
273
#define LOADER_PLATFORM_THREAD_ONCE_EXTERN_DEFINITION(var)
274
#define LOADER_PLATFORM_THREAD_ONCE(ctl, func)
275
276
#endif
277
278
#if COMMON_UNIX_PLATFORMS
279
280
// File IO
281
191k
static inline bool loader_platform_file_exists(const char *path) {
282
191k
    if (access(path, F_OK))
283
7.01k
        return false;
284
183k
    else
285
183k
        return true;
286
191k
}
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
281
156k
static inline bool loader_platform_file_exists(const char *path) {
282
156k
    if (access(path, F_OK))
283
2.00k
        return false;
284
154k
    else
285
154k
        return true;
286
156k
}
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
281
34.5k
static inline bool loader_platform_file_exists(const char *path) {
282
34.5k
    if (access(path, F_OK))
283
5.01k
        return false;
284
29.5k
    else
285
29.5k
        return true;
286
34.5k
}
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
287
288
// Returns true if the given string appears to be a relative or absolute
289
// path, as opposed to a bare filename.
290
19.1k
static inline bool loader_platform_is_path_absolute(const char *path) {
291
19.1k
    if (path[0] == '/')
292
456
        return true;
293
18.6k
    else
294
18.6k
        return false;
295
19.1k
}
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
290
19.1k
static inline bool loader_platform_is_path_absolute(const char *path) {
291
19.1k
    if (path[0] == '/')
292
456
        return true;
293
18.6k
    else
294
18.6k
        return false;
295
19.1k
}
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
296
297
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
298
299
// loader_platform_executable_path finds application path + name.
300
// Path cannot be longer than 1024, returns NULL if it is greater than that.
301
#if defined(__linux__) || defined(__GNU__)
302
49.8k
static inline char *loader_platform_executable_path(char *buffer, size_t size) {
303
49.8k
    ssize_t count = readlink("/proc/self/exe", buffer, size);
304
49.8k
    if (count == -1) return NULL;
305
49.8k
    if (count == 0) return NULL;
306
49.8k
    buffer[count] = '\0';
307
49.8k
    return buffer;
308
49.8k
}
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
302
31.0k
static inline char *loader_platform_executable_path(char *buffer, size_t size) {
303
31.0k
    ssize_t count = readlink("/proc/self/exe", buffer, size);
304
31.0k
    if (count == -1) return NULL;
305
31.0k
    if (count == 0) return NULL;
306
31.0k
    buffer[count] = '\0';
307
31.0k
    return buffer;
308
31.0k
}
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
302
18.7k
static inline char *loader_platform_executable_path(char *buffer, size_t size) {
303
18.7k
    ssize_t count = readlink("/proc/self/exe", buffer, size);
304
18.7k
    if (count == -1) return NULL;
305
18.7k
    if (count == 0) return NULL;
306
18.7k
    buffer[count] = '\0';
307
18.7k
    return buffer;
308
18.7k
}
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
309
#elif defined(__APPLE__)
310
#include <TargetConditionals.h>
311
// TARGET_OS_IPHONE isn't just iOS it's also iOS/tvOS/watchOS. See TargetConditionals.h documentation.
312
#if TARGET_OS_IPHONE
313
static inline char *loader_platform_executable_path(char *buffer, size_t size) {
314
    (void)size;
315
    buffer[0] = '\0';
316
    return buffer;
317
}
318
#endif
319
#if TARGET_OS_OSX
320
#include <libproc.h>
321
static inline char *loader_platform_executable_path(char *buffer, size_t size) {
322
    // proc_pidpath takes a uint32_t for the buffer size
323
    if (size > UINT32_MAX) {
324
        return NULL;
325
    }
326
    pid_t pid = getpid();
327
    int ret = proc_pidpath(pid, buffer, (uint32_t)size);
328
    if (ret <= 0) {
329
        return NULL;
330
    }
331
    buffer[ret] = '\0';
332
    return buffer;
333
}
334
#endif
335
#elif defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__)
336
#include <sys/sysctl.h>
337
static inline char *loader_platform_executable_path(char *buffer, size_t size) {
338
    int mib[] = {
339
        CTL_KERN,
340
#if defined(__NetBSD__)
341
        KERN_PROC_ARGS,
342
        -1,
343
        KERN_PROC_PATHNAME,
344
#else
345
        KERN_PROC,
346
        KERN_PROC_PATHNAME,
347
        -1,
348
#endif
349
    };
350
    if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), buffer, &size, NULL, 0) < 0) {
351
        return NULL;
352
    }
353
354
    return buffer;
355
}
356
#elif defined(__Fuchsia__) || defined(__OpenBSD__)
357
static inline char *loader_platform_executable_path(char *buffer, size_t size) { return NULL; }
358
#elif defined(__QNX__)
359
360
#ifndef SYSCONFDIR
361
#define SYSCONFDIR "/etc"
362
#endif
363
364
#include <fcntl.h>
365
#include <sys/stat.h>
366
367
static inline char *loader_platform_executable_path(char *buffer, size_t size) {
368
    int fd = open("/proc/self/exefile", O_RDONLY);
369
    size_t rdsize;
370
371
    if (fd == -1) {
372
        return NULL;
373
    }
374
375
    rdsize = read(fd, buffer, size);
376
    if (rdsize == size) {
377
        return NULL;
378
    }
379
    buffer[rdsize] = 0x00;
380
    close(fd);
381
382
    return buffer;
383
}
384
#endif  // defined (__QNX__)
385
386
// Compatibility with compilers that don't support __has_feature
387
#if !defined(__has_feature)
388
#define __has_feature(x) 0
389
#endif
390
391
#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
392
#define LOADER_ADDRESS_SANITIZER_ACTIVE  // TODO: Add proper build flag for ASAN support
393
#endif
394
395
// When loading the library, we use RTLD_LAZY so that not all symbols have to be
396
// resolved at this time (which improves performance). Note that if not all symbols
397
// can be resolved, this could cause crashes later. Use the LD_BIND_NOW environment
398
// variable to force all symbols to be resolved here.
399
57
#define LOADER_DLOPEN_MODE (RTLD_LAZY | RTLD_LOCAL)
400
401
#if defined(__Fuchsia__)
402
static inline loader_platform_dl_handle loader_platform_open_driver(const char *libPath) {
403
    return dlopen_fuchsia(libPath, LOADER_DLOPEN_MODE, true);
404
}
405
static inline loader_platform_dl_handle loader_platform_open_library(const char *libPath) {
406
    return dlopen_fuchsia(libPath, LOADER_DLOPEN_MODE, false);
407
}
408
#else
409
57
static inline loader_platform_dl_handle loader_platform_open_library(const char *libPath) {
410
57
    return dlopen(libPath, LOADER_DLOPEN_MODE);
411
57
}
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
409
57
static inline loader_platform_dl_handle loader_platform_open_library(const char *libPath) {
410
57
    return dlopen(libPath, LOADER_DLOPEN_MODE);
411
57
}
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
412
#endif
413
414
57
static inline const char *loader_platform_open_library_error(const char *libPath) {
415
57
    (void)libPath;
416
#if defined(__Fuchsia__)
417
    return dlerror_fuchsia();
418
#else
419
57
    return dlerror();
420
57
#endif
421
57
}
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
414
57
static inline const char *loader_platform_open_library_error(const char *libPath) {
415
57
    (void)libPath;
416
#if defined(__Fuchsia__)
417
    return dlerror_fuchsia();
418
#else
419
57
    return dlerror();
420
57
#endif
421
57
}
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
422
0
static inline void loader_platform_close_library(loader_platform_dl_handle library) {
423
0
    if (!loader_disable_dynamic_library_unloading) {
424
0
        dlclose(library);
425
0
    } else {
426
0
        (void)library;
427
0
    }
428
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
429
0
static inline void *loader_platform_get_proc_address(loader_platform_dl_handle library, const char *name) {
430
0
    assert(library);
431
0
    assert(name);
432
0
    return dlsym(library, name);
433
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
434
0
static inline const char *loader_platform_get_proc_address_error(const char *name) {
435
0
    (void)name;
436
0
    return dlerror();
437
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
438
439
// Thread mutex:
440
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
440
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
440
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
441
74.3k
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
441
24.3k
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
441
50.0k
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
442
74.3k
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
442
24.3k
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
442
50.0k
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
443
3.17k
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
443
3.17k
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
444
445
296k
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
445
230k
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
445
65.6k
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
446
447
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
448
4.85M
static inline char *loader_strncat(char *dest, size_t dest_sz, const char *src, size_t count) {
449
4.85M
    (void)dest_sz;
450
4.85M
    return strncat(dest, src, count);
451
4.85M
}
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
log.c:loader_strncat
Line
Count
Source
448
4.81M
static inline char *loader_strncat(char *dest, size_t dest_sz, const char *src, size_t count) {
449
4.81M
    (void)dest_sz;
450
4.81M
    return strncat(dest, src, count);
451
4.81M
}
settings.c:loader_strncat
Line
Count
Source
448
34.5k
static inline char *loader_strncat(char *dest, size_t dest_sz, const char *src, size_t count) {
449
34.5k
    (void)dest_sz;
450
34.5k
    return strncat(dest, src, count);
451
34.5k
}
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
452
2.82M
static inline char *loader_strncpy(char *dest, size_t dest_sz, const char *src, size_t count) {
453
2.82M
    (void)dest_sz;
454
2.82M
    return strncpy(dest, src, count);
455
2.82M
}
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
loader.c:loader_strncpy
Line
Count
Source
452
2.71M
static inline char *loader_strncpy(char *dest, size_t dest_sz, const char *src, size_t count) {
453
2.71M
    (void)dest_sz;
454
2.71M
    return strncpy(dest, src, count);
455
2.71M
}
loader_environment.c:loader_strncpy
Line
Count
Source
452
32.8k
static inline char *loader_strncpy(char *dest, size_t dest_sz, const char *src, size_t count) {
453
32.8k
    (void)dest_sz;
454
32.8k
    return strncpy(dest, src, count);
455
32.8k
}
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
452
81.4k
static inline char *loader_strncpy(char *dest, size_t dest_sz, const char *src, size_t count) {
453
81.4k
    (void)dest_sz;
454
81.4k
    return strncpy(dest, src, count);
455
81.4k
}
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
456
457
#elif defined(_WIN32)
458
459
// Get the key for the plug n play driver registry
460
// The string returned by this function should NOT be freed
461
static inline const char *LoaderPnpDriverRegistry() {
462
    BOOL is_wow;
463
    IsWow64Process(GetCurrentProcess(), &is_wow);
464
    return is_wow ? "Vulkan" VK_VARIANT_REG_STR "DriverNameWow" : "Vulkan" VK_VARIANT_REG_STR "DriverName";
465
}
466
static inline const wchar_t *LoaderPnpDriverRegistryWide() {
467
    BOOL is_wow;
468
    IsWow64Process(GetCurrentProcess(), &is_wow);
469
    return is_wow ? L"Vulkan" VK_VARIANT_REG_STR_W L"DriverNameWow" : L"Vulkan" VK_VARIANT_REG_STR_W L"DriverName";
470
}
471
472
// Get the key for the plug 'n play explicit layer registry
473
// The string returned by this function should NOT be freed
474
static inline const char *LoaderPnpELayerRegistry() {
475
    BOOL is_wow;
476
    IsWow64Process(GetCurrentProcess(), &is_wow);
477
    return is_wow ? "Vulkan" VK_VARIANT_REG_STR "ExplicitLayersWow" : "Vulkan" VK_VARIANT_REG_STR "ExplicitLayers";
478
}
479
static inline const wchar_t *LoaderPnpELayerRegistryWide() {
480
    BOOL is_wow;
481
    IsWow64Process(GetCurrentProcess(), &is_wow);
482
    return is_wow ? L"Vulkan" VK_VARIANT_REG_STR_W L"ExplicitLayersWow" : L"Vulkan" VK_VARIANT_REG_STR_W L"ExplicitLayers";
483
}
484
485
// Get the key for the plug 'n play implicit layer registry
486
// The string returned by this function should NOT be freed
487
static inline const char *LoaderPnpILayerRegistry() {
488
    BOOL is_wow;
489
    IsWow64Process(GetCurrentProcess(), &is_wow);
490
    return is_wow ? "Vulkan" VK_VARIANT_REG_STR "ImplicitLayersWow" : "Vulkan" VK_VARIANT_REG_STR "ImplicitLayers";
491
}
492
static inline const wchar_t *LoaderPnpILayerRegistryWide() {
493
    BOOL is_wow;
494
    IsWow64Process(GetCurrentProcess(), &is_wow);
495
    return is_wow ? L"Vulkan" VK_VARIANT_REG_STR_W L"ImplicitLayersWow" : L"Vulkan" VK_VARIANT_REG_STR_W L"ImplicitLayers";
496
}
497
498
// File IO
499
static inline bool loader_platform_file_exists(const char *path) {
500
    int path_utf16_size = MultiByteToWideChar(CP_UTF8, 0, path, -1, NULL, 0);
501
    if (path_utf16_size <= 0) {
502
        return false;
503
    }
504
    wchar_t *path_utf16 = (wchar_t *)loader_stack_alloc(path_utf16_size * sizeof(wchar_t));
505
    if (MultiByteToWideChar(CP_UTF8, 0, path, -1, path_utf16, path_utf16_size) != path_utf16_size) {
506
        return false;
507
    }
508
    if (_waccess(path_utf16, 0) == -1)
509
        return false;
510
    else
511
        return true;
512
}
513
514
// Returns true if the given string appears to be a relative or absolute
515
// path, as opposed to a bare filename.
516
static inline bool loader_platform_is_path_absolute(const char *path) {
517
    if (!path || !*path) {
518
        return false;
519
    }
520
    if (*path == DIRECTORY_SYMBOL || path[1] == ':') {
521
        return true;
522
    }
523
    return false;
524
}
525
526
// WIN32 runtime doesn't have dirname().
527
static inline char *loader_platform_dirname(char *path) {
528
    char *current, *next;
529
530
    // TODO/TBD: Do we need to deal with the Windows's ":" character?
531
532
    for (current = path; *current != '\0'; current = next) {
533
        next = strchr(current, DIRECTORY_SYMBOL);
534
        if (next == NULL) {
535
            if (current != path) *(current - 1) = '\0';
536
            return path;
537
        } else {
538
            // Point one character past the DIRECTORY_SYMBOL:
539
            next++;
540
        }
541
    }
542
    return path;
543
}
544
545
static inline char *loader_platform_executable_path(char *buffer, size_t size) {
546
    wchar_t *buffer_utf16 = (wchar_t *)loader_stack_alloc(size * sizeof(wchar_t));
547
    DWORD ret = GetModuleFileNameW(NULL, buffer_utf16, (DWORD)size);
548
    if (ret == 0) {
549
        return NULL;
550
    }
551
    if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
552
        return NULL;
553
    }
554
    int buffer_utf8_size = WideCharToMultiByte(CP_UTF8, 0, buffer_utf16, -1, NULL, 0, NULL, NULL);
555
    if (buffer_utf8_size <= 0 || (size_t)buffer_utf8_size > size) {
556
        return NULL;
557
    }
558
    if (WideCharToMultiByte(CP_UTF8, 0, buffer_utf16, -1, buffer, buffer_utf8_size, NULL, NULL) != buffer_utf8_size) {
559
        return NULL;
560
    }
561
    return buffer;
562
}
563
564
// Dynamic Loading:
565
static inline loader_platform_dl_handle loader_platform_open_library(const char *lib_path) {
566
    int lib_path_utf16_size = MultiByteToWideChar(CP_UTF8, 0, lib_path, -1, NULL, 0);
567
    if (lib_path_utf16_size <= 0) {
568
        return NULL;
569
    }
570
    wchar_t *lib_path_utf16 = (wchar_t *)loader_stack_alloc(lib_path_utf16_size * sizeof(wchar_t));
571
    if (MultiByteToWideChar(CP_UTF8, 0, lib_path, -1, lib_path_utf16, lib_path_utf16_size) != lib_path_utf16_size) {
572
        return NULL;
573
    }
574
    // Try loading the library the original way first.
575
    loader_platform_dl_handle lib_handle = LoadLibraryW(lib_path_utf16);
576
    if (lib_handle == NULL && GetLastError() == ERROR_MOD_NOT_FOUND) {
577
        // If that failed, then try loading it with broader search folders.
578
        lib_handle = LoadLibraryExW(lib_path_utf16, NULL, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR);
579
    }
580
    return lib_handle;
581
}
582
static inline const char *loader_platform_open_library_error(const char *libPath) {
583
    static char errorMsg[512];
584
    (void)snprintf(errorMsg, 511, "Failed to open dynamic library \"%s\" with error %lu", libPath, GetLastError());
585
    return errorMsg;
586
}
587
static inline void loader_platform_close_library(loader_platform_dl_handle library) {
588
    if (!loader_disable_dynamic_library_unloading) {
589
        FreeLibrary(library);
590
    } else {
591
        (void)library;
592
    }
593
}
594
static inline void *loader_platform_get_proc_address(loader_platform_dl_handle library, const char *name) {
595
    assert(library);
596
    assert(name);
597
    return (void *)GetProcAddress(library, name);
598
}
599
static inline const char *loader_platform_get_proc_address_error(const char *name) {
600
    static char errorMsg[120];
601
    (void)snprintf(errorMsg, 119, "Failed to find function \"%s\" in dynamic library", name);
602
    return errorMsg;
603
}
604
605
// Thread mutex:
606
static inline void loader_platform_thread_create_mutex(loader_platform_thread_mutex *pMutex) { InitializeCriticalSection(pMutex); }
607
static inline void loader_platform_thread_lock_mutex(loader_platform_thread_mutex *pMutex) { EnterCriticalSection(pMutex); }
608
static inline void loader_platform_thread_unlock_mutex(loader_platform_thread_mutex *pMutex) { LeaveCriticalSection(pMutex); }
609
static inline void loader_platform_thread_delete_mutex(loader_platform_thread_mutex *pMutex) { DeleteCriticalSection(pMutex); }
610
611
static inline void *thread_safe_strtok(char *str, const char *delimiters, char **context) {
612
    return strtok_s(str, delimiters, context);
613
}
614
615
static inline FILE *loader_fopen(const char *fileName, const char *mode) {
616
    FILE *file = NULL;
617
    errno_t err = fopen_s(&file, fileName, mode);
618
    if (err != 0) return NULL;
619
    return file;
620
}
621
622
static inline char *loader_strncat(char *dest, size_t dest_sz, const char *src, size_t count) {
623
    errno_t err = strncat_s(dest, dest_sz, src, count);
624
    if (err != 0) return NULL;
625
    return dest;
626
}
627
628
static inline char *loader_strncpy(char *dest, size_t dest_sz, const char *src, size_t count) {
629
    errno_t err = strncpy_s(dest, dest_sz, src, count);
630
    if (err != 0) return NULL;
631
    return dest;
632
}
633
634
#else  // defined(_WIN32)
635
636
#warning The "vk_loader_platform.h" file must be modified for this OS.
637
638
// NOTE: In order to support another OS, an #elif needs to be added (above the
639
// "#else // defined(_WIN32)") for that OS, and OS-specific versions of the
640
// contents of this file must be created.
641
642
// NOTE: Other OS-specific changes are also needed for this OS.  Search for
643
// files with "WIN32" in it, as a quick way to find files that must be changed.
644
645
#endif  // defined(_WIN32)