Coverage Report

Created: 2026-04-01 06:46

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/vulkan-loader/loader/loader.h
Line
Count
Source
1
/*
2
 *
3
 * Copyright (c) 2014-2023 The Khronos Group Inc.
4
 * Copyright (c) 2014-2023 Valve Corporation
5
 * Copyright (c) 2014-2023 LunarG, Inc.
6
 * Copyright (C) 2015 Google Inc.
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 *     http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 *
20
 * Author: Jon Ashburn <jon@lunarg.com>
21
 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
22
 * Author: Chia-I Wu <olvaffe@gmail.com>
23
 * Author: Chia-I Wu <olv@lunarg.com>
24
 * Author: Mark Lobodzinski <mark@LunarG.com>
25
 * Author: Lenny Komow <lenny@lunarg.com>
26
 * Author: Charles Giessen <charles@lunarg.com>
27
 *
28
 */
29
30
#pragma once
31
32
#include "loader_common.h"
33
#include "cJSON.h"
34
35
// Declare the once_init variable
36
LOADER_PLATFORM_THREAD_ONCE_EXTERN_DEFINITION(once_init)
37
38
0
static inline VkPhysicalDevice loader_unwrap_physical_device(VkPhysicalDevice physicalDevice) {
39
0
    if (VK_NULL_HANDLE == physicalDevice) {
40
0
        return VK_NULL_HANDLE;
41
0
    }
42
0
    struct loader_physical_device_tramp *phys_dev = (struct loader_physical_device_tramp *)physicalDevice;
43
0
    if (PHYS_TRAMP_MAGIC_NUMBER != phys_dev->magic) {
44
0
        return VK_NULL_HANDLE;
45
0
    }
46
0
    return phys_dev->phys_dev;
47
0
}
Unexecuted instantiation: instance_enumerate_fuzzer.c:loader_unwrap_physical_device
Unexecuted instantiation: trampoline.c:loader_unwrap_physical_device
Unexecuted instantiation: debug_utils.c:loader_unwrap_physical_device
Unexecuted instantiation: loader.c:loader_unwrap_physical_device
Unexecuted instantiation: loader_environment.c:loader_unwrap_physical_device
Unexecuted instantiation: loader_json.c:loader_unwrap_physical_device
Unexecuted instantiation: loader_linux.c:loader_unwrap_physical_device
Unexecuted instantiation: settings.c:loader_unwrap_physical_device
Unexecuted instantiation: terminator.c:loader_unwrap_physical_device
Unexecuted instantiation: wsi.c:loader_unwrap_physical_device
Unexecuted instantiation: extension_manual.c:loader_unwrap_physical_device
48
49
0
static inline void loader_set_dispatch(void *obj, const void *data) { *((const void **)obj) = data; }
Unexecuted instantiation: instance_enumerate_fuzzer.c:loader_set_dispatch
Unexecuted instantiation: trampoline.c:loader_set_dispatch
Unexecuted instantiation: debug_utils.c:loader_set_dispatch
Unexecuted instantiation: loader.c:loader_set_dispatch
Unexecuted instantiation: loader_environment.c:loader_set_dispatch
Unexecuted instantiation: loader_json.c:loader_set_dispatch
Unexecuted instantiation: loader_linux.c:loader_set_dispatch
Unexecuted instantiation: settings.c:loader_set_dispatch
Unexecuted instantiation: terminator.c:loader_set_dispatch
Unexecuted instantiation: wsi.c:loader_set_dispatch
Unexecuted instantiation: extension_manual.c:loader_set_dispatch
50
51
0
static inline VkLayerDispatchTable *loader_get_dispatch(const void *obj) {
52
0
    if (VK_NULL_HANDLE == obj) {
53
0
        return NULL;
54
0
    }
55
0
    VkLayerDispatchTable *disp = *((VkLayerDispatchTable **)obj);
56
0
    if (VK_NULL_HANDLE == disp || DEVICE_DISP_TABLE_MAGIC_NUMBER != disp->magic) {
57
0
        return NULL;
58
0
    }
59
0
    return disp;
60
0
}
Unexecuted instantiation: instance_enumerate_fuzzer.c:loader_get_dispatch
Unexecuted instantiation: trampoline.c:loader_get_dispatch
Unexecuted instantiation: debug_utils.c:loader_get_dispatch
Unexecuted instantiation: loader.c:loader_get_dispatch
Unexecuted instantiation: loader_environment.c:loader_get_dispatch
Unexecuted instantiation: loader_json.c:loader_get_dispatch
Unexecuted instantiation: loader_linux.c:loader_get_dispatch
Unexecuted instantiation: settings.c:loader_get_dispatch
Unexecuted instantiation: terminator.c:loader_get_dispatch
Unexecuted instantiation: wsi.c:loader_get_dispatch
Unexecuted instantiation: extension_manual.c:loader_get_dispatch
61
62
0
static inline struct loader_dev_dispatch_table *loader_get_dev_dispatch(const void *obj) {
63
0
    return *((struct loader_dev_dispatch_table **)obj);
64
0
}
Unexecuted instantiation: instance_enumerate_fuzzer.c:loader_get_dev_dispatch
Unexecuted instantiation: trampoline.c:loader_get_dev_dispatch
Unexecuted instantiation: debug_utils.c:loader_get_dev_dispatch
Unexecuted instantiation: loader.c:loader_get_dev_dispatch
Unexecuted instantiation: loader_environment.c:loader_get_dev_dispatch
Unexecuted instantiation: loader_json.c:loader_get_dev_dispatch
Unexecuted instantiation: loader_linux.c:loader_get_dev_dispatch
Unexecuted instantiation: settings.c:loader_get_dev_dispatch
Unexecuted instantiation: terminator.c:loader_get_dev_dispatch
Unexecuted instantiation: wsi.c:loader_get_dev_dispatch
Unexecuted instantiation: extension_manual.c:loader_get_dev_dispatch
65
66
0
static inline VkLayerInstanceDispatchTable *loader_get_instance_layer_dispatch(const void *obj) {
67
0
    return *((VkLayerInstanceDispatchTable **)obj);
68
0
}
Unexecuted instantiation: instance_enumerate_fuzzer.c:loader_get_instance_layer_dispatch
Unexecuted instantiation: trampoline.c:loader_get_instance_layer_dispatch
Unexecuted instantiation: debug_utils.c:loader_get_instance_layer_dispatch
Unexecuted instantiation: loader.c:loader_get_instance_layer_dispatch
Unexecuted instantiation: loader_environment.c:loader_get_instance_layer_dispatch
Unexecuted instantiation: loader_json.c:loader_get_instance_layer_dispatch
Unexecuted instantiation: loader_linux.c:loader_get_instance_layer_dispatch
Unexecuted instantiation: settings.c:loader_get_instance_layer_dispatch
Unexecuted instantiation: terminator.c:loader_get_instance_layer_dispatch
Unexecuted instantiation: wsi.c:loader_get_instance_layer_dispatch
Unexecuted instantiation: extension_manual.c:loader_get_instance_layer_dispatch
69
70
0
static inline struct loader_instance_dispatch_table *loader_get_instance_dispatch(const void *obj) {
71
0
    return *((struct loader_instance_dispatch_table **)obj);
72
0
}
Unexecuted instantiation: instance_enumerate_fuzzer.c:loader_get_instance_dispatch
Unexecuted instantiation: trampoline.c:loader_get_instance_dispatch
Unexecuted instantiation: debug_utils.c:loader_get_instance_dispatch
Unexecuted instantiation: loader.c:loader_get_instance_dispatch
Unexecuted instantiation: loader_environment.c:loader_get_instance_dispatch
Unexecuted instantiation: loader_json.c:loader_get_instance_dispatch
Unexecuted instantiation: loader_linux.c:loader_get_instance_dispatch
Unexecuted instantiation: settings.c:loader_get_instance_dispatch
Unexecuted instantiation: terminator.c:loader_get_instance_dispatch
Unexecuted instantiation: wsi.c:loader_get_instance_dispatch
Unexecuted instantiation: extension_manual.c:loader_get_instance_dispatch
73
74
0
static inline void loader_init_dispatch(void *obj, const void *data) {
75
#if defined(DEBUG)
76
    assert(valid_loader_magic_value(obj) &&
77
           "Incompatible ICD, first dword must be initialized to "
78
           "ICD_LOADER_MAGIC. See loader/README.md for details.");
79
#endif
80
81
0
    loader_set_dispatch(obj, data);
82
0
}
Unexecuted instantiation: instance_enumerate_fuzzer.c:loader_init_dispatch
Unexecuted instantiation: trampoline.c:loader_init_dispatch
Unexecuted instantiation: debug_utils.c:loader_init_dispatch
Unexecuted instantiation: loader.c:loader_init_dispatch
Unexecuted instantiation: loader_environment.c:loader_init_dispatch
Unexecuted instantiation: loader_json.c:loader_init_dispatch
Unexecuted instantiation: loader_linux.c:loader_init_dispatch
Unexecuted instantiation: settings.c:loader_init_dispatch
Unexecuted instantiation: terminator.c:loader_init_dispatch
Unexecuted instantiation: wsi.c:loader_init_dispatch
Unexecuted instantiation: extension_manual.c:loader_init_dispatch
83
84
// Global variables used across files
85
extern struct loader_struct loader;
86
extern loader_platform_thread_mutex loader_lock;
87
extern loader_platform_thread_mutex loader_preload_icd_lock;
88
89
bool compare_vk_extension_properties(const VkExtensionProperties *op1, const VkExtensionProperties *op2);
90
91
VkResult loader_validate_layers(const struct loader_instance *inst, const uint32_t layer_count,
92
                                const char *const *ppEnabledLayerNames, const struct loader_layer_list *list);
