Commit graph

29131 commits

Author SHA1 Message Date
Christopher Ferris
09385c935a Stop executing if skip occurs.
Bug: 141358530

Test: Forced a skip and verified it registers as a skip.
Change-Id: I9915c67ebae4389a26f28e16375ad4a41f3e4837
(cherry picked from commit 103b998a52)
2019-09-25 13:23:43 -07:00
Christopher Ferris
5cda74e065 Do not check tcache clear when doing a purge.
On systems where the tcache is disabled, the tcache clear option will
fail, and not really do a purge.

Bug: 137037462
Bug: 136236080

Test: Built taimen as malloc svelte and verified the M_PURGE mallopt
Test: call failed before this fix and passes afterwards.
Change-Id: Ib30e5f3e083a9c6d046adff30f2aa7eacaf6df10
Merged-In: Ib30e5f3e083a9c6d046adff30f2aa7eacaf6df10
(cherry picked from commit 3d0bafb945)
2019-07-08 19:16:31 -07:00
Christopher Ferris
fe0fbcff7f Temporarily disable unwind through signal test.
On cf_x86_phone-userdebug, both of the unwind through signal
tests fail. This has been failing forever, but seems to have suddenly
become an issue, so disable while I try to figure out why this is happening.

Bug: 132763120

Test: Ran on emulator and verified tests are skipped.
Change-Id: Iafc227d972a7783e94c701d73078c9570cea288e
Merged-In: Iafc227d972a7783e94c701d73078c9570cea288e
(cherry picked from commit d424fafbce)
2019-05-16 14:25:57 -07:00
Christopher Ferris
51ad27180b Merge "Add removed platform functions used by apps." into qt-dev 2019-05-08 22:39:54 +00:00
Christopher Ferris
020681fec7 Avoid using malloc debug code after exit.
I wrote a new unit test that would fail on the old version of the
code.

On a walleye big cpu, this costs about 40ns-50ns (going from ~430ns to ~480ns).
I think this is an acceptable performance degradation.

Bug: 131867816

Test: New unit tests pass.
Change-Id: I4c0f4373fb0694bf29c3824dbb1224a8a17e211e
Merged-In: I4c0f4373fb0694bf29c3824dbb1224a8a17e211e
(cherry picked from commit d269fcc935)
2019-05-08 13:36:58 -07:00
Christopher Ferris
235f35a266 Add removed platform functions used by apps.
Added get_malloc_leak_info and free_malloc_leak_info for arm 32 bit
only so that the kindle app will continue to run.

Bug: 132175052

Test: Ran kindle app, read pdf file. Verified libKindleReaderJNI.so
Test: is loaded in memory properly.
Change-Id: Ib1ea3a37b3729f9bcc2739c5f3a584ea8f66d200
2019-05-08 12:27:56 -07:00
Florian Mayer
2a67b023bd Match maximum command line size for startup tracing.
Fix too small buffer for the startup property not accounting for the
prefix.

Bug: 131893397

This is a cherry-pick of f6d221eeed.

Change-Id: Iad2398bc09c61b1144430bcbef58e5a832b85b0a
Merged-In: Iad2398bc09c61b1144430bcbef58e5a832b85b0a
2019-05-08 10:19:49 +01:00
Ryan Prichard
2a24f6bd5f Merge "Revert fwalk/sfp locking to fix concurrent reads" into qt-dev 2019-05-07 21:21:08 +00:00
Yi Kong
bffe6f16a8 Exclude libgcc_stripped wherever libgcc is excluded
Test: manual testing
Bug: 130267141
Bug: 29275768
Merged-In: If50420c05d36e6f680a36673e7c26ca7deb93b28
Change-Id: I1e74c7b13ce0e0fa0e9c98cf9139f85e36b0645d
(cherry picked from commit 7ac2afbde3)
2019-05-07 04:45:01 +00:00
Ryan Prichard
c8e263becf Revert fwalk/sfp locking to fix concurrent reads
The locking can fail in a couple of ways:

 - A concurrent fread from an unbuffered or line-buffered file flushes
   the output of other line-buffered files, and if _fwalk locks every
   file, then the fread blocks until other file reads have completed.

 - __sfp can initialize a file lock while _fwalk is locking/unlocking it.

