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_DWARF_EH_FRAME_H 18 #define _LIBUNWINDSTACK_DWARF_EH_FRAME_H 19 20 #include <stdint.h> 21 22 #include <unwindstack/DwarfSection.h> 23 24 namespace unwindstack { 25 26 // Forward declarations. 27 class Memory; 28 29 template <typename AddressType> 30 class DwarfEhFrame : public DwarfSectionImpl<AddressType> { 31 public: 32 // Add these so that the protected members of DwarfSectionImpl 33 // can be accessed without needing a this->. 34 using DwarfSectionImpl<AddressType>::memory_; 35 using DwarfSectionImpl<AddressType>::fde_count_; 36 using DwarfSectionImpl<AddressType>::last_error_; 37 38 struct FdeInfo { 39 AddressType pc; 40 uint64_t offset; 41 }; 42 DwarfEhFrame(Memory * memory)43 DwarfEhFrame(Memory* memory) : DwarfSectionImpl<AddressType>(memory) {} 44 virtual ~DwarfEhFrame() = default; 45 46 bool Init(uint64_t offset, uint64_t size) override; 47 48 bool GetFdeOffsetFromPc(uint64_t pc, uint64_t* fde_offset) override; 49 50 const DwarfFde* GetFdeFromIndex(size_t index) override; 51 IsCie32(uint32_t value32)52 bool IsCie32(uint32_t value32) override { return value32 == 0; } 53 IsCie64(uint64_t value64)54 bool IsCie64(uint64_t value64) override { return value64 == 0; } 55 GetCieOffsetFromFde32(uint32_t pointer)56 uint64_t GetCieOffsetFromFde32(uint32_t pointer) override { 57 return memory_.cur_offset() - pointer - 4; 58 } 59 GetCieOffsetFromFde64(uint64_t pointer)60 uint64_t GetCieOffsetFromFde64(uint64_t pointer) override { 61 return memory_.cur_offset() - pointer - 8; 62 } 63 AdjustPcFromFde(uint64_t pc)64 uint64_t AdjustPcFromFde(uint64_t pc) override { 65 // The eh_frame uses relative pcs. 66 return pc + memory_.cur_offset(); 67 } 68 69 const FdeInfo* GetFdeInfoFromIndex(size_t index); 70 71 bool GetFdeOffsetSequential(uint64_t pc, uint64_t* fde_offset); 72 73 bool GetFdeOffsetBinary(uint64_t pc, uint64_t* fde_offset, uint64_t total_entries); 74 75 protected: 76 uint8_t version_; 77 uint8_t ptr_encoding_; 78 uint8_t table_encoding_; 79 size_t table_entry_size_; 80 81 uint64_t ptr_offset_; 82 83 uint64_t entries_offset_; 84 uint64_t entries_end_; 85 uint64_t entries_data_offset_; 86 uint64_t cur_entries_offset_ = 0; 87 88 std::unordered_map<uint64_t, FdeInfo> fde_info_; 89 }; 90 91 } // namespace unwindstack 92 93 #endif // _LIBUNWINDSTACK_DWARF_EH_FRAME_H 94