93
94
VkResult loader_validate_instance_extensions(struct loader_instance *inst, const struct loader_extension_list *icd_exts,
95
                                             const struct loader_layer_list *instance_layer,
96
                                             const struct loader_envvar_all_filters *layer_filters,
97
                                             const VkInstanceCreateInfo *pCreateInfo);
98
99
#if defined(_WIN32)
100
BOOL __stdcall loader_initialize(PINIT_ONCE InitOnce, PVOID Parameter, PVOID *Context);
101
#else
102
void loader_initialize(void);
103
#endif
104
void loader_release(void);
105
void loader_preload_icds(void);
106
void loader_unload_preloaded_icds(void);
107
VkResult loader_init_library_list(struct loader_layer_list *instance_layers, loader_platform_dl_handle **libs);
108
109
// Allocate a new string able to hold source_str and place it in dest_str
110
VkResult loader_copy_to_new_str(const struct loader_instance *inst, const char *source_str, char **dest_str);
111
112
// Allocate a loader_string_list with enough space for allocated_count strings inside of it
113
VkResult create_string_list(const struct loader_instance *inst, uint32_t allocated_count, struct loader_string_list *string_list);
114
// Resize if there isn't enough space, then add the string str to the end of the loader_string_list
115
// This function takes ownership of the str passed in
116
VkResult append_str_to_string_list(const struct loader_instance *inst, struct loader_string_list *string_list, char *str);
117
// Resize if there isn't enough space, then add the string str to the start of the loader_string_list
118
// This function takes ownership of the str passed in
119
VkResult prepend_str_to_string_list(const struct loader_instance *inst, struct loader_string_list *string_list, char *str);
120
// Copy the string str to a new string and append it to string_list, resizing string_list if there isn't enough space.
121
// This function does not take ownership of the string, it merely copies it.
122
// This function automatically appends a null terminator to the string being copied
123
// The str_len parameter does not include the null terminator
124
VkResult copy_str_to_string_list(const struct loader_instance *inst, struct loader_string_list *string_list, const char *str,
125
                                 size_t str_len);
