Skip to content

Commit

Permalink
[hwasan] Fix allocator_interface implementation
Browse files Browse the repository at this point in the history
__sanitizer_get_current_allocated_bytes had as body, but allocator
caches were not registered to collect stats. It's done by
SizeClassAllocator64LocalCache::Init().

Reviewed By: thurston

Differential Revision: https://reviews.llvm.org/D151389
  • Loading branch information
vitalybuka committed May 25, 2023
1 parent 76b7dca commit d9b574c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
8 changes: 6 additions & 2 deletions compiler-rt/lib/hwasan/hwasan_allocator.cpp
Expand Up @@ -149,8 +149,9 @@ void HwasanAllocatorInit() {
atomic_store_relaxed(&hwasan_allocator_tagging_enabled,
!flags()->disable_allocator_tagging);
SetAllocatorMayReturnNull(common_flags()->allocator_may_return_null);
allocator.Init(common_flags()->allocator_release_to_os_interval_ms,
GetAliasRegionStart());
allocator.InitLinkerInitialized(
common_flags()->allocator_release_to_os_interval_ms,
GetAliasRegionStart());
for (uptr i = 0; i < sizeof(tail_magic); i++)
tail_magic[i] = GetCurrentThread()->GenerateRandomTag();
if (common_flags()->max_allocation_size_mb) {
Expand All @@ -165,8 +166,11 @@ void HwasanAllocatorLock() { allocator.ForceLock(); }

void HwasanAllocatorUnlock() { allocator.ForceUnlock(); }

void AllocatorThreadStart(AllocatorCache *cache) { allocator.InitCache(cache); }

void AllocatorThreadFinish(AllocatorCache *cache) {
allocator.SwallowCache(cache);
allocator.DestroyCache(cache);
}

static uptr TaggedSize(uptr size) {
Expand Down
1 change: 1 addition & 0 deletions compiler-rt/lib/hwasan/hwasan_allocator.h
Expand Up @@ -88,6 +88,7 @@ typedef SizeClassAllocator64<AP64> PrimaryAllocator;
typedef CombinedAllocator<PrimaryAllocator> Allocator;
typedef Allocator::AllocatorCache AllocatorCache;

void AllocatorThreadStart(AllocatorCache *cache);
void AllocatorThreadFinish(AllocatorCache *cache);

class HwasanChunkView {
Expand Down
1 change: 1 addition & 0 deletions compiler-rt/lib/hwasan/hwasan_thread.cpp
Expand Up @@ -58,6 +58,7 @@ void Thread::Init(uptr stack_buffer_start, uptr stack_buffer_size,
#endif
InitStackAndTls(state);
dtls_ = DTLS_Get();
AllocatorThreadStart(allocator_cache());
}

void Thread::InitStackRingBuffer(uptr stack_buffer_start,
Expand Down
Expand Up @@ -4,9 +4,6 @@
// No allocator.
// UNSUPPORTED: ubsan

// FIXME: implementation is incomplete.
// XFAIL: hwasan

#include <assert.h>
#include <sanitizer/allocator_interface.h>
#include <stdio.h>
Expand Down

0 comments on commit d9b574c

Please sign in to comment.