From 98aaf4cf086e2492796b11116e69e0ff01093663 Mon Sep 17 00:00:00 2001 From: Christopher Ferris Date: Fri, 3 May 2019 11:13:17 -0700 Subject: [PATCH] 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 --- libunwindstack/Unwinder.cpp | 3 ++- libunwindstack/tests/UnwinderTest.cpp | 36 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/libunwindstack/Unwinder.cpp b/libunwindstack/Unwinder.cpp index 26626b5cd..37323dc16 100644 --- a/libunwindstack/Unwinder.cpp +++ b/libunwindstack/Unwinder.cpp @@ -25,6 +25,7 @@ #include #include +#include #include @@ -168,7 +169,7 @@ void Unwinder::Unwind(const std::vector* 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(); diff --git a/libunwindstack/tests/UnwinderTest.cpp b/libunwindstack/tests/UnwinderTest.cpp index f6350216f..30e57a142 100644 --- a/libunwindstack/tests/UnwinderTest.cpp +++ b/libunwindstack/tests/UnwinderTest.cpp @@ -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(), ®s_, 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);