Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions loader/allocation.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#define DEBUG_DISABLE_APP_ALLOCATORS 0

void *loader_calloc(const VkAllocationCallbacks *pAllocator, size_t size, VkSystemAllocationScope allocation_scope) {
assert(size > 0 && "All allocations must have a size greater than zero!");
void *pMemory = NULL;
#if (DEBUG_DISABLE_APP_ALLOCATORS == 1)
{
Expand Down Expand Up @@ -67,6 +68,7 @@ void loader_free(const VkAllocationCallbacks *pAllocator, void *pMemory) {

void *loader_realloc(const VkAllocationCallbacks *pAllocator, void *pMemory, size_t orig_size, size_t size,
VkSystemAllocationScope allocation_scope) {
assert(size > 0 && "All allocations must have a size greater than zero!");
void *pNewMem = NULL;
if (pMemory == NULL || orig_size == 0) {
pNewMem = loader_calloc(pAllocator, size, allocation_scope);
Expand Down
2 changes: 1 addition & 1 deletion loader/extension_manual.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceToolPropertiesEXT(VkP
VkResult enumerate_res = VK_SUCCESS;

enumerate_res = icd_term->dispatch.EnumerateDeviceExtensionProperties(phys_dev_term->phys_dev, NULL, &ext_count, NULL);
if (enumerate_res != VK_SUCCESS) {
if (enumerate_res != VK_SUCCESS || ext_count == 0) {
goto out;
}

Expand Down
34 changes: 22 additions & 12 deletions loader/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -3699,11 +3699,13 @@ VkResult loader_icd_scan(const struct loader_instance *inst, struct loader_icd_t
goto out;
}

icd_details = loader_instance_heap_calloc(inst, sizeof(struct ICDManifestInfo) * manifest_files.count,
VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
if (NULL == icd_details) {
res = VK_ERROR_OUT_OF_HOST_MEMORY;
goto out;
if (manifest_files.count > 0) {
icd_details = loader_instance_heap_calloc(inst, sizeof(struct ICDManifestInfo) * manifest_files.count,
VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
if (NULL == icd_details) {
res = VK_ERROR_OUT_OF_HOST_MEMORY;
goto out;
}
}

for (uint32_t i = 0; i < manifest_files.count; i++) {
Expand Down Expand Up @@ -6037,13 +6039,16 @@ VkResult setup_loader_tramp_phys_devs(struct loader_instance *inst, uint32_t phy
new_count = phys_dev_count;
}

// We want an old to new index array and a new to old index array
old_to_new_index =
(int32_t *)loader_instance_heap_calloc(inst, sizeof(int32_t) * old_count, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
if (NULL == old_to_new_index) {
res = VK_ERROR_OUT_OF_HOST_MEMORY;
goto out;
if (old_count > 0) {
// We want an old to new index array and a new to old index array
old_to_new_index =
(int32_t *)loader_instance_heap_calloc(inst, sizeof(int32_t) * old_count, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
if (NULL == old_to_new_index) {
res = VK_ERROR_OUT_OF_HOST_MEMORY;
goto out;
}
}

new_to_old_index =
(int32_t *)loader_instance_heap_calloc(inst, sizeof(int32_t) * new_count, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
if (NULL == new_to_old_index) {
Expand Down Expand Up @@ -6648,6 +6653,11 @@ VkResult setup_loader_tramp_phys_dev_groups(struct loader_instance *inst, uint32
for (cur_idx = 0; cur_idx < group_count; ++cur_idx) {
phys_dev_count += groups[cur_idx].physicalDeviceCount;
}

if (phys_dev_count == 0) {
return VK_SUCCESS;
}

VkPhysicalDevice *devices = (VkPhysicalDevice *)loader_instance_heap_calloc(inst, sizeof(VkPhysicalDevice) * phys_dev_count,
VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
if (NULL == devices) {
Expand Down Expand Up @@ -7392,7 +7402,7 @@ VKAPI_ATTR VkResult VKAPI_CALL terminator_EnumeratePhysicalDeviceGroups(
}
}

if (NULL != pPhysicalDeviceGroupProperties) {
if (NULL != pPhysicalDeviceGroupProperties && total_count > 0) {
// Create an array for the new physical device groups, which will be stored
// in the instance for the Terminator code.
new_phys_dev_groups = (VkPhysicalDeviceGroupProperties **)loader_instance_heap_calloc(
Expand Down
22 changes: 20 additions & 2 deletions loader/loader_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,18 @@ VkResult windows_get_device_registry_files(const struct loader_instance *inst, u

// if after obtaining the DeviceNameSize, new device is added start over
do {
CM_Get_Device_ID_List_SizeW(&deviceNamesSize, displayGUID, flags);

loader_instance_heap_free(inst, pDeviceNames);
pDeviceNames = NULL;

CONFIGRET cm_ret = CM_Get_Device_ID_List_SizeW(&deviceNamesSize, displayGUID, flags);
if (CR_SUCCESS != cm_ret) {
loader_log(inst, VULKAN_LOADER_ERROR_BIT | log_target_flag, 0,
"windows_get_device_registry_files: Failed call to CM_Get_Device_ID_List_SizeW with error code %lu", cm_ret);
return VK_ERROR_INCOMPATIBLE_DRIVER;
}
if (deviceNamesSize == 0) {
break;
}

pDeviceNames = loader_instance_heap_calloc(inst, deviceNamesSize * sizeof(wchar_t), VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
if (pDeviceNames == NULL) {
Expand Down Expand Up @@ -593,6 +602,10 @@ VkResult windows_read_manifest_from_d3d_adapters(const struct loader_instance *i
goto out;
}

// Zero size adapter, skip it.
if (full_info->output_value_size == 0) {
continue;
}
// Convert the wide string to a narrow string
void *buffer = loader_instance_heap_realloc(inst, json_path, json_path_size, full_info->output_value_size,
VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
Expand Down Expand Up @@ -740,6 +753,11 @@ VkResult enumerate_adapter_physical_devices(struct loader_instance *inst, struct

// Get the actual physical devices
do {
// As the driver should return the count in the first call, making sure we don't call realloc with a size of zero.
if (count == 0) {
return VK_SUCCESS;
}

void *new_ptr = loader_instance_heap_realloc(inst, next_icd_phys_devs->physical_devices,
next_icd_phys_devs->device_count * sizeof(VkPhysicalDevice),
count * sizeof(VkPhysicalDevice), VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
Expand Down
Loading