For now, revert to the behavior Bionic had in previous releases. This
commit reverts the file locking parts of commit
468efc80da.

Bug: http://b/131251441
Bug: http://b/130189834
Test: bionic unit tests
Change-Id: I9e20b9cd8ccd14e7962f7308e174f08af72b56c6
(cherry picked from commit c485cdb024)
2019-05-06 16:46:30 -07:00
Christopher Ferris
125d32cb46 Fix malloc_info missing large allocs.
Also change the names of some of the functions to make it very obvious
that the functions being called are in je code.

Write new test to make sure mallinfo and malloc_info match.

Bug: 131864803

Test: New unit tests pass (along with all other bionic unit tests).
Change-Id: I26eda7e64f57a8c56cc8d70e3ed6a29dcb87f630
2019-05-03 14:15:12 +00:00
Christopher Ferris
58567dcd78 Make purging clear the current thread cache too.
Bug: 131362671

Test: Ran bionic unit tests.
Test: Wrote a test that did a purge and verified that the tcache->ncached
Test: number went from 3 to 0. Also verified that mallinfo reflects the
Test: cached entries being flushed.
Change-Id: I64e35618fa3b523cf29bdaceedef676abe440dd3
(cherry picked from commit 0f710fd593)
2019-05-01 13:32:20 -07:00
Ryan Prichard
8dc7da51b5 Merge "__cxa_finalize: skip fflush call on dlclose" into qt-dev 2019-04-30 19:43:17 +00:00
Ryan Prichard
1f2ea32463 __cxa_finalize: skip fflush call on dlclose
In __cxa_finalize, only call fflush(NULL) when the program is exiting, not
when a library is unloaded with dlclose. This change restores behavior
from 2015.

Flushing output is needed when the program exits, but flushing everything
is hazardous at other times because it can block -- fflush(NULL) locks
every file, so it also blocks on read operations.

Bug: http://b/130655235
Test: manual
Change-Id: I2f5ecffa6724bfd98a93d145ab5313c793c01ae6
(cherry picked from commit c5d8c6c6e4)
2019-04-26 14:52:18 -07:00
dimitry
62b214dc87 Make pthread_get/setschedparam weak for native bridge
Bug: http://b/130825973
Test: run affected app on cuttlefish
Change-Id: I776f26f5eaebdfdb1256ff621bd05ef5a90b852a
(cherry picked from commit c7b81108b4)
2019-04-26 10:27:00 +02:00
Yi Kong
b7944a3b2d Merge "Implement __gnu_[u]ldivmod_helper methods in libc" into qt-dev 2019-04-24 04:40:40 +00:00
Ryan Prichard
53080db75a Merge "PIMutexUnlock: load owner_tid in non-common case" into qt-dev 2019-04-23 20:55:52 +00:00
TreeHugger Robot
768eb27f0d Merge "Only write main library's RELRO by default." into qt-dev 2019-04-23 17:41:43 +00:00
Torne (Richard Coles)
ebfebd057a Only write main library's RELRO by default.
ANDROID_DLEXT_WRITE_RELRO was inadvertently writing out the RELRO
section of all libraries loaded during a given dlopen() call instead of
only the main library; since the other libraries are loaded at
unpredictable addresses this additional data is rarely useful.

Fix this to only happen when the
ANDROID_DLEXT_RESERVED_ADDRESS_RECURSIVE flag is being used.

Bug: 128623590
Test: DlExtRelroSharingTest.CheckRelroSizes
Change-Id: I05e8651d06ce2de77b8c85fe2b6238f9c09691ad
(cherry picked from commit 5d10374947)
2019-04-23 12:21:56 -04:00
Yi Kong
570ab497ae Implement __gnu_[u]ldivmod_helper methods in libc
These symbols were previously provided by Android's out-dated libgcc,
but they're removed/deprecated in upstream libgcc, and also won't be
available in libclang_rt.builtins. We need to provide these methods in
libc itself for compatiblity.

Test: build with these symbols stripped in libgcc
Bug: 29275768
Change-Id: Ie1ccdb711872bf3fc317cb908fed67c9a8955e42
Merged-In: I04a05258c6c06b5a22ead41e148b02792ffbc941
(cherry picked from commit b410d0e69e)
2019-04-23 08:11:52 +00:00
Ryan Prichard
ea722a0779 PIMutexUnlock: load owner_tid in non-common case
For a recursive or errorcheck PI mutex, the old_owner variable wasn't
being initialized. As a result, unlocking a doubly-locked recursive
mutex owned by another thread decremented the mutex counter. Instead, the
unlock call should fail with EPERM.

