From b0e9d659cd2ca685c26e7712df2dc1c065ac592e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Tue, 26 Sep 2023 12:40:48 +0100 Subject: [PATCH] Fix Heap Relocate Add block - Following #2757 --- src/CLR/Core/GarbageCollector_Compaction.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/CLR/Core/GarbageCollector_Compaction.cpp b/src/CLR/Core/GarbageCollector_Compaction.cpp index 195d930220..ca8be3edcf 100644 --- a/src/CLR/Core/GarbageCollector_Compaction.cpp +++ b/src/CLR/Core/GarbageCollector_Compaction.cpp @@ -349,7 +349,15 @@ void CLR_RT_GarbageCollector::Heap_Relocate_AddBlock(CLR_UINT8 *dst, CLR_UINT8 * reloc->m_start = src; reloc->m_end = &src[length]; reloc->m_destination = dst; - reloc->m_offset = (CLR_UINT32)(dst - src); + + if (reloc->m_destination < reloc->m_start) + { + reloc->m_offset = -(CLR_INT32)(reloc->m_start - reloc->m_destination); + } + else + { + reloc->m_offset = (CLR_INT32)(reloc->m_destination - reloc->m_start); + } if (++m_relocCount == m_relocTotal) {