summaryrefslogtreecommitdiff
path: root/libunwindstack/tests/MapInfoCreateMemoryTest.cpp
diff options
context:
space:
mode:
authorChristopher Ferris <cferris@google.com>2020-01-22 12:17:06 -0800
committerChristopher Ferris <cferris@google.com>2020-01-22 18:30:12 -0800
commit0f40a0530976bc7fe2213944d69851821eb402c7 (patch)
tree515b7c5168a6b3e58e5c73ebea9f0a7db38922e5 /libunwindstack/tests/MapInfoCreateMemoryTest.cpp
parent929c9e8b40fe6adb23a140a8584d69edb2cab636 (diff)
Properly handle empty map after read-only map.
Recently, the maps for an elf in memory might show up looking like: f0000-f1000 0 r-- /system/lib/libc.so f1000-f2000 0 --- f2000-f3000 1000 r-x /system/lib/libc.so f3000-f4000 2000 rw- /system/lib/libc.so The problem is that there is logic in the code that assumed that the map before the execute map must be the read-only map. In the case above, this is not true. Add a new prev_real_map that will point to the previous map that is not one of these empty maps. This will fix the backtraces that look like this: #00 pc 0000000000050d58 /apex/com.android.runtime/lib64/bionic/libc.so!libc.so (offset 0x50000) (syscall+24) (BuildId: 5252408bf30e395d49ee270b54c77ca4) To get rid of the !libc.so and the offset value, which is not correct. Added new unit tests to verify this. Added new offline test which an empty map between read-only and execute map. Before this change, the backtraces had lines like libc.so!libc.so (offset XXX) would be present. Bug: 148075852 Test: Ran unit tests. Change-Id: Ie04bfc96b8f91ed885cb1e655cf1e346efe48a45
Diffstat (limited to 'libunwindstack/tests/MapInfoCreateMemoryTest.cpp')
-rw-r--r--libunwindstack/tests/MapInfoCreateMemoryTest.cpp17
1 files changed, 9 insertions, 8 deletions
diff --git a/libunwindstack/tests/MapInfoCreateMemoryTest.cpp b/libunwindstack/tests/MapInfoCreateMemoryTest.cpp
index 6c1cfa222..6d8d58e55 100644
--- a/libunwindstack/tests/MapInfoCreateMemoryTest.cpp
+++ b/libunwindstack/tests/MapInfoCreateMemoryTest.cpp
@@ -89,7 +89,7 @@ class MapInfoCreateMemoryTest : public ::testing::Test {
};
TEST_F(MapInfoCreateMemoryTest, end_le_start) {
- MapInfo info(nullptr, 0x100, 0x100, 0, 0, elf_.path);
+ MapInfo info(nullptr, nullptr, 0x100, 0x100, 0, 0, elf_.path);
std::unique_ptr<Memory> memory(info.CreateMemory(process_memory_));
ASSERT_TRUE(memory.get() == nullptr);
@@ -108,7 +108,7 @@ TEST_F(MapInfoCreateMemoryTest, end_le_start) {
// Verify that if the offset is non-zero but there is no elf at the offset,
// that the full file is used.
TEST_F(MapInfoCreateMemoryTest, file_backed_non_zero_offset_full_file) {
- MapInfo info(nullptr, 0x100, 0x200, 0x100, 0, elf_.path);
+ MapInfo info(nullptr, nullptr, 0x100, 0x200, 0x100, 0, elf_.path);
std::unique_ptr<Memory> memory(info.CreateMemory(process_memory_));
ASSERT_TRUE(memory.get() != nullptr);
@@ -129,8 +129,9 @@ TEST_F(MapInfoCreateMemoryTest, file_backed_non_zero_offset_full_file) {
// Now verify the elf start offset is set correctly based on the previous
// info.
- MapInfo prev_info(nullptr, 0, 0x100, 0x10, 0, "");
+ MapInfo prev_info(nullptr, nullptr, 0, 0x100, 0x10, 0, "");
info.prev_map = &prev_info;
+ info.prev_real_map = &prev_info;
// No preconditions met, change each one until it should set the elf start
// offset to zero.
@@ -177,7 +178,7 @@ TEST_F(MapInfoCreateMemoryTest, file_backed_non_zero_offset_full_file) {
// Verify that if the offset is non-zero and there is an elf at that
// offset, that only part of the file is used.
TEST_F(MapInfoCreateMemoryTest, file_backed_non_zero_offset_partial_file) {
- MapInfo info(nullptr, 0x100, 0x200, 0x1000, 0, elf_at_1000_.path);
+ MapInfo info(nullptr, nullptr, 0x100, 0x200, 0x1000, 0, elf_at_1000_.path);
std::unique_ptr<Memory> memory(info.CreateMemory(process_memory_));
ASSERT_TRUE(memory.get() != nullptr);
@@ -202,7 +203,7 @@ TEST_F(MapInfoCreateMemoryTest, file_backed_non_zero_offset_partial_file) {
// embedded elf is bigger than the initial map, the new object is larger
// than the original map size. Do this for a 32 bit elf and a 64 bit elf.
TEST_F(MapInfoCreateMemoryTest, file_backed_non_zero_offset_partial_file_whole_elf32) {
- MapInfo info(nullptr, 0x5000, 0x6000, 0x1000, 0, elf32_at_map_.path);
+ MapInfo info(nullptr, nullptr, 0x5000, 0x6000, 0x1000, 0, elf32_at_map_.path);
std::unique_ptr<Memory> memory(info.CreateMemory(process_memory_));
ASSERT_TRUE(memory.get() != nullptr);
@@ -220,7 +221,7 @@ TEST_F(MapInfoCreateMemoryTest, file_backed_non_zero_offset_partial_file_whole_e
}
TEST_F(MapInfoCreateMemoryTest, file_backed_non_zero_offset_partial_file_whole_elf64) {
- MapInfo info(nullptr, 0x7000, 0x8000, 0x2000, 0, elf64_at_map_.path);
+ MapInfo info(nullptr, nullptr, 0x7000, 0x8000, 0x2000, 0, elf64_at_map_.path);
std::unique_ptr<Memory> memory(info.CreateMemory(process_memory_));
ASSERT_TRUE(memory.get() != nullptr);
@@ -243,14 +244,14 @@ TEST_F(MapInfoCreateMemoryTest, check_device_maps) {
// be returned if the file mapping fails, but the device check is incorrect.
std::vector<uint8_t> buffer(1024);
uint64_t start = reinterpret_cast<uint64_t>(buffer.data());
- MapInfo info(nullptr, start, start + buffer.size(), 0, 0x8000, "/dev/something");
+ MapInfo info(nullptr, nullptr, start, start + buffer.size(), 0, 0x8000, "/dev/something");
std::unique_ptr<Memory> memory(info.CreateMemory(process_memory_));
ASSERT_TRUE(memory.get() == nullptr);
}
TEST_F(MapInfoCreateMemoryTest, process_memory) {
- MapInfo info(nullptr, 0x2000, 0x3000, 0, PROT_READ, "");
+ MapInfo info(nullptr, nullptr, 0x2000, 0x3000, 0, PROT_READ, "");
Elf32_Ehdr ehdr = {};
TestInitEhdr<Elf32_Ehdr>(&ehdr, ELFCLASS32, EM_ARM);