summaryrefslogtreecommitdiff
path: root/lib/hwasan/hwasan_allocator.cc
diff options
context:
space:
mode:
authorAlex Shlyapnikov <alekseys@google.com>2018-01-17 23:20:36 +0000
committerAlex Shlyapnikov <alekseys@google.com>2018-01-17 23:20:36 +0000
commit6ae9c03ffaf72765033e3bec140b52741b0177aa (patch)
tree75e9316b11ef9017050e32747421c3b3674a1995 /lib/hwasan/hwasan_allocator.cc
parent47982b47999810f261eaff6b599e661be092ae10 (diff)
[Sanitizers] Make common allocator agnostic to failure handling modes.
Summary: Make common allocator agnostic to failure handling modes and move the decision up to the particular sanitizer's allocator, where the context is available (call stack, parameters, return nullptr/crash mode etc.) It simplifies the common allocator and allows the particular sanitizer's allocator to generate more specific and detailed error reports (which will be implemented later). The behavior is largely the same, except one case, the violation of the common allocator's check for "size + alignment" overflow is now reportied as OOM instead of "bad request". It feels like a worthy tradeoff and "size + alignment" is huge in this case anyway (thus, can be interpreted as not enough memory to satisfy the request). There's also a Report() statement added there. Reviewers: eugenis Subscribers: kubamracek, llvm-commits, #sanitizers Differential Revision: https://reviews.llvm.org/D42198 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@322784 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/hwasan/hwasan_allocator.cc')
-rw-r--r--lib/hwasan/hwasan_allocator.cc4
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/hwasan/hwasan_allocator.cc b/lib/hwasan/hwasan_allocator.cc
index 2acac8189..5bd46f8f5 100644
--- a/lib/hwasan/hwasan_allocator.cc
+++ b/lib/hwasan/hwasan_allocator.cc
@@ -128,7 +128,7 @@ static void *HwasanAllocate(StackTrace *stack, uptr size, uptr alignment,
if (size > kMaxAllowedMallocSize) {
Report("WARNING: HWAddressSanitizer failed to allocate %p bytes\n",
(void *)size);
- return Allocator::FailureHandler::OnBadRequest();
+ return ReturnNullOrDieOnFailure::OnBadRequest();
}
HwasanThread *t = GetCurrentThread();
void *allocated;
@@ -140,6 +140,8 @@ static void *HwasanAllocate(StackTrace *stack, uptr size, uptr alignment,
AllocatorCache *cache = &fallback_allocator_cache;
allocated = allocator.Allocate(cache, size, alignment);
}
+ if (UNLIKELY(!allocated))
+ return ReturnNullOrDieOnFailure::OnOOM();
Metadata *meta =
reinterpret_cast<Metadata *>(allocator.GetMetaData(allocated));
meta->state = CHUNK_ALLOCATED;