1818
1919#include < folly/Try.h>
2020#include < folly/logging/xlog.h>
21- #include < sanitizer/asan_interface.h>
2221
2322#include " cachelib/allocator/memory/SlabAllocator.h"
2423#include " cachelib/common/Exceptions.h"
@@ -52,7 +51,8 @@ AllocationClass::AllocationClass(ClassId classId,
5251 slabAlloc_.createPtrCompressor <FreeAlloc, CompressedPtr5B>()
5352#if FOLLY_SANITIZE_ADDRESS
5453 ,
55- allocationSize_
54+ // Only enable ASAN poisoning in the free list if configured
55+ slabAlloc_.isAsanPoisoningEnabled () ? allocationSize_ : 0
5656#endif
5757 } {
5858 checkState ();
@@ -110,7 +110,8 @@ AllocationClass::AllocationClass(
110110 slabAlloc_.createPtrCompressor<FreeAlloc, CompressedPtr5B>()
111111#if FOLLY_SANITIZE_ADDRESS
112112 ,
113- allocationSize_
113+ // Only enable ASAN poisoning in the free list if configured
114+ slabAlloc_.isAsanPoisoningEnabled() ? allocationSize_ : 0
114115#endif
115116 ),
116117 canAllocate_ (*object.canAllocate()) {
@@ -133,22 +134,22 @@ AllocationClass::AllocationClass(
133134
134135 // Free slabs are entirely unused
135136 for (auto * slab : freeSlabs_) {
136- ASAN_POISON_MEMORY_REGION (slab->memoryAtOffset (0 ), Slab::kSize );
137+ slabAlloc_. asanPoisonMemoryRegion (slab->memoryAtOffset (0 ), Slab::kSize );
137138 }
138139
139140 // Poison the internal fragmentation at the tail of fully allocated slabs
140141 const uint32_t usableSize = getAllocsPerSlab () * allocationSize_;
141142 if (usableSize < Slab::kSize ) {
142143 for (auto * slab : allocatedSlabs_) {
143- ASAN_POISON_MEMORY_REGION (slab->memoryAtOffset (usableSize),
144- Slab::kSize - usableSize);
144+ slabAlloc_. asanPoisonMemoryRegion (slab->memoryAtOffset (usableSize),
145+ Slab::kSize - usableSize);
145146 }
146147 }
147148
148149 // Poison the uncarved region of currSlab_
149150 if (currSlab_ != nullptr && currOffset_ < Slab::kSize ) {
150- ASAN_POISON_MEMORY_REGION (currSlab_->memoryAtOffset (currOffset_),
151- Slab::kSize - currOffset_);
151+ slabAlloc_. asanPoisonMemoryRegion (currSlab_->memoryAtOffset (currOffset_),
152+ Slab::kSize - currOffset_);
152153 }
153154}
154155
@@ -177,7 +178,7 @@ void* AllocationClass::allocateFromCurrentSlabLocked() noexcept {
177178 XDCHECK (canAllocateFromCurrentSlabLocked ());
178179 void * ret = currSlab_->memoryAtOffset (currOffset_);
179180 currOffset_ += allocationSize_;
180- ASAN_UNPOISON_MEMORY_REGION (ret, allocationSize_);
181+ slabAlloc_. asanUnpoisonMemoryRegion (ret, allocationSize_);
181182 return ret;
182183}
183184
@@ -208,7 +209,7 @@ void* AllocationClass::allocateLocked() {
208209 FreeAlloc* ret = freedAllocations_.getHead ();
209210 XDCHECK (ret != nullptr );
210211 freedAllocations_.pop ();
211- ASAN_UNPOISON_MEMORY_REGION (ret, allocationSize_);
212+ slabAlloc_. asanUnpoisonMemoryRegion (ret, allocationSize_);
212213 return reinterpret_cast <void *>(ret);
213214 }
214215
@@ -687,7 +688,7 @@ void AllocationClass::free(void* memory) {
687688 throw std::invalid_argument (
688689 folly::sformat (" Allocation {} is already marked as free" , memory));
689690 }
690- ASAN_POISON_MEMORY_REGION (memory, allocationSize_);
691+ slabAlloc_. asanPoisonMemoryRegion (memory, allocationSize_);
691692 allocState[idx] = true ;
692693 return ;
693694 }
0 commit comments