From 060f30deeb77f65e96925bf5c208419735067a44 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@300882 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/ArrayRecycler.h | 5 ++--- include/llvm/Support/Recycler.h | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/include/llvm/Support/ArrayRecycler.h b/include/llvm/Support/ArrayRecycler.h index b4222ca92c7..68696be6bf3 100644 --- a/include/llvm/Support/ArrayRecycler.h +++ b/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/include/llvm/Support/Recycler.h b/include/llvm/Support/Recycler.h index dc8b246ebf2..53db2e86d12 100644 --- a/include/llvm/Support/Recycler.h +++ b/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.40.0