Index: lib/asan/asan_allocator.cc =================================================================== --- lib/asan/asan_allocator.cc +++ lib/asan/asan_allocator.cc @@ -291,6 +291,35 @@ cf->allocator_release_to_os_interval_ms = release_to_os_interval_ms; } +// Returns a pointer to the `AsanChunk` in the target process. +// +// `alloc_beg` - Pointer to the beginning of the allocation in the target +// process, i.e. +// `allocator_view.GetBlockBegin(alloc_beg) == alloc_beg`. +// +// `allocator` - Pointer to the allocator in the local process. +template +static AsanChunk *GetAsanChunkInternal(uptr alloc_beg, uptr allocator) { + if (!alloc_beg) + return nullptr; + auto allocator_view = + reinterpret_cast *>(allocator); + + if (!allocator_view->FromPrimary(reinterpret_cast(alloc_beg))) { + const uptr *meta = AddressSpaceView::Load( + reinterpret_cast( + allocator_view->GetMetaData(reinterpret_cast(alloc_beg))), + 2); + AsanChunk *m = reinterpret_cast(meta[1]); + return m; + } + const uptr *alloc_magic = + AddressSpaceView::Load(reinterpret_cast(alloc_beg), 2); + if (alloc_magic[0] == kAllocBegMagic) + return reinterpret_cast(alloc_magic[1]); + return reinterpret_cast(alloc_beg); +} + struct Allocator { static const uptr kMaxAllowedMallocSize = FIRST_32_SECOND_64(3UL << 30, 1ULL << 40); @@ -758,16 +787,8 @@ // Assumes alloc_beg == allocator.GetBlockBegin(alloc_beg). AsanChunk *GetAsanChunk(void *alloc_beg) { - if (!alloc_beg) return nullptr; - if (!allocator.FromPrimary(alloc_beg)) { - uptr *meta = reinterpret_cast(allocator.GetMetaData(alloc_beg)); - AsanChunk *m = reinterpret_cast(meta[1]); - return m; - } - uptr *alloc_magic = reinterpret_cast(alloc_beg); - if (alloc_magic[0] == kAllocBegMagic) - return reinterpret_cast(alloc_magic[1]); - return reinterpret_cast(alloc_beg); + return GetAsanChunkInternal( + reinterpret_cast(alloc_beg), reinterpret_cast(&allocator)); } AsanChunk *GetAsanChunkByAddr(uptr p) {