diff options
Diffstat (limited to 'loader/loader.c')
-rw-r--r-- | loader/loader.c | 42 |
1 files changed, 34 insertions, 8 deletions
diff --git a/loader/loader.c b/loader/loader.c index 831f416f5..c2ba5c351 100644 --- a/loader/loader.c +++ b/loader/loader.c @@ -537,6 +537,15 @@ static VkResult loader_add_instance_extensions(const struct loader_instance *ins goto out; } + // Make sure we never call ourself by accident, this should never happen outside of error paths + if (fp_get_props == vkEnumerateInstanceExtensionProperties) { + loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0, + "loader_add_instance_extensions: %s's vkEnumerateInstanceExtensionProperties points to the loader, this would " + "lead to infinite recursion.", + lib_name); + goto out; + } + res = fp_get_props(NULL, &count, NULL); if (res != VK_SUCCESS) { loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0, @@ -1332,6 +1341,15 @@ static VkResult loader_scanned_icd_add(const struct loader_instance *inst, struc uint32_t interface_vers; VkResult res = VK_SUCCESS; + // This shouldn't happen, but the check is necessary because dlopen returns a handle to the main program when + // filename is NULL + if (filename == NULL) { + loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0, "loader_scanned_icd_add: A NULL filename was used, skipping this ICD", + filename); + res = VK_ERROR_INCOMPATIBLE_DRIVER; + goto out; + } + // TODO implement smarter opening/closing of libraries. For now this // function leaves libraries open and the scanned_icd_clear closes them #if defined(__Fuchsia__) @@ -3235,6 +3253,8 @@ struct ICDManifestInfo { uint32_t version; }; +// Takes a json file, opens, reads, and parses an ICD Manifest out of it. +// Should only return VK_SUCCESS, VK_ERROR_INCOMPATIBLE_DRIVER, or VK_ERROR_OUT_OF_HOST_MEMORY VkResult loader_parse_icd_manifest(const struct loader_instance *inst, char *file_str, struct ICDManifestInfo *icd, bool *skipped_portability_drivers) { VkResult res = VK_SUCCESS; @@ -3251,7 +3271,11 @@ VkResult loader_parse_icd_manifest(const struct loader_instance *inst, char *fil } res = loader_get_json(inst, file_str, &json); + if (res == VK_ERROR_OUT_OF_HOST_MEMORY) { + goto out; + } if (res != VK_SUCCESS || NULL == json) { + res = VK_ERROR_INCOMPATIBLE_DRIVER; goto out; } @@ -3581,14 +3605,15 @@ VkResult loader_scan_for_layers(struct loader_instance *inst, struct loader_laye } // Parse file into JSON struct - res = loader_get_json(inst, file_str, &json); - if (VK_ERROR_OUT_OF_HOST_MEMORY == res) { + VkResult local_res = loader_get_json(inst, file_str, &json); + if (VK_ERROR_OUT_OF_HOST_MEMORY == local_res) { + res = VK_ERROR_OUT_OF_HOST_MEMORY; goto out; - } else if (VK_SUCCESS != res || NULL == json) { + } else if (VK_SUCCESS != local_res || NULL == json) { continue; } - VkResult local_res = loader_add_layer_properties(inst, instance_layers, json, true, file_str); + local_res = loader_add_layer_properties(inst, instance_layers, json, true, file_str); cJSON_Delete(json); // If the error is anything other than out of memory we still want to try to load the other layers @@ -3646,14 +3671,15 @@ VkResult loader_scan_for_layers(struct loader_instance *inst, struct loader_laye } // Parse file into JSON struct - res = loader_get_json(inst, file_str, &json); - if (VK_ERROR_OUT_OF_HOST_MEMORY == res) { + VkResult local_res = loader_get_json(inst, file_str, &json); + if (VK_ERROR_OUT_OF_HOST_MEMORY == local_res) { + res = VK_ERROR_OUT_OF_HOST_MEMORY; goto out; - } else if (VK_SUCCESS != res || NULL == json) { + } else if (VK_SUCCESS != local_res || NULL == json) { continue; } - VkResult local_res = loader_add_layer_properties(inst, instance_layers, json, false, file_str); + local_res = loader_add_layer_properties(inst, instance_layers, json, false, file_str); cJSON_Delete(json); // If the error is anything other than out of memory we still want to try to load the other layers |