From 9ed1371adb219b791ac446812182e643c1f727dc Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Thu, 20 Apr 2017 20:28:18 +0000 Subject: [PATCH] [Support] Make asan poisoning for recyclers more aggressive by also poisoning the 'next' pointer. llvm-svn: 300882 --- llvm/include/llvm/Support/ArrayRecycler.h | 5 ++--- llvm/include/llvm/Support/Recycler.h | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/llvm/include/llvm/Support/ArrayRecycler.h b/llvm/include/llvm/Support/ArrayRecycler.h index b4222ca..68696be 100644 --- a/llvm/include/llvm/Support/ArrayRecycler.h +++ b/llvm/include/llvm/Support/ArrayRecycler.h @@ -47,22 +47,21 @@ template class ArrayRecycler { FreeList *Entry = Bucket[Idx]; if (!Entry) return nullptr; + __asan_unpoison_memory_region(Entry, Capacity::get(Idx).getSize()); Bucket[Idx] = Entry->Next; __msan_allocated_memory(Entry, Capacity::get(Idx).getSize()); - __asan_unpoison_memory_region(Entry, Capacity::get(Idx).getSize()); return reinterpret_cast(Entry); } // Add an entry to the free list at Bucket[Idx]. void push(unsigned Idx, T *Ptr) { assert(Ptr && "Cannot recycle NULL pointer"); - __asan_poison_memory_region(Ptr, Capacity::get(Idx).getSize()); - __asan_unpoison_memory_region(Ptr, sizeof(FreeList)); FreeList *Entry = reinterpret_cast(Ptr); if (Idx >= Bucket.size()) Bucket.resize(size_t(Idx) + 1); Entry->Next = Bucket[Idx]; Bucket[Idx] = Entry; + __asan_poison_memory_region(Ptr, Capacity::get(Idx).getSize()); } public: diff --git a/llvm/include/llvm/Support/Recycler.h b/llvm/include/llvm/Support/Recycler.h index dc8b246..53db2e8 100644 --- a/llvm/include/llvm/Support/Recycler.h +++ b/llvm/include/llvm/Support/Recycler.h @@ -42,17 +42,16 @@ class Recycler { FreeNode *pop_val() { auto *Val = FreeList; + __asan_unpoison_memory_region(Val, Size); FreeList = FreeList->Next; __msan_allocated_memory(Val, Size); - __asan_unpoison_memory_region(Val, Size); return Val; } void push(FreeNode *N) { - __asan_poison_memory_region(N, Size); - __asan_unpoison_memory_region(N, sizeof(FreeNode)); N->Next = FreeList; FreeList = N; + __asan_poison_memory_region(N, Size); } public: -- 2.7.4