Skip to content

Commit 4305f64

Browse files
committed
[msan] Implement __sanitizer_get_current_allocated_bytes
__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
1 parent 9357712 commit 4305f64

File tree

4 files changed

+10
-1
lines changed

4 files changed

+10
-1
lines changed

compiler-rt/lib/msan/msan_allocator.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,13 @@ AllocatorCache *GetAllocatorCache(MsanThreadLocalMallocStorage *ms) {
145145
return reinterpret_cast<AllocatorCache *>(ms->allocator_cache);
146146
}
147147

148+
void MsanThreadLocalMallocStorage::Init() {
149+
allocator.InitCache(GetAllocatorCache(this));
150+
}
151+
148152
void MsanThreadLocalMallocStorage::CommitBack() {
149153
allocator.SwallowCache(GetAllocatorCache(this));
154+
allocator.DestroyCache(GetAllocatorCache(this));
150155
}
151156

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

395400
uptr __sanitizer_get_allocated_size(const void *p) { return AllocationSize(p); }
401+
402+
void __sanitizer_purge_allocator() { allocator.ForceReleaseToOS(); }

compiler-rt/lib/msan/msan_allocator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace __msan {
2020
struct MsanThreadLocalMallocStorage {
2121
// Allocator cache contains atomic_uint64_t which must be 8-byte aligned.
2222
ALIGNED(8) uptr allocator_cache[96 * (512 * 8 + 16)]; // Opaque.
23+
void Init();
2324
void CommitBack();
2425

2526
private:

compiler-rt/lib/msan/msan_thread.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ void MsanThread::Init() {
4747
CHECK(MEM_IS_APP(stack_.bottom));
4848
CHECK(MEM_IS_APP(stack_.top - 1));
4949
ClearShadowForThreadStackAndTLS();
50+
malloc_storage().Init();
5051
}
5152

5253
void MsanThread::TSDDtor(void *tsd) {

compiler-rt/test/sanitizer_common/TestCases/allocator_interface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// UNSUPPORTED: ubsan
66

77
// FIXME: implementation is incomplete.
8-
// XFAIL: msan, lsan, hwasan
8+
// XFAIL: lsan, hwasan
99

1010
#include <assert.h>
1111
#include <sanitizer/allocator_interface.h>

0 commit comments

Comments
 (0)