diff options
Diffstat (limited to 'libc/bionic/malloc_heapprofd.cpp')
-rw-r--r-- | libc/bionic/malloc_heapprofd.cpp | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/libc/bionic/malloc_heapprofd.cpp b/libc/bionic/malloc_heapprofd.cpp index 51becf067..741b45e98 100644 --- a/libc/bionic/malloc_heapprofd.cpp +++ b/libc/bionic/malloc_heapprofd.cpp @@ -56,8 +56,8 @@ // +--->+-------------+------------------+ // | +->+kInitialState+----------------+ | malloc functions are not intercepted in any way. // | | +-------+-----+ | | -// | | | | | -// | | v | | +// | | | HandleHeapprofd | | +// | | v Signal() | | // | | +-------+----------------+ | | currently installing the ephemeral hooks. // | | |kInstallingEphemeralHook|<--+ | | // | | +-------+----------------+ | | | @@ -65,9 +65,9 @@ // | | v | | | // | | +-------+---------------+ | | | ephemeral hooks are installed. on the first call to // | | |kEphemeralHookInstalled| | | | malloc these hooks spawn a thread that installs the -// | | +-------+---------------+ | | | heapprofd hooks. -// | | | | | | -// | | v | | | +// | | +-------+---------------+ A B C heapprofd hooks. +// | | | MallocInit | | | +// | | v HeapprofdHook () | | | // | | +-------+--------------+ | | | first call to malloc happened. the hooks are reset to // | +--|kRemovingEphemeralHook| | | | kInitialState. // | +----------------------+ | | | @@ -81,7 +81,7 @@ // | +-------+------+ | | heapprofd hooks are installed. these forward calls to // | |kHookInstalled|-------------+ | malloc / free / etc. to heapprofd_client.so. // | +-------+------+ | -// | | | +// | | DispatchReset() | // | v | // | +-------+---------+ | currently resetting the hooks to default. // |----+kUninstallingHook| | @@ -92,6 +92,10 @@ // |kIncompatibleHooks+<------------+ precendence over heapprofd, so heapprofd will not get // +------------------+ enabled. this is a terminal state. // +// +// A) HandleHeapprofdSignal() +// B) HeapprofdInstallHooksAtInit() / InitHeapprofd() +// C) HeapprofdRememberHookConflict() enum MallocHeapprofdState : uint8_t { kInitialState, kInstallingEphemeralHook, @@ -321,12 +325,12 @@ void HeapprofdRememberHookConflict() { static void CommonInstallHooks(libc_globals* globals) { void* impl_handle = atomic_load(&gHeapprofdHandle); - bool reusing_handle = impl_handle != nullptr; - if (!reusing_handle) { + if (impl_handle == nullptr) { impl_handle = LoadSharedLibrary(kHeapprofdSharedLib, kHeapprofdPrefix, &globals->malloc_dispatch_table); if (impl_handle == nullptr) { return; } + atomic_store(&gHeapprofdHandle, impl_handle); } else if (!InitSharedLibrary(impl_handle, kHeapprofdSharedLib, kHeapprofdPrefix, &globals->malloc_dispatch_table)) { return; } @@ -337,11 +341,7 @@ static void CommonInstallHooks(libc_globals* globals) { // MaybeModifyGlobals locks at this point. atomic_store(&gPreviousDefaultDispatchTable, GetDefaultDispatchTable()); - if (FinishInstallHooks(globals, nullptr, kHeapprofdPrefix)) { - atomic_store(&gHeapprofdHandle, impl_handle); - } else if (!reusing_handle) { - dlclose(impl_handle); - } + FinishInstallHooks(globals, nullptr, kHeapprofdPrefix); } void HeapprofdInstallHooksAtInit(libc_globals* globals) { |