[compiler-rt] r176013 - [TSan] Add interceptor for malloc_usable_size()
Alexey Samsonov
samsonov at google.com
Mon Feb 25 00:43:11 PST 2013
Author: samsonov
Date: Mon Feb 25 02:43:10 2013
New Revision: 176013
URL: http://llvm.org/viewvc/llvm-project?rev=176013&view=rev
Log:
[TSan] Add interceptor for malloc_usable_size()
Modified:
compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
compiler-rt/trunk/lib/tsan/rtl/tsan_mman.cc
compiler-rt/trunk/lib/tsan/rtl/tsan_mman.h
compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h
compiler-rt/trunk/lib/tsan/tests/unit/tsan_mman_test.cc
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc?rev=176013&r1=176012&r2=176013&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc Mon Feb 25 02:43:10 2013
@@ -403,6 +403,11 @@ TSAN_INTERCEPTOR(void, cfree, void *p) {
user_free(thr, pc, p);
}
+TSAN_INTERCEPTOR(uptr, malloc_usable_size, void *p) {
+ SCOPED_INTERCEPTOR_RAW(malloc_usable_size, p);
+ return user_alloc_usable_size(thr, pc, p);
+}
+
#define OPERATOR_NEW_BODY(mangled_name) \
if (cur_thread()->in_symbolizer) \
return __libc_malloc(size); \
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=176013&r1=176012&r2=176013&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_mman.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_mman.cc Mon Feb 25 02:43:10 2013
@@ -127,6 +127,14 @@ void *user_realloc(ThreadState *thr, upt
return p2;
}
+uptr user_alloc_usable_size(ThreadState *thr, uptr pc, void *p) {
+ CHECK_GT(thr->in_rtl, 0);
+ if (p == 0)
+ return 0;
+ MBlock *b = (MBlock*)allocator()->GetMetaData(p);
+ return (b) ? b->size : 0;
+}
+
MBlock *user_mblock(ThreadState *thr, void *p) {
CHECK_NE(p, (void*)0);
Allocator *a = allocator();
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_mman.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_mman.h?rev=176013&r1=176012&r2=176013&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_mman.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_mman.h Mon Feb 25 02:43:10 2013
@@ -31,6 +31,7 @@ void *user_alloc(ThreadState *thr, uptr
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(ThreadState *thr, uptr pc, void *p);
// Given the pointer p into a valid allocated block,
// returns the descriptor of the block.
MBlock *user_mblock(ThreadState *thr, void *p);
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h?rev=176013&r1=176012&r2=176013&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h Mon Feb 25 02:43:10 2013
@@ -102,6 +102,7 @@ enum StatType {
StatInt_realloc,
StatInt_free,
StatInt_cfree,
+ StatInt_malloc_usable_size,
StatInt_mmap,
StatInt_mmap64,
StatInt_munmap,
Modified: compiler-rt/trunk/lib/tsan/tests/unit/tsan_mman_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/tests/unit/tsan_mman_test.cc?rev=176013&r1=176012&r2=176013&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/tests/unit/tsan_mman_test.cc (original)
+++ compiler-rt/trunk/lib/tsan/tests/unit/tsan_mman_test.cc Mon Feb 25 02:43:10 2013
@@ -117,6 +117,19 @@ TEST(Mman, UserRealloc) {
}
}
+TEST(Mman, UsableSize) {
+ ScopedInRtl in_rtl;
+ ThreadState *thr = cur_thread();
+ uptr pc = 0;
+ char *p = (char*)user_alloc(thr, pc, 10);
+ char *p2 = (char*)user_alloc(thr, pc, 20);
+ EXPECT_EQ(0U, user_alloc_usable_size(thr, pc, NULL));
+ EXPECT_EQ(10U, user_alloc_usable_size(thr, pc, p));
+ EXPECT_EQ(20U, user_alloc_usable_size(thr, pc, p2));
+ user_free(thr, pc, p);
+ user_free(thr, pc, p2);
+}
+
TEST(Mman, Stats) {
ScopedInRtl in_rtl;
ThreadState *thr = cur_thread();
More information about the llvm-commits
mailing list