aboutsummaryrefslogtreecommitdiff
path: root/libc/bionic/malloc_common.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [GWP-ASan] Provide runtime configuration through an env var + sysprop.Mitch Phillips2022-04-201-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch introduces GWP-ASan system properties and environment variables to control the internal sampling rates of GWP-ASan. This can be used for: 1. "Torture testing" the system, i.e. running it under an extremely high sampling rate under GWP-ASan. 2. Increasing sampling remotely to allow further crash report collection of rare issues. There are three sets of system properites: 1. libc.debug.gwp_asan.*.system_default: Default values for native executables and system apps. 2. libc.debug.gwp_asan.*.app_default: Default values for non-system apps, and 3. libc.debug.gwp_asan.*.<basename/app_name>: Default values for an individual app or native process. There are three variables that can be changed: 1. The allocation sampling rate (default: 2500) - using the environment variable GWP_ASAN_SAMPLE_RATE or the libc.debug.gwp_asan.sample_rate.* system property. 2. The process sampling rate (default: 128 for system apps/processes, 1 for opted-in apps) - using the environment variable GWP_ASAN_PROCESS_SAMPLING or the libc.debug.gwp_asan.process_sampling.* system property, 3. The number of slots available (default: 32) - using the environment variable GWP_ASAN_MAX_ALLOCS or the libc.debug.gwp_asan.max_allocs.* system property. If not specified, #3 will be calculated as a ratio of the default |2500 SampleRate : 32 slots|. So, a sample rate of "1250" (i.e. twice as frequent sampling) will result in a doubling of the max_allocs to "64". Bug: 219651032 Test: atest bionic-unit-tests Change-Id: Idb40a2a4d074e01ce3c4e635ad639a91a32d570f
* Fix broken return code of M_INITIALIZE_GWP_ASAN.Christopher Ferris2021-09-201-3/+2
| | | | | | | | | | When calling android_mallopt using M_INITIALIZE_GWP_ASAN, nothing was being returned. Fix this, add a test, and also refactor the code a bit so dynamic and static share the same code. Test: Unit tests pass in dynamic and static versions. Test: Passed using both jemalloc and scudo. Change-Id: Ibe54b6ccabdbd44d2378892e793df393978bc02b
* [MemInit] Remove old API, introduce new MemInit API.Mitch Phillips2021-01-251-3/+3
| | | | | | | | | | | | Introduces new heap-zero-init API. We've realised that it's better to be able to individually control MTE and heap zero-init. Having heap-zero-init not be controllable without affecting MTE affects our ability to turn off heap-zero-init in zygote-forked applications. Bug: 135772972 Test: On FVP: atest -s localhost:5555 malloc#zero_init \ Test: malloc#disable_mte heap_tagging_level Change-Id: I8c6722502733259934c699f4f1269eaf1641a09f
* Remove the now-unnecessary android_mallopt() options.Elliott Hughes2021-01-151-6/+0
| | | | | | | | | These are available from mallopt() now, and all callers have been switched over. Bug: http://b/135772972 Test: treehugger Change-Id: I90c7a7573b261c27001a2dfd4589b23861ad613b
* Make "disable memory mitigations" and "set heap tagging level" more available.Elliott Hughes2021-01-141-5/+13
| | | | | | | | | | | | | These were only available internally via android_mallopt(), but they're likely to be needed by more code in future, so move them into mallopt(). This change leaves the android_mallopt() options for now, but I plan on coming back to remove them after I've switched the handful of callers over to mallopt() instead. Bug: http://b/135772972 Test: treehugger Change-Id: Ia154614069a7623c6aca85975a91e6a156f04759
* [Tagged Pointers] Allow probing the current TP level w/ locking.Mitch Phillips2020-11-301-1/+3
| | | | | | | | | | | | | | | | | | | aosp/1484976 introduced a breaking change where DisableMemoryMitigations() now indiscriminately turns tagged pointers off. When android_mallopt(M_DISABLE_MEMORY_MITIGATIONS) is called, the correct behaviour is: - In SYNC/ASYNC MTE mode -> disable all tagged pointers. - If all tagged pointers are already disabled -> nop. - If we're in TBI mode -> nop (keep the TBI mode as-is). In order to do that we have to allow probing of the current heap tagging mode. In order to prevent TOCTOU between GetHeapTaggingLevel() and SetHeapTaggingLevel(), we expose a global mutex that should be held when calling these functions. Bug: 174263432 Test: atest CtsTaggingHostTestCases on Flame Change-Id: Ia96f7269d542c9041270458806aee36766d2fbbb
* Add an API for per-process disabling memory initialization.Peter Collingbourne2020-10-081-0/+4
| | | | | | | | | | | | | | | | | | | | | | | Introduce an android_mallopt(M_DISABLE_MEMORY_MITIGATIONS) API call that may be used to disable zero- or pattern-init on non-MTE hardware, or memory tagging on MTE hardware. The intent is that this function may be called at any time, including when there are multiple threads running. Disabling zero- or pattern-init is quite trivial, we just need to set a global variable to 0 via a Scudo API call (although there will be some separate work required on the Scudo side to make this operation thread-safe). It is a bit more tricky to disable MTE across a process, because the kernel does not provide an API for disabling tag checking in all threads in a process, only per-thread. We need to send a signal to each of the process's threads with a handler that issues the required prctl call, and lock thread creation for the duration of the API call to avoid races between thread enumeration and calls to pthread_create(). Bug: 135772972 Change-Id: I81ece86ace916eb6b435ab516cd431ec4b48a3bf
* [GWP-ASan] Fix non-reentrant libc_globals init behaviour.Mitch Phillips2020-02-111-1/+3
| | | | | | | | | | | | The WriteProtected mutator for __libc_globals isn't reentrant. Previously we were calling __libc_globals.mutate() inside of GWP-ASan's libc initialisation, which is called inside the __libc_globals.mutate(). This causes problems with malloc_debug and other malloc shims, as they fail to install when GWP-ASan is sampling their processes. Bug: 135634846 Test: atest bionic Change-Id: Iae51faa8d78677eeab6204b6ab4f3ae1b7517ba5
* [GWP-ASan] Integrate GWP-ASan into bionc's malloc() (using hooks).Mitch Phillips2020-02-101-0/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch introduces GWP-ASan - a sampled allocator framework that finds use-after-free and heap-buffer-overflow bugs in production environments. GWP-ASan is being introduced in an always-disabled mode. This means that GWP-ASan will be permanently disabled until a further patch turns on support. As such, there should be no visible functional change for the time being. GWP-ASan requires -fno-emulated-tls wherever it's linked from. We intentionally link GWP-ASan into libc so that it's part of the initial set of libraries, and thus has static TLS storage (so we can use Initial-Exec TLS instead of Global-Dynamic). As a benefit, this reduces overhead for a sampled process. GWP-ASan is always initialised via. a call to mallopt(M_INITIALIZE_GWP_ASAN, which must be done before a process is multithreaded). More information about GWP-ASan can be found in the upstream documentation: http://llvm.org/docs/GwpAsan.html Bug: 135634846 Test: atest bionic Change-Id: Ib9bd33337d17dab39ac32f4536bff71bd23498b0
* Add tagged pointers to bionic.Mitch Phillips2020-01-231-20/+57
| | | | | | | | | | | | | | | | | | | | | This patch introduces tagged pointers to bionic. We add a static tag to all pointers on arm64 compatible platforms (needs requisite top-byte-ignore hardware feature and relevant kernel patches). We dynamically detect TBI-compatible devices (a device with the TBI feature and kernel support) at process start time, and insert an implementation-dependent tag into the top byte of the pointer for all heap allocations. We then check that the tag has not been truncated when deallocating the memory. If an application incorrectly writes to the top byte of the pointer, we terminate the process at time of detection. This will allow MTE-incompatible applications to be caught early. Bug: 135754954 Bug: 147147490 Test: cd bionic && atest . Change-Id: Ie424325ba1e3c4443040ac265aeaa28d9e405d28
* Merge "Revert "Add tagged pointers to bionic.""Nicolas Geoffray2020-01-211-57/+20
|\
| * Revert "Add tagged pointers to bionic."Nicolas Geoffray2020-01-211-57/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This reverts commit 43d5f9d4dd83d15a859d9be1359c4a4a47381fea. Bug: 135754954 Bug: 147147490 Exempt-From-Owner-Approval: clean revert Reason for revert: Breaks ART gtest, see: https://ci.chromium.org/p/art/builders/ci/angler-armv8-non-gen-cc/561 The crash happens on mprotect of a page, the test crashes with ENOMEM. Change-Id: I52eea1abbfaf8d8e2226f92d30aa55aba3810528
* | Merge "Add tagged pointers to bionic."Mitch Phillips2020-01-201-20/+57
|\|
| * Add tagged pointers to bionic.Mitch Phillips2020-01-151-20/+57
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch introduces tagged pointers to bionic. We add a static tag to all pointers on arm64 compatible platforms (needs requisite top-byte-ignore hardware feature and relevant kernel patches). We dynamically detect TBI-compatible devices (a device with the TBI feature and kernel support) at process start time, and insert an implementation-dependent tag into the top byte of the pointer for all heap allocations. We then check that the tag has not been truncated when deallocating the memory. If an application incorrectly writes to the top byte of the pointer, we terminate the process at time of detection. This will allow MTE-incompatible applications to be caught early. Bug: 135754954 Bug: 147147490 Test: cd bionic && atest . Change-Id: I6e5b809fc81f55dd517f845eaf20f3c0ebd4d86e
* | Add an android_mallopt for controlling the heap tagging level.Peter Collingbourne2020-01-091-0/+4
|/ | | | | | | | | | This doesn't add any functionality for now, but there are a couple of changes in flight that will want to add enumerators to the mallopt, so let's give them a place to add them. Bug: 135772972 Bug: 135754954 Change-Id: I6e810020f66070e844500c6fa99b703963365659
* Rename iterate to malloc_iterate internally.Christopher Ferris2019-11-081-5/+6
| | | | | | | | | | | | I have no idea why I used the iterate name internally which is completely unlike every other function name. Change this to match everyone else so that it's now malloc_iterate everywhere. This is probably the last chance to change this before mainline modules begin, so make everything consistent. Test: Compiles, unit tests passes. Change-Id: I56d293377fa0fe1a3dc3dd85d6432f877cc2003c
* Make bionic_malloc.h a platform header.Christopher Ferris2019-09-161-1/+1
| | | | | | | | | | | | Instead of having platform directories directly include the private header, create a platform header directory and export it. Bug: 130763340 Test: Builds. Change-Id: Ie0f092b3fe077a3de8b90266c0b28bfbc20d0dfa Merged-In: Ie0f092b3fe077a3de8b90266c0b28bfbc20d0dfa (cherry picked from commit 8f582ef2f8a77d953d0e9f33387f592d20f852e2)
* Merge "Move all leak info functions to android_mallopt."Christopher Ferris2019-04-231-8/+1
|\
| * Move all leak info functions to android_mallopt.Christopher Ferris2019-04-191-8/+1
| | | | | | | | | | | | | | | | | | | | | | Bug: 130028357 Test: malloc_hooks unit tests. Test: Enable backtrace for mediaserver, run dumpsys media.player -m Test: Enable backtrace for calendar, run am dumpheap -n <PID> <FILE> Change-Id: I6774e28ccd9b3f2310127a5b39ccd15fe696a787 Merged-In: I6774e28ccd9b3f2310127a5b39ccd15fe696a787 (cherry picked from commit 3aadc5e80a5e2cf6b6760ed90d528709223bb449)
* | Workaround ASan not knowing about reallocarray.Elliott Hughes2019-04-201-1/+1
|/ | | | | | | | | | Ensure we call realloc@plt rather than (as was previously happening) inlining realloc into reallocarray, which makes the allocation invisible to ASan. Bug: http://b/129989984 Test: objdump Change-Id: If8a43cba11aa5a2f2f62bacd02ef6ef4032e0dbb
* Remove gMallocLeakZygoteChild.Christopher Ferris2019-04-161-3/+0
| | | | | | | | | | | | | | | Remove this global variable and change the setting of it to non-zero to a call to android_mallopt. In addition, change the initialize function to use pass a bool* instead of int*. Bug: 130028357 Test: Ran malloc_debug/malloc_hooks/perfetto tests. Change-Id: I20d382bdeaaf38aac6b9dcabea5b3dfab3c945f6 Merged-In: I20d382bdeaaf38aac6b9dcabea5b3dfab3c945f6 (cherry picked from commit 5225b342f0810c027df3d09fbbcef4d324b19b93)
* Add a platform API for setting an allocation limit.Christopher Ferris2019-03-151-2/+6
| | | | | | | | | | | | | | | | | | | | | | | | | Introduce an M_SET_ALLOCATION_LIMIT enumerator for android_mallopt(), which can be used to set an upper bound on the total size of all allocations made using the memory allocation APIs. This is useful for programs such as audioextractor and mediaserver which need to set such a limit as a security mitigation. Currently these programs are using setrlimit(RLIMIT_AS) which isn't exactly what these programs want to control. RLIMIT_AS is also problematic under sanitizers which allocate large amounts of address space as shadow memory, and is especially problematic under shadow call stack, which requires 16MB of address space per thread. Add new unit tests for bionic. Add new unit tests for malloc debug that verify that when the limit is enabled, malloc debug still functions for nearly every allocation function. Bug: 118642754 Test: Ran bionic-unit-tests/bionic-unit-tests-static. Test: Ran malloc debug tests and perfetto integration tests. Change-Id: I735403c4d2c87f00fb2cdef81d00af0af446b2bb
* Add malloc_info for sanitizer.Christopher Ferris2019-03-081-0/+6
| | | | | Test: hwasan builds. Change-Id: I39267c642af75b1ebb99633f25959638cc39628c
* Refactor the malloc_info code.Christopher Ferris2019-03-071-0/+9
| | | | | | | | | | | | | | malloc_info needs to be per native allocator, but the code treated it like a global function that doesn't depend on the native memory allocator. Update malloc debug to dump the actual pointers that it has been tracking. Test: bionic-unit-tests pass. Test: malloc debug tests pass. Test: malloc hook tests pass. Change-Id: I3b0d4d748489dd84c16d16933479dc8b8d79013e Merged-In: I3b0d4d748489dd84c16d16933479dc8b8d79013e (cherry picked from commit a3656a98b10d2a4a6194a5d9705ad9c2cc5877b0)
* Log when malloc functions fail.Elliott Hughes2019-02-261-7/+37
| | | | | | | | | | | | | | | | | | | | | | This shouldn't happen often, and resulting failures can be hard to debug. From the bionic unit tests now: W libc : malloc(18446744073709551615) failed: returning null pointer W libc : calloc(18446744073709551615, 100) failed: returning null pointer W libc : calloc(1, 18446744073709551615) failed: returning null pointer W libc : calloc(18446744073709551615, 18446744073709551615) failed: returning null pointer W libc : calloc(2, 18446744073709551615) failed: returning null pointer W libc : calloc(18446744073709551615, 2) failed: returning null pointer W libc : memalign(4096, 18446744073709551615) failed: returning null pointer W libc : realloc(0x0, 18446744073709551615) failed: returning null pointer W libc : realloc(0x75d7526070, 18446744073709551615) failed: returning null pointer W libc : reallocaray(0x0, 9223372036854775812, 2) failed: returning null pointer W libc : reallocaray(0x0, 2, 9223372036854775812) failed: returning null pointer Bug: http://b/12821450 Test: ran tests Change-Id: Ib176814404f4ba1297416dd3e1edd721bf59aeed
* Refactor malloc common into distinct pieces.Christopher Ferris2019-02-121-667/+36
| | | | | | | | | | | | | | | | | | | The pieces: - The malloc common shared by static and dynamic code (malloc_common.cpp). - The code for shared libraries that includes any dlopen'ing (malloc_common_dynamic.cpp). - The implementation of perfetto's heapprofd (malloc_heapprofd.cpp). This makes it easier to see what's going on in the many different areas. It should also make it easier to add the allocation capping option. Other related changes: - Update the unit tests for android_mallopt. All of the current options don't work on static binaries, so make sure that is reflected in the test. - A few names changes to make sure that all code is consistent. Test: Ran tests (malloc hooks/malloc debug/perfetto/bionic unit tests). Change-Id: I0893bfbc0f83d82506fac5d1f37cf92fbdef6f59
* Modify malloc common function pointers.Christopher Ferris2019-02-071-103/+90
| | | | | | | | | | | | | Instead of every function being its own atomic, have a single pointer that can be used to flip all pointers at once. This avoid cases where the set of pointers can be in an partial switched state. Also fix a few inconsistent naming of functions in the file. Test: Ran unit tests (malloc debug, malloc hooks, perfetto). Change-Id: I3f66da395414586a3fa87874d80dcdf5f702ed39 Merged-In: I3f66da395414586a3fa87874d80dcdf5f702ed39 (cherry picked from commit 77184aedaf973c6e81accfc737f4fc362dad31ac)
* Do not dlclose after failed reinit.Florian Mayer2019-01-301-5/+9
| | | | | | | | Update stale comment. The reinitialization logic is tested in HeapprofdEndToEnd::ReInit in https://android.googlesource.com/platform/external/perfetto/+/master/src/profiling/memory/heapprofd_end_to_end_test.cc Change-Id: Id496ee02e208d4f4cea7129b47ef327fb2bb67f2
* Allow to reset malloc hooks.Florian Mayer2019-01-281-23/+54
| | | | | | | | | | | | | | This is used to prevent the additional indirection even after heap profiling has finished, preventing any performance impact on processes that are not currently being profiled. Test: m Test: flash sailfish Test: try tearing down & re-enabling hooks Bug: 120186127 Change-Id: Idc5988111a47870d2c093fd6a017b47e65f5616b
* conditional zygote child heap profiling + android_internal_malloptRyan Savitski2019-01-231-23/+74
| | | | | | | | | | | | | | | | | | | | On user builds, heapprofd should only be allowed to profile apps that are either debuggable, or profileable (according to the manifest). This change exposes extra zygote-specific knowledge to bionic, and makes the dedicated signal handler check for the special case of being in a zygote child. With this & the corresponding framework change, we should now be handling the 4 combinations of: {java, native} x {profile_at_runtime, profile_at_startup}. See internal go/heapprofd-java-trigger for further context. Test: on-device unit tests (shared & static) on blueline-userdebug. Test: flashed blueline-userdebug, confirmed that java profiling activates from startup and at runtime. Bug: 120409382 Change-Id: Ic251afeca4324dc650ac1d4f46976b526eae692a (cherry picked from commit 998792e2b6e1b84222b5d124f13ecdcb446cb22f) Merged-In: Ic251afeca4324dc650ac1d4f46976b526eae692a
* Do not run heapprofd_initialize twice concurrently.Florian Mayer2018-12-201-28/+31
| | | | Change-Id: Ib3fd479ca690c90ca35d98386a1d3ec942715fa3
* Make __libc_init_malloc weak-for-native-bridgedimitry2018-12-041-0/+2
| | | | | | | Bug: http://b/120406045 Test: make Change-Id: Ieee30beca3f3bb8525030643b0245041cd4a6167
* Merge "Use cmdline instead for enabling heapprofd."Florian Mayer2018-11-301-12/+62
|\
| * Use cmdline instead for enabling heapprofd.Florian Mayer2018-11-301-12/+62
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Because we also want to profile Java applications, which have longer names, the character limit of comm is a problem. To avoid complexity, it is preferable to apply the same logic for finding running processes (which includes Java apps), and determining whether to profile a process from startup. Test: m Test: flash sailfish Test: setprop heapprofd.enable 1 setprop heapprofd.enable.ls 1 ls /system/bin/ls /system/bin/ls / Bug: 120175590 Change-Id: Id0859d4a333efcb05883e611ea6a31a51468f82c
* | Fix minor bug in dispatch table initialization order.Florian Mayer2018-11-271-7/+11
|/ | | | | | | | | | | | | Other minor changes: * document assignment that relies on _Atomic assignments to use atomic_store. * consistently use atomic_store when assigning to atomics. * remove incorrect comment. Test: m Test: flash & boot sailfish Change-Id: I4789c08f7ac28a2de8d6925d03af354514bfd9d7
* System property for heapprofd at process startup.Florian Mayer2018-11-091-0/+37
| | | | | | | | | | | | Test: m Test: flash sailfish Test: setprop heapprofd.enable 1; setprop heapprofd.enable.ls 1; ls; Bug: 117821125 Change-Id: I4a42e430e5e1e194a22f83683061751aa5dfe7ff
* Allow to re-initialize heapprofd.Florian Mayer2018-10-291-7/+31
| | | | | | | Without this change, any process can only be profiled by heapprofd once. Change-Id: I2d0f50eebcc3b219750354ccdc4ea22a2e39c4b6
* Add RT signal to load heapprofd library.Florian Mayer2018-10-181-36/+150
| | | | | | | | Tests: Ran malloc_debug_unit_tests Tests: Flashed to walleye, sent signal, observed "Unable to open shared library: heapprofd.so". Change-Id: Ia8ce216837e29e3edbda8789ca28023d53fa1fda
* Add reallocarray(3).Elliott Hughes2018-09-261-0/+9
| | | | | | | | | | | | Originally a BSD extension, now in glibc too. We've used it internally for a while. (cherry-pick of e4b13f7e3ca68edfcc5faedc5e7d4e13c4e8edb9.) Bug: http://b/112163459 Test: ran tests Change-Id: I813c3a62b13ddb91ba41e32a5a853d09207ea6bc Merged-In: I813c3a62b13ddb91ba41e32a5a853d09207ea6bc
* HWASan support in bionic.Evgenii Stepanov2018-08-211-0/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Allow sanitization of libc (excluding existing global sanitizers) and disallow sanitization of linker. The latter has not been necessary before because HWASan is the first sanitizer to support static binaries (with the exception of CFI, which is not used globally). * Static binary startup: initialize HWASan shadow very early so that almost entire libc can be sanitized. The rest of initialization is done in a global constructor; until that is done sanitized code can run but can't report errors (will simply crash with SIGTRAP). * Switch malloc_common from je_* to __sanitizer_*. * Call hwasan functions when entering and leaving threads. We can not intercept pthread_create when libc depends on libclang_rt.hwasan. An alternative to this would be a callback interface like requested here: https://sourceware.org/glibc/wiki/ThreadPropertiesAPI All of the above is behind a compile-time check __has_feature(hwaddress_sanitizer). This means that HWASan actually requires libc to be instrumented, and would not work otherwise. It's an implementation choice that greatly reduces complexity of the tool. Instrumented libc also guarantees that hwasan is present and initialized in every process, which allows piecemeal sanitization (i.e. library w/o main executable, or even individual static libraries), unlike ASan. Change-Id: If44c46b79b15049d1745ba46ec910ae4f355d19c
* Change heap dump format slightly.Christopher Ferris2018-06-151-0/+24
| | | | | | | | | | | | | | | | | | | | | | | Bump the version from v1.1 to v1.2 and add a build fingerprint line. Update the heap dump documentation to match the new format and reflect what made it in P and what made it in Q. Update the unit tests for this change. Add -O0 to unit test code to make it easier to debug. Add an external function that can be used by the framework code so that there is only one way to dump the heap. Bug: 110095681 Test: Ran unit tests. Test: Did a dump of a real process and verified fingerprint. Test: Did a dump of a process without malloc debug enabled. Change-Id: I769a476cbeaf4c85c5d75bd6d6385f0e3add948c Merged-In: I769a476cbeaf4c85c5d75bd6d6385f0e3add948c (cherry picked from commit c84a2a2601a4112ca6e43a33defb989c1da8c2f4)
* Implement malloc hooks.Christopher Ferris2018-02-131-111/+136
| | | | | | | | | | | | | | | | | | | | | Use the malloc debug framework to implement the malloc debug hooks since it can introduce a performance issue. Also, modify the bionic/tests/utils.h slightly to dump an error message when the exe failed. Bug: 30561479 Test: Ran malloc hook unit tests. Test: Ran malloc debug unit tests. Test: Enabled malloc hooks and ran bionic unit tests and verified no Test: unexpected failures. Test: Enabled malloc debug and malloc hooks and verified malloc debug wins. Test: Enabled malloc debug using env, property, and property with name Test: still works. Change-Id: Ib50046a0493c5c2050cf831befb812310bdcc249 (cherry picked from commit d6a1dc23796696f73f483943534d4c5c4b312d39)
* Add aligned_alloc to libc.Christopher Ferris2018-02-071-0/+13
| | | | | | | | | Bug: 72969374 Test: Bionic unit tests pass. Test: Malloc debug unit tests pass. Change-Id: I235985bbc638855d94249c97c98f14ab2924bda0 (cherry picked from commit d69ee59594088c0d92ba9273188ef53ea5e6cd6a)
* Add support for modifying decay timer.Christopher Ferris2017-05-151-0/+13
| | | | | | | | | | | | | | | Add the mallopt function, and only a single option so far. Bug: 36401135 Test: Built and booted bullhead. Test: Ran jemalloc unit tests. Test: Ran bionic unit tests. Test: Ran a test that allocated and free'd a large piece of memory, Test: and verified that after changing the parameter, the PSS Test: sticks around (decay timer set to 1), the PSS is purged (decay Test: timer set to 0). Change-Id: I6927929b0c539c1023d34772d9e26bb6a8a45877
* Move libc_log code into libasync_safe.Christopher Ferris2017-05-031-3/+3
| | | | | | | | | | | | | | | | | | This library is used by a number of different libraries in the system. Make it easy for platform libraries to use this library and create an actual exported include file. Change the names of the functions to reflect the new name of the library. Run clang_format on the async_safe_log.cpp file since the formatting is all over the place. Bug: 31919199 Test: Compiled for angler/bullhead, and booted. Test: Ran bionic unit tests. Test: Ran the malloc debug tests. Change-Id: I8071bf690c17b0ea3bc8dc5749cdd5b6ad58478a
* Enable malloc debug using environment variablesTamas Berghammer2016-11-171-16/+16
| | | | | | | | | | | | | | | | | | Previously malloc debug can be enabled only using global settings accessible to the root user only. This CL adds a new option to enable it using environment variables making it possible to use it with pure native (shell) applications on production builds (from shell user) and prepares it for using it from logwrapper on production devices. Remove the old environment variable and property since they are not necessary. Test: Enable malloc debug using environment variable and verify Test: that it only affects the commands launched from the shell. Test: Enable malloc debug using the property variable and verify Test: that it affects all commands. Test: Run all unit tests in 32 bit and 64 bit. Change-Id: Iecb75a3471552f619f196ad550c5f41fcd9ce8e5
* Init functions after debug malloc succeeds.Christopher Ferris2016-03-111-16/+19
| | | | | | | | Do not initialize all of the global function pointers associated with debug malloc until the initialization has completed correctly. Bug: 27600760 Change-Id: I0621b54bc2d9fab63805d7992d384e550d6fed2a
* Export malloc_backtraceColin Cross2016-02-181-0/+23
| | | | Change-Id: Ic1adb4dfd86b9ca698443a36263a3df2c91edda3
* Export malloc_iterate and friendsColin Cross2016-02-181-1/+52
| | | | | | | Export malloc_iterate, malloc_enable, and malloc_disable to be used by libmemunreachable. Change-Id: I08a50349af82a95d096b6b4cbac37ababe4b9b06
* Malloc debug rewrite.Christopher Ferris2016-01-251-0/+387
The major components of the rewrite: - Completely remove the qemu shared library code. Nobody was using it and it appears to have broken at some point. - Adds the ability to enable/disable different options independently. - Adds a new option that can enable the backtrace on alloc/free when a process gets a specific signal. - Adds a new way to enable malloc debug. If a special property is set, and the process has an environment variable set, then debug malloc will be enabled. This allows something that might be a derivative of app_process to be started with an environment variable being enabled. - get_malloc_leak_info() used to return one element for each pointer that had the exact same backtrace. The new version returns information for every one of the pointers with same backtrace. It turns out ddms already automatically coalesces these, so the old method simply hid the fact that there where multiple pointers with the same amount of backtrace. - Moved all of the malloc debug specific code into the library. Nothing related to the malloc debug data structures remains in libc. - Removed the calls to the debug malloc cleanup routine. Instead, I added an atexit call with the debug malloc cleanup routine. This gets around most problems related to the timing of doing the cleanup. The new properties and environment variables: libc.debug.malloc.options Set by option name (such as "backtrace"). Setting this to a bad value will cause a usage statement to be printed to the log. libc.debug.malloc.program Same as before. If this is set, then only the program named will be launched with malloc debug enabled. This is not a complete match, but if any part of the property is in the program name, malloc debug is enabled. libc.debug.malloc.env_enabled If set, then malloc debug is only enabled if the running process has the environment variable LIBC_DEBUG_MALLOC_ENABLE set. Bug: 19145921 Change-Id: I7b0e58cc85cc6d4118173fe1f8627a391b64c0d7