Loading libunwindstack/Maps.cpp +11 −9 Original line number Original line Diff line number Diff line Loading @@ -71,16 +71,18 @@ bool Maps::ParseLine(const char* line, MapInfo* map_info) { map_info->flags |= PROT_EXEC; map_info->flags |= PROT_EXEC; } } if (line[name_pos] != '\0') { map_info->name = &line[name_pos]; map_info->name = &line[name_pos]; size_t length = map_info->name.length() - 1; size_t length = map_info->name.length() - 1; if (map_info->name[length] == '\n') { if (map_info->name[length] == '\n') { map_info->name.erase(length); map_info->name.erase(length); } } // Mark a device map in /dev/and not in /dev/ashmem/ specially. // Mark a device map in /dev/and not in /dev/ashmem/ specially. if (!map_info->name.empty() && map_info->name.substr(0, 5) == "/dev/" && if (map_info->name.substr(0, 5) == "/dev/" && map_info->name.substr(5, 7) != "ashmem/") { map_info->name.substr(5, 7) != "ashmem/") { map_info->flags |= MAPS_FLAGS_DEVICE_MAP; map_info->flags |= MAPS_FLAGS_DEVICE_MAP; } } } return true; return true; } } Loading libunwindstack/tests/MapInfoTest.cpp +3 −3 Original line number Original line Diff line number Diff line Loading @@ -75,7 +75,7 @@ TEST_F(MapInfoTest, end_le_start) { // Make sure this test is valid. // Make sure this test is valid. info.end = 0x101; info.end = 0x101; memory.reset(info.CreateMemory(getpid())); memory.reset(info.CreateMemory(getpid())); ASSERT_FALSE(info.CreateMemory(getpid()) == nullptr); ASSERT_TRUE(memory.get() != nullptr); } } // Verify that if the offset is non-zero but there is no elf at the offset, // Verify that if the offset is non-zero but there is no elf at the offset, Loading Loading @@ -212,8 +212,8 @@ TEST_F(MapInfoTest, get_elf) { MapInfo info{.start = start, .end = start + 1024, .offset = 0, .name = ""}; MapInfo info{.start = start, .end = start + 1024, .offset = 0, .name = ""}; // The map contains garbage, but this should still produce an elf object. // The map contains garbage, but this should still produce an elf object. Elf* elf = info.GetElf(getpid(), false); std::unique_ptr<Elf> elf(info.GetElf(getpid(), false)); ASSERT_TRUE(elf != nullptr); ASSERT_TRUE(elf.get() != nullptr); ASSERT_FALSE(elf->valid()); ASSERT_FALSE(elf->valid()); ASSERT_EQ(0, munmap(map, 1024)); ASSERT_EQ(0, munmap(map, 1024)); Loading libunwindstack/tests/MemoryRangeTest.cpp +9 −16 Original line number Original line Diff line number Diff line Loading @@ -26,21 +26,13 @@ #include "MemoryFake.h" #include "MemoryFake.h" class MemoryRangeTest : public ::testing::Test { TEST(MemoryRangeTest, read) { protected: void SetUp() override { memory_ = new MemoryFake; } MemoryFake* memory_; }; TEST_F(MemoryRangeTest, read) { std::vector<uint8_t> src(1024); std::vector<uint8_t> src(1024); memset(src.data(), 0x4c, 1024); memset(src.data(), 0x4c, 1024); memory_->SetMemory(9001, src); MemoryFake* memory = new MemoryFake; memory->SetMemory(9001, src); MemoryRange range(memory_, 9001, 9001 + src.size()); MemoryRange range(memory, 9001, 9001 + src.size()); std::vector<uint8_t> dst(1024); std::vector<uint8_t> dst(1024); ASSERT_TRUE(range.Read(0, dst.data(), src.size())); ASSERT_TRUE(range.Read(0, dst.data(), src.size())); Loading @@ -49,12 +41,13 @@ TEST_F(MemoryRangeTest, read) { } } } } TEST_F(MemoryRangeTest, read_near_limit) { TEST(MemoryRangeTest, read_near_limit) { std::vector<uint8_t> src(4096); std::vector<uint8_t> src(4096); memset(src.data(), 0x4c, 4096); memset(src.data(), 0x4c, 4096); memory_->SetMemory(1000, src); MemoryFake* memory = new MemoryFake; memory->SetMemory(1000, src); MemoryRange range(memory_, 1000, 2024); MemoryRange range(memory, 1000, 2024); std::vector<uint8_t> dst(1024); std::vector<uint8_t> dst(1024); ASSERT_TRUE(range.Read(1020, dst.data(), 4)); ASSERT_TRUE(range.Read(1020, dst.data(), 4)); Loading @@ -71,7 +64,7 @@ TEST_F(MemoryRangeTest, read_near_limit) { ASSERT_TRUE(range.Read(1020, dst.data(), 4)); ASSERT_TRUE(range.Read(1020, dst.data(), 4)); } } TEST_F(MemoryRangeTest, read_overflow) { TEST(MemoryRangeTest, read_overflow) { std::vector<uint8_t> buffer(100); std::vector<uint8_t> buffer(100); std::unique_ptr<MemoryRange> overflow(new MemoryRange(new MemoryFakeAlwaysReadZero, 100, 200)); std::unique_ptr<MemoryRange> overflow(new MemoryRange(new MemoryFakeAlwaysReadZero, 100, 200)); Loading Loading
libunwindstack/Maps.cpp +11 −9 Original line number Original line Diff line number Diff line Loading @@ -71,16 +71,18 @@ bool Maps::ParseLine(const char* line, MapInfo* map_info) { map_info->flags |= PROT_EXEC; map_info->flags |= PROT_EXEC; } } if (line[name_pos] != '\0') { map_info->name = &line[name_pos]; map_info->name = &line[name_pos]; size_t length = map_info->name.length() - 1; size_t length = map_info->name.length() - 1; if (map_info->name[length] == '\n') { if (map_info->name[length] == '\n') { map_info->name.erase(length); map_info->name.erase(length); } } // Mark a device map in /dev/and not in /dev/ashmem/ specially. // Mark a device map in /dev/and not in /dev/ashmem/ specially. if (!map_info->name.empty() && map_info->name.substr(0, 5) == "/dev/" && if (map_info->name.substr(0, 5) == "/dev/" && map_info->name.substr(5, 7) != "ashmem/") { map_info->name.substr(5, 7) != "ashmem/") { map_info->flags |= MAPS_FLAGS_DEVICE_MAP; map_info->flags |= MAPS_FLAGS_DEVICE_MAP; } } } return true; return true; } } Loading
libunwindstack/tests/MapInfoTest.cpp +3 −3 Original line number Original line Diff line number Diff line Loading @@ -75,7 +75,7 @@ TEST_F(MapInfoTest, end_le_start) { // Make sure this test is valid. // Make sure this test is valid. info.end = 0x101; info.end = 0x101; memory.reset(info.CreateMemory(getpid())); memory.reset(info.CreateMemory(getpid())); ASSERT_FALSE(info.CreateMemory(getpid()) == nullptr); ASSERT_TRUE(memory.get() != nullptr); } } // Verify that if the offset is non-zero but there is no elf at the offset, // Verify that if the offset is non-zero but there is no elf at the offset, Loading Loading @@ -212,8 +212,8 @@ TEST_F(MapInfoTest, get_elf) { MapInfo info{.start = start, .end = start + 1024, .offset = 0, .name = ""}; MapInfo info{.start = start, .end = start + 1024, .offset = 0, .name = ""}; // The map contains garbage, but this should still produce an elf object. // The map contains garbage, but this should still produce an elf object. Elf* elf = info.GetElf(getpid(), false); std::unique_ptr<Elf> elf(info.GetElf(getpid(), false)); ASSERT_TRUE(elf != nullptr); ASSERT_TRUE(elf.get() != nullptr); ASSERT_FALSE(elf->valid()); ASSERT_FALSE(elf->valid()); ASSERT_EQ(0, munmap(map, 1024)); ASSERT_EQ(0, munmap(map, 1024)); Loading
libunwindstack/tests/MemoryRangeTest.cpp +9 −16 Original line number Original line Diff line number Diff line Loading @@ -26,21 +26,13 @@ #include "MemoryFake.h" #include "MemoryFake.h" class MemoryRangeTest : public ::testing::Test { TEST(MemoryRangeTest, read) { protected: void SetUp() override { memory_ = new MemoryFake; } MemoryFake* memory_; }; TEST_F(MemoryRangeTest, read) { std::vector<uint8_t> src(1024); std::vector<uint8_t> src(1024); memset(src.data(), 0x4c, 1024); memset(src.data(), 0x4c, 1024); memory_->SetMemory(9001, src); MemoryFake* memory = new MemoryFake; memory->SetMemory(9001, src); MemoryRange range(memory_, 9001, 9001 + src.size()); MemoryRange range(memory, 9001, 9001 + src.size()); std::vector<uint8_t> dst(1024); std::vector<uint8_t> dst(1024); ASSERT_TRUE(range.Read(0, dst.data(), src.size())); ASSERT_TRUE(range.Read(0, dst.data(), src.size())); Loading @@ -49,12 +41,13 @@ TEST_F(MemoryRangeTest, read) { } } } } TEST_F(MemoryRangeTest, read_near_limit) { TEST(MemoryRangeTest, read_near_limit) { std::vector<uint8_t> src(4096); std::vector<uint8_t> src(4096); memset(src.data(), 0x4c, 4096); memset(src.data(), 0x4c, 4096); memory_->SetMemory(1000, src); MemoryFake* memory = new MemoryFake; memory->SetMemory(1000, src); MemoryRange range(memory_, 1000, 2024); MemoryRange range(memory, 1000, 2024); std::vector<uint8_t> dst(1024); std::vector<uint8_t> dst(1024); ASSERT_TRUE(range.Read(1020, dst.data(), 4)); ASSERT_TRUE(range.Read(1020, dst.data(), 4)); Loading @@ -71,7 +64,7 @@ TEST_F(MemoryRangeTest, read_near_limit) { ASSERT_TRUE(range.Read(1020, dst.data(), 4)); ASSERT_TRUE(range.Read(1020, dst.data(), 4)); } } TEST_F(MemoryRangeTest, read_overflow) { TEST(MemoryRangeTest, read_overflow) { std::vector<uint8_t> buffer(100); std::vector<uint8_t> buffer(100); std::unique_ptr<MemoryRange> overflow(new MemoryRange(new MemoryFakeAlwaysReadZero, 100, 200)); std::unique_ptr<MemoryRange> overflow(new MemoryRange(new MemoryFakeAlwaysReadZero, 100, 200)); Loading