summaryrefslogtreecommitdiff
path: root/lib/sanitizer_common/sanitizer_allocator.cc
AgeCommit message (Collapse)Author
2017-11-21[sanitizers] Add init function to set alignment of low level allocatorWalter Lee
ASan requires that the min alignment be at least the shadow granularity, so add an init function to do that. Differential Revision: https://reviews.llvm.org/D39473 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318717 91177308-0d34-0410-b5e6-96231b3b80d8
2017-07-18[Sanitizers] ASan/MSan/LSan allocators set errno on failure.Alex Shlyapnikov
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
2017-06-29MergeAlex Shlyapnikov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@306746 91177308-0d34-0410-b5e6-96231b3b80d8
2017-06-28[Sanitizers] Operator new() interceptors always die on allocation errorAlex Shlyapnikov
Summary: Operator new interceptors behavior is now controlled by their nothrow property as well as by allocator_may_return_null flag value: - allocator_may_return_null=* + new() - die on allocation error - allocator_may_return_null=0 + new(nothrow) - die on allocation error - allocator_may_return_null=1 + new(nothrow) - return null Ideally new() should throw std::bad_alloc exception, but that is not trivial to achieve, hence TODO. Reviewers: eugenis Subscribers: kubamracek, llvm-commits Differential Revision: https://reviews.llvm.org/D34731 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@306604 91177308-0d34-0410-b5e6-96231b3b80d8
2017-06-20[Sanitizers] Move cached allocator_may_return_null flag to sanitizer_allocatorAlex Shlyapnikov
Summary: Move cached allocator_may_return_null flag to sanitizer_allocator.cc and provide API to consolidate and unify the behavior of all specific allocators. Make all sanitizers using CombinedAllocator to follow AllocatorReturnNullOrDieOnOOM() rules to behave the same way when OOM happens. When OOM happens, turn allocator_out_of_memory flag on regardless of allocator_may_return_null flag value (it used to not to be set when allocator_may_return_null == true). release_to_os_interval_ms and rss_limit_exceeded will likely be moved to sanitizer_allocator.cc too (later). Reviewers: eugenis Subscribers: srhines, kubamracek, llvm-commits Differential Revision: https://reviews.llvm.org/D34310 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@305858 91177308-0d34-0410-b5e6-96231b3b80d8
2017-06-16[Sanitizer] Remove CombinedAllocator::Allocate's 'cleared' parameterAlex Shlyapnikov
Summary: CombinedAllocator::Allocate cleared parameter is not used anywhere and seem to be obsolete. Reviewers: eugenis Subscribers: llvm-commits, kubamracek Differential Revision: https://reviews.llvm.org/D34289 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@305590 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-29Return memory to OS right after free (not in the async thread).Evgeniy Stepanov
Summary: In order to avoid starting a separate thread to return unused memory to the system (the thread interferes with process startup on Android, Zygota waits for all threads to exit before fork, but this thread never exits), try to return it right after free. Reviewers: eugenis Subscribers: cryptoad, filcab, danalbert, kubabrecka, llvm-commits Patch by Aleksey Shlyapnikov. Differential Revision: https://reviews.llvm.org/D27003 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@288091 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-28tsan: always define SANITIZER_GODmitry Vyukov
Currently we either define SANITIZER_GO for Go or don't define it at all for C++. This works fine with preprocessor (ifdef/ifndef/defined), but does not work for C++ if statements (e.g. if (SANITIZER_GO) {...}). Also this is different from majority of SANITIZER_FOO macros which are always defined to either 0 or 1. Always define SANITIZER_GO to either 0 or 1. This allows to use SANITIZER_GO in expressions and in flag default values. Also remove kGoMode and kCppMode, which were meant to be used in expressions, but they are not defined in sanitizer_common code, so SANITIZER_GO become prevalent. Also convert some preprocessor checks to C++ if's or ternary expressions. Majority of this change is done mechanically with: sed "s#ifdef SANITIZER_GO#if SANITIZER_GO#g" sed "s#ifndef SANITIZER_GO#if \!SANITIZER_GO#g" sed "s#defined(SANITIZER_GO)#SANITIZER_GO#g" git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@285443 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-29Don't use internal symbolizer if we are in process of reporting Out-of-Memory.Vitaly Buka
Reviewed by eugenis offline, as reviews.llvm.org is down. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@282805 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-20tsan: fix windows buildDmitry Vyukov
Currently fails as: gotsan.cc: In function 'void* __sanitizer::__libc_memalign(__sanitizer::uptr, __sanitizer::uptr)': gotsan.cc:6194:50: error: 'posix_memalign' was not declared in this scope uptr error = posix_memalign(&p, alignment, size); Windows does not provide posix_memalign. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@276107 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-06[tsan] Switch to InternalAlloc everywhere __libc_malloc is currently usedKuba Brecka
This patch replaces all uses of __libc_malloc and friends with the internal allocator. It seems that the only reason why we have calls to __libc_malloc in the first place was the lack of the internal allocator at the time. Using the internal allocator will also make sure that the system allocator is never used (this is the same behavior as ASan), and we don’t have to worry about working with unknown pointers coming from the system allocator. Differential Revision: http://reviews.llvm.org/D21025 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@271916 91177308-0d34-0410-b5e6-96231b3b80d8
2015-09-30[sanitizer_common] Apply modernize-use-nullptr, other minor fixesVedant Kumar
- Trim spaces. - Use nullptr in place of 0 for pointer variables. - Use '!p' in place of 'p == 0' for null pointer checks. Patch by Eugene Zelenko! Differential Revision: http://reviews.llvm.org/D13310 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@248964 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-12[Sanitizer] Introduce Allocator::may_return_null bool flag.Alexey Samsonov
Summary: Turn "allocator_may_return_null" common flag into an Allocator::may_return_null bool flag. We want to make sure that common flags are immutable after initialization. There are cases when we want to change this flag in the allocator at runtime: e.g. in unit tests and during ASan activation on Android. Test Plan: regression test suite, real-life applications Reviewers: kcc, eugenis Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D6623 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@224148 91177308-0d34-0410-b5e6-96231b3b80d8
2014-02-28tsan: allow to force use of __libc_malloc in sanitizer_commonDmitry Vyukov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@202504 91177308-0d34-0410-b5e6-96231b3b80d8
2014-02-26Reapply r201910. MSVC gets __func__ defined explicitly, even though itJoerg Sonnenberger
can't build anything here. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@202297 91177308-0d34-0410-b5e6-96231b3b80d8
2014-02-22Revert "Replace __FUNCTION__ with __func__, the latter being standard ↵Reid Kleckner
C99/C++11." This reverts commit r201910. While __func__ may be standard in C++11, it was only recently added to MSVC in 2013 CTP, and LLVM supports MSVC 2012. __FUNCTION__ may not be standard, but it's *very* portable. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@201916 91177308-0d34-0410-b5e6-96231b3b80d8
2014-02-21Replace __FUNCTION__ with __func__, the latter being standard C99/C++11.Joerg Sonnenberger
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@201910 91177308-0d34-0410-b5e6-96231b3b80d8
2013-09-06[sanitizer] make the allocator crash instead of returning 0 on huge size ↵Kostya Serebryany
(controlled by the allocator_may_return_null flag) git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@190127 91177308-0d34-0410-b5e6-96231b3b80d8
2013-05-29[sanitizer] Use raw check in internal allocator to prevent self-deadlocks. ↵Alexey Samsonov
Try to fix Windows build. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@182840 91177308-0d34-0410-b5e6-96231b3b80d8
2013-05-29Make InternalAlloc/InternalFree in sanitizer runtimes libc-free by switching ↵Alexey Samsonov
to a custom allocator. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@182836 91177308-0d34-0410-b5e6-96231b3b80d8
2013-04-03[Sanitizer] Kill the remainders of platform defines in favor of SANITIZER_ ↵Alexey Samsonov
defines git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@178627 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-19[sanitizer] Replace more platform checks with SANITIZER_ constants.Evgeniy Stepanov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@177400 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-25[sanitizer] improve the calloc overflow check (spotted by samsonov@)Kostya Serebryany
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@173443 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-25[sanitizer] fix calloc overflow in asan/tsan/msanKostya Serebryany
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@173441 91177308-0d34-0410-b5e6-96231b3b80d8
2012-12-03[tsan] remove unused InternalAllocBlock as part of larger refactoringKostya Serebryany
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@169123 91177308-0d34-0410-b5e6-96231b3b80d8
2012-11-24[asan/tsan] get rid of kPageSize completely in favor of GetPageSizeCached(). ↵Kostya Serebryany
This makes the code friendly to more platforms git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@168537 91177308-0d34-0410-b5e6-96231b3b80d8
2012-09-10[asan] There is no __libc_malloc on Android.Evgeniy Stepanov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@163498 91177308-0d34-0410-b5e6-96231b3b80d8
2012-08-27[Sanitizer] align allocation sizes in low level allocatorAlexey Samsonov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@162676 91177308-0d34-0410-b5e6-96231b3b80d8
2012-08-27[Sanitizer] move low-level (mmap-based) allocator to sanitizer_commonAlexey Samsonov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@162663 91177308-0d34-0410-b5e6-96231b3b80d8
2012-07-05tsan: Go language supportDmitry Vyukov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@159754 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-25tsan: remove internal allocator, switch to sanitizer_common one.Dmitry Vyukov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@159142 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-09[Sanitizer] Use __libc_malloc/__libc_free instead of malloc/free inside ↵Alexey Samsonov
internal allocator on Linux (important for TSan) git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@158261 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-07[Sanitizer] include stdlib.h header to get malloc/freeAlexey Samsonov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@158144 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-07[Sanitizer] Allocator for internal runtime purposes. Currently it calls ↵Alexey Samsonov
libcmalloc, but we might have to make it more low-level in future git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@158142 91177308-0d34-0410-b5e6-96231b3b80d8