Add MapAnonymous handling for null error_str
We use MapAnonymous with null error_str for app image loading when
we want to fail quickly. Also avoid doing CheckNonOverlapping in
CheckMapRequest if error_msg is null. The result from
CheckNonOverlapping is unused and CheckNonOverlapping is slow since
it creates a backtrace map.
Bug: 22858531
Bug: 26746779
(cherry picked from commit 83723aedac536fd8a3cd6e1662dbd6260e576194)
Change-Id: I0ff03a778b36303aa1e256fe7238dece5b3bbfab
diff --git a/runtime/mem_map_test.cc b/runtime/mem_map_test.cc
index 81c855e..e703b78 100644
--- a/runtime/mem_map_test.cc
+++ b/runtime/mem_map_test.cc
@@ -164,6 +164,19 @@
ASSERT_TRUE(error_msg.empty());
}
+TEST_F(MemMapTest, MapAnonymousFailNullError) {
+ CommonInit();
+ // Test that we don't crash with a null error_str when mapping at an invalid location.
+ std::unique_ptr<MemMap> map(MemMap::MapAnonymous("MapAnonymousInvalid",
+ reinterpret_cast<uint8_t*>(kPageSize),
+ 0x20000,
+ PROT_READ | PROT_WRITE,
+ false,
+ false,
+ nullptr));
+ ASSERT_EQ(nullptr, map.get());
+}
+
#ifdef __LP64__
TEST_F(MemMapTest, MapAnonymousEmpty32bit) {
CommonInit();