Fix broken return code of M_INITIALIZE_GWP_ASAN.
When calling android_mallopt using M_INITIALIZE_GWP_ASAN, nothing
was being returned. Fix this, add a test, and also refactor the
code a bit so dynamic and static share the same code.
Test: Unit tests pass in dynamic and static versions.
Test: Passed using both jemalloc and scudo.
Change-Id: Ibe54b6ccabdbd44d2378892e793df393978bc02b
diff --git a/tests/malloc_test.cpp b/tests/malloc_test.cpp
index eae44ce..74d5238 100644
--- a/tests/malloc_test.cpp
+++ b/tests/malloc_test.cpp
@@ -1268,6 +1268,22 @@
#endif
}
+TEST(android_mallopt, force_init_gwp_asan) {
+#if defined(__BIONIC__)
+ bool force_init = true;
+ ASSERT_TRUE(android_mallopt(M_INITIALIZE_GWP_ASAN, &force_init, sizeof(force_init)));
+
+ // Verify that trying to do the call again also passes no matter the
+ // value of force_init.
+ force_init = false;
+ ASSERT_TRUE(android_mallopt(M_INITIALIZE_GWP_ASAN, &force_init, sizeof(force_init)));
+ force_init = true;
+ ASSERT_TRUE(android_mallopt(M_INITIALIZE_GWP_ASAN, &force_init, sizeof(force_init)));
+#else
+ GTEST_SKIP() << "bionic extension";
+#endif
+}
+
void TestHeapZeroing(int num_iterations, int (*get_alloc_size)(int iteration)) {
std::vector<void*> allocs;
constexpr int kMaxBytesToCheckZero = 64;