diff options
author | Christopher Ferris <cferris@google.com> | 2018-10-09 18:49:11 -0700 |
---|---|---|
committer | Christopher Ferris <cferris@google.com> | 2018-10-12 11:29:06 -0700 |
commit | be916a0ef691618989e7a37e00c6e5bc698b8ecc (patch) | |
tree | 391432ca5c5c787869b8d5e8be80776855f780ec | |
parent | eb069a28d6b1d6a6a74e7bebeecd91140128821a (diff) | |
download | unwinding-be916a0ef691618989e7a37e00c6e5bc698b8ecc.tar.gz |
Fix up the definition of Elf::GetInfo.
The function should have returned a bool, so now it does.
Also use a different lighter weight function for validating the elf
in one place that didn't need to keep the max size value.
Test: Unit tests pass.
Change-Id: Ibde674e608091ba04abf22fad2fdc4dbdb2c6e73
-rw-r--r-- | libunwindstack/Elf.cpp | 14 | ||||
-rw-r--r-- | libunwindstack/MapInfo.cpp | 10 | ||||
-rw-r--r-- | libunwindstack/include/unwindstack/Elf.h | 2 |
3 files changed, 10 insertions, 16 deletions
diff --git a/libunwindstack/Elf.cpp b/libunwindstack/Elf.cpp index 4723606..56a0679 100644 --- a/libunwindstack/Elf.cpp +++ b/libunwindstack/Elf.cpp @@ -194,26 +194,26 @@ bool Elf::IsValidElf(Memory* memory) { return true; } -void Elf::GetInfo(Memory* memory, bool* valid, uint64_t* size) { +bool Elf::GetInfo(Memory* memory, uint64_t* size) { if (!IsValidElf(memory)) { - *valid = false; - return; + return false; } *size = 0; - *valid = true; - // Now read the section header information. uint8_t class_type; if (!memory->ReadFully(EI_CLASS, &class_type, 1)) { - return; + return false; } + + // Get the maximum size of the elf data from the header. if (class_type == ELFCLASS32) { ElfInterface32::GetMaxSize(memory, size); } else if (class_type == ELFCLASS64) { ElfInterface64::GetMaxSize(memory, size); } else { - *valid = false; + return false; } + return true; } bool Elf::IsValidPc(uint64_t pc) { diff --git a/libunwindstack/MapInfo.cpp b/libunwindstack/MapInfo.cpp index 64005ae..52b7535 100644 --- a/libunwindstack/MapInfo.cpp +++ b/libunwindstack/MapInfo.cpp @@ -53,10 +53,8 @@ Memory* MapInfo::GetFileMemory() { return nullptr; } - bool valid; uint64_t max_size; - Elf::GetInfo(memory.get(), &valid, &max_size); - if (!valid) { + if (!Elf::GetInfo(memory.get(), &max_size)) { // Init as if the whole file is an elf. if (memory->Init(name, 0)) { elf_offset = offset; @@ -109,11 +107,7 @@ Memory* MapInfo::CreateMemory(const std::shared_ptr<Memory>& process_memory) { // first part of the elf file. This is done if the linker rosegment // option is used. std::unique_ptr<MemoryRange> memory(new MemoryRange(process_memory, start, end - start, 0)); - bool valid; - uint64_t max_size; - Elf::GetInfo(memory.get(), &valid, &max_size); - if (valid) { - // Valid elf, we are done. + if (Elf::IsValidElf(memory.get())) { return memory.release(); } diff --git a/libunwindstack/include/unwindstack/Elf.h b/libunwindstack/include/unwindstack/Elf.h index f4cdbda..9af859d 100644 --- a/libunwindstack/include/unwindstack/Elf.h +++ b/libunwindstack/include/unwindstack/Elf.h @@ -94,7 +94,7 @@ class Elf { static bool IsValidElf(Memory* memory); - static void GetInfo(Memory* memory, bool* valid, uint64_t* size); + static bool GetInfo(Memory* memory, uint64_t* size); static uint64_t GetLoadBias(Memory* memory); |