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 @@ -398,16 +398,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; @@ -522,11 +512,16 @@ } uptr PointsIntoChunk(void *p) { - uptr addr = reinterpret_cast(p); - __hwasan::HwasanChunkView view = - __hwasan::FindHeapChunkByAddressFastLocked(addr); - if (!view.IsAllocated()) + void *block = allocator.GetBlockBeginFastLocked(p); + if (!block) + return 0; + Metadata *metadata = + reinterpret_cast(allocator.GetMetaData(block)); + if (!metadata || !metadata->IsAllocated()) return 0; + + uptr addr = reinterpret_cast(p); + HwasanChunkView view(addr, metadata); uptr chunk = view.Beg(); if (view.AddrIsInside(addr)) return chunk; @@ -536,9 +531,16 @@ } uptr GetUserBegin(uptr chunk) { - // FIXME: All usecases provide chunk address, FindHeapChunkByAddressFastLocked - // is not needed. - return __hwasan::FindHeapChunkByAddressFastLocked(chunk).Beg(); + void *block = + allocator.GetBlockBeginFastLocked(reinterpret_cast(chunk)); + if (!block) + return 0; + Metadata *metadata = + reinterpret_cast(allocator.GetMetaData(block)); + if (!metadata || !metadata->IsAllocated()) + return 0; + + return HwasanChunkView(reinterpret_cast(block), metadata).Beg(); } LsanMetadata::LsanMetadata(uptr chunk) {