Mesa (main): anv: Add a couple more checks in MapMemory

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Nov 9 03:12:53 UTC 2021


Module: Mesa
Branch: main
Commit: f9b69e43a5a94fe9bdc3ef574fd760b0fe6ada9f
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=f9b69e43a5a94fe9bdc3ef574fd760b0fe6ada9f

Author: Jason Ekstrand <jason at jlekstrand.net>
Date:   Sat Oct 30 16:32:47 2021 -0500

anv: Add a couple more checks in MapMemory

Reviwed-by: Paulo Zanoni <paulo.r.zanoni at intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13610>

---

 src/intel/vulkan/anv_device.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
index ede7ddd0faf..8d8530646ef 100644
--- a/src/intel/vulkan/anv_device.c
+++ b/src/intel/vulkan/anv_device.c
@@ -4033,11 +4033,20 @@ VkResult anv_MapMemory(
    assert(size > 0);
    assert(offset + size <= mem->bo->size);
 
-   /* FIXME: Is this supposed to be thread safe? Since vkUnmapMemory() only
-    * takes a VkDeviceMemory pointer, it seems like only one map of the memory
-    * at a time is valid. We could just mmap up front and return an offset
-    * pointer here, but that may exhaust virtual memory on 32 bit
-    * userspace. */
+   if (size != (size_t)size) {
+      return vk_errorf(device, VK_ERROR_MEMORY_MAP_FAILED,
+                       "requested size 0x%"PRIx64" does not fit in %u bits",
+                       size, (unsigned)(sizeof(size_t) * 8));
+   }
+
+   /* From the Vulkan 1.2.194 spec:
+    *
+    *    "memory must not be currently host mapped"
+    */
+   if (mem->bo->map != NULL) {
+      return vk_errorf(device, VK_ERROR_MEMORY_MAP_FAILED,
+                       "Memory object already mapped.");
+   }
 
    uint32_t gem_flags = 0;
 



More information about the mesa-commit mailing list