diff options
author | Josh Gao <jmgao@google.com> | 2018-01-24 14:45:58 -0800 |
---|---|---|
committer | Josh Gao <jmgao@google.com> | 2018-01-24 15:08:53 -0800 |
commit | 72282add20b19a0500140e0ffcab4b36a9548290 (patch) | |
tree | c46e312a0a391edf6f1496e8ff75097279a6be6c /linker/linker_memory.cpp | |
parent | 0d63a3c233040af004cc470d5f76547f3adc0148 (diff) |
linker_memory: return success in enable_fallback_allocator.
Instead of aborting when in use, return a bool instead.
Test: debuggerd_test
Change-Id: Ifd2e4439303c95054298b0a05e0cb648ded1306c
Diffstat (limited to 'linker/linker_memory.cpp')
-rw-r--r-- | linker/linker_memory.cpp | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/linker/linker_memory.cpp b/linker/linker_memory.cpp index 472c4e891..6a54c138f 100644 --- a/linker/linker_memory.cpp +++ b/linker/linker_memory.cpp @@ -32,27 +32,28 @@ #include <sys/cdefs.h> #include <unistd.h> +#include <atomic> + #include <async_safe/log.h> static LinkerMemoryAllocator g_linker_allocator; -static pid_t fallback_tid = 0; +static std::atomic<pid_t> fallback_tid(0); // Used by libdebuggerd_handler to switch allocators during a crash dump, in // case the linker heap is corrupted. Do not use this function. -extern "C" void __linker_enable_fallback_allocator() { - if (fallback_tid != 0) { - async_safe_fatal("attempted to use currently-in-use fallback allocator"); - } - - fallback_tid = gettid(); +extern "C" bool __linker_enable_fallback_allocator() { + pid_t expected = 0; + return fallback_tid.compare_exchange_strong(expected, gettid()); } extern "C" void __linker_disable_fallback_allocator() { - if (fallback_tid == 0) { + pid_t previous = fallback_tid.exchange(0); + if (previous == 0) { async_safe_fatal("attempted to disable unused fallback allocator"); + } else if (previous != gettid()) { + async_safe_fatal("attempted to disable fallback allocator in use by another thread (%d)", + previous); } - - fallback_tid = 0; } static LinkerMemoryAllocator& get_fallback_allocator() { |