From 0be484ece4cedccfa27f1b84b578c5542a634d73 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Mon, 28 Mar 2022 17:39:08 -0400 Subject: [PATCH] lavapipe: add an env var to enable poisoning memory allocations it's not random, but it's definitely not zero or any other expected value, which means it's going to break anything that was passing due to lucky uninitialized values Reviewed-by: Emma Anholt Reviewed-by: Dave Airlie Part-of: --- src/gallium/frontends/lavapipe/lvp_device.c | 4 ++++ src/gallium/frontends/lavapipe/lvp_private.h | 1 + 2 files changed, 5 insertions(+) diff --git a/src/gallium/frontends/lavapipe/lvp_device.c b/src/gallium/frontends/lavapipe/lvp_device.c index 4747ed941c8..057020af5d8 100644 --- a/src/gallium/frontends/lavapipe/lvp_device.c +++ b/src/gallium/frontends/lavapipe/lvp_device.c @@ -1675,6 +1675,7 @@ VKAPI_ATTR VkResult VKAPI_CALL lvp_CreateDevice( return vk_error(instance, VK_ERROR_OUT_OF_HOST_MEMORY); device->queue.state = device + 1; + device->poison_mem = debug_get_bool_option("LVP_POISON_MEMORY", false); struct vk_device_dispatch_table dispatch_table; vk_device_dispatch_table_from_entrypoints(&dispatch_table, @@ -1988,6 +1989,9 @@ VKAPI_ATTR VkResult VKAPI_CALL lvp_AllocateMemory( if (!mem->pmem) { goto fail; } + if (device->poison_mem) + /* this is a value that will definitely break things */ + memset(mem->pmem, UINT8_MAX / 2 + 1, pAllocateInfo->allocationSize); } mem->type_index = pAllocateInfo->memoryTypeIndex; diff --git a/src/gallium/frontends/lavapipe/lvp_private.h b/src/gallium/frontends/lavapipe/lvp_private.h index 32de5840fa8..5e8c8a4fa45 100644 --- a/src/gallium/frontends/lavapipe/lvp_private.h +++ b/src/gallium/frontends/lavapipe/lvp_private.h @@ -211,6 +211,7 @@ struct lvp_device { struct lvp_instance * instance; struct lvp_physical_device *physical_device; struct pipe_screen *pscreen; + bool poison_mem; }; void lvp_device_get_cache_uuid(void *uuid);