linker_memory: allow fallback allocator to be turned on and off.

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
(cherry picked from commit 222272ece93d35dbb4eb76076f29bbe719bf5c93)
diff --git a/linker/linker_memory.cpp b/linker/linker_memory.cpp
index 18ef93e..f8852e1 100644
--- a/linker/linker_memory.cpp
+++ b/linker/linker_memory.cpp
@@ -39,16 +39,22 @@
 
 // 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;