Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ef35aa5d authored by Josh Gao's avatar Josh Gao
Browse files

unwindstack: rename Memory::Read to ReadFully.

Rename Memory::Read to ReadFully to match its semantics with that of
android::base. ReadPartially will be renamed to Read in a follow up
commit, kept intentionally separate so that there aren't any callers
accidentally switched from ReadFully to Read.

Test: treehugger
Change-Id: I7d845ac5244c3025d92c8512e960e5d0d1da05af
parent 29c5378e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@
namespace unwindstack {

bool DwarfMemory::ReadBytes(void* dst, size_t num_bytes) {
  if (!memory_->Read(cur_offset_, dst, num_bytes)) {
  if (!memory_->ReadFully(cur_offset_, dst, num_bytes)) {
    return false;
  }
  cur_offset_ += num_bytes;
+2 −2
Original line number Diff line number Diff line
@@ -141,7 +141,7 @@ bool DwarfOp<AddressType>::op_deref() {
  // Read the address and dereference it.
  AddressType addr = StackPop();
  AddressType value;
  if (!regular_memory()->Read(addr, &value, sizeof(value))) {
  if (!regular_memory()->ReadFully(addr, &value, sizeof(value))) {
    last_error_ = DWARF_ERROR_MEMORY_INVALID;
    return false;
  }
@@ -159,7 +159,7 @@ bool DwarfOp<AddressType>::op_deref_size() {
  // Read the address and dereference it.
  AddressType addr = StackPop();
  AddressType value = 0;
  if (!regular_memory()->Read(addr, &value, bytes_to_read)) {
  if (!regular_memory()->ReadFully(addr, &value, bytes_to_read)) {
    last_error_ = DWARF_ERROR_MEMORY_INVALID;
    return false;
  }
+4 −3
Original line number Diff line number Diff line
@@ -142,7 +142,7 @@ bool DwarfSectionImpl<AddressType>::Eval(const DwarfCie* cie, Memory* regular_me
        return false;
      }
      if (loc->type == DWARF_LOCATION_EXPRESSION) {
        if (!regular_memory->Read(value, &cfa, sizeof(AddressType))) {
        if (!regular_memory->ReadFully(value, &cfa, sizeof(AddressType))) {
          last_error_ = DWARF_ERROR_MEMORY_INVALID;
          return false;
        }
@@ -175,7 +175,8 @@ bool DwarfSectionImpl<AddressType>::Eval(const DwarfCie* cie, Memory* regular_me
    const DwarfLocation* loc = &entry.second;
    switch (loc->type) {
      case DWARF_LOCATION_OFFSET:
        if (!regular_memory->Read(cfa + loc->values[0], &(*cur_regs)[reg], sizeof(AddressType))) {
        if (!regular_memory->ReadFully(cfa + loc->values[0], &(*cur_regs)[reg],
                                       sizeof(AddressType))) {
          last_error_ = DWARF_ERROR_MEMORY_INVALID;
          return false;
        }
@@ -210,7 +211,7 @@ bool DwarfSectionImpl<AddressType>::Eval(const DwarfCie* cie, Memory* regular_me
          return false;
        }
        if (loc->type == DWARF_LOCATION_EXPRESSION) {
          if (!regular_memory->Read(value, &(*cur_regs)[reg], sizeof(AddressType))) {
          if (!regular_memory->ReadFully(value, &(*cur_regs)[reg], sizeof(AddressType))) {
            last_error_ = DWARF_ERROR_MEMORY_INVALID;
            return false;
          }
+5 −5
Original line number Diff line number Diff line
@@ -131,7 +131,7 @@ bool Elf::IsValidElf(Memory* memory) {

  // Verify that this is a valid elf file.
  uint8_t e_ident[SELFMAG + 1];
  if (!memory->Read(0, e_ident, SELFMAG)) {
  if (!memory->ReadFully(0, e_ident, SELFMAG)) {
    return false;
  }

@@ -151,7 +151,7 @@ void Elf::GetInfo(Memory* memory, bool* valid, uint64_t* size) {

  // Now read the section header information.
  uint8_t class_type;
  if (!memory->Read(EI_CLASS, &class_type, 1)) {
  if (!memory->ReadFully(EI_CLASS, &class_type, 1)) {
    return;
  }
  if (class_type == ELFCLASS32) {
@@ -169,12 +169,12 @@ ElfInterface* Elf::CreateInterfaceFromMemory(Memory* memory) {
  }

  std::unique_ptr<ElfInterface> interface;
  if (!memory->Read(EI_CLASS, &class_type_, 1)) {
  if (!memory->ReadFully(EI_CLASS, &class_type_, 1)) {
    return nullptr;
  }
  if (class_type_ == ELFCLASS32) {
    Elf32_Half e_machine;
    if (!memory->Read(EI_NIDENT + sizeof(Elf32_Half), &e_machine, sizeof(e_machine))) {
    if (!memory->ReadFully(EI_NIDENT + sizeof(Elf32_Half), &e_machine, sizeof(e_machine))) {
      return nullptr;
    }

@@ -195,7 +195,7 @@ ElfInterface* Elf::CreateInterfaceFromMemory(Memory* memory) {
    }
  } else if (class_type_ == ELFCLASS64) {
    Elf64_Half e_machine;
    if (!memory->Read(EI_NIDENT + sizeof(Elf64_Half), &e_machine, sizeof(e_machine))) {
    if (!memory->ReadFully(EI_NIDENT + sizeof(Elf64_Half), &e_machine, sizeof(e_machine))) {
      return nullptr;
    }
    if (e_machine != EM_AARCH64 && e_machine != EM_X86_64) {
+5 −5
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ Memory* ElfInterface::CreateGnuDebugdataMemory() {
  Crc64GenerateTable();

  std::vector<uint8_t> src(gnu_debugdata_size_);
  if (!memory_->Read(gnu_debugdata_offset_, src.data(), gnu_debugdata_size_)) {
  if (!memory_->ReadFully(gnu_debugdata_offset_, src.data(), gnu_debugdata_size_)) {
    gnu_debugdata_offset_ = 0;
    gnu_debugdata_size_ = static_cast<uint64_t>(-1);
    return nullptr;
@@ -131,7 +131,7 @@ void ElfInterface::InitHeadersWithTemplate() {
template <typename EhdrType, typename PhdrType, typename ShdrType>
bool ElfInterface::ReadAllHeaders(uint64_t* load_bias) {
  EhdrType ehdr;
  if (!memory_->Read(0, &ehdr, sizeof(ehdr))) {
  if (!memory_->ReadFully(0, &ehdr, sizeof(ehdr))) {
    return false;
  }

@@ -242,7 +242,7 @@ bool ElfInterface::ReadSectionHeaders(const EhdrType& ehdr) {
    }

    if (shdr.sh_type == SHT_SYMTAB || shdr.sh_type == SHT_DYNSYM) {
      if (!memory_->Read(offset, &shdr, sizeof(shdr))) {
      if (!memory_->ReadFully(offset, &shdr, sizeof(shdr))) {
        return false;
      }
      // Need to go get the information about the section that contains
@@ -324,7 +324,7 @@ bool ElfInterface::GetSonameWithTemplate(std::string* soname) {
  uint64_t offset = dynamic_offset_;
  uint64_t max_offset = offset + dynamic_size_;
  for (uint64_t offset = dynamic_offset_; offset < max_offset; offset += sizeof(DynType)) {
    if (!memory_->Read(offset, &dyn, sizeof(dyn))) {
    if (!memory_->ReadFully(offset, &dyn, sizeof(dyn))) {
      return false;
    }

@@ -388,7 +388,7 @@ bool ElfInterface::Step(uint64_t pc, Regs* regs, Memory* process_memory, bool* f
template <typename EhdrType>
void ElfInterface::GetMaxSizeWithTemplate(Memory* memory, uint64_t* size) {
  EhdrType ehdr;
  if (!memory->Read(0, &ehdr, sizeof(ehdr))) {
  if (!memory->ReadFully(0, &ehdr, sizeof(ehdr))) {
    return;
  }
  if (ehdr.e_shnum == 0) {
Loading