diff options
| author | Alexey Samsonov <vonosmas@gmail.com> | 2014-07-01 18:01:20 +0000 |
|---|---|---|
| committer | Alexey Samsonov <vonosmas@gmail.com> | 2014-07-01 18:01:20 +0000 |
| commit | 06ff6cbf4d5b8a34e35363bdde82aa50771312f1 (patch) | |
| tree | 7810cfaaa7d55d8dcfdb3fd970d92515dad5fd21 | |
| parent | 9b35cf52d2a88cda5167c9638696adce5b152720 (diff) | |
| download | bcm5719-llvm-06ff6cbf4d5b8a34e35363bdde82aa50771312f1.tar.gz bcm5719-llvm-06ff6cbf4d5b8a34e35363bdde82aa50771312f1.zip | |
[TSan] Equalize the behavior of __tsan_get_allocated_size and user_alloc_usable_size.
The former used to crash with a null deref if it was given a not owned pointer,
while the latter returned 0. Now they both return 0. This is still not the best possible
behavior: it is better to print an error report with a stack trace, pointing
to the error in user code, as we do in ASan.
llvm-svn: 212112
| -rw-r--r-- | compiler-rt/lib/tsan/rtl/tsan_interceptors.cc | 2 | ||||
| -rw-r--r-- | compiler-rt/lib/tsan/rtl/tsan_mman.cc | 9 | ||||
| -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 | 11 |
4 files changed, 11 insertions, 13 deletions
diff --git a/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc b/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc index cd44f2b50bd..53c7c2618b0 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc @@ -520,7 +520,7 @@ TSAN_INTERCEPTOR(void, cfree, void *p) { TSAN_INTERCEPTOR(uptr, malloc_usable_size, void *p) { SCOPED_INTERCEPTOR_RAW(malloc_usable_size, p); - return user_alloc_usable_size(thr, pc, p); + return user_alloc_usable_size(p); } #define OPERATOR_NEW_BODY(mangled_name) \ diff --git a/compiler-rt/lib/tsan/rtl/tsan_mman.cc b/compiler-rt/lib/tsan/rtl/tsan_mman.cc index 8c037e155fe..5cc30bc4eec 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_mman.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_mman.cc @@ -119,7 +119,7 @@ void *user_realloc(ThreadState *thr, uptr pc, void *p, uptr sz) { if (p2 == 0) return 0; if (p) { - uptr oldsz = user_alloc_usable_size(thr, pc, p); + uptr oldsz = user_alloc_usable_size(p); internal_memcpy(p2, p, min(oldsz, sz)); } } @@ -128,7 +128,7 @@ void *user_realloc(ThreadState *thr, uptr pc, void *p, uptr sz) { return p2; } -uptr user_alloc_usable_size(ThreadState *thr, uptr pc, void *p) { +uptr user_alloc_usable_size(void *p) { if (p == 0) return 0; MBlock *b = ctx->metamap.GetBlock((uptr)p); @@ -202,10 +202,7 @@ bool __tsan_get_ownership(void *p) { } uptr __tsan_get_allocated_size(void *p) { - if (p == 0) - return 0; - MBlock *b = ctx->metamap.GetBlock((uptr)p); - return b->siz; + return user_alloc_usable_size(p); } void __tsan_on_thread_idle() { diff --git a/compiler-rt/lib/tsan/rtl/tsan_mman.h b/compiler-rt/lib/tsan/rtl/tsan_mman.h index 67c6ee5eaa2..7b4f9bd7c1d 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(ThreadState *thr, uptr pc, void *p); +uptr user_alloc_usable_size(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 d8afeaf4d9f..e52a85aacb4 100644 --- a/compiler-rt/lib/tsan/tests/unit/tsan_mman_test.cc +++ b/compiler-rt/lib/tsan/tests/unit/tsan_mman_test.cc @@ -51,8 +51,8 @@ TEST(Mman, User) { char *p2 = (char*)user_alloc(thr, pc, 20); EXPECT_NE(p2, (char*)0); EXPECT_NE(p2, p); - EXPECT_EQ(user_alloc_usable_size(thr, pc, p), (uptr)10); - EXPECT_EQ(user_alloc_usable_size(thr, pc, p2), (uptr)20); + EXPECT_EQ(10U, user_alloc_usable_size(p)); + EXPECT_EQ(20U, user_alloc_usable_size(p2)); user_free(thr, pc, p); user_free(thr, pc, p2); } @@ -107,11 +107,12 @@ TEST(Mman, UsableSize) { 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)); + EXPECT_EQ(0U, user_alloc_usable_size(NULL)); + EXPECT_EQ(10U, user_alloc_usable_size(p)); + EXPECT_EQ(20U, user_alloc_usable_size(p2)); user_free(thr, pc, p); user_free(thr, pc, p2); + EXPECT_EQ(0U, user_alloc_usable_size((void*)0x123)); } TEST(Mman, Stats) { |

