Random HWASan cleanups.

Makes CtsBionicTestCases pass under HWASan.

Bug: 193568145
Test: CtsBionicTestCases
Change-Id: I38ee8a8508827c0ffee61ce33bb8c6a3f40388c9
diff --git a/tests/dlext_test.cpp b/tests/dlext_test.cpp
index e3caf0e..47214b8 100644
--- a/tests/dlext_test.cpp
+++ b/tests/dlext_test.cpp
@@ -714,7 +714,7 @@
 }
 
 std::string DlExtRelroSharingTest::FindMappingName(void* ptr) {
-  uint64_t addr = reinterpret_cast<uint64_t>(ptr);
+  uint64_t addr = reinterpret_cast<uint64_t>(untag_address(ptr));
   std::string found_name = "<not found>";
 
   EXPECT_TRUE(android::procinfo::ReadMapFile("/proc/self/maps",
diff --git a/tests/heap_tagging_level_test.cpp b/tests/heap_tagging_level_test.cpp
index 5f5904f..edbd995 100644
--- a/tests/heap_tagging_level_test.cpp
+++ b/tests/heap_tagging_level_test.cpp
@@ -52,6 +52,9 @@
   if (mte_supported()) {
     GTEST_SKIP() << "Tagged pointers are not used on MTE hardware.";
   }
+  if (running_with_hwasan()) {
+    GTEST_SKIP() << "Tagged heap pointers feature is disabled under HWASan.";
+  }
 
   void *x = malloc(1);
 
@@ -119,6 +122,9 @@
 
 TEST(heap_tagging_level, none_pointers_untagged) {
 #if defined(__BIONIC__)
+  if (running_with_hwasan()) {
+    GTEST_SKIP() << "HWASan is unaffected by heap tagging level.";
+  }
   EXPECT_TRUE(SetHeapTaggingLevel(M_HEAP_TAGGING_LEVEL_NONE));
   std::unique_ptr<int[]> p = std::make_unique<int[]>(4);
   EXPECT_EQ(untag_address(p.get()), p.get());
@@ -135,7 +141,13 @@
 
   EXPECT_FALSE(SetHeapTaggingLevel(static_cast<HeapTaggingLevel>(12345)));
 
-  if (mte_supported() && running_with_mte()) {
+  if (running_with_hwasan()) {
+    // NONE -> ...
+    EXPECT_FALSE(SetHeapTaggingLevel(M_HEAP_TAGGING_LEVEL_TBI));
+    EXPECT_FALSE(SetHeapTaggingLevel(M_HEAP_TAGGING_LEVEL_ASYNC));
+    EXPECT_FALSE(SetHeapTaggingLevel(M_HEAP_TAGGING_LEVEL_SYNC));
+    EXPECT_TRUE(SetHeapTaggingLevel(M_HEAP_TAGGING_LEVEL_NONE));
+  } else if (mte_supported() && running_with_mte()) {
     // ASYNC -> ...
     EXPECT_FALSE(SetHeapTaggingLevel(M_HEAP_TAGGING_LEVEL_TBI));
     EXPECT_TRUE(SetHeapTaggingLevel(M_HEAP_TAGGING_LEVEL_ASYNC));
diff --git a/tests/leak_test.cpp b/tests/leak_test.cpp
index 80618e5..0a881e1 100644
--- a/tests/leak_test.cpp
+++ b/tests/leak_test.cpp
@@ -112,11 +112,17 @@
 TEST(pthread_leak, join) {
   SKIP_WITH_NATIVE_BRIDGE;  // http://b/37920774
 
+  // Warm up. HWASan allocates an extra page on the first iteration, but never after.
+  pthread_t thread;
+  ASSERT_EQ(0, pthread_create(
+                   &thread, nullptr, [](void*) -> void* { return nullptr; }, nullptr));
+  ASSERT_EQ(0, pthread_join(thread, nullptr));
+
   LeakChecker lc;
 
   for (int i = 0; i < 100; ++i) {
-    pthread_t thread;
-    ASSERT_EQ(0, pthread_create(&thread, nullptr, [](void*) -> void* { return nullptr; }, nullptr));
+    ASSERT_EQ(0, pthread_create(
+                     &thread, nullptr, [](void*) -> void* { return nullptr; }, nullptr));
     ASSERT_EQ(0, pthread_join(thread, nullptr));
   }
 }
diff --git a/tests/malloc_test.cpp b/tests/malloc_test.cpp
index eae44ce..3f22007 100644
--- a/tests/malloc_test.cpp
+++ b/tests/malloc_test.cpp
@@ -700,7 +700,10 @@
   FILE* fp = fdopen(tf.fd, "w+");
   tf.release();
   ASSERT_TRUE(fp != nullptr);
-  ASSERT_EQ(0, malloc_info(0, fp));
+  if (malloc_info(0, fp) != 0) {
+    *allocator_scudo = false;
+    return;
+  }
   ASSERT_EQ(0, fclose(fp));
 
   std::string contents;