summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/scudo/standalone/secondary.h
Commit message (Collapse)AuthorAgeFilesLines
* scudo: Replace a couple of macros with their expansions.Peter Collingbourne2019-11-271-1/+1
| | | | | | | | | The macros INLINE and COMPILER_CHECK always expand to the same thing (inline and static_assert respectively). Both expansions are standards compliant C++ and are used consistently in the rest of LLVM, so let's improve consistency with the rest of LLVM by replacing them with the expansions. Differential Revision: https://reviews.llvm.org/D70793
* [scudo][standalone] Make tests work on FuchsiaKostya Kortchinsky2019-11-271-4/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This CL makes unit tests compatible with Fuchsia's zxtest. This required a few changes here and there, but also unearthed some incompatibilities that had to be addressed. A header is introduced to allow to account for the zxtest/gtest differences, some `#if SCUDO_FUCHSIA` are used to disable incompatible code (the 32-bit primary, or the exclusive TSD). It also brought to my attention that I was using `__scudo_default_options` in different tests, which ended up in a single binary, and I am not sure how that ever worked. So move this to the main cpp. Additionally fully disable the secondary freelist on Fuchsia as we do not track VMOs for secondary allocations, so no release possible. With some modifications to Scudo's BUILD.gn in Fuchsia: ``` [==========] 79 tests from 23 test cases ran (10280 ms total). [ PASSED ] 79 tests ``` Reviewers: mcgrathr, phosek, hctim, pcc, eugenis, cferris Subscribers: srhines, jfb, #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D70682
* [scudo][standalone] Enabled SCUDO_DEBUG for tests + fixesKostya Kortchinsky2019-11-151-1/+1
| | | | | | | | | | | | | | | | | | | Summary: `SCUDO_DEBUG` was not enabled for unit tests, meaning the `DCHECK`s were never tripped. While turning this on, I discovered that a few of those not-exercised checks were actually wrong. This CL addresses those incorrect checks. Not that to work in tests `CHECK_IMPL` has to explicitely use the `scudo` namespace. Also changes a C cast to a C++ cast. Reviewers: hctim, pcc, cferris, eugenis, vitalybuka Subscribers: mgorny, #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D70276
* [scudo][standalone] Fix Secondary bug w/ freelistKostya Kortchinsky2019-10-311-4/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: cferris@ found an issue due to the new Secondary free list behavior and unfortunately it's completely my fault. The issue is twofold: - I lost track of the (major) fact that the Combined assumes that all chunks returned by the Secondary are zero'd out apprioriately when dealing with `ZeroContents`. With the introduction of the freelist, it's no longer the case as there can be a small portion of memory between the header and the next page boundary that is left untouched (the rest is zero'd via release). So the next time that block is returned, it's not fully zero'd out. - There was no test that would exercise that behavior :( There are several ways to fix this, the one I chose makes the most sense to me: we pass `ZeroContents` to the Secondary's `allocate` and it zero's out the block if requested and it's coming from the freelist. The prevents an extraneous `memset` in case the block comes from `map`. Another possbility could have been to `memset` in `deallocate`, but it's probably overzealous as all secondary blocks don't need to be zero'd out. Add a test that would have found the issue prior to fix. Reviewers: morehouse, hctim, cferris, pcc, eugenis, vitalybuka Subscribers: #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D69675
* [scudo][standalone] Add a free list to the SecondaryKostya Kortchinsky2019-10-301-1/+153
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: The secondary allocator is slow, because we map and unmap each block on allocation and deallocation. While I really like the security benefits of such a behavior, this yields very disappointing performance numbers on Android for larger allocation benchmarks. So this change adds a free list to the secondary, that will hold recently deallocated chunks, and (currently) release the extraneous memory. This allows to save on some memory mapping operations on allocation and deallocation. I do not think that this lowers the security of the secondary, but can increase the memory footprint a little bit (RSS & VA). The maximum number of blocks the free list can hold is templatable, `0U` meaning that we fallback to the old behavior. The higher that number, the higher the extra memory footprint. I added default configurations for all our platforms, but they are likely to change in the near future based on needs and feedback. Reviewers: hctim, morehouse, cferris, pcc, eugenis, vitalybuka Subscribers: mgorny, #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D69570
* [scudo][standalone] Consolidate listsKostya Kortchinsky2019-10-281-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This is a clean patch using the last diff of D69265, but using git instead of svn, since svn went ro and arc was making my life harded than it needed to be. I was going to introduce a couple more lists and realized that our lists are currently a bit all over the place. While we have a singly linked list type relatively well defined, we are using doubly linked lists defined on the fly for the stats and for the secondary blocks. This CL adds a doubly linked list object, reorganizing the singly list one to extract as much of the common code as possible. We use this new type in the stats and the secondary. We also reorganize the list tests to benefit from this consolidation. There are a few side effect changes such as using for iterator loops that are, in my opinion, cleaner in a couple of places. Reviewers: hctim, morehouse, pcc, cferris Reviewed By: hctim Subscribers: jfb, #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D69516
* [scudo][standalone] Get statistics in a char bufferKostya Kortchinsky2019-10-091-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Following up on D68471, this CL introduces some `getStats` APIs to gather statistics in char buffers (`ScopedString` really) instead of printing them out right away. Ultimately `printStats` will just output the buffer, but that allows us to potentially do some work on the intermediate buffer, and can be used for a `mallocz` type of functionality. This allows us to pretty much get rid of all the `Printf` calls around, but I am keeping the function in for debugging purposes. This changes the existing tests to use the new APIs when required. I will add new tests as suggested in D68471 in another CL. Reviewers: morehouse, hctim, vitalybuka, eugenis, cferris Reviewed By: morehouse Subscribers: delcypher, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D68653 llvm-svn: 374173
* [scudo][standalone] Optimization passKostya Kortchinsky2019-07-241-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This introduces a bunch of small optimizations with the purpose of making the fastpath tighter: - tag more conditions as `LIKELY`/`UNLIKELY`: as a rule of thumb we consider that every operation related to the secondary is unlikely - attempt to reduce the number of potentially extraneous instructions - reorganize the `Chunk` header to not straddle a word boundary and use more appropriate types Note that some `LIKELY`/`UNLIKELY` impact might be less obvious as they are in slow paths (for example in `secondary.cc`), but at this point I am throwing a pretty wide net, and it's consistant and doesn't hurt. This was mosly done for the benfit of Android, but other platforms benefit from it too. An aarch64 Android benchmark gives: - before: ``` BM_youtube/min_time:15.000/repeats:4/manual_time_mean 445244 us 659385 us 4 BM_youtube/min_time:15.000/repeats:4/manual_time_median 445007 us 658970 us 4 BM_youtube/min_time:15.000/repeats:4/manual_time_stddev 885 us 1332 us 4 ``` - after: ``` BM_youtube/min_time:15.000/repeats:4/manual_time_mean 415697 us 621925 us 4 BM_youtube/min_time:15.000/repeats:4/manual_time_median 415913 us 622061 us 4 BM_youtube/min_time:15.000/repeats:4/manual_time_stddev 990 us 1163 us 4 ``` Additional since `-Werror=conversion` is enabled on some platforms we are built on, enable it upstream to catch things early: a few sign conversions had slept through and needed additional casting. Reviewers: hctim, morehouse, eugenis, vitalybuka Reviewed By: vitalybuka Subscribers: srhines, mgorny, javed.absar, kristof.beyls, delcypher, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D64664 llvm-svn: 366918
* [scudo][standalone] Merge Spin & Blocking mutex into a Hybrid oneKostya Kortchinsky2019-07-111-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: We ran into a problem on Fuchsia where yielding threads would never be deboosted, ultimately resulting in several threads spinning on the same TSD, and no possibility for another thread to be scheduled, dead-locking the process. While this was fixed in Zircon, this lead to discussions about if spinning without a break condition was a good decision, and settled on a new hybrid model that would spin for a while then block. Currently we are using a number of iterations for spinning that is mostly arbitrary (based on sanitizer_common values), but this can be tuned in the future. Since we are touching `common.h`, we also use this change as a vehicle for an Android optimization (the page size is fixed in Bionic, so use a fixed value too). Reviewers: morehouse, hctim, eugenis, dvyukov, vitalybuka Reviewed By: hctim Subscribers: srhines, delcypher, jfb, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D64358 llvm-svn: 365790
* [scudo][standalone] Introduce the Secondary allocatorKostya Kortchinsky2019-04-241-0/+97
Summary: The Secondary allocator wraps the platform allocation primitives. It is meant to be used for larger sizes that the Primary can't fullfill, as it will be slower, and sizes are multiple of the system page size. This also changes some of the existing code, notably the opaque platform data being passed to the platform specific functions: we can shave a couple of syscalls on Fuchsia by storing additional data (this addresses a TODO). Reviewers: eugenis, vitalybuka, hctim, morehouse Reviewed By: morehouse Subscribers: mgorny, delcypher, jfb, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D60787 llvm-svn: 359097
OpenPOWER on IntegriCloud