Commit graph

81 commits

Author SHA1 Message Date
Christopher Ferris
88bef19e64 Merge "Add support for scudo native allocator." 2019-09-19 14:42:23 +00:00
Colin Cross
4e3387cb5f Lengthen ScopedDisableMallocTimeout timeout to 10 seconds
memunreachable_unit_test is flaking sometimes with timeouts in
ScopedDisableMallocTimeout.  They can't be real deadlocks, which
is what this timeout is designed to detect, the Enable() called
from the signal handler wasn't doing anything because disabled_
hadn't been set yet.

Lengthen the timeout to 10 seconds, and set disabled_ before
starting to take the malloc locks in malloc_disable.  If this
really deadlocked then calling malloc_enable inside malloc_disable
would make a mess of the locks, but it would at least unlock
whatever lock was deadlocked and give the test a chance to
report the error.

Bug: 141229513
Test: atest memunreachable_unit_test
Change-Id: I3578964577025aaa4bbba09027afd22997d4adbd
2019-09-18 17:07:22 -07:00
Christopher Ferris
5db009286d Add support for scudo native allocator.
Bug: 137795072

Test: All unit tests pass when using scudo or jemalloc.
Change-Id: I20c71811d9e43663c495a1e51988acfef9fc8584
2019-09-18 16:41:25 -07:00
Josh Gao
f9b9bc7e61 Merge "Mark some tests as requiring root."
am: b245609059

Change-Id: I49cb34eebb6bb7e8ebb80f3e2edf45f36e7a2f97
2019-08-27 19:59:55 -07:00
Josh Gao
6cad139bcc Mark some tests as requiring root.
Bug: http://b/140123924
Test: mma
Change-Id: I3ad277179018631c50d9295cdb173dd9dfa7ac59
2019-08-27 16:09:32 -07:00
Steven Moreland
451e764bdc Merge "libhwbinder users use libhidlbase" into qt-dev
am: 490f1cf074

Change-Id: Ib20f4dc87cb2aea1350af98be9bb65eb7575a6fd
2019-06-20 13:09:55 -07:00
Steven Moreland
aedef73b9c libhwbinder users use libhidlbase
libhwbinder symbols are being moved into libhidlbase in order to
optimize linking/memory usage. libhwbinder will no longer be
required in the future (however removing references to it will come
separately).

