Skip to content

Commit

Permalink
[msan] Implement __sanitizer_get_current_allocated_bytes
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: kstoimenov

Differential Revision: https://reviews.llvm.org/D151352
  • Loading branch information
vitalybuka committed May 24, 2023
1 parent 9357712 commit 4305f64
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
7 changes: 7 additions & 0 deletions compiler-rt/lib/msan/msan_allocator.cpp
Expand Up @@ -145,8 +145,13 @@ AllocatorCache *GetAllocatorCache(MsanThreadLocalMallocStorage *ms) {
return reinterpret_cast<AllocatorCache *>(ms->allocator_cache);
}

void MsanThreadLocalMallocStorage::Init() {
allocator.InitCache(GetAllocatorCache(this));
}

void MsanThreadLocalMallocStorage::CommitBack() {
allocator.SwallowCache(GetAllocatorCache(this));
allocator.DestroyCache(GetAllocatorCache(this));
}

static void *MsanAllocate(StackTrace *stack, uptr size, uptr alignment,
Expand Down Expand Up @@ -393,3 +398,5 @@ const void *__sanitizer_get_allocated_begin(const void *p) {
}

uptr __sanitizer_get_allocated_size(const void *p) { return AllocationSize(p); }

void __sanitizer_purge_allocator() { allocator.ForceReleaseToOS(); }
1 change: 1 addition & 0 deletions compiler-rt/lib/msan/msan_allocator.h
Expand Up @@ -20,6 +20,7 @@ namespace __msan {
struct MsanThreadLocalMallocStorage {
// Allocator cache contains atomic_uint64_t which must be 8-byte aligned.
ALIGNED(8) uptr allocator_cache[96 * (512 * 8 + 16)]; // Opaque.
void Init();
void CommitBack();

private:
Expand Down
1 change: 1 addition & 0 deletions compiler-rt/lib/msan/msan_thread.cpp
Expand Up @@ -47,6 +47,7 @@ void MsanThread::Init() {
CHECK(MEM_IS_APP(stack_.bottom));
CHECK(MEM_IS_APP(stack_.top - 1));
ClearShadowForThreadStackAndTLS();
malloc_storage().Init();
}

void MsanThread::TSDDtor(void *tsd) {
Expand Down
Expand Up @@ -5,7 +5,7 @@
// UNSUPPORTED: ubsan

// FIXME: implementation is incomplete.
// XFAIL: msan, lsan, hwasan
// XFAIL: lsan, hwasan

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

0 comments on commit 4305f64

Please sign in to comment.