From ec64f3e738f87d3c37f72bafd5a2dbee9042a443 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Mon, 25 Jun 2012 15:03:15 +0000 Subject: [PATCH] tsan: remove internal allocator, switch to sanitizer_common one. llvm-svn: 159141 --- compiler-rt/lib/tsan/rtl/tsan_allocator.cc | 47 ---------------- compiler-rt/lib/tsan/rtl/tsan_allocator.h | 29 ---------- compiler-rt/lib/tsan/rtl/tsan_mman.cc | 7 +-- .../tsan/unit_tests/tsan_allocator_test.cc | 56 ------------------- 4 files changed, 3 insertions(+), 136 deletions(-) delete mode 100644 compiler-rt/lib/tsan/rtl/tsan_allocator.cc delete mode 100644 compiler-rt/lib/tsan/rtl/tsan_allocator.h delete mode 100644 compiler-rt/lib/tsan/unit_tests/tsan_allocator_test.cc diff --git a/compiler-rt/lib/tsan/rtl/tsan_allocator.cc b/compiler-rt/lib/tsan/rtl/tsan_allocator.cc deleted file mode 100644 index 1571b47089ea..000000000000 --- a/compiler-rt/lib/tsan/rtl/tsan_allocator.cc +++ /dev/null @@ -1,47 +0,0 @@ -//===-- tsan_allocator-----------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file is a part of ThreadSanitizer (TSan), a race detector. -// -//===----------------------------------------------------------------------===// -#include "tsan_allocator.h" - -// Provisional implementation. -extern "C" void *__libc_malloc(__sanitizer::uptr size); -extern "C" void __libc_free(void *ptr); - -namespace __tsan { - -u64 kBlockMagic = 0x6A6CB03ABCEBC041ull; - -void AllocInit() { -} - -void *Alloc(uptr sz) { - void *p = __libc_malloc(sz + sizeof(u64)); - ((u64*)p)[0] = kBlockMagic; - return (char*)p + sizeof(u64); -} - -void Free(void *p) { - CHECK_NE(p, (char*)0); - p = (char*)p - sizeof(u64); - CHECK_EQ(((u64*)p)[0], kBlockMagic); - ((u64*)p)[0] = 0; - __libc_free(p); -} - -void *AllocBlock(void *p) { - CHECK_NE(p, (void*)0); - u64 *pp = (u64*)((uptr)p & ~0x7); - for (; pp[0] != kBlockMagic; pp--) {} - return pp + 1; -} - -} // namespace __tsan diff --git a/compiler-rt/lib/tsan/rtl/tsan_allocator.h b/compiler-rt/lib/tsan/rtl/tsan_allocator.h deleted file mode 100644 index 7018bced29fc..000000000000 --- a/compiler-rt/lib/tsan/rtl/tsan_allocator.h +++ /dev/null @@ -1,29 +0,0 @@ -//===-- tsan_allocator.h ----------------------------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file is a part of ThreadSanitizer (TSan), a race detector. -// -//===----------------------------------------------------------------------===// -#ifndef TSAN_ALLOCATOR_H -#define TSAN_ALLOCATOR_H - -#include "tsan_defs.h" - -namespace __tsan { - -void AllocInit(); -void *Alloc(uptr sz); -void Free(void *p); // Does not accept NULL. -// Given the pointer p into a valid allocated block, -// returns a pointer to the beginning of the block. -void *AllocBlock(void *p); - -} // namespace __tsan - -#endif // TSAN_ALLOCATOR_H diff --git a/compiler-rt/lib/tsan/rtl/tsan_mman.cc b/compiler-rt/lib/tsan/rtl/tsan_mman.cc index 20c695a3aecb..7f956dfe26bf 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_mman.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_mman.cc @@ -12,7 +12,6 @@ //===----------------------------------------------------------------------===// #include "sanitizer_common/sanitizer_common.h" #include "tsan_mman.h" -#include "tsan_allocator.h" #include "tsan_rtl.h" #include "tsan_report.h" #include "tsan_flags.h" @@ -33,7 +32,7 @@ void *user_alloc(ThreadState *thr, uptr pc, uptr sz) { CHECK_GT(thr->in_rtl, 0); if (sz + sizeof(MBlock) < sz) return 0; - MBlock *b = (MBlock*)Alloc(sz + sizeof(MBlock)); + MBlock *b = (MBlock*)InternalAlloc(sz + sizeof(MBlock)); if (b == 0) return 0; b->size = sz; @@ -55,7 +54,7 @@ void user_free(ThreadState *thr, uptr pc, void *p) { if (CTX() && CTX()->initialized && thr->in_rtl == 1) { MemoryRangeFreed(thr, pc, (uptr)p, b->size); } - Free(b); + InternalFree(b); SignalUnsafeCall(thr, pc); } @@ -90,7 +89,7 @@ void *user_alloc_aligned(ThreadState *thr, uptr pc, uptr sz, uptr align) { MBlock *user_mblock(ThreadState *thr, void *p) { CHECK_GT(thr->in_rtl, 0); CHECK_NE(p, (void*)0); - MBlock *b = (MBlock*)AllocBlock(p); + MBlock *b = (MBlock*)InternalAllocBlock(p); // FIXME: Output a warning, it's a user error. if (p < (char*)(b + 1) || p > (char*)(b + 1) + b->size) { TsanPrintf("user_mblock p=%p b=%p size=%zu beg=%p end=%p\n", diff --git a/compiler-rt/lib/tsan/unit_tests/tsan_allocator_test.cc b/compiler-rt/lib/tsan/unit_tests/tsan_allocator_test.cc deleted file mode 100644 index be5bb606002f..000000000000 --- a/compiler-rt/lib/tsan/unit_tests/tsan_allocator_test.cc +++ /dev/null @@ -1,56 +0,0 @@ -//===-- tsan_allocator_test.c----------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file is a part of ThreadSanitizer (TSan), a race detector. -// -//===----------------------------------------------------------------------===// -#include "tsan_allocator.h" -#include "gtest/gtest.h" -#include - -namespace __tsan { - -TEST(Allocator, Basic) { - char *p = (char*)Alloc(10); - EXPECT_NE(p, (char*)0); - char *p2 = (char*)Alloc(20); - EXPECT_NE(p2, (char*)0); - EXPECT_NE(p2, p); - for (int i = 0; i < 10; i++) { - p[i] = 42; - EXPECT_EQ(p, AllocBlock(p + i)); - } - for (int i = 0; i < 20; i++) { - ((char*)p2)[i] = 42; - EXPECT_EQ(p2, AllocBlock(p2 + i)); - } - Free(p); - Free(p2); -} - -TEST(Allocator, Stress) { - const int kCount = 1000; - char *ptrs[kCount]; - unsigned rnd = 42; - for (int i = 0; i < kCount; i++) { - uptr sz = rand_r(&rnd) % 1000; - char *p = (char*)Alloc(sz); - EXPECT_NE(p, (char*)0); - for (uptr j = 0; j < sz; j++) { - p[j] = 42; - EXPECT_EQ(p, AllocBlock(p + j)); - } - ptrs[i] = p; - } - for (int i = 0; i < kCount; i++) { - Free(ptrs[i]); - } -} - -} // namespace __tsan