126
// Copy the string str to a new string and prepend it to string_list, resizing string_list if there isn't enough space.
127
// This function does not take ownership of the string, it merely copies it.
128
// This function automatically appends a null terminator to the string being copied
129
// The str_len parameter does not include the null terminator
130
VkResult copy_str_to_start_of_string_list(const struct loader_instance *inst, struct loader_string_list *string_list,
131
                                          const char *str, size_t str_len);
132
133
// Free any string inside of loader_string_list and then free the list itself
134
void free_string_list(const struct loader_instance *inst, struct loader_string_list *string_list);
135
136
VkResult loader_init_generic_list(const struct loader_instance *inst, struct loader_generic_list *list_info, size_t element_size);
137
VkResult loader_resize_generic_list(const struct loader_instance *inst, struct loader_generic_list *list_info);
138
VkResult loader_get_next_available_entry(const struct loader_instance *inst, struct loader_used_object_list *list_info,
139
                                         uint32_t *free_index, const VkAllocationCallbacks *pAllocator);
140
void loader_release_object_from_list(struct loader_used_object_list *list_info, uint32_t index_to_free);
141
bool has_vk_extension_property_array(const VkExtensionProperties *vk_ext_prop, const uint32_t count,
142
                                     const VkExtensionProperties *ext_array);
143
bool has_vk_extension_property(const VkExtensionProperties *vk_ext_prop, const struct loader_extension_list *ext_list);
144
// This function takes ownership of layer_property in the case that allocation fails
145
VkResult loader_append_layer_property(const struct loader_instance *inst, struct loader_layer_list *layer_list,
146
                                      struct loader_layer_properties *layer_property);
147
VkResult loader_add_layer_properties(const struct loader_instance *inst, struct loader_layer_list *layer_instance_list, cJSON *json,
148
                                     bool is_implicit, char *filename);
