summaryrefslogtreecommitdiff
path: root/lib/scudo/scudo_allocator.cpp
diff options
context:
space:
mode:
authorKostya Kortchinsky <kostyak@google.com>2017-02-03 20:49:42 +0000
committerKostya Kortchinsky <kostyak@google.com>2017-02-03 20:49:42 +0000
commit044cfea04848ec011bb35575a28dfb0165db85cf (patch)
tree5b28c0d65bf4931631912d3c13cc47100aeee156 /lib/scudo/scudo_allocator.cpp
parentc38680b2e6f08700b52826931c7cd3cea0380d75 (diff)
[scudo] 32-bit quarantine sizes adjustments and bug fixes
Summary: The local and global quarantine sizes were not offering a distinction for 32-bit and 64-bit platforms. This is addressed with lower values for 32-bit. When writing additional tests for the quarantine, it was discovered that when calling some of the allocator interface function prior to any allocation operation having occured, the test would crash due to the allocator not being initialized. This was addressed by making sure the allocator is initialized for those scenarios. Relevant tests were added in interface.cpp and quarantine.cpp. Last change being the removal of the extraneous link dependencies for the tests thanks to rL293220, anf the addition of the gc-sections linker flag. Reviewers: kcc, alekseyshl Reviewed By: alekseyshl Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D29341 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@294037 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/scudo/scudo_allocator.cpp')
-rw-r--r--lib/scudo/scudo_allocator.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/lib/scudo/scudo_allocator.cpp b/lib/scudo/scudo_allocator.cpp
index a6d6aafe3..dab6abedc 100644
--- a/lib/scudo/scudo_allocator.cpp
+++ b/lib/scudo/scudo_allocator.cpp
@@ -354,6 +354,8 @@ struct Allocator {
// Helper function that checks for a valid Scudo chunk.
bool isValidPointer(const void *UserPtr) {
+ if (UNLIKELY(!ThreadInited))
+ initThread();
uptr ChunkBeg = reinterpret_cast<uptr>(UserPtr);
if (!IsAligned(ChunkBeg, MinAlignment)) {
return false;
@@ -580,6 +582,14 @@ struct Allocator {
AllocatorQuarantine.Drain(&ThreadQuarantineCache,
QuarantineCallback(&Cache));
}
+
+ uptr getStats(AllocatorStat StatType) {
+ if (UNLIKELY(!ThreadInited))
+ initThread();
+ uptr stats[AllocatorStatCount];
+ BackendAllocator.GetStats(stats);
+ return stats[StatType];
+ }
};
static Allocator Instance(LINKER_INITIALIZED);
@@ -664,15 +674,11 @@ using namespace __scudo;
// MallocExtension helper functions
uptr __sanitizer_get_current_allocated_bytes() {
- uptr stats[AllocatorStatCount];
- getAllocator().GetStats(stats);
- return stats[AllocatorStatAllocated];
+ return Instance.getStats(AllocatorStatAllocated);
}
uptr __sanitizer_get_heap_size() {
- uptr stats[AllocatorStatCount];
- getAllocator().GetStats(stats);
- return stats[AllocatorStatMapped];
+ return Instance.getStats(AllocatorStatMapped);
}
uptr __sanitizer_get_free_bytes() {