Bug: http://b/130841532
Test: bionic-unit-tests
Test: bionic-unit-tests-glibc --gtest_filter='pthread.pthread_mutex_lock*'
Change-Id: I37adb094cb2ce8d51df7b4f48e8d6bc144436418
(cherry picked from commit 4b6c0f5dce)
2019-04-23 00:19:30 -07:00
Elliott Hughes
84cb324786 Reland ifuncs for strcmp and strlen.
This reverts commit e4788d4c7e,
which undid this change during the Q betas.

Bug: http://b/120989619

(cherry picked from commit 927fe99692)

Change-Id: Ie8fc0fc0965055f312c2c0cc0f64adb7594ffdb4
2019-04-22 16:33:38 -07:00
Elliott Hughes
5bab966ca8 Workaround ASan not knowing about reallocarray.
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

(cherry picked from commit 390be50067)

Change-Id: I0676b70cb9a7d7323252eabfff055c0e806915ef
2019-04-22 07:51:39 -07:00
Christopher Ferris
2601d43459 Move all leak info functions to android_mallopt.
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 3aadc5e80a)
2019-04-19 11:16:17 -07:00
Christopher Ferris
21f5850627 Merge "Remove gMallocLeakZygoteChild." into qt-dev 2019-04-17 17:30:22 +00:00
Daniel Mentz
bc3e37ca23 clean_header: Run outside of $ANDROID_BUILD_TOP
Enable the use case where we run clean_header.py from outside of
$ANDROID_BUILD_TOP. Previously, this script required the current working
directory to be under $ANDROID_BUILD_TOP. Running it from a different
directory resulted in the following error message:

 clean_header.py: error: Not in android tree pointed at by ANDROID_BUILD_TOP (....)

(cherry picked from commit d12d6f67bc)

Bug: 128420573
Change-Id: If07b0345401f5dd35b41876a3838209595bf8ab1
Merged-In: I48210ea1a0033228a9aaa4124d28247b07cee6d4
2019-04-16 14:26:20 -07:00
Daniel Mentz
5ca5d4aa1d clean_header: Fix error handling for no-such-file case
The function cleanupFile should always return a single value (as opposed
to a tuple or list). In addition, if it encounters an error, it is
expected to return a value that evaluates to False. As it stands,
however, it returns (None, None) in certain error cases. Change this
function to return None, in those cases.

We previously saw the following error message, when we tried to run
clean_header.py on a non-existent file.

Traceback (most recent call last):
  File "clean_header.py", line 208, in <module>
    b.updateGitFiles()
  File "utils.py", line 164, in updateGitFiles
    self._writeFile(dst)
  File "utils.py", line 136, in _writeFile
    f.write(self.new_data[dst])
TypeError: expected a string or other character buffer object

(cherry picked from commit 6d6b4cedd1)

Bug: 128420573
Change-Id: Id1dfab71e7efdee14950520df69f2e35219ee353
Merged-In: I5f717dd1a4388f598f0fd4bfd5e6129017de9095
2019-04-16 14:26:02 -07:00
Christopher Ferris
ab1c43dd6d Remove gMallocLeakZygoteChild.
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 5225b342f0)
2019-04-16 10:59:36 -07:00
Christopher Ferris
c8c4babc33 Add malloc benchmarks.
Adding some benchmarks that keep a certain number of allocation
around. This benchmark should not be used as an absolute for determining
what is a good/bad native allocator. However, it should be used to make
sure that numbers are not completely changed between allocator versions.

Also update the malloc sql benchmark to match the same style as these
new benchmarks.

Bug: 129743239

Test: Ran these benchmarks.
Change-Id: I1995d98fd269b61d9c96efed6eff3ed278e24c97
Merged-In: I1995d98fd269b61d9c96efed6eff3ed278e24c97
(cherry picked from commit 7ec2c8a9b6)
2019-04-09 13:26:50 -07:00
Jiyong Park
ff94a13d2d Don't load libc_malloc_* libs from runtime ns for libc_scudo
malloc_common_dynamic.cpp is compiled into both libc.so and
libc_scudo.so. When compiled for libc_scudo.so, it doesn't try to load
libc_malloc_* libs from the runtime linker namespace. This is because,
unlike libc.so which is shared from the runtime APEX, libc_scudo.so is
copied to any APEX that it needs. Furthermore, libdl_android which
provides android_get_exported_namespace is not available for vendors. So
the vendor variant of libc_scudo.so can't anyway locate the runtime
namespace.

