[compiler-rt] r212112 - [TSan] Equalize the behavior of __tsan_get_allocated_size and user_alloc_usable_size.
Alexey Samsonov
vonosmas at gmail.com
Tue Jul 1 11:01:20 PDT 2014
Author: samsonov
Date: Tue Jul 1 13:01:20 2014
New Revision: 212112
URL: http://llvm.org/viewvc/llvm-project?rev=212112&view=rev
Log:
[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.
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/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=212112&r1=212111&r2=212112&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc Tue Jul 1 13:01:20 2014
@@ -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) \
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=212112&r1=212111&r2=212112&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_mman.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_mman.cc Tue Jul 1 13:01:20 2014
@@ -119,7 +119,7 @@ void *user_realloc(ThreadState *thr, upt
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, upt
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() {
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=212112&r1=212111&r2=212112&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_mman.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_mman.h Tue Jul 1 13:01:20 2014
@@ -31,7 +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);
+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);
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=212112&r1=212111&r2=212112&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 Tue Jul 1 13:01:20 2014
@@ -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) {
More information about the llvm-commits
mailing list