diff options
author | Alexander Potapenko <glider@google.com> | 2013-02-07 11:40:03 +0000 |
---|---|---|
committer | Alexander Potapenko <glider@google.com> | 2013-02-07 11:40:03 +0000 |
commit | 6a11cc1bc665f13a0fcafe4a6a84761216675af7 (patch) | |
tree | a19bcb6265d29c87336f0f3a6f9289f4a8a3a6ff /lib/sanitizer_common/sanitizer_allocator.h | |
parent | 74d0540ceae99c550b00f75883a737f4a1de6351 (diff) | |
download | compiler-rt-6a11cc1bc665f13a0fcafe4a6a84761216675af7.tar.gz compiler-rt-6a11cc1bc665f13a0fcafe4a6a84761216675af7.tar.bz2 compiler-rt-6a11cc1bc665f13a0fcafe4a6a84761216675af7.tar.xz |
[ASan] Implement asan_mz_size(), asan_mz_force_lock() and asan_mz_force_unlock() for allocator2.
Switch to allocator2 on Darwin.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@174603 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/sanitizer_common/sanitizer_allocator.h')
-rw-r--r-- | lib/sanitizer_common/sanitizer_allocator.h | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/sanitizer_common/sanitizer_allocator.h b/lib/sanitizer_common/sanitizer_allocator.h index a9082508..caf7263b 100644 --- a/lib/sanitizer_common/sanitizer_allocator.h +++ b/lib/sanitizer_common/sanitizer_allocator.h @@ -403,6 +403,20 @@ class SizeClassAllocator64 { } } + // ForceLock() and ForceUnlock() are needed to implement Darwin malloc zone + // introspection API. + void ForceLock() { + for (uptr i = 0; i < kNumClasses; i++) { + GetRegionInfo(i)->mutex.Lock(); + } + } + + void ForceUnlock() { + for (int i = (int)kNumClasses - 1; i >= 0; i--) { + GetRegionInfo(i)->mutex.Unlock(); + } + } + typedef SizeClassMap SizeClassMapT; static const uptr kNumClasses = SizeClassMap::kNumClasses; static const uptr kNumClassesRounded = SizeClassMap::kNumClassesRounded; @@ -635,6 +649,20 @@ class SizeClassAllocator32 { UnmapWithCallback(reinterpret_cast<uptr>(state_), sizeof(State)); } + // ForceLock() and ForceUnlock() are needed to implement Darwin malloc zone + // introspection API. + void ForceLock() { + for (int i = 0; i < kNumClasses; i++) { + GetSizeClassInfo(i)->mutex.Lock(); + } + } + + void ForceUnlock() { + for (int i = kNumClasses - 1; i >= 0; i--) { + GetSizeClassInfo(i)->mutex.Unlock(); + } + } + void PrintStats() { } @@ -941,6 +969,16 @@ class LargeMmapAllocator { Printf("\n"); } + // ForceLock() and ForceUnlock() are needed to implement Darwin malloc zone + // introspection API. + void ForceLock() { + mutex_.Lock(); + } + + void ForceUnlock() { + mutex_.Unlock(); + } + private: static const int kMaxNumChunks = 1 << FIRST_32_SECOND_64(15, 18); struct Header { @@ -1092,6 +1130,18 @@ class CombinedAllocator { secondary_.PrintStats(); } + // ForceLock() and ForceUnlock() are needed to implement Darwin malloc zone + // introspection API. + void ForceLock() { + primary_.ForceLock(); + secondary_.ForceLock(); + } + + void ForceUnlock() { + secondary_.ForceUnlock(); + primary_.ForceUnlock(); + } + private: PrimaryAllocator primary_; SecondaryAllocator secondary_; |