[llvm-commits] [compiler-rt] r159141 - in /compiler-rt/trunk/lib/tsan: rtl/tsan_allocator.cc rtl/tsan_allocator.h rtl/tsan_mman.cc unit_tests/tsan_allocator_test.cc
Dmitry Vyukov
dvyukov at google.com
Mon Jun 25 08:03:15 PDT 2012
Author: dvyukov
Date: Mon Jun 25 10:03:15 2012
New Revision: 159141
URL: http://llvm.org/viewvc/llvm-project?rev=159141&view=rev
Log:
tsan: remove internal allocator, switch to sanitizer_common one.
Removed:
compiler-rt/trunk/lib/tsan/rtl/tsan_allocator.cc
compiler-rt/trunk/lib/tsan/rtl/tsan_allocator.h
compiler-rt/trunk/lib/tsan/unit_tests/tsan_allocator_test.cc
Modified:
compiler-rt/trunk/lib/tsan/rtl/tsan_mman.cc
Removed: compiler-rt/trunk/lib/tsan/rtl/tsan_allocator.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_allocator.cc?rev=159140&view=auto
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_allocator.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_allocator.cc (removed)
@@ -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
Removed: compiler-rt/trunk/lib/tsan/rtl/tsan_allocator.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_allocator.h?rev=159140&view=auto
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_allocator.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_allocator.h (removed)
@@ -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
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_mman.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_mman.cc?rev=159141&r1=159140&r2=159141&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_mman.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_mman.cc Mon Jun 25 10:03:15 2012
@@ -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 @@
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 @@
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 @@
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",
Removed: compiler-rt/trunk/lib/tsan/unit_tests/tsan_allocator_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/unit_tests/tsan_allocator_test.cc?rev=159140&view=auto
==============================================================================
--- compiler-rt/trunk/lib/tsan/unit_tests/tsan_allocator_test.cc (original)
+++ compiler-rt/trunk/lib/tsan/unit_tests/tsan_allocator_test.cc (removed)
@@ -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 <stdlib.h>
-
-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
More information about the llvm-commits
mailing list