Add memory allocation checks
This CL adds ASSERT checks on maximum memory size in VkMemory.cpp
Bug: b/144988972
Change-Id: I0d6b33a96c344a1c10949a470077e01307e42a87
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/70048
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Presubmit-Ready: Alexis Hétu <sugoi@google.com>
Commit-Queue: Alexis Hétu <sugoi@google.com>
Tested-by: Alexis Hétu <sugoi@google.com>
Kokoro-Result: kokoro <noreply+kokoro@google.com>
diff --git a/src/Vulkan/VkMemory.cpp b/src/Vulkan/VkMemory.cpp
index c522e5f..9d5c9f93 100644
--- a/src/Vulkan/VkMemory.cpp
+++ b/src/Vulkan/VkMemory.cpp
@@ -15,12 +15,15 @@
#include "VkMemory.hpp"
#include "VkConfig.hpp"
+#include "System/Debug.hpp"
#include "System/Memory.hpp"
namespace vk {
void *allocateDeviceMemory(size_t bytes, size_t alignment)
{
+ ASSERT(bytes <= vk::MAX_MEMORY_ALLOCATION_SIZE);
+
#if defined(SWIFTSHADER_ZERO_INITIALIZE_DEVICE_MEMORY)
return sw::allocateZeroOrPoison(bytes, alignment);
#else
@@ -35,6 +38,8 @@
void *allocateHostMemory(size_t bytes, size_t alignment, const VkAllocationCallbacks *pAllocator, VkSystemAllocationScope allocationScope)
{
+ ASSERT(bytes <= vk::MAX_MEMORY_ALLOCATION_SIZE);
+
if(pAllocator)
{
return pAllocator->pfnAllocation(pAllocator->pUserData, bytes, alignment, allocationScope);