| Christopher Ferris | 723cf9b | 2017-01-19 20:08:48 -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_ARM_EXIDX_H | 
 | 18 | #define _LIBUNWINDSTACK_ARM_EXIDX_H | 
 | 19 |  | 
 | 20 | #include <stdint.h> | 
 | 21 |  | 
 | 22 | #include <deque> | 
 | 23 |  | 
 | 24 | #include "Memory.h" | 
 | 25 | #include "Regs.h" | 
 | 26 |  | 
 | 27 | enum ArmStatus : size_t { | 
 | 28 |   ARM_STATUS_NONE = 0, | 
 | 29 |   ARM_STATUS_NO_UNWIND, | 
 | 30 |   ARM_STATUS_FINISH, | 
 | 31 |   ARM_STATUS_RESERVED, | 
 | 32 |   ARM_STATUS_SPARE, | 
 | 33 |   ARM_STATUS_TRUNCATED, | 
 | 34 |   ARM_STATUS_READ_FAILED, | 
 | 35 |   ARM_STATUS_MALFORMED, | 
 | 36 |   ARM_STATUS_INVALID_ALIGNMENT, | 
 | 37 |   ARM_STATUS_INVALID_PERSONALITY, | 
 | 38 | }; | 
 | 39 |  | 
 | 40 | enum ArmOp : uint8_t { | 
 | 41 |   ARM_OP_FINISH = 0xb0, | 
 | 42 | }; | 
 | 43 |  | 
 | 44 | class ArmExidx { | 
 | 45 |  public: | 
 | 46 |   ArmExidx(Regs32* regs, Memory* elf_memory, Memory* process_memory) | 
 | 47 |       : regs_(regs), elf_memory_(elf_memory), process_memory_(process_memory) {} | 
 | 48 |   virtual ~ArmExidx() {} | 
 | 49 |  | 
 | 50 |   void LogRawData(); | 
 | 51 |  | 
 | 52 |   bool ExtractEntryData(uint32_t entry_offset); | 
 | 53 |  | 
 | 54 |   bool Eval(); | 
 | 55 |  | 
 | 56 |   bool Decode(); | 
 | 57 |  | 
 | 58 |   std::deque<uint8_t>* data() { return &data_; } | 
 | 59 |  | 
 | 60 |   ArmStatus status() { return status_; } | 
 | 61 |  | 
 | 62 |   Regs32* regs() { return regs_; } | 
 | 63 |  | 
 | 64 |   uint32_t cfa() { return cfa_; } | 
 | 65 |   void set_cfa(uint32_t cfa) { cfa_ = cfa; } | 
 | 66 |  | 
 | 67 |   void set_log(bool log) { log_ = log; } | 
 | 68 |   void set_log_skip_execution(bool skip_execution) { log_skip_execution_ = skip_execution; } | 
 | 69 |   void set_log_indent(uint8_t indent) { log_indent_ = indent; } | 
 | 70 |  | 
 | 71 |  private: | 
 | 72 |   bool GetByte(uint8_t* byte); | 
 | 73 |  | 
 | 74 |   bool DecodePrefix_10_00(uint8_t byte); | 
 | 75 |   bool DecodePrefix_10_01(uint8_t byte); | 
 | 76 |   bool DecodePrefix_10_10(uint8_t byte); | 
 | 77 |   bool DecodePrefix_10_11_0000(); | 
 | 78 |   bool DecodePrefix_10_11_0001(); | 
 | 79 |   bool DecodePrefix_10_11_0010(); | 
 | 80 |   bool DecodePrefix_10_11_0011(); | 
 | 81 |   bool DecodePrefix_10_11_01nn(); | 
 | 82 |   bool DecodePrefix_10_11_1nnn(uint8_t byte); | 
 | 83 |   bool DecodePrefix_10(uint8_t byte); | 
 | 84 |  | 
 | 85 |   bool DecodePrefix_11_000(uint8_t byte); | 
 | 86 |   bool DecodePrefix_11_001(uint8_t byte); | 
 | 87 |   bool DecodePrefix_11_010(uint8_t byte); | 
 | 88 |   bool DecodePrefix_11(uint8_t byte); | 
 | 89 |  | 
 | 90 |   Regs32* regs_ = nullptr; | 
 | 91 |   uint32_t cfa_ = 0; | 
 | 92 |   std::deque<uint8_t> data_; | 
 | 93 |   ArmStatus status_ = ARM_STATUS_NONE; | 
 | 94 |  | 
 | 95 |   Memory* elf_memory_; | 
 | 96 |   Memory* process_memory_; | 
 | 97 |  | 
 | 98 |   bool log_ = false; | 
 | 99 |   uint8_t log_indent_ = 0; | 
 | 100 |   bool log_skip_execution_ = false; | 
 | 101 | }; | 
 | 102 |  | 
 | 103 | #endif  // _LIBUNWINDSTACK_ARM_EXIDX_H |