OSDN Git Service

linker_memory: allow fallback allocator to be turned on and off.
authorJosh Gao <jmgao@google.com>
Tue, 7 Mar 2017 01:46:47 +0000 (17:46 -0800)
committerJosh Gao <jmgao@google.com>
Thu, 9 Mar 2017 00:43:59 +0000 (16:43 -0800)
Let the fallback allocator be used on multiple threads (as long as only
one thread is using it at once).

Bug: http://b/35858739
Change-Id: Id3e2fc6b7c093c6e56870524ffda28946de09e29

linker/linker_memory.cpp

index 18ef93e..f8852e1 100644 (file)
@@ -39,16 +39,22 @@ static 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_use_fallback_allocator() {
+extern "C" void __linker_enable_fallback_allocator() {
   if (fallback_tid != 0) {
-    __libc_format_log(ANDROID_LOG_ERROR, "libc",
-                      "attempted to set fallback allocator multiple times");
-    return;
+    __libc_fatal("attempted to use currently-in-use fallback allocator");
   }
 
   fallback_tid = gettid();
 }
 
+extern "C" void __linker_disable_fallback_allocator() {
+  if (fallback_tid == 0) {
+    __libc_fatal("attempted to disable unused fallback allocator");
+  }
+
+  fallback_tid = 0;
+}
+
 static LinkerMemoryAllocator& get_fallback_allocator() {
   static LinkerMemoryAllocator fallback_allocator;
   return fallback_allocator;