diff options
author | Christopher Ferris <cferris@google.com> | 2018-11-15 14:06:26 -0800 |
---|---|---|
committer | Christopher Ferris <cferris@google.com> | 2018-11-15 14:06:26 -0800 |
commit | 55d83530f1cbda48e15857c92892b5b2377462d4 (patch) | |
tree | f620406095a3c4754a5657d0e3016acecabef110 | |
parent | 5ef2ecdda1cb8d1987490209a4fdd0d4d528b97a (diff) | |
download | unwinding-55d83530f1cbda48e15857c92892b5b2377462d4.tar.gz |
Remove overly restrictive check for memory.
Remove unit test that is not needed any more.
Slightly reorganize the code around the changed check.
Bug: 77958880
Test: Ran backtrace tests with new linker options.
Test: Ran libunwindstack unit tests.
Change-Id: Ie95707323fb51616a093cafb83e0343fa24e7e61
-rw-r--r-- | libunwindstack/MapInfo.cpp | 26 | ||||
-rw-r--r-- | libunwindstack/tests/MapInfoGetElfTest.cpp | 21 |
2 files changed, 11 insertions, 36 deletions
diff --git a/libunwindstack/MapInfo.cpp b/libunwindstack/MapInfo.cpp index fe32b5e..e3b48ca 100644 --- a/libunwindstack/MapInfo.cpp +++ b/libunwindstack/MapInfo.cpp @@ -96,11 +96,6 @@ Memory* MapInfo::CreateMemory(const std::shared_ptr<Memory>& process_memory) { } } - // If the map isn't readable, don't bother trying to read from process memory. - if (!(flags & PROT_READ)) { - return nullptr; - } - // Need to verify that this elf is valid. It's possible that // only part of the elf file to be mapped into memory is in the executable // map. In this case, there will be another read-only map that includes the @@ -132,18 +127,19 @@ Memory* MapInfo::CreateMemory(const std::shared_ptr<Memory>& process_memory) { } } - if (ro_map_info != nullptr) { - // Make sure that relative pc values are corrected properly. - elf_offset = offset - closest_offset; + if (ro_map_info == nullptr) { + return nullptr; + } - MemoryRanges* ranges = new MemoryRanges; - ranges->Insert(new MemoryRange(process_memory, ro_map_info->start, - ro_map_info->end - ro_map_info->start, 0)); - ranges->Insert(new MemoryRange(process_memory, start, end - start, elf_offset)); + // Make sure that relative pc values are corrected properly. + elf_offset = offset - closest_offset; - return ranges; - } - return nullptr; + MemoryRanges* ranges = new MemoryRanges; + ranges->Insert(new MemoryRange(process_memory, ro_map_info->start, + ro_map_info->end - ro_map_info->start, 0)); + ranges->Insert(new MemoryRange(process_memory, start, end - start, elf_offset)); + + return ranges; } Elf* MapInfo::GetElf(const std::shared_ptr<Memory>& process_memory, ArchEnum expected_arch) { diff --git a/libunwindstack/tests/MapInfoGetElfTest.cpp b/libunwindstack/tests/MapInfoGetElfTest.cpp index f3b4679..99f8fa3 100644 --- a/libunwindstack/tests/MapInfoGetElfTest.cpp +++ b/libunwindstack/tests/MapInfoGetElfTest.cpp @@ -290,27 +290,6 @@ TEST_F(MapInfoGetElfTest, file_backed_non_zero_offset_partial_file_whole_elf64) ASSERT_TRUE(elf->memory()->ReadFully(0x1000, buffer.data(), 1)); } -TEST_F(MapInfoGetElfTest, process_memory_not_read_only) { - MapInfo info(nullptr, 0x9000, 0xa000, 0x1000, 0, ""); - - // Create valid elf data in process memory only. - Elf64_Ehdr ehdr; - TestInitEhdr<Elf64_Ehdr>(&ehdr, ELFCLASS64, EM_AARCH64); - ehdr.e_shoff = 0x2000; - ehdr.e_shentsize = sizeof(Elf64_Shdr) + 100; - ehdr.e_shnum = 0; - memory_->SetMemory(0x9000, &ehdr, sizeof(ehdr)); - - Elf* elf = info.GetElf(process_memory_, ARCH_ARM64); - ASSERT_TRUE(elf != nullptr); - ASSERT_FALSE(elf->valid()); - - info.elf.reset(); - info.flags = PROT_READ; - elf = info.GetElf(process_memory_, ARCH_ARM64); - ASSERT_TRUE(elf->valid()); -} - TEST_F(MapInfoGetElfTest, check_device_maps) { MapInfo info(nullptr, 0x7000, 0x8000, 0x1000, PROT_READ | MAPS_FLAGS_DEVICE_MAP, "/dev/something"); |