149
bool loader_find_layer_name_in_list(const char *name, const struct loader_pointer_layer_list *layer_list);
150
VkResult loader_add_layer_properties_to_list(const struct loader_instance *inst, struct loader_pointer_layer_list *list,
151
                                             struct loader_layer_properties *props);
152
void loader_free_layer_properties(const struct loader_instance *inst, struct loader_layer_properties *layer_properties);
153
bool loader_implicit_layer_is_enabled(const struct loader_instance *inst, const struct loader_envvar_all_filters *filters,
154
                                      const struct loader_layer_properties *prop);
155
VkResult loader_add_meta_layer(const struct loader_instance *inst, const struct loader_envvar_all_filters *filters,
156
                               struct loader_layer_properties *prop, struct loader_pointer_layer_list *target_list,
157
                               struct loader_pointer_layer_list *expanded_target_list, const struct loader_layer_list *source_list,
158
                               bool *out_found_all_component_layers);
159
VkResult loader_add_to_ext_list(const struct loader_instance *inst, struct loader_extension_list *ext_list,
160
                                uint32_t prop_list_count, const VkExtensionProperties *props);
161
VkResult loader_add_device_extensions(const struct loader_instance *inst,
162
                                      PFN_vkEnumerateDeviceExtensionProperties fpEnumerateDeviceExtensionProperties,
163
                                      VkPhysicalDevice physical_device, const char *lib_name,
164
                                      struct loader_extension_list *ext_list);
165
VkResult loader_init_generic_list(const struct loader_instance *inst, struct loader_generic_list *list_info, size_t element_size);
166
void loader_destroy_generic_list(const struct loader_instance *inst, struct loader_generic_list *list);
167
void loader_destroy_pointer_layer_list(const struct loader_instance *inst, struct loader_pointer_layer_list *layer_list);
168
TEST_FUNCTION_EXPORT void loader_delete_layer_list_and_properties(const struct loader_instance *inst,
169
                                                                  struct loader_layer_list *layer_list);
170
void loader_remove_layer_in_list(const struct loader_instance *inst, struct loader_layer_list *layer_list,
171
                                 uint32_t layer_to_remove);
172
VkResult loader_init_scanned_icd_list(const struct loader_instance *inst, struct loader_icd_tramp_list *icd_tramp_list);
173
void loader_clear_scanned_icd_list(const struct loader_instance *inst, struct loader_icd_tramp_list *icd_tramp_list);
174
VkResult loader_icd_scan(const struct loader_instance *inst, struct loader_icd_tramp_list *icd_tramp_list,
175
                         const VkInstanceCreateInfo *pCreateInfo, bool *skipped_portability_drivers);
176
void loader_icd_close_objects(struct loader_instance *ptr_inst, struct loader_icd_term *icd_term);
177
void loader_icd_destroy(struct loader_instance *ptr_inst, struct loader_icd_term *icd_term,
178
                        const VkAllocationCallbacks *pAllocator);
179
VkResult loader_scan_for_layers(struct loader_instance *inst, struct loader_layer_list *instance_layers,
180
                                const struct loader_envvar_all_filters *layer_filters);
181
VkResult loader_scan_for_implicit_layers(struct loader_instance *inst, struct loader_layer_list *instance_layers,
182
                                         const struct loader_envvar_all_filters *layer_filters);
183
VkResult loader_get_icd_loader_instance_extensions(const struct loader_instance *inst, struct loader_icd_tramp_list *icd_tramp_list,
184
                                                   struct loader_extension_list *inst_exts);
185
struct loader_icd_term *loader_get_icd_and_device(const void *device, struct loader_device **found_dev);
186
struct loader_instance *loader_get_instance(const VkInstance instance);
187
loader_platform_dl_handle loader_open_layer_file(const struct loader_instance *inst, struct loader_layer_properties *prop);
188
struct loader_device *loader_create_logical_device(const struct loader_instance *inst, const VkAllocationCallbacks *pAllocator);
189
void loader_add_logical_device(struct loader_icd_term *icd_term, struct loader_device *found_dev);
190
void loader_remove_logical_device(struct loader_icd_term *icd_term, struct loader_device *found_dev,
191
                                  const VkAllocationCallbacks *pAllocator);
192
// NOTE: Outside of loader, this entry-point is only provided for error
193
// cleanup.
194
void loader_destroy_logical_device(struct loader_device *dev, const VkAllocationCallbacks *pAllocator);
195
196
VkResult loader_enable_instance_layers(struct loader_instance *inst, const VkInstanceCreateInfo *pCreateInfo,
197
                                       const struct loader_layer_list *instance_layers,
198
                                       const struct loader_envvar_all_filters *layer_filters);
