forked from OSchip/llvm-project
[TSan] Add interceptor for malloc_usable_size()
llvm-svn: 176013
This commit is contained in:
parent
10bccda948
commit
85f0a7e644
|
@ -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); \
|
||||
|
|
|
@ -127,6 +127,14 @@ void *user_realloc(ThreadState *thr, uptr pc, void *p, uptr sz) {
|
|||
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();
|
||||
|
|
|
@ -31,6 +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);
|
||||
// Given the pointer p into a valid allocated block,
|
||||
// returns the descriptor of the block.
|
||||
MBlock *user_mblock(ThreadState *thr, void *p);
|
||||
|
|
|
@ -102,6 +102,7 @@ enum StatType {
|
|||
StatInt_realloc,
|
||||
StatInt_free,
|
||||
StatInt_cfree,
|
||||
StatInt_malloc_usable_size,
|
||||
StatInt_mmap,
|
||||
StatInt_mmap64,
|
||||
StatInt_munmap,
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue