summaryrefslogtreecommitdiff
path: root/libunwindstack/tests/DexFilesTest.cpp
diff options
context:
space:
mode:
authorChristopher Ferris <cferris@google.com>2018-10-17 10:57:53 -0700
committerChristopher Ferris <cferris@google.com>2018-10-17 14:23:10 -0700
commit56d0e07d703c7727b51b0354f555d4b825b747ac (patch)
tree2c6409eab9862d492f762757a47910beacfe4caa /libunwindstack/tests/DexFilesTest.cpp
parent6853a187e37b541fb536154cc6a6057dae1e916a (diff)
Fix which maps to search for globals.
If multiple threads are unwinding at the same time, new maps that contain the global variables for dex files and jit information are created. This leads to threads creating more new maps that then get searched, then more maps, then more searching until virtual address space exhaustion. Fix this so that we only search maps that have a corresponding rw map that could contain the global memory. Small refactor to combine the code to search for global variables into one class that both classes inherit from. Modify unit tests for the new pattern checking. Bug: 117761427 Test: Ran unit tests for libunwindstack/libbacktrace/simpleperf. Test: Ran art 004-ThreadStress that used to fail. Change-Id: I837ca6b9d0383100079de090bc7d019598e0cdfe
Diffstat (limited to 'libunwindstack/tests/DexFilesTest.cpp')
-rw-r--r--libunwindstack/tests/DexFilesTest.cpp32
1 files changed, 18 insertions, 14 deletions
diff --git a/libunwindstack/tests/DexFilesTest.cpp b/libunwindstack/tests/DexFilesTest.cpp
index c6d7f330e..3ac3ca61b 100644
--- a/libunwindstack/tests/DexFilesTest.cpp
+++ b/libunwindstack/tests/DexFilesTest.cpp
@@ -44,15 +44,15 @@ class DexFilesTest : public ::testing::Test {
dex_files_->SetArch(ARCH_ARM);
maps_.reset(
- new BufferMaps("1000-4000 ---s 00000000 00:00 0\n"
- "4000-6000 r--s 00000000 00:00 0\n"
- "6000-8000 -wxs 00000000 00:00 0\n"
- "a000-c000 r--p 00000000 00:00 0\n"
- "c000-f000 rw-p 00000000 00:00 0\n"
- "f000-11000 r--p 00000000 00:00 0\n"
- "100000-110000 rw-p 0000000 00:00 0\n"
- "200000-210000 rw-p 0000000 00:00 0\n"
- "300000-400000 rw-p 0000000 00:00 0\n"));
+ new BufferMaps("1000-4000 ---s 00000000 00:00 0 /fake/elf\n"
+ "4000-6000 r--s 00000000 00:00 0 /fake/elf\n"
+ "6000-8000 -wxs 00000000 00:00 0 /fake/elf\n"
+ "a000-c000 r--p 00000000 00:00 0 /fake/elf2\n"
+ "c000-f000 rw-p 00001000 00:00 0 /fake/elf2\n"
+ "f000-11000 r--p 00000000 00:00 0 /fake/elf3\n"
+ "100000-110000 rw-p 0001000 00:00 0 /fake/elf3\n"
+ "200000-210000 rw-p 0002000 00:00 0 /fake/elf3\n"
+ "300000-400000 rw-p 0003000 00:00 0 /fake/elf3\n"));
ASSERT_TRUE(maps_->Parse());
// Global variable in a section that is not readable.
@@ -96,8 +96,9 @@ class DexFilesTest : public ::testing::Test {
void WriteDex(uint64_t dex_file);
static constexpr size_t kMapGlobalNonReadable = 2;
- static constexpr size_t kMapGlobalSetToZero = 4;
+ static constexpr size_t kMapGlobalSetToZero = 3;
static constexpr size_t kMapGlobal = 5;
+ static constexpr size_t kMapGlobalRw = 6;
static constexpr size_t kMapDexFileEntries = 7;
static constexpr size_t kMapDexFiles = 8;
@@ -256,6 +257,9 @@ TEST_F(DexFilesTest, get_method_information_search_libs) {
map_info->name = "/system/lib/libart.so";
dex_files_.reset(new DexFiles(process_memory_, libs));
dex_files_->SetArch(ARCH_ARM);
+ // Set the rw map to the same name or this will not scan this entry.
+ map_info = maps_->Get(kMapGlobalRw);
+ map_info->name = "/system/lib/libart.so";
// Make sure that clearing out copy of the libs doesn't affect the
// DexFiles object.
libs.clear();
@@ -271,7 +275,7 @@ TEST_F(DexFilesTest, get_method_information_global_skip_zero_32) {
MapInfo* info = maps_->Get(kMapDexFiles);
// First global variable found, but value is zero.
- WriteDescriptor32(0xc800, 0);
+ WriteDescriptor32(0xa800, 0);
WriteDescriptor32(0xf800, 0x200000);
WriteEntry32(0x200000, 0, 0, 0x300000);
@@ -286,7 +290,7 @@ TEST_F(DexFilesTest, get_method_information_global_skip_zero_32) {
dex_files_->SetArch(ARCH_ARM);
method_name = "fail";
method_offset = 0x123;
- WriteDescriptor32(0xc800, 0x100000);
+ WriteDescriptor32(0xa800, 0x100000);
dex_files_->GetMethodInformation(maps_.get(), info, 0x300100, &method_name, &method_offset);
EXPECT_EQ("fail", method_name);
EXPECT_EQ(0x123U, method_offset);
@@ -298,7 +302,7 @@ TEST_F(DexFilesTest, get_method_information_global_skip_zero_64) {
MapInfo* info = maps_->Get(kMapDexFiles);
// First global variable found, but value is zero.
- WriteDescriptor64(0xc800, 0);
+ WriteDescriptor64(0xa800, 0);
WriteDescriptor64(0xf800, 0x200000);
WriteEntry64(0x200000, 0, 0, 0x300000);
@@ -314,7 +318,7 @@ TEST_F(DexFilesTest, get_method_information_global_skip_zero_64) {
dex_files_->SetArch(ARCH_ARM64);
method_name = "fail";
method_offset = 0x123;
- WriteDescriptor64(0xc800, 0x100000);
+ WriteDescriptor64(0xa800, 0x100000);
dex_files_->GetMethodInformation(maps_.get(), info, 0x300100, &method_name, &method_offset);
EXPECT_EQ("fail", method_name);
EXPECT_EQ(0x123U, method_offset);