From c6b3fc6930f7b49398293c6889d01b553f13b379 Mon Sep 17 00:00:00 2001 From: Gurchetan Singh Date: Fri, 17 Apr 2026 10:46:25 -0700 Subject: [PATCH] gfxstream: fix string array marshalling This is a follow-up to: - commit e27e41a8 ("vulkan,spirv: update headers") - commit c4cecd9d ("gfxstream: cereal: fix 'None' in gfxstream codegen") The second commit fixed compile, but still produced a crash on the host side: $0 __memcpy_evex_unaligned_erms () at ../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S:833 $1 0x00007f116f8ee285 in memcpy (__dest=0x7f0d258cd340, __dest@entry=0x7f0ed55e9458, __src=0x7f0e78072ff7, __src@entry=0x72795f61, __len=1920556897) at prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.17-4.8/sysroot/usr/include/x86_64-linux-gnu/bits/string3.h:51 $2 gfxstream::host::vk::VulkanStream::loadStringInPlaceWithStreamPtr (this=this@entry=0x7f0e78022b50, forOutput=forOutput@entry=0x7f0d97fff018, streamPtr=streamPtr@entry=0x7f0ed55e9458) at hardware/google/gfxstream/host/vulkan/vulkan_stream.cpp:100 $3 0x00007f116f8ee3de in gfxstream::host::vk::VulkanStream::loadStringArrayInPlaceWithStreamPtr (this=0x7f0e78022b50, forOutput=, streamPtr=0x7f0ed55e9458) at hardware/google/gfxstream/host/vulkan/vulkan_stream.cpp:122 $4 0x00007f116f9f2fcb in gfxstream::host::vk::reservedunmarshal_VkDeviceCreateInfo (vkStream=vkStream@entry=0x7f0e78022b50, Fix up lenAccess string marshaling to prevent this. TEST=launch_cvd --gpu_mode=gfxstream_guest_angle_host_swiftshader Reviewed-by: David Gilhooley Part-of: --- .../codegen/scripts/cereal/marshaling.py | 9 ++---- .../scripts/cereal/reservedmarshaling.py | 30 +++++++++---------- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/src/gfxstream/codegen/scripts/cereal/marshaling.py b/src/gfxstream/codegen/scripts/cereal/marshaling.py index a140916ad0c..6b385a3b6f8 100644 --- a/src/gfxstream/codegen/scripts/cereal/marshaling.py +++ b/src/gfxstream/codegen/scripts/cereal/marshaling.py @@ -455,9 +455,8 @@ class VulkanMarshalingCodegen(VulkanTypeIterator): lenAccess = self.lenAccessor(vulkanType) if self.direction == "write": - if lenAccess is not None: - self.cgen.stmt("saveStringArray(%s, %s, %s)" % (self.streamVarName, - access, lenAccess)) + self.cgen.stmt("saveStringArray(%s, %s, %s)" % (self.streamVarName, + access, lenAccess if lenAccess is not None else "0")) else: castExpr = \ self.makeCastExpr( \ @@ -471,9 +470,7 @@ class VulkanMarshalingCodegen(VulkanTypeIterator): lenAccess = self.lenAccessor(vulkanType) if lenAccess is not None: finalLenExpr = "%s * %s" % (lenAccess, self.cgen.sizeofExpr(vulkanType)) - else: - finalLenExpr = self.cgen.sizeofExpr(vulkanType) - self.genStreamCall(vulkanType, access, finalLenExpr) + self.genStreamCall(vulkanType, access, finalLenExpr) # Old version VkEncoder may have some sType values conflict with VkDecoder # of new versions. For host decoder, it should not carry the incorrect old diff --git a/src/gfxstream/codegen/scripts/cereal/reservedmarshaling.py b/src/gfxstream/codegen/scripts/cereal/reservedmarshaling.py index 9b675937ced..4c922d21d92 100644 --- a/src/gfxstream/codegen/scripts/cereal/reservedmarshaling.py +++ b/src/gfxstream/codegen/scripts/cereal/reservedmarshaling.py @@ -548,26 +548,24 @@ class VulkanReservedMarshalingCodegen(VulkanTypeIterator): lenAccessGuard = self.lenAccessorGuard(vulkanType) if self.direction == "write": + self.cgen.beginBlock() + + self.cgen.stmt("uint32_t c = 0") if lenAccess is not None: - self.cgen.beginBlock() - - self.cgen.stmt("uint32_t c = 0") - if lenAccessGuard is not None: - self.cgen.beginIf(lenAccessGuard) + self.cgen.beginIf(lenAccessGuard) self.cgen.stmt("c = %s" % (lenAccess)) - if lenAccessGuard is not None: - self.cgen.endIf() - self.genMemcpyAndIncr(self.ptrVar, "(uint32_t*)" ,"&c", "sizeof(uint32_t)", toBe = True, actualSize = 4) - - self.cgen.beginFor("uint32_t i = 0", "i < c", "++i") - self.cgen.stmt("uint32_t l = %s ? strlen(%s[i]): 0" % (access, access)) - self.genMemcpyAndIncr(self.ptrVar, "(uint32_t*)" ,"&l", "sizeof(uint32_t)", toBe = True, actualSize = 4) - self.cgen.beginIf("l") - self.genMemcpyAndIncr(self.ptrVar, "(char*)", "(%s[i])" % access, "l") self.cgen.endIf() - self.cgen.endFor() - self.cgen.endBlock() + self.genMemcpyAndIncr(self.ptrVar, "(uint32_t*)" ,"&c", "sizeof(uint32_t)", toBe = True, actualSize = 4) + self.cgen.beginFor("uint32_t i = 0", "i < c", "++i") + self.cgen.stmt("uint32_t l = %s ? strlen(%s[i]): 0" % (access, access)) + self.genMemcpyAndIncr(self.ptrVar, "(uint32_t*)" ,"&l", "sizeof(uint32_t)", toBe = True, actualSize = 4) + self.cgen.beginIf("l") + self.genMemcpyAndIncr(self.ptrVar, "(char*)", "(%s[i])" % access, "l") + self.cgen.endIf() + self.cgen.endFor() + + self.cgen.endBlock() else: castExpr = \ self.makeCastExpr( \