Control Flow Integrity (cfi) fix
The cfi bot is throwing an error because an object is being assigned
with memory containing an invalid vtable. This is caused by assigning
a chunk of memory to an object before calling placement new using that
memory.
This cl assigns the pointer after the object has been constructed to
avoid triggering this error.
Bug: chromium:1116053
Change-Id: I541d7dc0e884aed7470b97d7d1d91a9bb67edb2d
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/47788
Tested-by: Alexis Hétu <sugoi@google.com>
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/Vulkan/VkDeviceMemory.cpp b/src/Vulkan/VkDeviceMemory.cpp
index 191916f..84a2a7e 100644
--- a/src/Vulkan/VkDeviceMemory.cpp
+++ b/src/Vulkan/VkDeviceMemory.cpp
@@ -263,13 +263,13 @@
DeviceMemory::DeviceMemory(const VkMemoryAllocateInfo *pAllocateInfo, void *mem)
: size(pAllocateInfo->allocationSize)
, memoryTypeIndex(pAllocateInfo->memoryTypeIndex)
- , external(reinterpret_cast<ExternalBase *>(mem))
{
ASSERT(size);
ExternalMemoryTraits traits;
findTraits(pAllocateInfo, &traits);
- traits.instanceInit(external, pAllocateInfo);
+ traits.instanceInit(mem, pAllocateInfo);
+ external = reinterpret_cast<ExternalBase *>(mem);
}
void DeviceMemory::destroy(const VkAllocationCallbacks *pAllocator)