diff --git a/compiler-rt/lib/hwasan/hwasan_allocator.h b/compiler-rt/lib/hwasan/hwasan_allocator.h --- a/compiler-rt/lib/hwasan/hwasan_allocator.h +++ b/compiler-rt/lib/hwasan/hwasan_allocator.h @@ -95,6 +95,8 @@ uptr ActualSize() const; // Size allocated by the allocator. u32 GetAllocStackId() const; bool FromSmallHeap() const; + bool AddrIsInside(uptr addr) const; + private: friend class __lsan::LsanMetadata; uptr block_; 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 @@ -71,6 +71,10 @@ return allocator.FromPrimary(reinterpret_cast(block_)); } +bool HwasanChunkView::AddrIsInside(uptr addr) const { + return (addr >= Beg()) && (addr < Beg() + UsedSize()); +} + inline void Metadata::SetAllocated(u32 stack, u64 size) { Thread *t = GetCurrentThread(); u64 context = t ? t->unique_id() : kMainTid; @@ -482,6 +486,36 @@ // --- Implementation of LSan-specific functions --- {{{1 namespace __lsan { +void LockAllocator() { + __hwasan::HwasanAllocatorLock(); +} + +void UnlockAllocator() { + __hwasan::HwasanAllocatorUnlock(); +} + +void GetAllocatorGlobalRange(uptr *begin, uptr *end) { + *begin = (uptr)&__hwasan::allocator; + *end = *begin + sizeof(__hwasan::allocator); +} + +uptr PointsIntoChunk(void *p) { + uptr addr = reinterpret_cast(p); + __hwasan::HwasanChunkView view = __hwasan::FindHeapChunkByAddress(addr); + if (!view.IsAllocated()) + return 0; + uptr chunk = view.Beg(); + if (view.AddrIsInside(addr)) + return chunk; + if (IsSpecialCaseOfOperatorNew0(chunk, view.UsedSize(), addr)) + return chunk; + return 0; +} + +uptr GetUserBegin(uptr chunk) { + return __hwasan::FindHeapChunkByAddress(chunk).Beg(); +} + LsanMetadata::LsanMetadata(uptr chunk) { metadata_ = chunk ? reinterpret_cast<__hwasan::Metadata *>( chunk - __hwasan::kChunkHeaderSize) @@ -515,6 +549,10 @@ return m->GetAllocStackId(); } +void ForEachChunk(ForEachChunkCallback callback, void *arg) { + __hwasan::allocator.ForEachChunk(callback, arg); +} + } // namespace __lsan using namespace __hwasan;