Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions compiler-rt/lib/sanitizer_common/sanitizer_allocator_dlsym.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,19 @@ struct DlSymAllocator {
static void *Allocate(uptr size_in_bytes, uptr align = kWordSize) {
void *ptr = InternalAlloc(size_in_bytes, nullptr, align);
CHECK(internal_allocator()->FromPrimary(ptr));
Details::OnAllocate(ptr,
internal_allocator()->GetActuallyAllocatedSize(ptr));
Details::OnAllocate(ptr, GetSize(ptr));
return ptr;
}

static void *Callocate(usize nmemb, usize size) {
void *ptr = InternalCalloc(nmemb, size);
CHECK(internal_allocator()->FromPrimary(ptr));
Details::OnAllocate(ptr,
internal_allocator()->GetActuallyAllocatedSize(ptr));
Details::OnAllocate(ptr, GetSize(ptr));
return ptr;
}

static void Free(void *ptr) {
uptr size = internal_allocator()->GetActuallyAllocatedSize(ptr);
uptr size = GetSize(ptr);
Details::OnFree(ptr, size);
InternalFree(ptr);
}
Expand All @@ -63,7 +61,7 @@ struct DlSymAllocator {
Free(ptr);
return nullptr;
}
uptr size = internal_allocator()->GetActuallyAllocatedSize(ptr);
uptr size = GetSize(ptr);
uptr memcpy_size = Min(new_size, size);
void *new_ptr = Allocate(new_size);
if (new_ptr)
Expand All @@ -77,6 +75,10 @@ struct DlSymAllocator {
return Realloc(ptr, count * size);
}

static uptr GetSize(void *ptr) {
return internal_allocator()->GetActuallyAllocatedSize(ptr);
}

static void OnAllocate(const void *ptr, uptr size) {}
static void OnFree(const void *ptr, uptr size) {}
};
Expand Down
8 changes: 8 additions & 0 deletions compiler-rt/lib/tysan/tysan_interceptors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ INTERCEPTOR(void *, malloc, uptr size) {
return res;
}

#if SANITIZER_APPLE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drive by question: how do we decide between TYSAN_INTERCEPT___STRDUP and SANITIZER_APPLE style conditions?

INTERCEPTOR(uptr, malloc_size, void *ptr) {
if (DlsymAlloc::PointerIsMine(ptr))
return DlsymAlloc::GetSize(ptr);
return REAL(malloc_size)(ptr);
}
#endif

INTERCEPTOR(void *, realloc, void *ptr, uptr size) {
if (DlsymAlloc::Use() || DlsymAlloc::PointerIsMine(ptr))
return DlsymAlloc::Realloc(ptr, size);
Expand Down
Loading