Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 55659067 authored by Christopher Ferris's avatar Christopher Ferris
Browse files

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
parent 5729cff6
Loading
Loading
Loading
Loading
+11 −15
Original line number Diff line number Diff line
@@ -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,7 +127,10 @@ Memory* MapInfo::CreateMemory(const std::shared_ptr<Memory>& process_memory) {
    }
  }

  if (ro_map_info != nullptr) {
  if (ro_map_info == nullptr) {
    return nullptr;
  }

  // Make sure that relative pc values are corrected properly.
  elf_offset = offset - closest_offset;

@@ -143,8 +141,6 @@ Memory* MapInfo::CreateMemory(const std::shared_ptr<Memory>& process_memory) {

  return ranges;
}
  return nullptr;
}

Elf* MapInfo::GetElf(const std::shared_ptr<Memory>& process_memory, ArchEnum expected_arch) {
  // Make sure no other thread is trying to add the elf to this map.
+0 −21
Original line number Diff line number Diff line
@@ -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");