diff options
| author | Mark Lobodzinski <mark@lunarg.com> | 2015-11-19 14:13:44 -0700 |
|---|---|---|
| committer | Mark Lobodzinski <mark@lunarg.com> | 2015-11-19 14:13:44 -0700 |
| commit | f40e1f43ce56fe98a7bfc9a37f48b05b5e3c021d (patch) | |
| tree | 37e28a21bd90288c59ce79b631a249f45b32a0ab | |
| parent | 20626f8efae394d0264764739a8e37c9f112cfa6 (diff) | |
| download | usermoji-f40e1f43ce56fe98a7bfc9a37f48b05b5e3c021d.tar.xz | |
layers: Additional MapMemory validation checks in MemTracker
| -rw-r--r-- | layers/mem_tracker.cpp | 17 | ||||
| -rw-r--r-- | layers/vk_validation_layer_details.md | 2 |
2 files changed, 16 insertions, 3 deletions
diff --git a/layers/mem_tracker.cpp b/layers/mem_tracker.cpp index 52be170c..344c7fc5 100644 --- a/layers/mem_tracker.cpp +++ b/layers/mem_tracker.cpp @@ -1268,12 +1268,24 @@ VkBool32 validateMemRange( { VkBool32 skipCall = VK_FALSE; + if (size == 0) { + skipCall = log_msg(my_data->report_data, VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_DEVICE_MEMORY, (uint64_t)mem, 0, + MEMTRACK_INVALID_MAP, "MEM", "VkMapMemory: Attempting to map memory range of size zero"); + } + auto mem_element = my_data->memObjMap.find(mem); if (mem_element != my_data->memObjMap.end()) { + // It is an application error to call VkMapMemory on an object that is already mapped + if (mem_element->second.memRange.size != 0) { + skipCall = log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE_MEMORY, (uint64_t)mem, 0, + MEMTRACK_INVALID_MAP, "MEM", "VkMapMemory: Attempting to map memory on an already-mapped object %#" PRIxLEAST64, (uint64_t)mem); + } + + // Validate that offset + size is within object's allocationSize if ((offset + size) > mem_element->second.allocInfo.allocationSize) { skipCall = log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE_MEMORY, (uint64_t)mem, 0, - MEMTRACK_INVALID_MAP, "MEM", "Mapping Memory from %" PRIu64 " to %" PRIu64 " with total array size %" PRIu64, - offset, size + offset, mem_element->second.allocInfo.allocationSize); + MEMTRACK_INVALID_MAP, "MEM", "Mapping Memory from %" PRIu64 " to %" PRIu64 " with total array size %" PRIu64, + offset, size + offset, mem_element->second.allocInfo.allocationSize); } } return skipCall; @@ -1348,6 +1360,7 @@ VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkMapMemory( VkBool32 skipCall = VK_FALSE; VkResult result = VK_ERROR_VALIDATION_FAILED; loader_platform_thread_lock_mutex(&globalLock); + MT_MEM_OBJ_INFO *pMemObj = get_mem_obj_info(my_data, mem); if ((memProps.memoryTypes[pMemObj->allocInfo.memoryTypeIndex].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) == 0) { diff --git a/layers/vk_validation_layer_details.md b/layers/vk_validation_layer_details.md index 4088c7e2..4e06cb20 100644 --- a/layers/vk_validation_layer_details.md +++ b/layers/vk_validation_layer_details.md @@ -169,7 +169,7 @@ The MemTracker layer tracks memory objects and references and validates that the | Immutable Memory Binding | Validates that non-sparse memory bindings are immutable, so objects are not re-boundt | REBIND_OBJECT | vkBindBufferMemory, vkBindImageMemory | RebindMemory | NA | | Image/Buffer Usage bits | Verify correct USAGE bits set based on how Images and Buffers are used | INVALID_USAGE_FLAG | vkCreateImage, vkCreateBuffer, vkCreateBufferView, vkCmdCopyBuffer, vkCmdCopyQueryPoolResults, vkCmdCopyImage, vkCmdBlitImage, vkCmdCopyBufferToImage, vkCmdCopyImageToBuffer, vkCmdUpdateBuffer, vkCmdFillBuffer | InvalidUsageBits | NA | | Objects Not Destroyed Warning | Warns if any memory objects have not been freed before their objects are destroyed | MEM_OBJ_CLEAR_EMPTY_BINDINGS | vkDestroyDevice | TBD | NA | -| Memory Map Range Checks | Validates that Memory Mapping Requests are valid for the Memory Object | INVALID_MAP | vkMapMemory | TBD | NA | +| Memory Map Range Checks | Validates that Memory Mapping Requests are valid for the Memory Object (in-range, not currently mapped on Map, currently mapped on UnMap, size is non-zero) | INVALID_MAP | vkMapMemory | TBD | NA | | NA | Enum used for informational messages | NONE | | NA | None | | NA | Enum used for errors in the layer itself. This does not indicate an app issue, but instead a bug in the layer. | INTERNAL_ERROR | | NA | None | |
