diff options
author | Alex Shlyapnikov <alekseys@google.com> | 2017-07-18 19:11:04 +0000 |
---|---|---|
committer | Alex Shlyapnikov <alekseys@google.com> | 2017-07-18 19:11:04 +0000 |
commit | 13c2d08571baab9982f01acb1d302049bdace581 (patch) | |
tree | d284ec82188f89173bb52f4872c811dd5d02f733 /lib/lsan | |
parent | e726963d587b1d95320da4f5f05cd563e36eb8fe (diff) |
[Sanitizers] ASan/MSan/LSan allocators set errno on failure.
Summary:
ASan/MSan/LSan allocators set errno on allocation failures according to
malloc/calloc/etc. expected behavior.
MSan allocator was refactored a bit to make its structure more similar
with other allocators.
Also switch Scudo allocator to the internal errno definitions.
TSan allocator changes will follow.
Reviewers: eugenis
Subscribers: llvm-commits, kubamracek
Differential Revision: https://reviews.llvm.org/D35275
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@308344 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/lsan')
-rw-r--r-- | lib/lsan/lsan_allocator.cc | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/lib/lsan/lsan_allocator.cc b/lib/lsan/lsan_allocator.cc index 96d5cb6a9..2df58b44f 100644 --- a/lib/lsan/lsan_allocator.cc +++ b/lib/lsan/lsan_allocator.cc @@ -15,6 +15,7 @@ #include "lsan_allocator.h" #include "sanitizer_common/sanitizer_allocator.h" +#include "sanitizer_common/sanitizer_allocator_checks.h" #include "sanitizer_common/sanitizer_allocator_interface.h" #include "sanitizer_common/sanitizer_errno.h" #include "sanitizer_common/sanitizer_internal_defs.h" @@ -125,22 +126,16 @@ uptr GetMallocUsableSize(const void *p) { return m->requested_size; } -inline void *check_ptr(void *ptr) { - if (UNLIKELY(!ptr)) - errno = errno_ENOMEM; - return ptr; -} - void *lsan_memalign(uptr alignment, uptr size, const StackTrace &stack) { if (UNLIKELY(!IsPowerOfTwo(alignment))) { errno = errno_EINVAL; return Allocator::FailureHandler::OnBadRequest(); } - return check_ptr(Allocate(stack, size, alignment, kAlwaysClearMemory)); + return SetErrnoOnNull(Allocate(stack, size, alignment, kAlwaysClearMemory)); } void *lsan_malloc(uptr size, const StackTrace &stack) { - return check_ptr(Allocate(stack, size, 1, kAlwaysClearMemory)); + return SetErrnoOnNull(Allocate(stack, size, 1, kAlwaysClearMemory)); } void lsan_free(void *p) { @@ -148,15 +143,15 @@ void lsan_free(void *p) { } void *lsan_realloc(void *p, uptr size, const StackTrace &stack) { - return check_ptr(Reallocate(stack, p, size, 1)); + return SetErrnoOnNull(Reallocate(stack, p, size, 1)); } void *lsan_calloc(uptr nmemb, uptr size, const StackTrace &stack) { - return check_ptr(Calloc(nmemb, size, stack)); + return SetErrnoOnNull(Calloc(nmemb, size, stack)); } void *lsan_valloc(uptr size, const StackTrace &stack) { - return check_ptr( + return SetErrnoOnNull( Allocate(stack, size, GetPageSizeCached(), kAlwaysClearMemory)); } |