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

Commit 98aaf4cf authored by Christopher Ferris's avatar Christopher Ferris
Browse files

Ignore memory from elf on /memfd:

In ART, some of the maps are /memfd:/jit-cache and it triggers the warning
about unreadable elf files. Do not set the elf from memory not file
flag in this case.

Bug: 131909548

Test: New unit tests pass.
Test: No warnings dumping stacks with this change done.
Change-Id: Ifba5e65da609525ded75430da173c614f6e4801e
parent 84235b71
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@
#include <algorithm>

#include <android-base/stringprintf.h>
#include <android-base/strings.h>

#include <demangle.h>

@@ -168,7 +169,7 @@ void Unwinder::Unwind(const std::vector<std::string>* initial_map_names_to_skip,
      // If this elf is memory backed, and there is a valid file, then set
      // an indicator that we couldn't open the file.
      if (!elf_from_memory_not_file_ && map_info->memory_backed_elf && !map_info->name.empty() &&
          map_info->name[0] != '[') {
          map_info->name[0] != '[' && !android::base::StartsWith(map_info->name, "/memfd:")) {
        elf_from_memory_not_file_ = true;
      }
      step_pc = regs_->pc();
+36 −0
Original line number Diff line number Diff line
@@ -126,6 +126,12 @@ class UnwinderTest : public ::testing::Test {
    const auto& info5 = *--maps_->end();
    info5->memory_backed_elf = true;

    elf = new ElfFake(new MemoryFake);
    elf->FakeSetInterface(new ElfInterfaceFake(nullptr));
    AddMapInfo(0xc3000, 0xc4000, 0, PROT_READ | PROT_WRITE | PROT_EXEC, "/memfd:/jit-cache", elf);
    const auto& info6 = *--maps_->end();
    info6->memory_backed_elf = true;

    process_memory_.reset(new MemoryFake);
  }

@@ -1234,6 +1240,36 @@ TEST_F(UnwinderTest, elf_from_memory_but_empty_filename) {
  EXPECT_EQ(PROT_READ | PROT_WRITE | PROT_EXEC, frame->map_flags);
}

TEST_F(UnwinderTest, elf_from_memory_but_from_memfd) {
  ElfInterfaceFake::FakePushFunctionData(FunctionData("Frame0", 0));

  regs_.set_pc(0xc3050);
  regs_.set_sp(0x10000);
  ElfInterfaceFake::FakePushStepData(StepData(0, 0, true));

  Unwinder unwinder(64, maps_.get(), &regs_, process_memory_);
  unwinder.Unwind();
  EXPECT_EQ(ERROR_NONE, unwinder.LastErrorCode());
  EXPECT_FALSE(unwinder.elf_from_memory_not_file());

  ASSERT_EQ(1U, unwinder.NumFrames());

  auto* frame = &unwinder.frames()[0];
  EXPECT_EQ(0U, frame->num);
  EXPECT_EQ(0x50U, frame->rel_pc);
  EXPECT_EQ(0xc3050U, frame->pc);
  EXPECT_EQ(0x10000U, frame->sp);
  EXPECT_EQ("Frame0", frame->function_name);
  EXPECT_EQ(0U, frame->function_offset);
  EXPECT_EQ("/memfd:/jit-cache", frame->map_name);
  EXPECT_EQ(0U, frame->map_elf_start_offset);
  EXPECT_EQ(0U, frame->map_exact_offset);
  EXPECT_EQ(0xc3000U, frame->map_start);
  EXPECT_EQ(0xc4000U, frame->map_end);
  EXPECT_EQ(0U, frame->map_load_bias);
  EXPECT_EQ(PROT_READ | PROT_WRITE | PROT_EXEC, frame->map_flags);
}

// Verify format frame code.
TEST_F(UnwinderTest, format_frame) {
  RegsFake regs_arm(10);