diff options
| author | Alexey Samsonov <vonosmas@gmail.com> | 2014-07-07 17:39:31 +0000 |
|---|---|---|
| committer | Alexey Samsonov <vonosmas@gmail.com> | 2014-07-07 17:39:31 +0000 |
| commit | 91bb8e0e3a6312f673b04454de2eeea0be682c0a (patch) | |
| tree | b1047d5cea1a03ee5b9c5526806f607bc91dbba5 /compiler-rt/lib/tsan | |
| parent | 761439962b996292e5c49a19f3b1ee6cd5584f70 (diff) | |
| download | bcm5719-llvm-91bb8e0e3a6312f673b04454de2eeea0be682c0a.tar.gz bcm5719-llvm-91bb8e0e3a6312f673b04454de2eeea0be682c0a.zip | |
Generalize sanitizer allocator public interface.
Introduce new public header <sanitizer/allocator_interface.h> and a set
of functions __sanitizer_get_ownership(), __sanitizer_malloc_hook() etc.
that will eventually replace their tool-specific equivalents
(__asan_get_ownership(), __msan_get_ownership() etc.). Tool-specific
functions are now deprecated and implemented as stubs redirecting
to __sanitizer_ versions (which are implemented differently in each tool).
Replace all uses of __xsan_ versions with __sanitizer_ versions in unit
and lit tests.
llvm-svn: 212469
Diffstat (limited to 'compiler-rt/lib/tsan')
| -rw-r--r-- | compiler-rt/lib/tsan/rtl/tsan_mman.cc | 47 | ||||
| -rw-r--r-- | compiler-rt/lib/tsan/rtl/tsan_mman.h | 2 | ||||
| -rw-r--r-- | compiler-rt/lib/tsan/tests/unit/tsan_mman_test.cc | 45 |
3 files changed, 58 insertions, 36 deletions
diff --git a/compiler-rt/lib/tsan/rtl/tsan_mman.cc b/compiler-rt/lib/tsan/rtl/tsan_mman.cc index 5cc30bc4eec..8542a8fd0a5 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_mman.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_mman.cc @@ -10,6 +10,7 @@ // This file is a part of ThreadSanitizer (TSan), a race detector. // //===----------------------------------------------------------------------===// +#include "sanitizer_common/sanitizer_allocator_interface.h" #include "sanitizer_common/sanitizer_common.h" #include "sanitizer_common/sanitizer_placement_new.h" #include "tsan_mman.h" @@ -22,10 +23,17 @@ extern "C" void WEAK __tsan_malloc_hook(void *ptr, uptr size) { (void)ptr; (void)size; } +extern "C" void WEAK __sanitizer_malloc_hook(void *ptr, uptr size) { + (void)ptr; + (void)size; +} extern "C" void WEAK __tsan_free_hook(void *ptr) { (void)ptr; } +extern "C" void WEAK __sanitizer_free_hook(void *ptr) { + (void)ptr; +} namespace __tsan { @@ -128,7 +136,7 @@ void *user_realloc(ThreadState *thr, uptr pc, void *p, uptr sz) { return p2; } -uptr user_alloc_usable_size(void *p) { +uptr user_alloc_usable_size(const void *p) { if (p == 0) return 0; MBlock *b = ctx->metamap.GetBlock((uptr)p); @@ -140,6 +148,7 @@ void invoke_malloc_hook(void *ptr, uptr size) { if (ctx == 0 || !ctx->initialized || thr->ignore_interceptors) return; __tsan_malloc_hook(ptr, size); + __sanitizer_malloc_hook(ptr, size); } void invoke_free_hook(void *ptr) { @@ -147,6 +156,7 @@ void invoke_free_hook(void *ptr) { if (ctx == 0 || !ctx->initialized || thr->ignore_interceptors) return; __tsan_free_hook(ptr); + __sanitizer_free_hook(ptr); } void *internal_alloc(MBlockType typ, uptr sz) { @@ -173,37 +183,58 @@ void internal_free(void *p) { using namespace __tsan; extern "C" { -uptr __tsan_get_current_allocated_bytes() { +uptr __sanitizer_get_current_allocated_bytes() { uptr stats[AllocatorStatCount]; allocator()->GetStats(stats); return stats[AllocatorStatAllocated]; } +uptr __tsan_get_current_allocated_bytes() { + return __sanitizer_get_current_allocated_bytes(); +} -uptr __tsan_get_heap_size() { +uptr __sanitizer_get_heap_size() { uptr stats[AllocatorStatCount]; allocator()->GetStats(stats); return stats[AllocatorStatMapped]; } +uptr __tsan_get_heap_size() { + return __sanitizer_get_heap_size(); +} -uptr __tsan_get_free_bytes() { +uptr __sanitizer_get_free_bytes() { return 1; } +uptr __tsan_get_free_bytes() { + return __sanitizer_get_free_bytes(); +} -uptr __tsan_get_unmapped_bytes() { +uptr __sanitizer_get_unmapped_bytes() { return 1; } +uptr __tsan_get_unmapped_bytes() { + return __sanitizer_get_unmapped_bytes(); +} -uptr __tsan_get_estimated_allocated_size(uptr size) { +uptr __sanitizer_get_estimated_allocated_size(uptr size) { return size; } +uptr __tsan_get_estimated_allocated_size(uptr size) { + return __sanitizer_get_estimated_allocated_size(size); +} -bool __tsan_get_ownership(void *p) { +int __sanitizer_get_ownership(const void *p) { return allocator()->GetBlockBegin(p) != 0; } +int __tsan_get_ownership(const void *p) { + return __sanitizer_get_ownership(p); +} -uptr __tsan_get_allocated_size(void *p) { +uptr __sanitizer_get_allocated_size(const void *p) { return user_alloc_usable_size(p); } +uptr __tsan_get_allocated_size(const void *p) { + return __sanitizer_get_allocated_size(p); +} void __tsan_on_thread_idle() { ThreadState *thr = cur_thread(); diff --git a/compiler-rt/lib/tsan/rtl/tsan_mman.h b/compiler-rt/lib/tsan/rtl/tsan_mman.h index 7b4f9bd7c1d..4f87ad6e4e1 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_mman.h +++ b/compiler-rt/lib/tsan/rtl/tsan_mman.h @@ -31,7 +31,7 @@ void *user_alloc(ThreadState *thr, uptr pc, uptr sz, void user_free(ThreadState *thr, uptr pc, void *p); void *user_realloc(ThreadState *thr, uptr pc, void *p, uptr sz); void *user_alloc_aligned(ThreadState *thr, uptr pc, uptr sz, uptr align); -uptr user_alloc_usable_size(void *p); +uptr user_alloc_usable_size(const void *p); // Invoking malloc/free hooks that may be installed by the user. void invoke_malloc_hook(void *ptr, uptr size); diff --git a/compiler-rt/lib/tsan/tests/unit/tsan_mman_test.cc b/compiler-rt/lib/tsan/tests/unit/tsan_mman_test.cc index e52a85aacb4..0c4a8ffc81e 100644 --- a/compiler-rt/lib/tsan/tests/unit/tsan_mman_test.cc +++ b/compiler-rt/lib/tsan/tests/unit/tsan_mman_test.cc @@ -11,20 +11,11 @@ // //===----------------------------------------------------------------------===// #include <limits> +#include <sanitizer/allocator_interface.h> #include "tsan_mman.h" #include "tsan_rtl.h" #include "gtest/gtest.h" -extern "C" { -uptr __tsan_get_current_allocated_bytes(); -uptr __tsan_get_heap_size(); -uptr __tsan_get_free_bytes(); -uptr __tsan_get_unmapped_bytes(); -uptr __tsan_get_estimated_allocated_size(uptr size); -bool __tsan_get_ownership(void *p); -uptr __tsan_get_allocated_size(void *p); -} - namespace __tsan { TEST(Mman, Internal) { @@ -118,30 +109,30 @@ TEST(Mman, UsableSize) { TEST(Mman, Stats) { ThreadState *thr = cur_thread(); - uptr alloc0 = __tsan_get_current_allocated_bytes(); - uptr heap0 = __tsan_get_heap_size(); - uptr free0 = __tsan_get_free_bytes(); - uptr unmapped0 = __tsan_get_unmapped_bytes(); + uptr alloc0 = __sanitizer_get_current_allocated_bytes(); + uptr heap0 = __sanitizer_get_heap_size(); + uptr free0 = __sanitizer_get_free_bytes(); + uptr unmapped0 = __sanitizer_get_unmapped_bytes(); - EXPECT_EQ(__tsan_get_estimated_allocated_size(10), (uptr)10); - EXPECT_EQ(__tsan_get_estimated_allocated_size(20), (uptr)20); - EXPECT_EQ(__tsan_get_estimated_allocated_size(100), (uptr)100); + EXPECT_EQ(10U, __sanitizer_get_estimated_allocated_size(10)); + EXPECT_EQ(20U, __sanitizer_get_estimated_allocated_size(20)); + EXPECT_EQ(100U, __sanitizer_get_estimated_allocated_size(100)); char *p = (char*)user_alloc(thr, 0, 10); - EXPECT_EQ(__tsan_get_ownership(p), true); - EXPECT_EQ(__tsan_get_allocated_size(p), (uptr)10); + EXPECT_TRUE(__sanitizer_get_ownership(p)); + EXPECT_EQ(10U, __sanitizer_get_allocated_size(p)); - EXPECT_EQ(__tsan_get_current_allocated_bytes(), alloc0 + 16); - EXPECT_GE(__tsan_get_heap_size(), heap0); - EXPECT_EQ(__tsan_get_free_bytes(), free0); - EXPECT_EQ(__tsan_get_unmapped_bytes(), unmapped0); + EXPECT_EQ(alloc0 + 16, __sanitizer_get_current_allocated_bytes()); + EXPECT_GE(__sanitizer_get_heap_size(), heap0); + EXPECT_EQ(free0, __sanitizer_get_free_bytes()); + EXPECT_EQ(unmapped0, __sanitizer_get_unmapped_bytes()); user_free(thr, 0, p); - EXPECT_EQ(__tsan_get_current_allocated_bytes(), alloc0); - EXPECT_GE(__tsan_get_heap_size(), heap0); - EXPECT_EQ(__tsan_get_free_bytes(), free0); - EXPECT_EQ(__tsan_get_unmapped_bytes(), unmapped0); + EXPECT_EQ(alloc0, __sanitizer_get_current_allocated_bytes()); + EXPECT_GE(__sanitizer_get_heap_size(), heap0); + EXPECT_EQ(free0, __sanitizer_get_free_bytes()); + EXPECT_EQ(unmapped0, __sanitizer_get_unmapped_bytes()); } TEST(Mman, CallocOverflow) { |

