summaryrefslogtreecommitdiff
path: root/lib/scudo/standalone
Commit message (Collapse)AuthorAgeFilesLines
* scudo: Update TLS_SLOT_SANITIZER value.Peter Collingbourne2019-10-181-1/+1
| | | | | | | | | | Android now allocates only 8 fixed TLS slots. Somehow we were getting away with using a non-existent slot until now, but in some cases the TLS slots were being placed at the end of a page, which led to a segfault at startup. Differential Revision: https://reviews.llvm.org/D69191 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@375276 91177308-0d34-0410-b5e6-96231b3b80d8
* [scudo][standalone] Get statistics in a char bufferKostya Kortchinsky2019-10-0914-69/+145
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@374173 91177308-0d34-0410-b5e6-96231b3b80d8
* [scudo][standalone] Correct releaseToOS behaviorKostya Kortchinsky2019-10-073-27/+67
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: There was an issue in `releaseToOSMaybe`: one of the criteria to decide if we should proceed with the release was wrong. Namely: ``` const uptr N = Sci->Stats.PoppedBlocks - Sci->Stats.PushedBlocks; if (N * BlockSize < PageSize) return; // No chance to release anything. ``` I meant to check if the amount of bytes in the free list was lower than a page, but this actually checks if the amount of **in use** bytes was lower than a page. The correct code is: ``` const uptr BytesInFreeList = Region->AllocatedUser - (Region->Stats.PoppedBlocks - Region->Stats.PushedBlocks) * BlockSize; if (BytesInFreeList < PageSize) return 0; // No chance to release anything. ``` Consequences of the bug: - if a class size has less than a page worth of in-use bytes (allocated or in a cache), reclaiming would not occur, whatever the amount of blocks in the free list; in real world scenarios this is unlikely to happen and be impactful; - if a class size had less than a page worth of free bytes (and enough in-use bytes, etc), then reclaiming would be attempted, with likely no result. This means the reclaiming was overzealous at times. I didn't have a good way to test for this, so I changed the prototype of the function to return the number of bytes released, allowing to get the information needed. The test added fails with the initial criteria. Another issue is that `ReleaseToOsInterval` can actually be 0, meaning we always try to release (side note: it's terrible for performances). so change a `> 0` check to `>= 0`. Additionally, decrease the `CanRelease` threshold to `PageSize / 32`. I still have to make that configurable but I will do it at another time. Finally, rename some variables in `printStats`: I feel like "available" was too ambiguous, so change it to "total". Reviewers: morehouse, hctim, eugenis, vitalybuka, cferris Reviewed By: morehouse Subscribers: delcypher, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D68471 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@373930 91177308-0d34-0410-b5e6-96231b3b80d8
* [scudo][standalone] Make malloc_info return a minimal XMLKostya Kortchinsky2019-10-043-4/+16
| | | | | | | | | | | | | | | | | | | | | Summary: Initially, our malloc_info was returning ENOTSUP, but Android would rather have it return successfully and write a barebone XML to the stream, so we will oblige. Add an associated test. Reviewers: cferris, morehouse, hctim, eugenis, vitalybuka Reviewed By: morehouse Subscribers: delcypher, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D68427 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@373754 91177308-0d34-0410-b5e6-96231b3b80d8
* [scudo][standalone] Android related improvementsKostya Kortchinsky2019-09-115-15/+44
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This changes a few things to improve memory footprint and performances on Android, and fixes a test compilation error: - add `stdlib.h` to `wrappers_c_test.cc` to address https://bugs.llvm.org/show_bug.cgi?id=42810 - change Android size class maps, based on benchmarks, to improve performances and lower the Svelte memory footprint. Also change the 32-bit region size for said configuration - change the `reallocate` logic to reallocate in place for sizes larger than the original chunk size, when they still fit in the same block. This addresses patterns from `memory_replay` dumps like the following: ``` 202: realloc 0xb48fd000 0xb4930650 12352 202: realloc 0xb48fd000 0xb48fd000 12420 202: realloc 0xb48fd000 0xb48fd000 12492 202: realloc 0xb48fd000 0xb48fd000 12564 202: realloc 0xb48fd000 0xb48fd000 12636 202: realloc 0xb48fd000 0xb48fd000 12708 202: realloc 0xb48fd000 0xb48fd000 12780 202: realloc 0xb48fd000 0xb48fd000 12852 202: realloc 0xb48fd000 0xb48fd000 12924 202: realloc 0xb48fd000 0xb48fd000 12996 202: realloc 0xb48fd000 0xb48fd000 13068 202: realloc 0xb48fd000 0xb48fd000 13140 202: realloc 0xb48fd000 0xb48fd000 13212 202: realloc 0xb48fd000 0xb48fd000 13284 202: realloc 0xb48fd000 0xb48fd000 13356 202: realloc 0xb48fd000 0xb48fd000 13428 202: realloc 0xb48fd000 0xb48fd000 13500 202: realloc 0xb48fd000 0xb48fd000 13572 202: realloc 0xb48fd000 0xb48fd000 13644 202: realloc 0xb48fd000 0xb48fd000 13716 202: realloc 0xb48fd000 0xb48fd000 13788 ... ``` In this situation we were deallocating the old chunk, and allocating a new one for every single one of those, but now we can keep the same chunk (we just updated the header), which saves some heap operations. Reviewers: hctim, morehouse, vitalybuka, eugenis, cferris, rengolin Reviewed By: morehouse Subscribers: srhines, delcypher, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D67293 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@371628 91177308-0d34-0410-b5e6-96231b3b80d8
* [scudo][standalone] Fix malloc_iterateKostya Kortchinsky2019-08-203-3/+46
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: cferris's Bionic tests found an issue in Scudo's `malloc_iterate`. We were inclusive of both boundaries, which resulted in a `Block` that was located on said boundary to be possibly accounted for twice, or just being accounted for while iterating on regions that are not ours (usually the unmapped ones in between Primary regions). The fix is to exclude the upper boundary in `iterateOverChunks`, and add a regression test. This additionally corrects a typo in a comment, and change the 64-bit Primary iteration function to not assume that `BatchClassId` is 0. Reviewers: cferris, morehouse, hctim, vitalybuka, eugenis Reviewed By: hctim Subscribers: delcypher, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D66231 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@369400 91177308-0d34-0410-b5e6-96231b3b80d8
* [scudo][standalone] Add more stats to mallinfoKostya Kortchinsky2019-08-147-6/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Android requires additional stats in mallinfo. While we can provide right away the number of bytes mapped (Primary+Secondary), there was no way to get the number of free bytes (only makes sense for the Primary since the Secondary unmaps everything on deallocation). An approximation could be `StatMapped - StatAllocated`, but since we are mapping in `1<<17` increments for the 64-bit Primary, it's fairly inaccurate. So we introduce `StatFree` (note it's `Free`, not `Freed`!), which keeps track of the amount of Primary blocks currently unallocated. Reviewers: cferris, eugenis, vitalybuka, hctim, morehouse Reviewed By: morehouse Subscribers: delcypher, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D66112 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@368866 91177308-0d34-0410-b5e6-96231b3b80d8
* [scudo][standalone] Minor correctionsKostya Kortchinsky2019-08-126-16/+14
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: Few corrections with no functional change: - replacing `%zd` with `%zu` all around: the values are unsigned - prefer `MAP_ANONYMOUS` to `MAP_ANON` (it's deprecated) - remove the unused `enum LinkerInitialized` - mark a parameter as `UNUSED` in Fuchsia's `getRandom` - correct the casing of a variable and use `nullptr` instead of 0 for pointers in `list.h` - reorder some `typedef` to be consistent between `signed` and `unsigned` Reviewers: eugenis, vitalybuka, morehouse, hctim Reviewed By: vitalybuka, morehouse Subscribers: delcypher, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D65660 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@368585 91177308-0d34-0410-b5e6-96231b3b80d8
* compiler-rt: Rename .cc file in lib/scudo/standalone/tests to .cppNico Weber2019-08-0123-46/+49
| | | | | | | | | Like r367463, but for scudo/standalone/tests. With this, all files in compiler-rt/lib have extension cpp. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@367569 91177308-0d34-0410-b5e6-96231b3b80d8
* compiler-rt: Rename .cc file in lib/scudo/standalone to .cppNico Weber2019-08-0115-33/+37
| | | | | | | Like r367463, but for scudo/standalone. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@367568 91177308-0d34-0410-b5e6-96231b3b80d8
* [scudo][standalone] Optimization passKostya Kortchinsky2019-07-2414-94/+91
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@366918 91177308-0d34-0410-b5e6-96231b3b80d8
* [scudo][standalone] NFC correctionsKostya Kortchinsky2019-07-117-19/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: A few corrections: - rename `TransferBatch::MaxCached` to `getMaxCached` to conform with the style guide; - move `getBlockBegin` from `Chunk::` to `Allocator::`: I believe it was a fallacy to have this be a `Chunk` method, as chunks' relationship to backend blocks are up to the frontend allocator. It makes more sense now, particularly with regard to the offset. Update the associated chunk test as the method isn't available there anymore; - add a forgotten `\n` to a log string; - for `releaseToOs`, instead of starting at `1`, start at `0` and `continue` on `BatchClassId`: in the end it's identical but doesn't assume a particular class id for batches; - change a `CHECK` to a `reportOutOfMemory`: it's a clearer message Reviewers: hctim, morehouse, eugenis, vitalybuka Reviewed By: hctim Subscribers: delcypher, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D64570 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@365816 91177308-0d34-0410-b5e6-96231b3b80d8
* [scudo][standalone] Merge Spin & Blocking mutex into a Hybrid oneKostya Kortchinsky2019-07-1117-158/+144
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@365790 91177308-0d34-0410-b5e6-96231b3b80d8
* [scudo][standalone] Link tests against libatomicKostya Kortchinsky2019-07-031-0/+2
| | | | | | | | | | | | | | | | | | | | | | Summary: Some clang versions (< 6.0) do not inline the atomic builtin functions leaving unresolved references to `__atomic_load_8` and so on (seems to be mostly 64-bit atomics on 32-bit platforms). I tried without success to use some cmake magic to detect when that would be the case, and decided to fall back to unconditionally linking libatomic. Reviewers: morehouse, eugenis, vitalybuka, hctim, tejohnson Reviewed By: tejohnson Subscribers: mgorny, delcypher, jfb, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D64134 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@365052 91177308-0d34-0410-b5e6-96231b3b80d8
* [scudo][standalone] Potential fix for missing sized deleteKostya Kortchinsky2019-07-032-1/+4
| | | | | | | | | | | | | | | | | | | | | Summary: In some setups, using `-fsized-deallocation` would end up not finding a sized delete operator at link time. For now, avoid using the flag and declare the sized delete operator in the cpp test only. This is a tentative fix as I do not have the failing setup. Reviewers: rnk, morehouse, hctim, eugenis, vitalybuka Reviewed By: rnk, hctim Subscribers: mgorny, delcypher, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D64086 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@365045 91177308-0d34-0410-b5e6-96231b3b80d8
* Revert Remove scudo standalone tests from check-allReid Kleckner2019-07-011-2/+0
| | | | | | | | This reverts r364877 (git commit dfae3705b75e6b5e1e163c78ab2df705a3388d89) This didn't solve my problem so I've reverted it. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@364878 91177308-0d34-0410-b5e6-96231b3b80d8
* Remove scudo standalone tests from check-allReid Kleckner2019-07-011-0/+2
| | | | | | | | | They appear to fail to link in various 32-bit configurations for unknown reasons. This change was already reverted, and it seems preferable to me to make forward progress and remove this once the problems are fully understood. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@364877 91177308-0d34-0410-b5e6-96231b3b80d8
* [scudo][standalone] Introduce the C & C++ wrappers [fixed]Kostya Kortchinsky2019-06-2713-37/+921
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This is a redo of D63612. Two problems came up on some bots: - `__builtin_umull_overflow` was not declared. This is likely due to an older clang or gcc, so add a guard with `__has_builtin` and fallback to a division in the event the builtin doesn't exist; - contradicting definition for `malloc`, etc. This is AFAIU due to the fact that we ended up transitively including `stdlib.h` in the `.inc` due to it being the flags parser header: so move the include to the cc instead. This should fix the issues, but since those didn't come up in my local tests it's mostly guesswork. Rest is the same! Reviewers: morehouse, hctim, eugenis, vitalybuka, dyung, hans Reviewed By: morehouse, dyung, hans Subscribers: srhines, mgorny, delcypher, jfb, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D63831 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@364547 91177308-0d34-0410-b5e6-96231b3b80d8
* Revert r364332 "[scudo][standalone] Introduce the C & C++ wrappers"Hans Wennborg2019-06-2611-909/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Makes the build fail with e.g. llvm/projects/compiler-rt/lib/scudo/standalone/wrappers_c.inc:20:68: error: declaration of 'void* calloc(size_t, size_t)' has a different exception specifier INTERFACE WEAK void *SCUDO_PREFIX(calloc)(size_t nmemb, size_t size) { ^ See llvm-commits thread. > Summary: > This CL adds C & C++ wrappers and associated tests. Those use default > configurations for a Scudo combined allocator that will likely be > tweaked in the future. > > This is the final CL required to have a functional C & C++ allocator > based on Scudo. > > The structure I have chosen is to define the core C allocation > primitives in an `.inc` file that can be customized through defines. > This allows to easily have 2 (or more) sets of wrappers backed by > different combined allocators, as demonstrated by the `Bionic` > wrappers: one set for the "default" allocator, one set for the "svelte" > allocator. > > Currently all the tests added have been gtests, but I am planning to > add some more lit tests as well. > > Reviewers: morehouse, eugenis, vitalybuka, hctim, rengolin > > Reviewed By: morehouse > > Subscribers: srhines, mgorny, delcypher, jfb, #sanitizers, llvm-commits > > Tags: #llvm, #sanitizers > > Differential Revision: https://reviews.llvm.org/D63612 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@364400 91177308-0d34-0410-b5e6-96231b3b80d8
* [scudo] Correct a behavior on the shared TSD registryKostya Kortchinsky2019-06-251-3/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: There is an error in the shared TSD registry logic when looking for a TSD in the slow path. There is an unlikely event when a TSD's precedence was 0 after attempting a `tryLock` which indicated that it was grabbed by another thread in between. We dealt with that case by continuing to the next iteration, but that meant that the `Index` was not increased and we ended up trying to lock the same TSD. This would manifest in heavy contention, and in the end we would still lock a TSD, but that was a wasted iteration. So, do not `continue`, just skip the TSD as a potential candidate. This is in both the standalone & non-standalone versions. Reviewers: morehouse, eugenis, vitalybuka, hctim Reviewed By: morehouse Subscribers: delcypher, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D63783 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@364345 91177308-0d34-0410-b5e6-96231b3b80d8
* [scudo][standalone] Introduce the C & C++ wrappersKostya Kortchinsky2019-06-2511-36/+909
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This CL adds C & C++ wrappers and associated tests. Those use default configurations for a Scudo combined allocator that will likely be tweaked in the future. This is the final CL required to have a functional C & C++ allocator based on Scudo. The structure I have chosen is to define the core C allocation primitives in an `.inc` file that can be customized through defines. This allows to easily have 2 (or more) sets of wrappers backed by different combined allocators, as demonstrated by the `Bionic` wrappers: one set for the "default" allocator, one set for the "svelte" allocator. Currently all the tests added have been gtests, but I am planning to add some more lit tests as well. Reviewers: morehouse, eugenis, vitalybuka, hctim, rengolin Reviewed By: morehouse Subscribers: srhines, mgorny, delcypher, jfb, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D63612 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@364332 91177308-0d34-0410-b5e6-96231b3b80d8
* [scudo][standalone] Fuchsia related changesKostya Kortchinsky2019-06-183-38/+37
| | | | | | | | | | | | | | | | | | | | | | Summary: Fuchsia wants to use mutexes with PI in the Scudo code, as opposed to our own implementation. This required making `lock` & `unlock` platform specific (as opposed to `wait` & `wake`) [code courtesy of John Grossman]. There is an additional flag required now for mappings as well: `ZX_VM_ALLOW_FAULTS`. Reviewers: morehouse, mcgrathr, eugenis, vitalybuka, hctim Reviewed By: morehouse Subscribers: delcypher, jfb, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D63435 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@363705 91177308-0d34-0410-b5e6-96231b3b80d8
* [scudo][standalone] Introduce the combined allocatorKostya Kortchinsky2019-06-175-0/+870
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: The Combined allocator hold together all the other components, and provides a memory allocator interface based on various template parameters. This will be in turn used by "wrappers" that will provide the standard C and C++ memory allocation functions, but can be used as is as well. This doesn't depart significantly from the current Scudo implementation except for a few details: - Quarantine batches are now protected by a header a well; - an Allocator instance has its own TSD registry, as opposed to a static one for everybody; - a function to iterate over busy chunks has been added, for Android purposes; This also adds the associated tests, and a few default configurations for several platforms, that will likely be further tuned later on. Reviewers: morehouse, hctim, eugenis, vitalybuka Reviewed By: morehouse Subscribers: srhines, mgorny, delcypher, jfb, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D63231 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@363569 91177308-0d34-0410-b5e6-96231b3b80d8
* [scudo][standalone] Unmap memory in testsKostya Kortchinsky2019-06-118-16/+74
| | | | | | | | | | | | | | | | | | | | | Summary: The more tests are added, the more we are limited by the size of the address space on 32-bit. Implement `unmapTestOnly` all around (like it is in sanitzer_common) to be able to free up some memory. This is not intended to be a proper "destructor" for an allocator, but allows us to not fail due to having no memory left. Reviewers: morehouse, vitalybuka, eugenis, hctim Reviewed By: morehouse Subscribers: delcypher, jfb, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D63146 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@363095 91177308-0d34-0410-b5e6-96231b3b80d8
* [scudo][standalone] Introduce the thread specific data structuresKostya Kortchinsky2019-06-1010-11/+512
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This CL adds the structures dealing with thread specific data for the allocator. This includes the thread specific data structure itself and two registries for said structures: an exclusive one, where each thread will have its own TSD struct, and a shared one, where a pool of TSD structs will be shared by all threads, with dynamic reassignment at runtime based on contention. This departs from the current Scudo implementation: we intend to make the Registry a template parameter of the allocator (as opposed to a single global entity), allowing various allocators to coexist with different TSD registry models. As a result, TSD registry and Allocator are tightly coupled. This also corrects a couple of things in other files that I noticed while adding this. Reviewers: eugenis, vitalybuka, morehouse, hctim Reviewed By: morehouse Subscribers: srhines, mgorny, delcypher, jfb, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D62258 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@362962 91177308-0d34-0410-b5e6-96231b3b80d8
* [scudo][standalone] Introduce the Primary(s) and LocalCacheKostya Kortchinsky2019-05-207-9/+1128
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This CL introduces the 32 & 64-bit primary allocators, and associated Local Cache. While the general idea is mostly similar to what exists in sanitizer_common, it departs from the original code somewhat significantly: - the 64-bit primary no longer uses a free array at the end of a region but uses batches of free blocks in region 0, allowing for a convergence with the 32-bit primary behavior; - as a result, there is only one (templated) local cache type for both primary allocators, and memory reclaiming can be implemented similarly for the 32-bit & 64-bit platforms; - 64-bit primary regions are handled a bit differently: we do not reserve 4TB of memory that we split, but reserve `NumClasses * 2^RegionSizeLog`, each region being offseted by a random number of pages from its computed base. A side effect of this is that the 64-bit primary works on 32-bit platform (I don't think we want to encourage it but it's an interesting side effect); Reviewers: vitalybuka, eugenis, morehouse, hctim Reviewed By: morehouse Subscribers: srhines, mgorny, delcypher, jfb, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D61745 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@361159 91177308-0d34-0410-b5e6-96231b3b80d8
* [scudo][standalone] Introduce the chunk headerKostya Kortchinsky2019-05-086-3/+249
| | | | | | | | | | | | | | | | | | | | | | Summary: ... and its related functions. The structure and its functionalities are identical to existing ones. The header stores information on a `scudo::Chunk` to be able to detect inconsitencies or potential corruption attempts. It is checksummed for that purpose. Reviewers: morehouse, eugenis, vitalybuka, hctim Reviewed By: vitalybuka Subscribers: mgorny, delcypher, jfb, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D61654 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@360290 91177308-0d34-0410-b5e6-96231b3b80d8
* [scudo][standalone] Introduce the QuarantineKostya Kortchinsky2019-05-075-0/+534
| | | | | | | | | | | | | | | | | | | | | Summary: The Quarantine is used to hold chunks for a little while prior to actually releasing them for potential reuse. The code is pretty much the same as the sanitizer_common one, with additional shuffling of the quarantine batches to decrease predictability of allocation patterns when it is enabled. Reviewers: vitalybuka, eugenis, hctim, morehouse Reviewed By: morehouse Subscribers: mgorny, delcypher, jfb, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D61385 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@360163 91177308-0d34-0410-b5e6-96231b3b80d8
* [compiler-rt] Set the ZX_VMO_RESIZABLE option for zx_vmo_createPetr Hosek2019-05-021-1/+1
| | | | | | | | | | | | | Currently VMO in Zircon create using the zx_vmo_create is resizable by default, but we'll be changing this in the future, requiring an explicit flag to make the VMO resizable. Prepare for this change by passing ZX_VMO_RESIZABLE option to all zx_vmo_create calls that need resizable VMO. Differential Revision: https://reviews.llvm.org/D61450 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@359803 91177308-0d34-0410-b5e6-96231b3b80d8
* [compiler-rt][tests] Propagate COMPILER_RT_UNITTEST_LINK_FLAGSHubert Tong2019-05-011-1/+1
| | | | | | | | | | | | | | | | | | | | | `COMPILER_RT_UNITTEST_LINK_FLAGS` is dropped in many places, unlike `COMPILER_RT_UNITTEST_CFLAGS`. This patch attempts to remove that inconsistency. Previously reviewed as part of D58951. Reviewers: sfertile, peter.smith, pzheng, phosek, Hahnfeld, nemanjai, jasonliu Reviewed By: sfertile Subscribers: jsji, kubamracek, dberris, mgorny, delcypher, jdoerfert, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D60143 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@359733 91177308-0d34-0410-b5e6-96231b3b80d8
* [scudo][standalone] Add the memory reclaiming mechanismKostya Kortchinsky2019-04-306-3/+527
| | | | | | | | | | | | | | | | | | | | | | Summary: This CL implements the memory reclaiming function `releaseFreeMemoryToOS` and its associated classes. Most of this code was originally written by Aleksey for the Primary64 in sanitizer_common, and I made some changes to be able to implement 32-bit reclaiming as well. The code has be restructured a bit to accomodate for freelist of batches instead of the freearray used in the current sanitizer_common code. Reviewers: eugenis, vitalybuka, morehouse, hctim Reviewed By: vitalybuka Subscribers: srhines, mgorny, delcypher, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D61214 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@359567 91177308-0d34-0410-b5e6-96231b3b80d8
* [scudo][standalone] Introduce the SizeClassMapKostya Kortchinsky2019-04-255-1/+190
| | | | | | | | | | | | | | | | | | | | | | Summary: As with the sanitizer_common allocator, the SCM allows for efficient mapping between sizes and size-classes, table-free. It doesn't depart significantly from the original, except that we allow the use of size-class 0 for other purposes (as opposed to chunks of size 0). The Primary will use it to hold TransferBatches. Reviewers: vitalybuka, eugenis, hctim, morehouse Reviewed By: vitalybuka Subscribers: srhines, mgorny, delcypher, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D61088 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@359199 91177308-0d34-0410-b5e6-96231b3b80d8
* [scudo][standalone] Introduce the Secondary allocatorKostya Kortchinsky2019-04-2414-88/+476
| | | | | | | | | | | | | | | | | | | | | | | | 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 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@359097 91177308-0d34-0410-b5e6-96231b3b80d8
* [scudo][standalone] Add flags & related parsersKostya Kortchinsky2019-04-099-0/+510
| | | | | | | | | | | | | | | | | | | | | | | Summary: As with other Sanitizers, and the current version of Scudo, we can provide flags in differents way: at compile time, through a weak function, through an environment variable. This change adds support for the configuration flags, and the string parsers. Those are fairly similar to the sanitizer_common way of doing things. Reviewers: morehouse, hctim, vitalybuka Reviewed By: morehouse, vitalybuka Subscribers: mgorny, delcypher, jdoerfert, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D59597 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@358011 91177308-0d34-0410-b5e6-96231b3b80d8
* [scudo][standalone] Add error reportsKostya Kortchinsky2019-03-206-37/+339
| | | | | | | | | | | | | | | | | | | | | Summary: This change adds fatal error messages for various error conditions that will be added later in the code. This also addresses a `TODO` now that we have `reportCheckFailed` (which lead me to notice a few variables that were not cased properly so I changed that as well). Reviewers: morehouse, hctim, vitalybuka Reviewed By: morehouse, hctim, vitalybuka Subscribers: mgorny, delcypher, jfb, jdoerfert, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D59551 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@356556 91177308-0d34-0410-b5e6-96231b3b80d8
* [scudo][standalone] Add string utility functionsKostya Kortchinsky2019-03-197-13/+385
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: Add some string utility functions, notably to format strings, get lengths, convert a string to a number. Those functions will be used in reports and flags (coming up next). They were mostly borrowed from sanitizer_common. Make use of the string length function in a couple places in the platform code that was checked in with inlined version of it. Add some tests. Reviewers: morehouse, eugenis, vitalybuka, hctim Reviewed By: morehouse, vitalybuka Subscribers: mgorny, delcypher, jdoerfert, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D59262 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@356457 91177308-0d34-0410-b5e6-96231b3b80d8
* [scudo][standalone] Implement checksumming functionsKostya Kortchinsky2019-03-126-0/+216
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This CL implements the checksumming functions. This departs from the current Scudo code in one aspect: the software version is no longer CRC32 but a BSD checksum. This is because the software CRC32 was too impactful in terms of performances, the BSD checksum has no array lookup which is better (and saves 1KB of data). As with the current version, we only flip the CRC compiler flag for a single compilation unit by default, to allow for a library compiled with HW CRC32 to work on a system without HW CRC32. There is some platform & hardware specific code in those files, but since departs from a mere platform split, it felt right to me to have it that way. Reviewers: morehouse, eugenis, vitalybuka, hctim, mcgrathr Reviewed By: morehouse Subscribers: mgorny, delcypher, jfb, jdoerfert, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D59116 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@355923 91177308-0d34-0410-b5e6-96231b3b80d8
* [scudo][standalone] Adding a stats classKostya Kortchinsky2019-03-074-0/+152
| | | | | | | | | | | | | | | | | | | | Summary: This adds simple local & global stats classes to be used by the Primary and Secondary, and associated test. Note that we don't need the strict atomicity of the addition & subtraction (as is in sanitizer_common) so we just use load & store. Reviewers: morehouse, vitalybuka, eugenis, flowerhack, dmmoore415 Reviewed By: morehouse, vitalybuka Subscribers: mgorny, delcypher, jfb, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D59031 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@355643 91177308-0d34-0410-b5e6-96231b3b80d8
* [scudo][standalone] Add bytemap classesKostya Kortchinsky2019-03-054-0/+178
| | | | | | | | | | | | | | | | | | | | Summary: The bytemap classes will be used by the primary32 allocator to associate classes with memory regions. It's similar to the sanitizer_common one except for the fact that the base (level1) maps are mapped instead of being static to reduce the memory footprint of an uninitialized allocator. Reviewers: vitalybuka, eugenis, morehouse, flowerhack, dmmoore415, mcgrathr Reviewed By: vitalybuka, morehouse Subscribers: mgorny, delcypher, jfb, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D58723 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@355416 91177308-0d34-0410-b5e6-96231b3b80d8
* [scudo][standalone] Fix tests makefileKostya Kortchinsky2019-03-011-2/+2
| | | | | | | | | | | | | | | | | | | | | Summary: A missing `STATIC` entailed some annoying to debug failures wrt 32 vs 64 binaries. Additionally I noticed I was using the wrong variable (the Scudo one as opposed to the Scudo Standalone one). See https://reviews.llvm.org/D58184#1412417 and below for discussion. Reviewers: vitalybuka, eugenis, brzycki Reviewed By: vitalybuka, brzycki Subscribers: mgorny, delcypher, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D58794 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@355203 91177308-0d34-0410-b5e6-96231b3b80d8
* [scudo][standalone] Add a standalone vector classKostya Kortchinsky2019-02-275-4/+167
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: This CL adds a standalone vector class that will be used by the scoped strings when they land. We reimplement our own vector class because we can't use the std library one. It's mostly borrowed from the current sanitizer_common one, with LLVM code style changes. Additionnally a casing change in a function name that slipped through the previous review (the function isn't used yet). Reviewers: vitalybuka, eugenis, flowerhack, dmmoore415, mcgrathr, morehouse Reviewed By: vitalybuka Subscribers: mgorny, delcypher, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D58689 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@354999 91177308-0d34-0410-b5e6-96231b3b80d8
* [scudo][standalone] Introduce platform specific code & mutexesKostya Kortchinsky2019-02-2615-52/+986
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: This CL adds the platform specific code for Fuchsia, Linux & Android, as well as some tests related to those (more tests to come later). While some of it is pretty much a straight port of the existing scudo & sanitizer_common code, the memory mapping functions have been reworked a bit to fit the limited usage scenario that Scudo has for them. For Fuchsia, I can now track the Vmar/Vmo pair for memory mappings if there is an intent to grow or decommit some mapping (that will be useful for the Primary). Reviewers: eugenis, vitalybuka, mcgrathr, phosek, flowerhack, morehouse, dmmoore415 Reviewed By: vitalybuka, morehouse Subscribers: kcc, dvyukov, srhines, mgorny, delcypher, jfb, jdoerfert, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D58184 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@354895 91177308-0d34-0410-b5e6-96231b3b80d8
* [compiler-rt] Cleanup usage of C++ ABI libraryJonas Hahnfeld2019-02-161-1/+5
| | | | | | | | | | | | | Add missed value "libcxxabi" and introduce SANITIZER_TEST_CXX for linking unit tests. This needs to be a full C++ library and cannot be libcxxabi. Recommit r354132 which I reverted in r354153 because it broke a sanitizer bot. This was because of the "fixes" for pthread linking, so I've removed these changes. Differential Revision: https://reviews.llvm.org/D58012 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@354198 91177308-0d34-0410-b5e6-96231b3b80d8
* Revert "[compiler-rt] Cleanup usage of C++ ABI library"Jonas Hahnfeld2019-02-151-4/+1
| | | | | | | This reverts r354132 because it breaks sanitizer-x86_64-linux: http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux/builds/19915 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@354153 91177308-0d34-0410-b5e6-96231b3b80d8
* [compiler-rt] Cleanup usage of C++ ABI libraryJonas Hahnfeld2019-02-151-1/+4
| | | | | | | | | Add missed value "libcxxabi" and introduce SANITIZER_TEST_CXX for linking unit tests. This needs to be a full C++ library and cannot be libcxxabi. Differential Revision: https://reviews.llvm.org/D58012 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@354132 91177308-0d34-0410-b5e6-96231b3b80d8
* [scudo][standalone] Do not error out on spurious C(XX) flagsKostya Kortchinsky2019-02-071-1/+3
| | | | | | | | | | | | | | | | | | | | | | Summary: The standalone Scudo version is being built with `-Werror` which can be tripped by extraneous command line arguments. We have little control over those as they can be passed down to us by `CMAKE_C(XX)_FLAGS`, the reported scenario involving `-stdlib=libc++` (see https://reviews.llvm.org/D57412#1384504). To work around this, disable `-Wunused-command-line-argument`. Reviewers: eugenis, vitalybuka, Eugene.Zelenko Reviewed By: eugenis Subscribers: mgorny, delcypher, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D57757 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@353418 91177308-0d34-0410-b5e6-96231b3b80d8
* [scudo] Initial standalone skeleton check-inKostya Kortchinsky2019-02-0410-0/+917
Summary: This is the initial check-in for the Standalone version of Scudo. The project is initially going to live in scudo/standalone then will replace scudo. See http://lists.llvm.org/pipermail/llvm-dev/2019-January/129113.html for details. This initial CL is meant to lay out the project structure, of both code & tests, providing a minimal amount of functionalities, namely various definitions, some atomic helpers and an intrusive list. (empty.cc is just here to have a compilation unit, but will go away in the upcoming CLs). Initial support is restricted to Linux i386 & x86_64 in make files and will be extended once things land & work. We will grow organically from here, adding functionalities in limited amounts. Reviewers: morehouse, eugenis, vitalybuka, kcc, mcgrathr, flowerhack Reviewed By: morehouse, vitalybuka Subscribers: srhines, mgorny, krytarowski, delcypher, jfb, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D57412 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@353055 91177308-0d34-0410-b5e6-96231b3b80d8