From: Charles Giessen Date: Sat, 6 May 2023 03:28:50 +0000 (-0600) Subject: Move library list allocation to out of layer search function X-Git-Tag: upstream/1.3.268~149 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bead4f48e12d07f214ab6ac97128b01b24a54b43;p=platform%2Fupstream%2FVulkan-Loader.git Move library list allocation to out of layer search function The allocation of the library list shouldn't be happening in the call to loader_scan_for_implicit_layers. --- diff --git a/loader/loader.c b/loader/loader.c index 593cc754..6b6661d1 100644 --- a/loader/loader.c +++ b/loader/loader.c @@ -236,6 +236,16 @@ void loader_free_layer_properties(const struct loader_instance *inst, struct loa memset(layer_properties, 0, sizeof(struct loader_layer_properties)); } +VkResult loader_init_library_list(struct loader_layer_list *instance_layers, loader_platform_dl_handle **libs) { + if (instance_layers->count > 0) { + *libs = loader_calloc(NULL, sizeof(loader_platform_dl_handle) * instance_layers->count, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); + if (*libs == NULL) { + return VK_ERROR_OUT_OF_HOST_MEMORY; + } + } + return VK_SUCCESS; +} + // Combine path elements, separating each element with the platform-specific // directory separator, and save the combined string to a destination buffer, // not exceeding the given length. Path elements are given as variable args, @@ -3968,8 +3978,7 @@ out: return res; } -VkResult loader_scan_for_implicit_layers(struct loader_instance *inst, struct loader_layer_list *instance_layers, - loader_platform_dl_handle **libs) { +VkResult loader_scan_for_implicit_layers(struct loader_instance *inst, struct loader_layer_list *instance_layers) { struct loader_envvar_filter enable_filter; struct loader_envvar_disable_layers_filter disable_filter; char *file_str; @@ -4121,15 +4130,6 @@ VkResult loader_scan_for_implicit_layers(struct loader_instance *inst, struct lo } } - // We'll need to save the dl handles so we can close them later - if (instance_layers->count > 0 && NULL != libs) { - *libs = loader_calloc(NULL, sizeof(loader_platform_dl_handle) * instance_layers->count, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); - if (*libs == NULL) { - res = VK_ERROR_OUT_OF_HOST_MEMORY; - goto out; - } - } - out: loader_instance_heap_free(inst, override_paths); @@ -6887,7 +6887,7 @@ terminator_EnumerateInstanceExtensionProperties(const VkEnumerateInstanceExtensi loader_scanned_icd_clear(NULL, &icd_tramp_list); // Append enabled implicit layers. - res = loader_scan_for_implicit_layers(NULL, &instance_layers, NULL); + res = loader_scan_for_implicit_layers(NULL, &instance_layers); if (VK_SUCCESS != res) { goto out; } diff --git a/loader/loader.h b/loader/loader.h index c037c776..7660f90f 100644 --- a/loader/loader.h +++ b/loader/loader.h @@ -97,6 +97,8 @@ void loader_initialize(void); void loader_release(void); void loader_preload_icds(void); void loader_unload_preloaded_icds(void); +VkResult loader_init_library_list(struct loader_layer_list *instance_layers, loader_platform_dl_handle **libs); + bool has_vk_extension_property_array(const VkExtensionProperties *vk_ext_prop, const uint32_t count, const VkExtensionProperties *ext_array); bool has_vk_extension_property(const VkExtensionProperties *vk_ext_prop, const struct loader_extension_list *ext_list); @@ -130,8 +132,7 @@ VkResult loader_icd_scan(const struct loader_instance *inst, struct loader_icd_t void loader_icd_destroy(struct loader_instance *ptr_inst, struct loader_icd_term *icd_term, const VkAllocationCallbacks *pAllocator); VkResult loader_scan_for_layers(struct loader_instance *inst, struct loader_layer_list *instance_layers); -VkResult loader_scan_for_implicit_layers(struct loader_instance *inst, struct loader_layer_list *instance_layers, - loader_platform_dl_handle **libs); +VkResult loader_scan_for_implicit_layers(struct loader_instance *inst, struct loader_layer_list *instance_layers); VkResult loader_get_icd_loader_instance_extensions(const struct loader_instance *inst, struct loader_icd_tramp_list *icd_tramp_list, struct loader_extension_list *inst_exts); struct loader_icd_term *loader_get_icd_and_device(const void *device, struct loader_device **found_dev, uint32_t *icd_index); diff --git a/loader/trampoline.c b/loader/trampoline.c index f597af83..7c468974 100644 --- a/loader/trampoline.c +++ b/loader/trampoline.c @@ -164,7 +164,12 @@ LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionPropert size_t lib_count = 0; memset(&layers, 0, sizeof(layers)); - res = loader_scan_for_implicit_layers(NULL, &layers, &libs); + res = loader_scan_for_implicit_layers(NULL, &layers); + if (VK_SUCCESS != res) { + return res; + } + + res = loader_init_library_list(&layers, &libs); if (VK_SUCCESS != res) { return res; } @@ -257,7 +262,12 @@ LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties( size_t lib_count = 0; memset(&layers, 0, sizeof(layers)); - res = loader_scan_for_implicit_layers(NULL, &layers, &libs); + res = loader_scan_for_implicit_layers(NULL, &layers); + if (VK_SUCCESS != res) { + return res; + } + + res = loader_init_library_list(&layers, &libs); if (VK_SUCCESS != res) { return res; } @@ -357,7 +367,12 @@ LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceVersion(uint32_t size_t lib_count = 0; memset(&layers, 0, sizeof(layers)); - res = loader_scan_for_implicit_layers(NULL, &layers, &libs); + res = loader_scan_for_implicit_layers(NULL, &layers); + if (VK_SUCCESS != res) { + return res; + } + + res = loader_init_library_list(&layers, &libs); if (VK_SUCCESS != res) { return res; }