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