summaryrefslogtreecommitdiff
path: root/lib/sanitizer_common/sanitizer_allocator.h
AgeCommit message (Collapse)Author
2017-10-25[sanitizer] Random shuffling of chunks for the 32-bit Primary AllocatorKostya Kortchinsky
Summary: The 64-bit primary has had random shuffling of chunks for a while, this implements it for the 32-bit primary. Scudo is currently the only user of `kRandomShuffleChunks`. This change consists of a few modifications: - move the random shuffling functions out of the 64-bit primary to `sanitizer_common.h`. Alternatively I could move them to `sanitizer_allocator.h` as they are only used in the allocator, I don't feel strongly either way; - small change in the 64-bit primary to make the `rand_state` initialization `UNLIKELY`; - addition of a `rand_state` in the 32-bit primary's `SizeClassInfo` and shuffling of chunks when populating the free list. - enabling the `random_shuffle.cpp` test on platforms using the 32-bit primary for Scudo. Some comments on why the shuffling is done that way. Initially I just implemented a `Shuffle` function in the `TransferBatch` which was simpler but I came to realize this wasn't good enough: for chunks of 10000 bytes for example, with a `CompactSizeClassMap`, a batch holds only 1 chunk, meaning shuffling the batch has no effect, while a region is usually 1MB, eg: 104 chunks of that size. So I decided to "stage" the newly gathered chunks in a temporary array that would be shuffled prior to placing the chunks in batches. The result is looping twice through n_chunks even if shuffling is not enabled, but I didn't notice any significant significant performance impact. Reviewers: alekseyshl Reviewed By: alekseyshl Subscribers: srhines, llvm-commits, kubamracek Differential Revision: https://reviews.llvm.org/D39244 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@316596 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
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-21[sanitizer] better allocator stats (with rss)Kostya Serebryany
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@276343 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-20[sanitizers] split sanitizer_allocator.h into a number of smaller .h files; NFCKostya Serebryany
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@276195 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-07[compiler-rt] Fix sanitizer memory allocator on win64.Etienne Bergeron
Summary: This patch is fixing unittests for sanitizer memory allocator. There was two issues: 1) The VirtualAlloc can't reserve twice a memory range. The memory space used by the SizeClass allocator is reserved with NoAccess and pages are commited on demand (using MmapFixedOrDie). 2) The address space is allocated using two VirtualAlloc calls. The first one for the memory space, the second one for the AdditionnalSpace (after). On windows, they need to be freed separately. Reviewers: rnk Subscribers: llvm-commits, wang0109, kubabrecka, chrisha Differential Revision: http://reviews.llvm.org/D21900 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@274772 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-02[sanitizer] Fix a crash in SizeClassAllocator32 with an out-of-range pointerKuba Brecka
This happens on a 64-bit platform that uses SizeClassAllocator32 (e.g. ASan on AArch64). When querying a large invalid pointer, `__sanitizer_get_allocated_size(0xdeadbeefdeadbeef)`, an assertion will fail. This patch changes PointerIsMine to return false if the pointer is outside of [kSpaceBeg, kSpaceBeg + kSpaceSize). Differential Revision: http://reviews.llvm.org/D15008 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@268243 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-23[sanitizer] add a function MmapNoAccess that mmaps a protected region ↵Kostya Serebryany
*somewhere*; use MmapNoAccess in the Allocator when SpaceBeg is not a constant. In this mode the allocator will be a bit more hardened git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@267256 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-22[sanitizer] rename MmapNoAccess to MmapFixedNoAccess; NFCKostya Serebryany
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@267253 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-22[sanitizer] partially un-revert r267094: Allow the sanitizer allocator to ↵Kostya Serebryany
use a non-fixed address range. An allocator with a non-fixed address range will be attack-resistan. NFC for the sanitizers at this point. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@267252 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-22Revert "[sanitizer] Allow the sanitizer allocator to use a non-fixed address ↵Renato Golin
range. An allocator with a non-fixed address range will be attack-resistan. NFC for the sanitizers at this point." This reverts commit r267094, because it broke a lot of MSAN tests in AArch64. Being NFC and all, this needs some deeper investigation before it goes in again. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@267136 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-22[sanitizer] Allow the sanitizer allocator to use a non-fixed address range. ↵Kostya Serebryany
An allocator with a non-fixed address range will be attack-resistan. NFC for the sanitizers at this point. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@267094 91177308-0d34-0410-b5e6-96231b3b80d8
2015-09-29[sanitizer] Fix Clang-tidy modernize-use-nullptr warnings in ↵Kostya Serebryany
lib/sanitizer_common headers, unify closing inclusion guards. Patch by Eugene Zelenko git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@248816 91177308-0d34-0410-b5e6-96231b3b80d8
2015-08-28[compiler-rt] [tsan] Enable TSan for AArch64/42-bit VMAAdhemerval Zanella
This patch adds support for tsan on aarch64-linux with 42-bit VMA (current default config for 64K pagesize kernels). The support is enabled by defining the SANITIZER_AARCH64_VMA to 42 at build time for both clang/llvm and compiler-rt. The default VMA is 39 bits. It also enabled tsan for previous supported VMA (39). git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@246330 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-10Split Mprotect into MmapNoAccess and MprotectNoAccess to be more portableTimur Iskhodzhanov
On Windows, we have to know if a memory to be protected is mapped or not. On POSIX, Mprotect was semantically different from mprotect most people know. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@234602 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-09[sanitizer] use the right memory orderKostya Serebryany
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@225546 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-06[asan] add a flag soft_rss_limit_mbKostya Serebryany
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@225323 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-19[ASan] Change activation strategy.Alexey Samsonov
Now ASan deactivation doesn't modify common or ASan-specific runtime flags. Flags stay constant after initialization, and "deactivation" instead stashes initialized runtime state, and deactivates the runtime. Activation then just restores the original state (possibly, overriden by some activation flags provided in system property on Android). git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@224614 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-19[sanitizer] Rename InitIfLinkerInitialized to InitLinkerInitialized.Sergey Matveev
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@224577 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-17[sanitizer] add CombinedAllocator::InitIfLinkerInitialized and use it in ↵Kostya Serebryany
lsan: speeds up lsan start-up time by ~25% git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@224469 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-10-24tsan: support mmap(MAP_32BIT)Dmitry Vyukov
Allow user memory in the first TB of address space. This also enabled non-pie binaries and freebsd. Fixes issue: https://code.google.com/p/thread-sanitizer/issues/detail?id=5 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@220571 91177308-0d34-0410-b5e6-96231b3b80d8
2014-10-23[sanitizer] Add a bunch of sanity checks.Evgeniy Stepanov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@220528 91177308-0d34-0410-b5e6-96231b3b80d8
2014-06-30Fix apparent thinko in r209744: allocator stats can be zeroAlexey Samsonov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@212071 91177308-0d34-0410-b5e6-96231b3b80d8
2014-05-28tsan: do not use 64-bit atomics in allocator codeDmitry Vyukov
64-bit atomics make porting of asan to 32-bits platforms problematic. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@209744 91177308-0d34-0410-b5e6-96231b3b80d8
2014-01-27[sanitizer] revert r200197: the buggy kernel ↵Kostya Serebryany
(https://bugzilla.kernel.org/show_bug.cgi?id=67651) is almost unusable with asan even with this workaround (too slow), so this workaround makes no sense. The asan/msan bootstrap bot was changed to use a non-buggy kernel git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@200217 91177308-0d34-0410-b5e6-96231b3b80d8
2014-01-27[sanitizer] increase the mmap granularity in sanitizer allocator from 2^16 ↵Kostya Serebryany
to 2^18. This is a partial workaround for the fresh Kernel bug https://bugzilla.kernel.org/show_bug.cgi?id=67651 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@200197 91177308-0d34-0410-b5e6-96231b3b80d8
2013-11-25[sanitizer] Implement TwoLevelByteMap and use it for the internal allocator ↵Kostya Serebryany
on 64-bit. Summary: Implement TwoLevelByteMap and use it for the internal allocator on 64-bit. This reduces bss on 64-bit by ~8Mb because we don't use FlatByteMap on 64-bits any more. Dmitry, please check my understanding of atomics. Reviewers: dvyukov Reviewed By: dvyukov CC: samsonov, llvm-commits Differential Revision: http://llvm-reviews.chandlerc.com/D2259 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@195637 91177308-0d34-0410-b5e6-96231b3b80d8
2013-11-24[sanitizer] Do not clear memory which comes from secondary allocator.Sergey Matveev
Secondary allocator is mmap-based, so the memory is already zeroed. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@195571 91177308-0d34-0410-b5e6-96231b3b80d8
2013-11-23[sanitizer] use 16-byte aligned bzero in performance critical place (mostly ↵Kostya Serebryany
for lsan) git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@195549 91177308-0d34-0410-b5e6-96231b3b80d8
2013-10-25Rename SpinMutex::AssertHeld to CheckLocked, for consistency with BlockingMutex.Peter Collingbourne
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@193447 91177308-0d34-0410-b5e6-96231b3b80d8
2013-10-17[asan] Fix a deadlock between asan's allocator and lsanKostya Serebryany
Summary: This fixes a deadlock which happens in lsan on a large memalign-allocated chunk that resides in lsan's root set. Reviewers: samsonov, earthdok Reviewed By: earthdok CC: llvm-commits Differential Revision: http://llvm-reviews.chandlerc.com/D1957 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@192885 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-08-08tsan: better diagnostics for invalid addresses passed to free()Dmitry Vyukov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@187980 91177308-0d34-0410-b5e6-96231b3b80d8
2013-08-05Lint fixesAlexey Samsonov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@187726 91177308-0d34-0410-b5e6-96231b3b80d8
2013-08-02[msan] Allocator statistics interface and malloc hooks.Evgeniy Stepanov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@187653 91177308-0d34-0410-b5e6-96231b3b80d8
2013-06-24Revert to C-style callbacks for iteration over allocator chunks.Sergey Matveev
Also clean up LSan code, fix some comments and replace void* with uptr to bring down the number of reinterpret_casts. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@184700 91177308-0d34-0410-b5e6-96231b3b80d8
2013-06-06[lsan] Implement __lsan_ignore_object().Sergey Matveev
Leak annotation similar to HeapChecker's IgnoreObject(). git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@183412 91177308-0d34-0410-b5e6-96231b3b80d8
2013-05-31[lsan] Use the fast version of GetBlockBegin for leak checking in LSan and ASan.Sergey Matveev
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@182994 91177308-0d34-0410-b5e6-96231b3b80d8
2013-05-30[sanitizer] introduce LargeMmapAllocator::GetBlockBeginFastSingleThreaded, ↵Kostya Serebryany
required for LeakSanitizer to work faster. Also fix lint. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@182917 91177308-0d34-0410-b5e6-96231b3b80d8
2013-05-29Fix MSVC W3 compiler warningsTimur Iskhodzhanov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@182857 91177308-0d34-0410-b5e6-96231b3b80d8
2013-05-20[sanitizer] factor out ByteMap from SizeClassAllocator32 so that it can be ↵Kostya Serebryany
later replaced with a more memory-efficient implementation on 64-bit. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@182234 91177308-0d34-0410-b5e6-96231b3b80d8
2013-05-16[sanitizer] fix gcc buildKostya Serebryany
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@182006 91177308-0d34-0410-b5e6-96231b3b80d8
2013-05-16[sanitizer] Fix the region overflow condition in ↵Sergey Matveev
SanitizerAllocator64::PopulateFreeList(). git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@182002 91177308-0d34-0410-b5e6-96231b3b80d8
2013-05-16[sanitizer] fix a gcc warningKostya Serebryany
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@181992 91177308-0d34-0410-b5e6-96231b3b80d8
2013-05-16[sanitizer] fix the GetBlockBegin overflow bug while preserving the ↵Kostya Serebryany
performance optimization (use 32-bit division when possible). Improve the benchmarks that checks for performance of GetBlockBegin/GetMetaData git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@181989 91177308-0d34-0410-b5e6-96231b3b80d8
2013-04-08[sanitizer] Fix boundary condition in LargeMmapAllocator::GetBlockBegin. ↵Kostya Serebryany
Patch by Sergey Matveev git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@179007 91177308-0d34-0410-b5e6-96231b3b80d8