Repository navigation
Force size 0 allocations to be size 1 allocations to avoid misreporting OOM - #2086
aitor-lunarg wants to merge 1 commit into
Conversation
…ng OOM calloc or custom Vulkan host allocators can return null for size 0 allocations. Certain checks in the loader will report OOM if the pointer returned by the allocation calls is null even if the execution can continue without any issues. Fix this issue by requesting 1 byte instead of 0.
|
CI Vulkan-Loader build queued with queue ID 172940. |
|
CI Vulkan-Loader build # 3916 running. |
|
CI Vulkan-Loader build queued with queue ID 172958. |
|
CI Vulkan-Loader build # 3917 running. |
|
CI Vulkan-Loader build # 3917 passed. |
|
I am not in favor of this solution because it hides bad code just to minimize code changes. The codebase just went through a large refactor to replace alloca with calloc/realloc. The rest of the code already operated under the presumption of not calling calloc/realloc with size zero. That said, there isn't a strict enforcement of this rule. I have had clang-tidy warn about it in the past using the option I am much more in favor of just biting the bullet and fixing the callsites to not have a size of zero. |
Agreed! Closing in favour of an upcoming PR handling these cases individually |
Commit message:
Found through CTS test
dEQP-VK.api.device_init.enumerate_devices_alloc_leak.basic. Loader would report VK_ERROR_OUT_OF_HOST_MEMORY when the custom Vulkan host allocator returns null for size 0 allocations. Root cause lies in https://github.com/KhronosGroup/Vulkan-Loader/blob/main/loader/loader.c#L6043 which was made visible after #2076The mentioned check expects that the returned pointer is not null. However, when requesting a size 0 allocation, according to https://man7.org/linux/man-pages/man3/calloc.3p.html
and the Vulkan spec in https://registry.khronos.org/vulkan/specs/latest/html/vkspec.html#memory-host:
Which means we could get a null pointer for a size 0 allocation. This does not mean the host run out of memory, and following what the Vulkan spec states, since the requested allocation is 0 even if we get a null pointer we should be able to continue execution.
This PR makes 0 size allocations into 1 size allocations so that we get a valid pointer. This way, we don't have to modify every single location where memory is requested and checks for non-null.
Alternatively, we could modify all memory allocation locations if this approach is a no-go.