diff --git a/compiler-rt/lib/msan/msan_allocator.h b/compiler-rt/lib/msan/msan_allocator.h --- a/compiler-rt/lib/msan/msan_allocator.h +++ b/compiler-rt/lib/msan/msan_allocator.h @@ -20,6 +20,7 @@ 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: diff --git a/compiler-rt/lib/msan/msan_allocator.cpp b/compiler-rt/lib/msan/msan_allocator.cpp --- a/compiler-rt/lib/msan/msan_allocator.cpp +++ b/compiler-rt/lib/msan/msan_allocator.cpp @@ -145,8 +145,13 @@ return reinterpret_cast(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, @@ -393,3 +398,5 @@ } uptr __sanitizer_get_allocated_size(const void *p) { return AllocationSize(p); } + +void __sanitizer_purge_allocator() { allocator.ForceReleaseToOS(); } diff --git a/compiler-rt/lib/msan/msan_thread.cpp b/compiler-rt/lib/msan/msan_thread.cpp --- a/compiler-rt/lib/msan/msan_thread.cpp +++ b/compiler-rt/lib/msan/msan_thread.cpp @@ -47,6 +47,7 @@ CHECK(MEM_IS_APP(stack_.bottom)); CHECK(MEM_IS_APP(stack_.top - 1)); ClearShadowForThreadStackAndTLS(); + malloc_storage().Init(); } void MsanThread::TSDDtor(void *tsd) { diff --git a/compiler-rt/test/sanitizer_common/TestCases/allocator_interface.cpp b/compiler-rt/test/sanitizer_common/TestCases/allocator_interface.cpp --- a/compiler-rt/test/sanitizer_common/TestCases/allocator_interface.cpp +++ b/compiler-rt/test/sanitizer_common/TestCases/allocator_interface.cpp @@ -5,7 +5,7 @@ // UNSUPPORTED: ubsan // FIXME: implementation is incomplete. -// XFAIL: msan, lsan, hwasan +// XFAIL: lsan, hwasan #include #include