diff --git a/compiler-rt/lib/hwasan/hwasan_allocator.cpp b/compiler-rt/lib/hwasan/hwasan_allocator.cpp --- a/compiler-rt/lib/hwasan/hwasan_allocator.cpp +++ b/compiler-rt/lib/hwasan/hwasan_allocator.cpp @@ -389,16 +389,6 @@ return HwasanChunkView(reinterpret_cast(block), metadata); } -static inline HwasanChunkView FindHeapChunkByAddressFastLocked(uptr address) { - void *block = - allocator.GetBlockBeginFastLocked(reinterpret_cast(address)); - if (!block) - return HwasanChunkView(); - Metadata *metadata = - reinterpret_cast(allocator.GetMetaData(block)); - return HwasanChunkView(reinterpret_cast(block), metadata); -} - static uptr AllocationSize(const void *tagged_ptr) { const void *untagged_ptr = UntagPtr(tagged_ptr); if (!untagged_ptr) return 0; @@ -513,23 +503,33 @@ } uptr PointsIntoChunk(void *p) { - uptr addr = reinterpret_cast(p); - __hwasan::HwasanChunkView view = - __hwasan::FindHeapChunkByAddressFastLocked(addr); - if (!view.IsAllocated()) + void *block = __hwasan::allocator.GetBlockBeginFastLocked(p); + if (!block) + return 0; + __hwasan::Metadata *metadata = reinterpret_cast<__hwasan::Metadata *>( + __hwasan::allocator.GetMetaData(block)); + if (!metadata || !metadata->IsAllocated()) return 0; - uptr chunk = view.Beg(); - if (view.AddrIsInside(addr)) + + uptr chunk = reinterpret_cast(p); + if (__hwasan::HwasanChunkView(chunk, metadata).AddrIsInside(chunk)) return chunk; - if (IsSpecialCaseOfOperatorNew0(chunk, view.UsedSize(), addr)) + if (IsSpecialCaseOfOperatorNew0(chunk, metadata->GetRequestedSize(), chunk)) return chunk; return 0; } uptr GetUserBegin(uptr chunk) { - // FIXME: All usecases provide chunk address, FindHeapChunkByAddressFastLocked - // is not needed. - return __hwasan::FindHeapChunkByAddressFastLocked(chunk).Beg(); + void *block = + __hwasan::allocator.GetBlockBeginFastLocked(reinterpret_cast(chunk)); + if (!block) + return 0; + __hwasan::Metadata *metadata = reinterpret_cast<__hwasan::Metadata *>( + __hwasan::allocator.GetMetaData(block)); + if (!metadata || !metadata->IsAllocated()) + return 0; + + return reinterpret_cast(block); } LsanMetadata::LsanMetadata(uptr chunk) {