From 1e6d135325357d8c32fd0b0d7f668cad91d478bc Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Sat, 29 May 2021 17:18:17 -0700 Subject: [PATCH] [scudo] Untag pointer in iterateOverChunks Pointer comparison in Lambda will not work on tagged pointers. Reviewed By: pcc Differential Revision: https://reviews.llvm.org/D103496 --- compiler-rt/lib/scudo/standalone/combined.h | 2 ++ compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/compiler-rt/lib/scudo/standalone/combined.h b/compiler-rt/lib/scudo/standalone/combined.h index f58eaa9..079edab 100644 --- a/compiler-rt/lib/scudo/standalone/combined.h +++ b/compiler-rt/lib/scudo/standalone/combined.h @@ -727,6 +727,8 @@ public: void iterateOverChunks(uptr Base, uptr Size, iterate_callback Callback, void *Arg) { initThreadMaybe(); + if (archSupportsMemoryTagging()) + Base = untagPointer(Base); const uptr From = Base; const uptr To = Base + Size; bool MayHaveTaggedPrimary = allocatorSupportsMemoryTagging() && diff --git a/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp b/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp index eed8f03..62410fc 100644 --- a/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp +++ b/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// +#include "memtag.h" #include "scudo/interface.h" #include "tests/scudo_unit_test.h" @@ -277,6 +278,10 @@ static uintptr_t BoundaryP; static size_t Count; static void callback(uintptr_t Base, size_t Size, void *Arg) { + if (scudo::archSupportsMemoryTagging()) { + Base = scudo::untagPointer(Base); + BoundaryP = scudo::untagPointer(BoundaryP); + } if (Base == BoundaryP) Count++; } -- 2.7.4