diff --git a/libunwindstack/Elf.cpp b/libunwindstack/Elf.cpp index 472360698..56a067960 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 64005ae12..52b7535cd 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& process_memory) { // first part of the elf file. This is done if the linker rosegment // option is used. std::unique_ptr 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 f4cdbdaf4..9af859de5 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);