Bug: 130213757
Bug: 122566199
Test: `m libc_scudo libc_scudo` is successful
Test: inspect the built library to see if it has reference to
android_get_exported_namespace

Change-Id: I4c41de361fdb3fa34b95218923f4ce4e9c010f9e
2019-04-10 02:29:25 +09:00
TreeHugger Robot
478f7f12b3 Merge "Load libc_malloc_* libraries from the runtime APEX" into qt-dev 2019-04-09 03:51:45 +00:00
Ryan Prichard
05c2966b2e Merge "Fix dlsym and dladdr for TLS symbols" into qt-dev 2019-04-05 20:03:19 +00:00
Jiyong Park
4e46ac69c2 Load libc_malloc_* libraries from the runtime APEX
/system/lib/libc.so is a symlink to libc.so in the runtime APEX.
libc_malloc_* libraries are bundled with libc.so because they share
implementation details.

However, since libc.so is loaded in the default namespace where the
runtime APEX path (/apex/com.android.runtime/lib) is not accessible,
libc.so has been using libc_malloc_* from /system/lib. This is
wrong because libc.so (from the runtime APEX) and libc_malloc_* (from
the platform) may not be in-sync.

libc.so now uses android_dlopen_ext to load libc_malloc_* libraries
correctly from the "runtime" linker namespace.

Bug: 122566199
Test: bionic-unit-tests

Change-Id: I46980fbe89e93ea79a7760c9b8eb007af0ada8d8
(cherry picked from commit aea5c34423)
2019-04-06 00:19:37 +09:00
Ryan Prichard
3f05d3e971 Fix dlsym and dladdr for TLS symbols
* dlsym: call __tls_get_addr for TLS symbols

 * dladdr: skip TLS symbols

Bug: b/123772574
Test: bionic unit tests
Change-Id: I59a8bc4a7d455e1018b0d577b027b6417c8487cd
(cherry picked from commit e4d620bc80)
2019-04-04 16:46:59 -07:00
Adrian-CJ Hung
62bb17a890 Workaround potential access to unmapped stack
Issue:
Process is crashed near the end (startup_handshake_lock.unlock()) in
pthread_create().

The newly created child thread passes this handshake_lock unexpectedly
=> its stack is unmapped & its associated pthread_internal_t data
structure can’t be accessed.

Analysis:
The created child thread should be blocked by startup_handshake_lock.lock()
and enter __futex_wait_ex()

But if the parent thread is in the middle of startup_handshake_lock.unlock():

  void unlock() {
    if (atomic_exchange_explicit(&state, Unlocked, memory_order_seq_cst) == LockedWithWaiter) {  // => the state is modified to Unlocked

    // (a) if the child thread is back to running and pass the while() check in Lock::lock()
    // (b) the child thread executes its start_routine and then pthread_exit
    // (c) the stack of the child thread (where its pthread_internal_t (so the startup_handshake_lock) is located) will be unmapped

     __futex_wake_ex(&state, process_shared, 1);   // => when the parent thread is back to running
                                                   // the “state” & “process_shared” of startup_handshake_lock can’t be accessed (unmapped)
                                                   // so the process will be crashed
    }
  }

Bug: 129744706
Test: Monkey

(cherry picked from commit 8c1a14d4f3)

Change-Id: I88f3e1f205f802ece751aacd63fe7d3cc56f2a5f
2019-04-04 12:49:33 -07:00
Bill Rassieur
20a0001e05 Merge master@5406228 into git_qt-dev-plus-aosp.
am: 5da3333d1b

Change-Id: I25c9f2606c7d692fb1b7d40d8205122b27f74dda
2019-04-03 16:10:52 -07:00
Torne (Richard Coles)
07603294cd Merge "Fix DLEXT_WRITE_RELRO when loading multiple libs." am: 865866ee2b am: c950489599
am: ce62c05753

