Commit graph

28 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
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
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
Christopher Ferris
9a4f572a95 Merge "Small test fixes." 2017-05-06 06:30:41 +00:00
Christopher Ferris
47e02f429d Small test fixes.
Bug: 31919199

Test: Ran the unit tests.
Change-Id: I62bdb007f9cfa57e3faaa05993fd6e23ce32b82f
2017-05-05 17:09:49 -07:00
Yi Kong
ae797ec305 Remove unused lambda captures
Test: build
Bug: 37752547
Change-Id: Id318f412ad81b6e7de3ad644cba4405bb04f2729
2017-05-05 14:09:10 -07:00
Chih-hung Hsieh
6dc68cb5f9 Merge "Fix google-explicit-constructor warnings in system/core." 2016-07-29 16:57:17 +00:00
Chih-Hung Hsieh
223bb4e21d Suppress clang-tidy performance warnings in libmemunreachable.
Bug: 30413862
Change-Id: If3ed64d2e1ca1f46599de9fe97c769f468ee1a68
Test: build with WITH_TIDY=1
2016-07-27 16:01:41 -07:00
Chih-Hung Hsieh
034c475931 Fix google-explicit-constructor warnings in system/core.
* Declare explicit conversion constructors.
* Add NOLINT for implicit conversion constructors.
* Fix also some misaligned indendations.

Bug: 28341362
Change-Id: Idf911f35923b408d92285cc1a053f382ba08c63e
Test: build with clang-tidy
2016-07-26 11:26:01 -07:00
Chih-Hung Hsieh
eabd5108b3 Fix misc-macro-parentheses warnings in libion, libsparse, libmem*
Bug: 28705665
Change-Id: I3dd5c086787f5e48ab100a71a42109ea0e417bf9
2016-05-18 15:41:16 -07:00
Colin Cross
0965c0247b Handle segfaults while walking native heap
Vendor blobs on ryu mprotect heap pages, causing segfaults when dumping
unreachable memory.  Handle segfaults within HeapWalker by mapping a
zero page over any unreadable pages.  HeapWalker runs in the forked
process, so the mapping will not affect the original process.

Bug: 28269332
Change-Id: I16245af722123f2ad467cbc6f245a70666c55544
(cherry picked from commit ba5d9ff6d9)
2016-04-29 15:14:06 -07:00
Elliott Hughes
2c5d1d7cd9 Add operator int() to unique_fd.
Change-Id: I7512559be7befbb8772d5529e06550267a2f1543
2016-03-28 12:15:36 -07:00
Colin Cross
c1228c7f2b Combine leaks with same stacktrace
Combine similar leaks (those with identical stack traces) into a single
leak report, and sort the resulting leaks by total leak size across all
similar leaks and their references.

Bug: 27208635
Change-Id: Ia2bf2ccf3fcbc110d1c7ba60e3b77348d1c63d8d
(cherry picked from commit 7a22e81c20)
2016-03-07 15:52:39 -08:00
Colin Cross
d6b3a2a0a3 Fold leaks that are referenced by other leaks
Find leaks that have no references at all, or are only referenced by
other leaks in the same strongly connected component, and hide all
referenced leaks.

Bug: 27208635
Change-Id: Ifbfd14e24e2ba0f8af7c1b887e57f34362720f2d
(cherry picked from commit 8e8f34c558)
2016-03-07 15:52:39 -08:00
Colin Cross
54a1610404 Compile some tests for the host
Compile some tests for the host to ease debugging with valgrind or gdb.

Bug: 27208635
Change-Id: Ib46fcfa333ceb721f26efca00b2fa60b9fba44e6
(cherry picked from commit b8e20f557f)
2016-03-07 15:52:39 -08:00
Colin Cross
bcb4ed3eaa imprecise mark and sweep native memory leak detector
libmemunreachable uses an imprecise mark and sweep pass over all memory
allocated by jemalloc in order to find unreachable allocations.

Change-Id: Ia70bbf31f5b40ff71dab28cfd6cd06c5ef01a2d4
2016-02-08 17:08:49 -08:00