199
200
VkResult loader_create_instance_chain(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
201
                                      struct loader_instance *inst, VkInstance *created_instance);
202
203
void loader_activate_instance_layer_extensions(struct loader_instance *inst, VkInstance created_inst);
204
205
VKAPI_ATTR VkResult VKAPI_CALL loader_layer_create_device(VkInstance instance, VkPhysicalDevice physicalDevice,
206
                                                          const VkDeviceCreateInfo *pCreateInfo,
207
                                                          const VkAllocationCallbacks *pAllocator, VkDevice *pDevice,
208
                                                          PFN_vkGetInstanceProcAddr layerGIPA, PFN_vkGetDeviceProcAddr *nextGDPA);
209
VKAPI_ATTR void VKAPI_CALL loader_layer_destroy_device(VkDevice device, const VkAllocationCallbacks *pAllocator,
210
                                                       PFN_vkDestroyDevice destroyFunction);
211
212
VkResult loader_create_device_chain(const VkPhysicalDevice pd, const VkDeviceCreateInfo *pCreateInfo,
213
                                    const VkAllocationCallbacks *pAllocator, const struct loader_instance *inst,
214
                                    struct loader_device *dev, PFN_vkGetInstanceProcAddr callingLayer,
215
                                    PFN_vkGetDeviceProcAddr *layerNextGDPA);
216
217
VkResult loader_validate_device_extensions(struct loader_instance *this_instance,
218
                                           const struct loader_pointer_layer_list *activated_device_layers,
219
                                           const struct loader_extension_list *icd_exts, const VkDeviceCreateInfo *pCreateInfo);
220
221
VkResult setup_loader_tramp_phys_devs(struct loader_instance *inst, uint32_t phys_dev_count, VkPhysicalDevice *phys_devs);
222
VkResult setup_loader_tramp_phys_dev_groups(struct loader_instance *inst, uint32_t group_count,
223
                                            VkPhysicalDeviceGroupProperties *groups);
224
void unload_drivers_without_physical_devices(struct loader_instance *inst);
225
226
VkResult loader_apply_settings_device_configurations(struct loader_instance *inst, uint32_t *pPhysicalDeviceCount,
227
                                                     VkPhysicalDevice *pPhysicalDevices);
228
229
VkStringErrorFlags vk_string_validate(const int max_length, const char *char_array);
230
char *loader_get_next_path(char *path);
231
VkResult add_if_manifest_file(const struct loader_instance *inst, const char *file_name, struct loader_string_list *out_files);
232
VkResult prepend_if_manifest_file(const struct loader_instance *inst, const char *file_name, struct loader_string_list *out_files);
233
VkResult add_data_files(const struct loader_instance *inst, char *search_path, struct loader_string_list *out_files);
234
235
loader_api_version loader_make_version(uint32_t version);
236
loader_api_version loader_combine_version(uint32_t major, uint32_t minor, uint32_t patch);
237
238
// Helper macros for determining if a version is valid or not
239
bool loader_check_version_meets_required(loader_api_version required, loader_api_version version);
240
241
VkResult loader_filter_enumerated_physical_device(const struct loader_instance *inst,
242
                                                  const struct loader_envvar_id_filter *device_id_filter,
243
                                                  const struct loader_envvar_id_filter *vendor_id_filter,
244
                                                  const struct loader_envvar_id_filter *driver_id_filter,
245
                                                  const uint32_t in_PhysicalDeviceCount,
246
                                                  const VkPhysicalDevice *in_pPhysicalDevices, uint32_t *out_pPhysicalDeviceCount,
247
                                                  VkPhysicalDevice *out_pPhysicalDevices);
248
249
VkResult loader_filter_enumerated_physical_device_groups(
250
    const struct loader_instance *inst, const struct loader_envvar_id_filter *device_id_filter,
251
    const struct loader_envvar_id_filter *vendor_id_filter, const struct loader_envvar_id_filter *driver_id_filter,
252
    const uint32_t in_PhysicalDeviceGroupCount, const VkPhysicalDeviceGroupProperties *in_pPhysicalDeviceGroupProperties,
253
    uint32_t *out_PhysicalDeviceGroupCount, VkPhysicalDeviceGroupProperties *out_pPhysicalDeviceGroupProperties);
254
255
// Convenience macros for common versions
256
#if !defined(LOADER_VERSION_1_0_0)
257
0
#define LOADER_VERSION_1_0_0 loader_combine_version(1, 0, 0)
258
#endif
259
260
#if !defined(LOADER_VERSION_1_1_0)
261
6.03k
#define LOADER_VERSION_1_1_0 loader_combine_version(1, 1, 0)
262
#endif