Bug: 134961554
Test: boot
Change-Id: I2b9a4fb9d87913b6c0e4291d3debadbf27511111
2019-06-18 15:38:10 -07:00
Treehugger Robot
f261f518ea Merge "memunreachable_test: don't use write to escape addresses" 2019-05-25 00:20:24 +00:00
George Burgess IV
373cb301ad memunreachable_test: don't use write to escape addresses
A recent change
(https://android-review.googlesource.com/c/platform/bionic/+/961601)
caused this test to fail. This change allowed LLVM to optimize what was
previously `__write_chk` into a standard call to `write`.

LLVM knows things about `write`. In particular, it knows that `write`
doesn't capture its buffer param, which `Ref` assumes isn't possible.

LLVM can't reason much about `volatile` operations; storing this to a
`volatile` ptr should be good enough. If not, there are a few other
tricks we can play here.

Bug: 133479661
Test: `atest
memunreachable_test:memunreachable_test.MemunreachableTest#stack --
--abi x86` on internal-master

Change-Id: I905e510210cafdf83fa1b50f2f090d4f8b9653da
2019-05-24 13:51:12 -07:00
Colin Cross
05719708d0 Make libmemunreachable vendor_available
Allow vendor processes to use libmemunreachable.

Bug: 132302484
Test: m checkbuild
Change-Id: I9ed1543bd3fb20208785a160251e912a0c7e334d
2019-05-20 15:18:08 -07:00
Colin Cross
086e33f4bb Hide most symbols in libmemunreachable
In preparation for making libmemunreachble vendor_available, hide
everything but the public ABI using a version script.  The unit
tests now have to compile statically against libmemunreachable,
so split out the tests that run against the public API into a
separate test.

Bug: 132302484
Test: atest memunreachable_test memunreachable_unit_test
Change-Id: Ie9dec073fdeee342776566abedd50f7498476eca
2019-05-20 15:18:03 -07:00
Colin Cross
025ed8aacd Improve memunreachable ABI before making it vendor_available
vendor_available: true means that some prebuilts will end up with
references to classes defined in memunreachable.h.  Add version
numbers and reserved fields to the classes and default initialize
everything to zero.

Bug: 132302484
Test: memunreachable_unit_test
Change-Id: Ic183fcc766acd2c4c7dc62efafcc2c75a636e407
2019-05-20 12:57:48 -07:00
Colin Cross
87315e9d2f Catch SIGBUS in HeapWalker
SIGBUS shouldn't happen, since all of the regions being walked
were previously read out of /prod/pid/maps, but it seems to happen
rarely.  Catch it so it can produce a better log message.

Bug: 128983715
Test: atest memunreachable_test
Change-Id: I82d3941a382a0451c0dda12f5eb849ad8d697bc9
2019-03-20 16:06:52 -07:00
Evgenii Stepanov
3e1c604c07 Fix libmemunreachable vs hwasan conflict.
* Scan memory in a non-sanitized function.
* Don't scan hwasan shadow mappings.
  Shadow is ~33G and never contains any heap pointers. The scan takes
  about a minute on my device.

Bug: 112438058
Test: memunreachable_test with SANITIZE_TARGET=hwaddress
      the test still fails, but now there are no hwasan reports or new
      tombstones, and it completes in less than a minute

Change-Id: Ibe4811c67609ca9fe317edc250993b915570a638
2019-03-19 17:17:47 -07:00
Sandeep Patil
f31c70989b procinfo: Read inode number from /proc/<pid>/maps
Adjust all callbacks to include the inode number as well.

Fixes: 123532375
Test: libprocinfo_test
Test: libdmabufinfo_test
Test: libmeminfo_test

Change-Id: I71fd75d90d5ee44585011c5ae654a1dd7e185458
Signed-off-by: Sandeep Patil <sspatil@google.com>
2019-02-11 01:38:08 +00:00
Colin Cross
3ca1976fa7 Validate allocations against mappings
Bug 120032857 is seeing what appears to be allocations with incorrect
end addresses, leading to a much later crash when it tries to map
a zero page outside the valid virtual address space.  Detect allocations
that extend outside the highest or lowest memory mapping and crash
immediately instead.

Test: memunreachable_test
Bug: 120032857
Change-Id: I9be670a025143e7078360a6bf7a83219279614d9
2018-11-29 11:02:56 -08:00
Colin Cross
d780dcbaa5 Reduce logging around segfaults
The excessive logging of pages with segfaults is making it hard to
see what caused the problem, only log the first page that segfaults,
the range that was being walked when the first segfault happened,
and the total number of pages that segfaulted.

Bug: 120032857
Test: memunreachable_test --gtest_filter=HeapWalkerTest.segv
Change-Id: I71821a3f5be65f2fbcb36afc4b7b1ffa4a48e660
2018-11-27 17:00:56 -08:00
Chih-hung Hsieh
141fcfb5c5 Merge "Revert "Use ld when lld fails"" 2018-11-08 20:27:58 +00:00
Chih-hung Hsieh
060056d4f2 Revert "Use ld when lld fails"
This reverts commit 29e54f8e75.

Bug: 78118944
Reason for revert: This now passed TH boot tests.

Change-Id: I5bcff44a96ade6354b1f3247ebe1f47f3898de96
2018-11-07 23:54:10 +00:00
Chih-Hung Hsieh
747eb149d0 Add noexcept to move constructors and assignment operators.
Bug: 116614593
Test: build with WITH_TIDY=1
Change-Id: I5a7461386946ca623ab509609092aa0ac8418b80
2018-10-05 16:43:47 +00:00
Pirama Arumuga Nainar
02ab36e220 Do not construct std::function with Allocator argument
Bug: http://b/116702964

This breaks when built with C++17, where these constructors are removed.
Looks like libc++ ignored the allocator arguments anyway - so this
should be NFC even with C++17.

Test: memunreachable_test on the host and Sailfish with C++14, C++17
Change-Id: I638326a900781f64d0562b5ec38e990659967039
2018-09-26 20:24:13 +00:00
Joel Fernandes
ed59ff4729 Remove ashmem from system/core
This topic removes ashmem from ART. Changes the names in system/core
too. It only affects "dalvik-" ashmem regions which are the majority.

Change-Id: Id993b4510d9b1461954cd8a6bf8ccede45fdaacc
Signed-off-by: Joel Fernandes <joelaf@google.com>
2018-08-24 12:30:09 -07:00
Elliott Hughes
95c34a72af bionic supplies PR_SET_VMA now.
Bug: N/A
Test: builds
Change-Id: I8254711543cbf11bdf905ea441655ca1c1e82aac
2018-08-22 12:06:20 -07:00
Elliott Hughes
38488907a0 Move libbacktrace off cutils.
There's still <cutils/atomic.h> in a test, but I don't understand why
that isn't just std::atomic.

Also add a shared tgkill wrapper to libbase.

Bug: N/A
Test: ran tests
Change-Id: Idd4baa1e1670a84b3a8f35803cc5ffe5aae008a6
2018-07-11 13:55:07 -07:00
Elliott Hughes
1c1b6a0cdb libmemunreachable: fix docs formatting.
Bug: N/A
Test: gittiles
Change-Id: I59e7d22562cffa4e4a3c2a186523ae0f15623950
2018-05-30 10:53:46 -07:00
Colin Cross
18f3685600 Document using libmemunreachable on an app
Document dumpsys meminfo --unreachable, and how to enable
malloc_debug backtraces on a single app.

Test: none
Change-Id: I649afdfff1c7438f74950395639b06c39cae3ca0
2018-05-17 16:17:28 -07:00
Yabin Cui
0f837fe8ca Merge "libprocinfo: add functions reading process map file." 2018-05-15 18:01:56 +00:00
Colin Cross
ca71f170b7 Make memunreachable_test more robust against false negative leaks
For some reason, the memunreachable tests are rock solid on the
devices covered by APCT, but catch a ton of false-negatives on
hikey960, which show up as failures that look like:
system/core/libmemunreachable/tests/MemUnreachable_test.cpp:200: Failure
Expected equality of these values:
  1U
    Which is: 1
  info.leaks.size()
    Which is: 0

These happen when a stray copy of a pointer is lying around that
points to the memory it is expected to leak.  The stray pointers
can be on the stack or in the jemalloc thread cache of freed
allocations, which is always considered active memory.

Add some extra cleanups to get rid of old pointers.
1.  Clear the tcache when destructing UnreachableMemoryInfo
2.  Clear the stack and tcache before and after each test
3.  Make MemunreachbleTest.twice match MemunreachableTest.stack

Also fix MemunreachableTest.notdumpable, which was only passing
when run as root, which was bypassing what the test was trying
to cover.  Make the test pass when run as non-root, and skip
when the test is running as root.

Bug: 79701104
Test: memunreachable_test
Test: memunreachable_test as root
Change-Id: Ia6c6df11e76405d08118afcc19c1fe80a6684c56
2018-05-14 15:24:28 -07:00
Yabin Cui
3841accba8 libprocinfo: add functions reading process map file.
Add test and benchmark.
Also switch libbacktrace, libunwindstack, libmemunreachable
to use libprocinfo for map file reading.
The benchmark shows using libprocinfo speeds up map file reading
in libbacktrace and libunwindstack 18% - 36% on walleye.

Bug: http://b/79118393
Test: run procinfo_test.
Test: run libunwindstack_test.
Test: run libbacktrace_test.
Test: run memunreachable_test.

Change-Id: Icf281c352f4103fc8d4ba6732c5c07b943330ca1
2018-05-14 14:00:18 -07:00
Elliott Hughes
40fdf3f4ab Add test_suites lines.
Bug: N/A
Test: builds
Change-Id: Ic5e2b9206bcfcb53c774989013b5db6aab462e42
2018-04-27 16:12:06 -07:00
Chih-Hung Hsieh
29e54f8e75 Use ld when lld fails
* Android's clang lld link rules do not work with the special link order of
  libunwind_llvm yet.

Bug: 78118944
Test: make checkbuild and boot
Change-Id: Ife9707f111dfd24cb84b56754a4fc3f826f722c4
2018-04-16 16:00:15 -07:00
Colin Cross
f013b62152 Remove test_suites: ["vts"] from memunreachable_binder_test
memunreachable_binder_test is pulled in by
test/vts/tools/build/tasks/list/vts_test_bin_package_list.mk, it
doesn't need to be listed in test_suites.

Fixes warnings:
build/make/core/base_rules.mk:620: warning: overriding commands for target `out/host/linux-x86/vts/android-vts/testcases/memunreachable_binder_test'
build/make/core/base_rules.mk:620: warning: ignoring old commands for target `out/host/linux-x86/vts/android-vts/testcases/memunreachable_binder_test'

Test: vts-tradefed run commandAndExit vts -m VtsKernelBinderTest
Change-Id: Ifd282b2f5bb652295fa34ad247919eb85ea7abc8
2018-03-15 14:57:22 -07:00
Colin Cross
51e6c252c4 Make memunreachable_binder_test suitable for VTS
Link statically against libmemunreachable to avoid runtime
dependency on libmemunreachable.so.
Provide a better error when run as non-root.
Rename the test to MemunreachableBinderTest.
Add comments explaining the test sequence.

Bug: 28275695
Test: memunreachable_binder_test
Change-Id: Iddfba636205b7ca3ad31a6ba2c4e85abadd32d0d
2018-02-27 18:29:18 -08:00
Elliott Hughes
dc699a269f bpfmt.
Bug: N/A
Test: builds
Change-Id: I89ad00e1c4c7e0767bc80a7ac7935a4d55e090ac
2018-02-16 17:58:14 -08:00
Daniel Colascione
b650aef2a0 Add explanation for clone use
Test: no code changes
Change-Id: I70c8af8261cda3163677557fd78ae0119b1f1be0
2018-02-08 15:07:47 -08:00
Elliott Hughes
693d63f9cf Add OWNERS.
Bug: N/A
Test: N/A
Change-Id: Ie785058c0f5eb9b4086c98ccba6e63e3ed411b65
2017-12-07 13:30:03 -08:00
George Burgess IV
80136a1e41 Silence static analyzer warnings about memory leaks
The static analyzer complains that this memory is leaked regardless of
how I try to work around it (unless we escape the memory by using a
global or something, but...). Basically, as long as there's some sort
of operation on the reinterpret_cast'ed pointer, it complains. If we
remove the bitwise negations, it doesn't. Doing so would presumably
defeat the purpose of this test, though, so add a NOLINT.

Bug: 27101951
Test: mma. No more static analyzer warning for this file.
Change-Id: If9008946a2145d17b8651535141bfd7ec9224739
2017-09-24 13:36:29 -07:00
George Burgess IV
180e5e7021 Fix static analyzer warnings
The static analyzer was complaining that we were potentially leaking
memory here (in `ASSERT_NE(ptr, nullptr)` after `new (char)`). This
wasn't correct, but it's also not possible for `new` to return nullptr
without std::nothrow.

In any case, swap to direct calls to `::operator new`, since it looks
like this test explicitly wants calls to `::operator new` to be emitted
(which the C++ standard doesn't guarantee for all `new` expressions).

Bug: 27101951
Test: mma; static analyzer warnings are gone. Also ran
memunreachable_test on marlin; no failures.
Change-Id: Ia740e41079f263040da978ba1ccc71c9c39f53fd
2017-09-12 17:01:20 -07:00
dimitry
b6ba817de4 Define current ABI string in android-base/macros.h
Test: make
Change-Id: I8200d7b3232edba43a583c5ff1e1b0f78c768f69
2017-08-23 20:46:38 +02:00
Lennart Wieboldt
cd15fc7ba8 Remove LOCAL_CLANG and clang: true
clang is the default compiler since Android nougat

Test: mma & verified it´s still build with clang
Change-Id: I34adaeef2f6558a09f26027271222bad94780507
Signed-off-by: Lennart Wieboldt <lennart.1997@gmx.de>
2017-07-25 14:29:50 +02:00
Colin Cross
454285dfcc Merge "libmemunreachable: track kernel binder references" 2017-07-13 19:41:26 +00:00
Colin Cross
f572b91c4f libmemunreachable: track kernel binder references
The kernel can hold references to binder objects that have no userspace
references.  Allow libmemunreachable to call into libbinder and
libhwbinder to get lists of kernel references.  Use undefined weak
symbols so that libmemunreachable will continue to work in processes
that do not have libbinder.

Test: memunreachable_binder_test
Bug: 28275695
Change-Id: I9eae73f2a51a49a7025ffe6309ccdc2693a2391b
2017-07-12 14:59:11 -07:00
Colin Cross
b9e74ba400 Add test config for memunreachable_test
Test: none
Change-Id: Ieb297a2fcece6365a074cd470b3ca56e2baea926
2017-07-07 01:07:05 +00:00
Colin Cross
eac4ecc34f Fix ScopedSignalHandler
I4ae2d82fdfdd58cf8ef1dfb6c401cef4ba9d3e88 broke memunreachable_test
by replacing signal_ with signal.

Test: memunreachable_test
Change-Id: I8148321e3a94530867106708a33b5b63ed867380
2017-06-29 17:13:35 -07:00
Colin Cross
76464d958b Fix stack test on arm32
The stack test puts a pointer to an allocation on the stack, checks
that there are no leaks, then lets it go out of scope and checks
that libmemunreachable can find a leak.  This works on arm64, but
on arm32 the pointer on the stack doesn't get overwitten and the
leak is not detected.  Rewrite the pointer to be NULL instead.

Test: memunreachable_test
Change-Id: I5959a34cbb572a5d8670270077a85d247a3a4880
2017-06-22 14:21:52 -07:00
Colin Cross
f3ce8bc8ae libmemunreachable: turn off MEM_ALOGV messages
The move to async safe logging in I3d3b2111f6f6bf8a0d7039295d34d5168c191651
caused MEM_ALOGV messages to print even when NDEBUG was set.

Test: builds
Change-Id: Ibebe69d8c96f8f2556991c1eb5446a77782d43c7
2017-06-22 13:46:56 -07:00
Colin Cross
a9939e9a23 Move libmemunreachable into namespace android
Putting libmemunreachable in the global C++ namespace was an oversight,
move it into namespace android.

Test: m -j checkbuild
Change-Id: I0799906f6463178cb04a719bb4054cad33a50dbe
2017-06-22 10:58:23 -07:00
Colin Cross
a83881e33c libmemunreachable: clang-format everything
clang-format -i --sort-includes $(find . -name "*.cpp" -o -name "*.h")

Test: builds
Change-Id: Ia8e0677fe7f3f26dddba3a851cd2dfab9f14e421
2017-06-22 10:58:05 -07:00
Elliott Hughes
199c27734f Merge "Shave a stack frame off asserts." 2017-06-21 15:09:55 +00:00
Elliott Hughes
56731b4e2f Shave a stack frame off asserts.
We can't implement MEM_LOG_ALWAYS_FATAL_IF any more, but it wasn't really
useful anyway.

Bug: N/A
Test: ran `crasher assert` and `crasher64 assert`
Change-Id: I4ae2d82fdfdd58cf8ef1dfb6c401cef4ba9d3e88
2017-06-20 17:31:29 -07:00