| Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 1 | /* | 
 | 2 |  * Copyright (C) 2016 The Android Open Source Project | 
 | 3 |  * | 
 | 4 |  * Licensed under the Apache License, Version 2.0 (the "License"); | 
 | 5 |  * you may not use this file except in compliance with the License. | 
 | 6 |  * You may obtain a copy of the License at | 
 | 7 |  * | 
 | 8 |  *      http://www.apache.org/licenses/LICENSE-2.0 | 
 | 9 |  * | 
 | 10 |  * Unless required by applicable law or agreed to in writing, software | 
 | 11 |  * distributed under the License is distributed on an "AS IS" BASIS, | 
 | 12 |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
 | 13 |  * See the License for the specific language governing permissions and | 
 | 14 |  * limitations under the License. | 
 | 15 |  */ | 
 | 16 |  | 
 | 17 | #ifndef _LIBUNWINDSTACK_ELF_INTERFACE_ARM_H | 
 | 18 | #define _LIBUNWINDSTACK_ELF_INTERFACE_ARM_H | 
 | 19 |  | 
 | 20 | #include <elf.h> | 
 | 21 | #include <stdint.h> | 
 | 22 |  | 
 | 23 | #include <iterator> | 
 | 24 | #include <unordered_map> | 
 | 25 |  | 
| Christopher Ferris | d226a51 | 2017-07-14 10:37:19 -0700 | [diff] [blame] | 26 | #include <unwindstack/ElfInterface.h> | 
 | 27 | #include <unwindstack/Memory.h> | 
 | 28 |  | 
 | 29 | namespace unwindstack { | 
| Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 30 |  | 
 | 31 | class ElfInterfaceArm : public ElfInterface32 { | 
 | 32 |  public: | 
 | 33 |   ElfInterfaceArm(Memory* memory) : ElfInterface32(memory) {} | 
 | 34 |   virtual ~ElfInterfaceArm() = default; | 
 | 35 |  | 
 | 36 |   class iterator : public std::iterator<std::bidirectional_iterator_tag, uint32_t> { | 
 | 37 |    public: | 
 | 38 |     iterator(ElfInterfaceArm* interface, size_t index) : interface_(interface), index_(index) { } | 
 | 39 |  | 
 | 40 |     iterator& operator++() { index_++; return *this; } | 
 | 41 |     iterator& operator++(int increment) { index_ += increment; return *this; } | 
 | 42 |     iterator& operator--() { index_--; return *this; } | 
 | 43 |     iterator& operator--(int decrement) { index_ -= decrement; return *this; } | 
 | 44 |  | 
 | 45 |     bool operator==(const iterator& rhs) { return this->index_ == rhs.index_; } | 
 | 46 |     bool operator!=(const iterator& rhs) { return this->index_ != rhs.index_; } | 
 | 47 |  | 
 | 48 |     uint32_t operator*() { | 
 | 49 |       uint32_t addr = interface_->addrs_[index_]; | 
 | 50 |       if (addr == 0) { | 
 | 51 |         if (!interface_->GetPrel31Addr(interface_->start_offset_ + index_ * 8, &addr)) { | 
 | 52 |           return 0; | 
 | 53 |         } | 
 | 54 |         interface_->addrs_[index_] = addr; | 
 | 55 |       } | 
 | 56 |       return addr; | 
 | 57 |     } | 
 | 58 |  | 
 | 59 |    private: | 
 | 60 |     ElfInterfaceArm* interface_ = nullptr; | 
 | 61 |     size_t index_ = 0; | 
 | 62 |   }; | 
 | 63 |  | 
 | 64 |   iterator begin() { return iterator(this, 0); } | 
 | 65 |   iterator end() { return iterator(this, total_entries_); } | 
 | 66 |  | 
| Christopher Ferris | 819f131 | 2019-10-03 13:35:48 -0700 | [diff] [blame] | 67 |   bool Init(int64_t* section_bias) override; | 
| Christopher Ferris | 4cc36d2 | 2018-06-06 14:47:31 -0700 | [diff] [blame] | 68 |  | 
| Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 69 |   bool GetPrel31Addr(uint32_t offset, uint32_t* addr); | 
 | 70 |  | 
 | 71 |   bool FindEntry(uint32_t pc, uint64_t* entry_offset); | 
 | 72 |  | 
| Christopher Ferris | 5afddb0 | 2018-06-29 16:30:55 -0700 | [diff] [blame] | 73 |   void HandleUnknownType(uint32_t type, uint64_t ph_offset, uint64_t ph_filesz) override; | 
| Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 74 |  | 
| Christopher Ferris | 4cc36d2 | 2018-06-06 14:47:31 -0700 | [diff] [blame] | 75 |   bool Step(uint64_t pc, Regs* regs, Memory* process_memory, bool* finished) override; | 
| Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 76 |  | 
| Christopher Ferris | 4cc36d2 | 2018-06-06 14:47:31 -0700 | [diff] [blame] | 77 |   bool StepExidx(uint64_t pc, Regs* regs, Memory* process_memory, bool* finished); | 
| Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 78 |  | 
| Christopher Ferris | 4cc36d2 | 2018-06-06 14:47:31 -0700 | [diff] [blame] | 79 |   bool GetFunctionName(uint64_t addr, std::string* name, uint64_t* offset) override; | 
| Christopher Ferris | 704ec9a | 2018-03-15 14:35:01 -0700 | [diff] [blame] | 80 |  | 
| Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 81 |   uint64_t start_offset() { return start_offset_; } | 
 | 82 |  | 
| Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 83 |   size_t total_entries() { return total_entries_; } | 
 | 84 |  | 
| Christopher Ferris | 4cc36d2 | 2018-06-06 14:47:31 -0700 | [diff] [blame] | 85 |   void set_load_bias(uint64_t load_bias) { load_bias_ = load_bias; } | 
 | 86 |  | 
| Christopher Ferris | e69f470 | 2017-10-19 16:08:58 -0700 | [diff] [blame] | 87 |  protected: | 
| Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 88 |   uint64_t start_offset_ = 0; | 
 | 89 |   size_t total_entries_ = 0; | 
| Christopher Ferris | 4cc36d2 | 2018-06-06 14:47:31 -0700 | [diff] [blame] | 90 |   uint64_t load_bias_ = 0; | 
| Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 91 |  | 
 | 92 |   std::unordered_map<size_t, uint32_t> addrs_; | 
 | 93 | }; | 
 | 94 |  | 
| Christopher Ferris | d226a51 | 2017-07-14 10:37:19 -0700 | [diff] [blame] | 95 | }  // namespace unwindstack | 
 | 96 |  | 
| Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 97 | #endif  // _LIBUNWINDSTACK_ELF_INTERFACE_ARM_H |