summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/tsan/rtl/tsan_mman.cc
Commit message (Collapse)AuthorAgeFilesLines
* compiler-rt: Rename .cc file in lib/tsan/rtl to .cppNico Weber2019-08-011-396/+0
| | | | | | Like r367463, but for tsan/rtl. llvm-svn: 367564
* [sanitizer] Implement reallocarray.Evgeniy Stepanov2019-05-011-0/+10
| | | | | | | | | | | | | | | | Summary: It's a cross of calloc and realloc. Sanitizers implement calloc-like check for size overflow. Reviewers: vitalybuka, kcc Subscribers: kubamracek, #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D61108 llvm-svn: 359708
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-4/+3
| | | | | | | | | | | | | | | | | to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
* [TSan] Report proper error on allocator failures instead of CHECK(0)-ingAlex Shlyapnikov2018-06-181-11/+39
| | | | | | | | | | | | | | | | | | | | | | Summary: Following up on and complementing D44404 and other sanitizer allocators. Currently many allocator specific errors (OOM, for example) are reported as a text message and CHECK(0) termination, no stack, no details, not too helpful nor informative. To improve the situation, detailed and structured common errors were defined and reported under the appropriate conditions. Common tests were generalized a bit to cover a slightly different TSan stack reporting format, extended to verify errno value and returned pointer value check is now explicit to facilitate debugging. Reviewers: dvyukov Subscribers: srhines, kubamracek, delcypher, #sanitizers, llvm-commits Differential Revision: https://reviews.llvm.org/D48087 llvm-svn: 334975
* [Sanitizers] Make common allocator agnostic to failure handling modes.Alex Shlyapnikov2018-01-171-7/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | 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 llvm-svn: 322784
* [sanitizer] Move the errno/ENOMEM allocator checks logic to separate .ccKostya Kortchinsky2017-10-111-0/+1
| | | | | | | | | | | | | | | | | | | | | | Summary: This is a new attempt at D38706, which had 2 issues. The first one was that it broke TSan, because `sanitizer_errno.h` was not directly included in `tsan_mman.cc`. This fixes the include. The second one was that it broke the nolibc build, because `__errno_location` couldn't be found. This adds the new .cc to the libcdep list instead of the base one. Reviewers: alekseyshl Reviewed By: alekseyshl Subscribers: kubamracek, mgorny, llvm-commits Differential Revision: https://reviews.llvm.org/D38743 llvm-svn: 315509
* [tsan] Check for pvalloc overlowKostya Kortchinsky2017-08-021-0/+4
| | | | | | | | | | | | | | | | | | Summary: `CheckForPvallocOverflow` was introduced with D35818 to detect when pvalloc would wrap when rounding up to the next multiple of the page size. Add this check to TSan's pvalloc implementation. Reviewers: alekseyshl Reviewed By: alekseyshl Subscribers: llvm-commits, kubamracek Differential Revision: https://reviews.llvm.org/D36245 llvm-svn: 309897
* [Sanitizers] TSan allocator set errno on failure.Alex Shlyapnikov2017-07-241-18/+68
| | | | | | | | | | | | | | | | | | Summary: Set proper errno code on allocation failures and change realloc, pvalloc, aligned_alloc, memalign and posix_memalign implementation to satisfy their man-specified requirements. Modify allocator API implementation to bring it closer to other sanitizers allocators. Reviewers: dvyukov Subscribers: llvm-commits, kubamracek Differential Revision: https://reviews.llvm.org/D35690 llvm-svn: 308929
* [Sanitizers] ASan/MSan/LSan allocators set errno on failure.Alex Shlyapnikov2017-07-181-0/+1
| | | | | | | | | | | | | | | | | | | | | 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 llvm-svn: 308344
* tsan: prepare clock for future changesDmitry Vyukov2017-07-121-0/+2
| | | | | | | Pass ClockCache to ThreadClock::set and introduce ThreadCache::ResetCached. For now both are unused, but will reduce future diffs. llvm-svn: 307784
* MergeAlex Shlyapnikov2017-06-291-1/+1
| | | | llvm-svn: 306746
* [Sanitizers] Move cached allocator_may_return_null flag to sanitizer_allocatorAlex Shlyapnikov2017-06-201-5/+4
| | | | | | | | | | | | | | | | | | | | | | | | | 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 llvm-svn: 305858
* Release memory to OS only when the requested range covers the entire pageEvgeniy Stepanov2016-11-301-1/+2
| | | | | | | | | | | | | | | | | Summary: The current code was sometimes attempting to release huge chunks of memory due to undesired RoundUp/RoundDown interaction when the requested range is fully contained within one memory page. Reviewers: eugenis Subscribers: kubabrecka, llvm-commits Patch by Aleksey Shlyapnikov. Differential Revision: https://reviews.llvm.org/D27228 llvm-svn: 288271
* Return memory to OS right after free (not in the async thread).Evgeniy Stepanov2016-11-291-1/+3
| | | | | | | | | | | | | | | | | | 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 llvm-svn: 288091
* Don't use internal symbolizer if we are in process of reporting Out-of-Memory.Vitaly Buka2016-09-291-2/+2
| | | | | | Reviewed by eugenis offline, as reviews.llvm.org is down. llvm-svn: 282805
* [asan] first attempt at releasing free-d memory back to the system using ↵Kostya Serebryany2016-08-261-1/+1
| | | | | | madvise. Requires quite some tuning. llvm-svn: 279887
* [tsan] Fix behavior of realloc(nullptr, 0) on DarwinKuba Brecka2016-08-021-11/+7
| | | | | | | | On Darwin, there are some apps that rely on realloc(nullptr, 0) returning a valid pointer. TSan currently returns nullptr in this case, let's fix it to avoid breaking binary compatibility. Differential Revision: https://reviews.llvm.org/D22800 llvm-svn: 277458
* [sanitizers] introduce yet another API function: ↵Kostya Serebryany2016-06-161-0/+2
| | | | | | __sanitizer_install_malloc_and_free_hooks llvm-svn: 272943
* tsan: fix another crash due to processorsDmitry Vyukov2016-05-101-18/+33
| | | | | | | | | | | | | | | | | | Another stack where we try to free sync objects, but don't have a processors is: // ResetRange // __interceptor_munmap // __deallocate_stack // start_thread // clone Again, it is a latent bug that lead to memory leaks. Also, increase amount of memory we scan in MetaMap::ResetRange. Without that the test does not fail, as we fail to free the sync objects on stack. llvm-svn: 269041
* tsan: fix a crashDmitry Vyukov2016-05-061-0/+37
| | | | | | | | | | | | | Fixes crash reported in: https://bugs.chromium.org/p/v8/issues/detail?id=4995 The problem is that we don't have a processor in a free interceptor during thread exit. The crash was introduced by introduction of Processors. However, previously we silently leaked memory which wasn't any better. llvm-svn: 268782
* [tsan] Return 0 from malloc_size for non-malloc'd pointersKuba Brecka2016-04-301-1/+5
| | | | | | | | In http://reviews.llvm.org/D19100, I introduced a bug: On OS X, existing programs rely on malloc_size() to detect whether a pointer comes from heap memory (malloc_size returns non-zero) or not. We have to distinguish between a zero-sized allocation (where we need to return 1 from malloc_size, due to other binary compatibility reasons, see http://reviews.llvm.org/D19100), and pointers that are not returned from malloc at all. Differential Revision: http://reviews.llvm.org/D19653 llvm-svn: 268157
* tsan: change tsan/Go interface for obtaining the current ProcessorDmitry Vyukov2016-04-271-8/+8
| | | | | | | | | | | | | | | Current interface assumes that Go calls ProcWire/ProcUnwire to establish the association between thread and proc. With the wisdom of hindsight, this interface does not work very well. I had to sprinkle Go scheduler with wire/unwire calls, and any mistake leads to hard to debug crashes. This is not something one wants to maintian. Fortunately, there is a simpler solution. We can ask Go runtime as to what is the current Processor, and that question is very easy to answer on Go side. Switch to such interface. llvm-svn: 267703
* tsan: split thread into logical and physical stateDmitry Vyukov2016-04-271-14/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | This is reincarnation of http://reviews.llvm.org/D17648 with the bug fix pointed out by Adhemerval (zatrazz). Currently ThreadState holds both logical state (required for race-detection algorithm, user-visible) and physical state (various caches, most notably malloc cache). Move physical state in a new Process entity. Besides just being the right thing from abstraction point of view, this solves several problems: Cache everything on P level in Go. Currently we cache on a mix of goroutine and OS thread levels. This unnecessary increases memory consumption. Properly handle free operations in Go. Frees are issue by GC which don't have goroutine context. As the result we could not do anything more than just clearing shadow. For example, we leaked sync objects and heap block descriptors. This will allow to get rid of libc malloc in Go (now we have Processor context for internal allocator cache). This in turn will allow to get rid of dependency on libc entirely. Potentially we can make Processor per-CPU in C++ mode instead of per-thread, which will reduce resource consumption. The distinction between Thread and Processor is currently used only by Go, C++ creates Processor per OS thread, which is equivalent to the current scheme. llvm-svn: 267678
* tsan: revert r262037Dmitry Vyukov2016-02-261-14/+14
| | | | | | Broke aarch64 and darwin bots. llvm-svn: 262046
* tsan: split thread into logical and physical stateDmitry Vyukov2016-02-261-14/+14
| | | | | | | | | | | | | | | | | | | | Currently ThreadState holds both logical state (required for race-detection algorithm, user-visible) and physical state (various caches, most notably malloc cache). Move physical state in a new Process entity. Besides just being the right thing from abstraction point of view, this solves several problems: 1. Cache everything on P level in Go. Currently we cache on a mix of goroutine and OS thread levels. This unnecessary increases memory consumption. 2. Properly handle free operations in Go. Frees are issue by GC which don't have goroutine context. As the result we could not do anything more than just clearing shadow. For example, we leaked sync objects and heap block descriptors. 3. This will allow to get rid of libc malloc in Go (now we have Processor context for internal allocator cache). This in turn will allow to get rid of dependency on libc entirely. 4. Potentially we can make Processor per-CPU in C++ mode instead of per-thread, which will reduce resource consumption. The distinction between Thread and Processor is currently used only by Go, C++ creates Processor per OS thread, which is equivalent to the current scheme. llvm-svn: 262037
* [tsan] Fix weakly imported functions on OS XKuba Brecka2015-11-301-2/+4
| | | | | | | | | | On OS X, for weak function (that user can override by providing their own implementation in the main binary), we need extern `"C" SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE NOINLINE`. Fixes a broken test case on OS X, java_symbolization.cc, which uses a weak function __tsan_symbolize_external. Differential Revision: http://reviews.llvm.org/D14907 llvm-svn: 254298
* tsan: speed up race deduplicationDmitry Vyukov2015-09-031-5/+5
| | | | | | | | | | | | | | | | | | | | | | | Race deduplication code proved to be a performance bottleneck in the past if suppressions/annotations are used, or just some races left unaddressed. And we still get user complaints about this: https://groups.google.com/forum/#!topic/thread-sanitizer/hB0WyiTI4e4 ReportRace already has several layers of caching for racy pcs/addresses to make deduplication faster. However, ReportRace still takes a global mutex (ThreadRegistry and ReportMutex) during deduplication and also calls mmap/munmap (which take process-wide semaphore in kernel), this makes deduplication non-scalable. This patch moves race deduplication outside of global mutexes and also removes all mmap/munmap calls. As the result, race_stress.cc with 100 threads and 10000 iterations become 30x faster: before: real 0m21.673s user 0m5.932s sys 0m34.885s after: real 0m0.720s user 0m23.646s sys 0m1.254s http://reviews.llvm.org/D12554 llvm-svn: 246758
* tsan: fix unbounded memory consumption for large mallocsDmitry Vyukov2015-06-241-0/+17
| | | | | | | This happens only in corner cases, but we observed this on a real app. See the test for description of the exact scenario that lead to unbounded memory consumption. llvm-svn: 240535
* [Sanitizer] Introduce Allocator::may_return_null bool flag.Alexey Samsonov2014-12-121-2/+11
| | | | | | | | | | | | | | | | | | | | 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 llvm-svn: 224148
* [TSan] Use StackTrace from sanitizer_common where applicableAlexey Samsonov2014-11-031-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This change removes `__tsan::StackTrace` class. There are now three alternatives: # Lightweight `__sanitizer::StackTrace`, which doesn't own a buffer of PCs. It is used in functions that need stack traces in read-only mode, and helps to prevent unnecessary allocations/copies (e.g. for StackTraces fetched from StackDepot). # `__sanitizer::BufferedStackTrace`, which stores buffer of PCs in a constant array. It is used in TraceHeader (non-Go version) # `__tsan::VarSizeStackTrace`, which owns buffer of PCs, dynamically allocated via TSan internal allocator. Test Plan: compiler-rt test suite Reviewers: dvyukov, kcc Reviewed By: kcc Subscribers: llvm-commits, kcc Differential Revision: http://reviews.llvm.org/D6004 llvm-svn: 221194
* tsan: fix false positive related to signalsDmitry Vyukov2014-10-151-4/+6
| | | | | | | Write interceptor calls malloc, which causes a false unsafe-call-in-signal-handler report. See the test. llvm-svn: 219784
* tsan: fix crash when a program registers zillions of atexit callbacksDmitry Vyukov2014-09-171-1/+0
| | | | | | | | | | I don't remember that crash on mmap in internal allocator ever yielded anything useful, only crashes in rare wierd untested situations. One of the reasons for crash was to catch if tsan starts allocating clocks using mmap. Tsan does not allocate clocks using internal_alloc anymore. Solve it once and for all by allowing mmaps. llvm-svn: 217929
* tsan: restructure signal handling to allow recursive handlingDmitry Vyukov2014-09-021-1/+2
| | | | | | | Fixes issue https://code.google.com/p/thread-sanitizer/issues/detail?id=71 llvm-svn: 216903
* [Sanitizer] Kill deprecated allocator interfaces in ASan, MSan and TSan in ↵Alexey Samsonov2014-08-121-30/+0
| | | | | | | | favor of a unified interface in <sanitizer/allocator_interface.h>. llvm-svn: 215469
* Generalize sanitizer allocator public interface.Alexey Samsonov2014-07-071-8/+39
| | | | | | | | | | | | | | Introduce new public header <sanitizer/allocator_interface.h> and a set of functions __sanitizer_get_ownership(), __sanitizer_malloc_hook() etc. that will eventually replace their tool-specific equivalents (__asan_get_ownership(), __msan_get_ownership() etc.). Tool-specific functions are now deprecated and implemented as stubs redirecting to __sanitizer_ versions (which are implemented differently in each tool). Replace all uses of __xsan_ versions with __sanitizer_ versions in unit and lit tests. llvm-svn: 212469
* [TSan] Equalize the behavior of __tsan_get_allocated_size and ↵Alexey Samsonov2014-07-011-6/+3
| | | | | | | | | | | user_alloc_usable_size. The former used to crash with a null deref if it was given a not owned pointer, while the latter returned 0. Now they both return 0. This is still not the best possible behavior: it is better to print an error report with a stack trace, pointing to the error in user code, as we do in ASan. llvm-svn: 212112
* tsan: refactor storage of meta information for heap blocks and sync objectsDmitry Vyukov2014-05-291-74/+29
| | | | | | | | | | | | | | | The new storage (MetaMap) is based on direct shadow (instead of a hashmap + per-block lists). This solves a number of problems: - eliminates quadratic behaviour in SyncTab::GetAndLock (https://code.google.com/p/thread-sanitizer/issues/detail?id=26) - eliminates contention in SyncTab - eliminates contention in internal allocator during allocation of sync objects - removes a bunch of ad-hoc code in java interface - reduces java shadow from 2x to 1/2x - allows to memorize heap block meta info for Java and Go - allows to cleanup sync object meta info for Go - which in turn enabled deadlock detector for Go llvm-svn: 209810
* tsan: refactor suppressions machineryDmitry Vyukov2014-05-281-2/+2
| | | | | | | | | | The refactoring makes suppressions more flexible and allow to suppress based on arbitrary number of stacks. In particular it fixes: https://code.google.com/p/thread-sanitizer/issues/detail?id=64 "Make it possible to suppress deadlock reports by any stack (not just first)" llvm-svn: 209757
* tsan: do not use 64-bit atomics in allocator codeDmitry Vyukov2014-05-281-8/+4
| | | | | | 64-bit atomics make porting of asan to 32-bits platforms problematic. llvm-svn: 209744
* tsan: deobfuscate global ctx variableDmitry Vyukov2014-03-201-5/+2
| | | | llvm-svn: 204327
* tsan: remove in_rtl counterDmitry Vyukov2013-12-241-9/+3
| | | | | | | | This is intended to address the following problem. Episodically we see CHECK-failures when recursive interceptors call back into user code. Effectively we are not "in_rtl" at this point, but it's very complicated and fragile to properly maintain in_rtl property. Instead get rid of it. It was used mostly for sanity CHECKs, which basically never uncover real problems. Instead introduce ignore_interceptors flag, which is used in very few narrow places to disable recursive interceptors (e.g. during runtime initialization). llvm-svn: 197979
* tsan: allow to ignore memory accesses in malloc and freeDmitry Vyukov2013-09-201-4/+10
| | | | llvm-svn: 191072
* [tsan] make calloc crash instead of returning 0 on overflow (controlled by ↵Kostya Serebryany2013-09-061-1/+1
| | | | | | the allocator_may_return_null flag) llvm-svn: 190135
* Make InternalAlloc/InternalFree in sanitizer runtimes libc-free by switching ↵Alexey Samsonov2013-05-291-2/+6
| | | | | | to a custom allocator. llvm-svn: 182836
* tsan: fix crash when data race happens on out-of-bounds accesses.Dmitry Vyukov2013-04-241-2/+4
| | | | llvm-svn: 180180
* tsan: return 0 on malloc() failure instead of crashingDmitry Vyukov2013-03-221-0/+2
| | | | llvm-svn: 177741
* tsan: smaller memory block headers (32b->16b)Dmitry Vyukov2013-03-181-19/+38
| | | | llvm-svn: 177312
* tsan: add support for idle threadsDmitry Vyukov2013-03-181-0/+5
| | | | llvm-svn: 177292
* tsan: mark shadow for thread stack as "don't need" when thread exitsDmitry Vyukov2013-03-181-4/+1
| | | | llvm-svn: 177288
* tsan: move implementation out of h fileDmitry Vyukov2013-03-181-0/+12
| | | | llvm-svn: 177269
OpenPOWER on IntegriCloud