diff options
| author | Mark Young <marky@lunarg.com> | 2017-05-19 12:29:43 -0600 |
|---|---|---|
| committer | Mark Young <marky@lunarg.com> | 2017-05-19 13:50:17 -0600 |
| commit | a7b230ac5941b4071ce3e6a6f30947dcc20fb94c (patch) | |
| tree | 7cf09e37da9bf8816c3aa78547ccc05b67d0657a | |
| parent | 9090258a7daf83e0c3af7554f8ef83663246b9d5 (diff) | |
| download | usermoji-a7b230ac5941b4071ce3e6a6f30947dcc20fb94c.tar.xz | |
loader: gh1771-Fix realloc handling
Fix how the loader handles realloc calls. Instead of always overriding
the pointer, check to see if the allocation succeeds.
Also, set the paths in our run_all_tests.ps1 to global paths.
Finally, fix a spelling error in the test names.
Change-Id: I7b2e0d246dbe6353d29fb56367397c5d8767aaa2
| -rw-r--r-- | loader/loader.c | 119 |
1 files changed, 60 insertions, 59 deletions
diff --git a/loader/loader.c b/loader/loader.c index 72c7df2b..b2bf86fd 100644 --- a/loader/loader.c +++ b/loader/loader.c @@ -259,7 +259,7 @@ static inline char *loader_getenv(const char *name, const struct loader_instance } static inline char *loader_secure_getenv(const char *name, const struct loader_instance *inst) { - // No secure version for Winddows as far as I know + // No secure version for Windows as far as I know return loader_getenv(name, inst); } @@ -449,24 +449,23 @@ VkResult loaderGetRegistryFiles(const struct loader_instance *inst, char *locati *reg_data = loader_instance_heap_alloc(inst, total_size, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); if (NULL == *reg_data) { loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, - "loaderGetRegistryFiles: Failed to allocate " - "space for registry data for key %s", - name); + "loaderGetRegistryFiles: Failed to allocate space for registry data for key %s", name); result = VK_ERROR_OUT_OF_HOST_MEMORY; goto out; } *reg_data[0] = '\0'; } else if (strlen(*reg_data) + name_size + 1 > total_size) { - *reg_data = loader_instance_heap_realloc(inst, *reg_data, total_size, total_size * 2, - VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); - if (NULL == *reg_data) { - loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, - "loaderGetRegistryFiles: Failed to reallocate " - "space for registry value of size %d for key %s", - total_size * 2, name); + void *new_ptr = loader_instance_heap_realloc(inst, *reg_data, total_size, total_size * 2, + VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); + if (NULL == new_ptr) { + loader_log( + inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, + "loaderGetRegistryFiles: Failed to reallocate space for registry value of size %d for key %s", + total_size * 2, name); result = VK_ERROR_OUT_OF_HOST_MEMORY; goto out; } + *reg_data = new_ptr; total_size *= 2; } loader_log( @@ -628,14 +627,13 @@ static struct loader_layer_properties *loader_get_next_layer_property(const stru // Ensure enough room to add an entry if ((layer_list->count + 1) * sizeof(struct loader_layer_properties) > layer_list->capacity) { - layer_list->list = loader_instance_heap_realloc(inst, layer_list->list, layer_list->capacity, layer_list->capacity * 2, - VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); - if (layer_list->list == NULL) { - loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, - "loader_get_next_layer_property: realloc failed for " - "layer list"); + void *new_ptr = loader_instance_heap_realloc(inst, layer_list->list, layer_list->capacity, layer_list->capacity * 2, + VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); + if (NULL == new_ptr) { + loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, "loader_get_next_layer_property: realloc failed for layer list"); return NULL; } + layer_list->list = new_ptr; layer_list->capacity *= 2; } @@ -856,15 +854,15 @@ VkResult loader_add_to_ext_list(const struct loader_instance *inst, struct loade // add to list at end // check for enough capacity if (ext_list->count * sizeof(VkExtensionProperties) >= ext_list->capacity) { - ext_list->list = loader_instance_heap_realloc(inst, ext_list->list, ext_list->capacity, ext_list->capacity * 2, - VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); - - if (ext_list->list == NULL) { + void *new_ptr = loader_instance_heap_realloc(inst, ext_list->list, ext_list->capacity, ext_list->capacity * 2, + VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); + if (new_ptr == NULL) { loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, "loader_add_to_ext_list: Failed to reallocate " "space for extension list"); return VK_ERROR_OUT_OF_HOST_MEMORY; } + ext_list->list = new_ptr; // double capacity ext_list->capacity *= 2; @@ -898,15 +896,15 @@ VkResult loader_add_to_dev_ext_list(const struct loader_instance *inst, struct l // add to list at end // check for enough capacity if (idx * sizeof(struct loader_dev_ext_props) >= ext_list->capacity) { - ext_list->list = loader_instance_heap_realloc(inst, ext_list->list, ext_list->capacity, ext_list->capacity * 2, - VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); + void *new_ptr = loader_instance_heap_realloc(inst, ext_list->list, ext_list->capacity, ext_list->capacity * 2, + VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); - if (ext_list->list == NULL) { + if (NULL == new_ptr) { loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, - "loader_add_to_dev_ext_list: Failed to reallocate " - "space for device extension list"); + "loader_add_to_dev_ext_list: Failed to reallocate space for device extension list"); return VK_ERROR_OUT_OF_HOST_MEMORY; } + ext_list->list = new_ptr; // double capacity ext_list->capacity *= 2; @@ -1054,14 +1052,14 @@ VkResult loader_add_to_layer_list(const struct loader_instance *inst, struct loa // Check for enough capacity if (((list->count + 1) * sizeof(struct loader_layer_properties)) >= list->capacity) { size_t new_capacity = list->capacity * 2; - list->list = + void *new_ptr = loader_instance_heap_realloc(inst, list->list, list->capacity, new_capacity, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); - if (NULL == list->list) { + if (NULL == new_ptr) { loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, - "loader_add_to_layer_list: Realloc failed for " - "when attempting to add new layer"); + "loader_add_to_layer_list: Realloc failed for when attempting to add new layer"); return VK_ERROR_OUT_OF_HOST_MEMORY; } + list->list = new_ptr; list->capacity = new_capacity; } @@ -1574,17 +1572,16 @@ static VkResult loader_scanned_icd_add(const struct loader_instance *inst, struc // check for enough capacity if ((icd_tramp_list->count * sizeof(struct loader_scanned_icd)) >= icd_tramp_list->capacity) { - icd_tramp_list->scanned_list = - loader_instance_heap_realloc(inst, icd_tramp_list->scanned_list, icd_tramp_list->capacity, icd_tramp_list->capacity * 2, - VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); - if (NULL == icd_tramp_list->scanned_list) { + void *new_ptr = loader_instance_heap_realloc(inst, icd_tramp_list->scanned_list, icd_tramp_list->capacity, + icd_tramp_list->capacity * 2, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); + if (NULL == new_ptr) { res = VK_ERROR_OUT_OF_HOST_MEMORY; loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, - "loader_scanned_icd_add: Realloc failed on icd library" - " list for ICD %s", - filename); + "loader_scanned_icd_add: Realloc failed on icd library list for ICD %s", filename); goto out; } + icd_tramp_list->scanned_list = new_ptr; + // double capacity icd_tramp_list->capacity *= 2; } @@ -2618,7 +2615,7 @@ out: static VkResult loader_get_manifest_files(const struct loader_instance *inst, const char *env_override, const char *source_override, bool is_layer, bool warn_if_not_present, const char *location, const char *relative_location, struct loader_manifest_files *out_files) { - const char * override = NULL; + const char *override = NULL; char *override_getenv = NULL; char *loc, *orig_loc = NULL; char *reg = NULL; @@ -2858,19 +2855,25 @@ static VkResult loader_get_manifest_files(const struct loader_instance *inst, co if (out_files->count == 0) { out_files->filename_list = loader_instance_heap_alloc(inst, alloced_count * sizeof(char *), VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); + if (NULL == out_files->filename_list) { + loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, + "loader_get_manifest_files: Failed to allocate space for manifest file name list"); + res = VK_ERROR_OUT_OF_HOST_MEMORY; + goto out; + } } else if (out_files->count == alloced_count) { - out_files->filename_list = + void *new_ptr = loader_instance_heap_realloc(inst, out_files->filename_list, alloced_count * sizeof(char *), alloced_count * sizeof(char *) * 2, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); + if (NULL == new_ptr) { + loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, + "loader_get_manifest_files: Failed to reallocate space for manifest file name list"); + res = VK_ERROR_OUT_OF_HOST_MEMORY; + goto out; + } + out_files->filename_list = new_ptr; alloced_count *= 2; } - if (out_files->filename_list == NULL) { - loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, - "loader_get_manifest_files: Failed to allocate " - "space for manifest file name list"); - res = VK_ERROR_OUT_OF_HOST_MEMORY; - goto out; - } out_files->filename_list[out_files->count] = loader_instance_heap_alloc(inst, strlen(name) + 1, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); if (out_files->filename_list[out_files->count] == NULL) { @@ -3608,23 +3611,20 @@ static bool loader_add_dev_ext_table(struct loader_instance *inst, uint32_t *ptr if (list->capacity == 0) { list->index = loader_instance_heap_alloc(inst, 8 * sizeof(*(list->index)), VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); if (list->index == NULL) { - loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, - "loader_add_dev_ext_table: Failed to allocate memory " - "for list index", + loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, "loader_add_dev_ext_table: Failed to allocate memory for list index", funcName); return false; } list->capacity = 8 * sizeof(*(list->index)); } else if (list->capacity < (list->count + 1) * sizeof(*(list->index))) { - list->index = loader_instance_heap_realloc(inst, list->index, list->capacity, list->capacity * 2, - VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); - if (list->index == NULL) { + void *new_ptr = loader_instance_heap_realloc(inst, list->index, list->capacity, list->capacity * 2, + VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); + if (NULL == new_ptr) { loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, - "loader_add_dev_ext_table: Failed to reallocate memory " - "for list index", - funcName); + "loader_add_dev_ext_table: Failed to reallocate memory for list index", funcName); return false; } + list->index = new_ptr; list->capacity *= 2; } @@ -3786,12 +3786,13 @@ static bool loader_add_phys_dev_ext_table(struct loader_instance *inst, uint32_t } list->capacity = 8 * sizeof(*(list->index)); } else if (list->capacity < (list->count + 1) * sizeof(*(list->index))) { - list->index = loader_instance_heap_realloc(inst, list->index, list->capacity, list->capacity * 2, - VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); - if (list->index == NULL) { + void *new_ptr = loader_instance_heap_realloc(inst, list->index, list->capacity, list->capacity * 2, + VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); + if (NULL == new_ptr) { loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, "loader_add_phys_dev_ext_table() can't reallocate list memory"); return false; } + list->index = new_ptr; list->capacity *= 2; } @@ -4944,7 +4945,7 @@ VkResult setupLoaderTrampPhysDevs(VkInstance instance) { goto out; } - // Query how many gpus there + // Query how many GPUs there res = inst->disp->layer_inst_disp.EnumeratePhysicalDevices(instance, &total_count, NULL); if (res != VK_SUCCESS) { loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
