Merge "Fix up the definition of Elf::GetInfo."

This commit is contained in:
Christopher Ferris 2018-10-13 17:47:18 +00:00 committed by Gerrit Code Review
commit 6853a187e3
3 changed files with 10 additions and 16 deletions

View File

@ -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) {

View File

@ -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();
}

View File

@ -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);