Change-Id: I234ee6e837fe2609918cee82121aa3994afbd4d8
2019-04-03 09:12:36 -07:00
Torne (Richard Coles)
ce62c05753 Merge "Fix DLEXT_WRITE_RELRO when loading multiple libs." am: 865866ee2b
am: c950489599

Change-Id: Iea5e24a6a46094cf87d77852ccc8b124c4bdb075
2019-04-03 08:36:06 -07:00
Torne (Richard Coles)
c950489599 Merge "Fix DLEXT_WRITE_RELRO when loading multiple libs."
am: 865866ee2b

Change-Id: I96ec82554fbb96b983d09db9c998274dda9e1a1a
2019-04-03 08:27:54 -07:00
Treehugger Robot
865866ee2b Merge "Fix DLEXT_WRITE_RELRO when loading multiple libs." 2019-04-03 15:19:57 +00:00
Pirama Arumuga Nainar
74ce129f90 Merge "Move bionic-unit-tests-static to libclang_rt.builtins" am: 96c21e43b4 am: b993b94d41
am: 55615c7b2c

Change-Id: I40b8dc97589c0a48fed037d3a35be6e25ef1b48a
2019-04-03 08:19:53 -07:00
Pirama Arumuga Nainar
55615c7b2c Merge "Move bionic-unit-tests-static to libclang_rt.builtins" am: 96c21e43b4
am: b993b94d41

Change-Id: Ifea68caa592bd22d36ab392ca8e3016c5b46e9b7
2019-04-03 08:11:26 -07:00
Pirama Arumuga Nainar
b993b94d41 Merge "Move bionic-unit-tests-static to libclang_rt.builtins"
am: 96c21e43b4

Change-Id: I79c2c06cd179d6cb1fa63e69735ae4bff0559145
2019-04-03 08:06:09 -07:00
Treehugger Robot
96c21e43b4 Merge "Move bionic-unit-tests-static to libclang_rt.builtins" 2019-04-03 14:45:47 +00:00
Pirama Arumuga Nainar
0d16a31664 Move bionic-unit-tests-static to libclang_rt.builtins
Bug: http://b/129728267
Bug: http://b/117167374

This test is now built with XOM (because libm now uses XOM) but it
should also use libclang_rt.builtins since libgcc is not built with XOM.

Test: bionic-unit-tests-static passes (but used to segfault with XOM
exceptions without this change).

Change-Id: I0b1dfe52e48db5f5e9386c7722ecd91e155be56f
2019-04-02 22:45:29 -07:00
Torne (Richard Coles)
fa9f7f28d4 Fix DLEXT_WRITE_RELRO when loading multiple libs.
ANDROID_DLEXT_WRITE_RELRO was causing the GNU RELRO sections of
libraries to become corrupted if more than one library was being loaded
at once (i.e. if the root library has DT_NEEDED entries for libraries
that weren't already loaded). The file offset was not being correctly
propagated between calls, so after writing out the (correct) RELRO data
to the file, it was mapping the data at file offset 0 for all libraries,
which corrupted the data for all but one of the libraries.

Fix this by passing file_offset as a pointer the same way that
phdr_table_map_gnu_relro does.

Bug: 128623590
Test: tbd
Change-Id: I196cd336bd5a67454e89fd85487356b1c7856871
2019-04-02 18:06:12 -04:00
Christopher Ferris
2fb7b814b0 Merge "Disable info messages by default for malloc debug." am: e6fd53b751 am: f2905f4ce3
am: 8e1ffaf89f

Change-Id: I64fd19ded1111960c8080f7c7f9eea84ca99651c
2019-04-02 14:24:47 -07:00
Christopher Ferris
8e1ffaf89f Merge "Disable info messages by default for malloc debug." am: e6fd53b751
am: f2905f4ce3

Change-Id: Iddb4900532ef816f8bf061a142cd0ec74b45a850
2019-04-02 13:40:11 -07:00
Christopher Ferris
f2905f4ce3 Merge "Disable info messages by default for malloc debug."
am: e6fd53b751

Change-Id: I088f92572a5b0af474a311f6bf73b48924b2960a
2019-04-02 13:06:53 -07:00
Christopher Ferris
e6fd53b751 Merge "Disable info messages by default for malloc debug." 2019-04-02 19:46:29 +00:00