[GWP-ASan] Export GWP-ASan regions to libdebuggerd.

Exports GWP-ASan allocator information callbacks to libdebuggerd so that
tombstoned can get information from the GWP-ASan allocator in the case
of a crash.

Bug: 135634846
Test: atest bionic-unit-tests

Change-Id: Ie16426af55602fb2a76c4e69217773354c365843
diff --git a/libc/bionic/gwp_asan_wrappers.cpp b/libc/bionic/gwp_asan_wrappers.cpp
index 57c9284..d3e6a14 100644
--- a/libc/bionic/gwp_asan_wrappers.cpp
+++ b/libc/bionic/gwp_asan_wrappers.cpp
@@ -26,8 +26,10 @@
  * SUCH DAMAGE.
  */
 
+#include <platform/bionic/android_unsafe_frame_pointer_chase.h>
 #include <platform/bionic/malloc.h>
 #include <private/bionic_arc4random.h>
+#include <private/bionic_globals.h>
 #include <private/bionic_malloc_dispatch.h>
 #include <stddef.h>
 #include <stdint.h>
@@ -65,11 +67,15 @@
   Opts.SampleRate = 2500;
   Opts.InstallSignalHandlers = false;
   Opts.InstallForkHandlers = true;
+  Opts.Backtrace = android_unsafe_frame_pointer_chase;
 
   GuardedAlloc.init(Opts);
   // TODO(b/149790891): The log line below causes ART tests to fail as they're
   // not expecting any output. Disable the output for now.
   // info_log("GWP-ASan has been enabled.");
+
+  __libc_shared_globals()->gwp_asan_state = GuardedAlloc.getAllocatorState();
+  __libc_shared_globals()->gwp_asan_metadata = GuardedAlloc.getMetadataRegion();
   return true;
 }
 
diff --git a/libc/private/bionic_globals.h b/libc/private/bionic_globals.h
index 4cc9bbe..6e7eb76 100644
--- a/libc/private/bionic_globals.h
+++ b/libc/private/bionic_globals.h
@@ -65,6 +65,10 @@
 __LIBC_HIDDEN__ extern WriteProtected<libc_globals> __libc_globals;
 
 struct abort_msg_t;
+namespace gwp_asan {
+struct AllocatorState;
+struct AllocationMetadata;
+};  // namespace gwp_asan
 
 // Globals shared between the dynamic linker and libc.so.
 struct libc_shared_globals {
@@ -96,6 +100,9 @@
   // Values passed from the linker to libc.so.
   const char* init_progname = nullptr;
   char** init_environ = nullptr;
+
+  const gwp_asan::AllocatorState *gwp_asan_state = nullptr;
+  const gwp_asan::AllocationMetadata *gwp_asan_metadata = nullptr;
 };
 
 __LIBC_HIDDEN__ libc_shared_globals* __libc_shared_globals();
diff --git a/linker/linker_debuggerd_android.cpp b/linker/linker_debuggerd_android.cpp
index b8c82f9..42ea2b7 100644
--- a/linker/linker_debuggerd_android.cpp
+++ b/linker/linker_debuggerd_android.cpp
@@ -39,6 +39,12 @@
       return __libc_shared_globals()->abort_msg;
     },
     .post_dump = &notify_gdb_of_libraries,
+    .get_gwp_asan_state = []() {
+      return __libc_shared_globals()->gwp_asan_state;
+    },
+    .get_gwp_asan_metadata = []() {
+      return __libc_shared_globals()->gwp_asan_metadata;
+    },
   };
   debuggerd_init(&callbacks);
 }