OLD | NEW |
---|---|
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_EH_FRAME_H_ | 5 #ifndef V8_EH_FRAME_H_ |
6 #define V8_EH_FRAME_H_ | 6 #define V8_EH_FRAME_H_ |
7 | 7 |
8 #include <cstdint> | 8 #include "src/list.h" |
9 #include "src/macro-assembler.h" | |
9 | 10 |
10 namespace v8 { | 11 namespace v8 { |
11 namespace internal { | 12 namespace internal { |
12 | 13 |
13 class Code; | 14 struct CodeDesc; |
15 | |
16 class EhFrameWriter { | |
17 public: | |
18 static const int kCIESize; | |
19 | |
20 EhFrameWriter(); | |
21 | |
22 void AdvanceLocation(int pc_offset); | |
23 | |
24 // <base address> = <base register> + <base offset> | |
rmcilroy
2016/06/30 15:23:11
What is the base address? Please explain how it re
Stefano Sanfilippo
2016/07/04 18:21:15
Done.
| |
25 void DefineBaseAddressRegister(Register base_register); | |
26 void DefineBaseAddressOffset(int base_offset); | |
27 void IncreaseBaseAddressOffset(int base_delta) { | |
28 DefineBaseAddressOffset(base_offset_ + base_delta); | |
29 } | |
30 void DefineBaseAddressRegisterOffset(Register base_register, int base_offset); | |
rmcilroy
2016/06/30 15:23:11
DefineBaseAddressRegisterAndOffset
Stefano Sanfilippo
2016/07/04 18:21:14
Done.
| |
31 | |
32 // Offset relative to <base address> | |
33 void SaveRegisterToStack(Register name, int offset); | |
34 void SaveRegisterToStack(Register name) { | |
35 SaveRegisterToStack(name, base_offset_); | |
36 } | |
37 void RegisterIsValid(Register name); | |
38 | |
39 void Finish(int code_size); | |
40 | |
41 // Remember to call Finish() before GetEhFrame()! | |
rmcilroy
2016/06/30 15:23:11
Make it clear that the EhWriter must outlive the C
Stefano Sanfilippo
2016/07/04 18:21:14
Done.
| |
42 void GetEhFrame(CodeDesc* desc); | |
43 | |
44 int last_pc_offset() const { return last_pc_offset_; } | |
45 Register base_register() const { return base_register_; } | |
46 int base_offset() const { return base_offset_; } | |
47 | |
48 #ifdef ENABLE_DISASSEMBLER | |
49 static void DisassembleToStream(std::ostream& stream, // NOLINT | |
50 const byte* start, const byte* end); | |
51 #endif | |
52 | |
53 protected: | |
54 void WriteByte(byte value) { eh_frame_buffer_.Add(value); } | |
55 | |
56 void WriteBytes(const byte* value, int size) { | |
57 eh_frame_buffer_.AddAll(Vector<byte>(const_cast<byte*>(value), size)); | |
58 } | |
59 | |
60 void WriteInt16(uint16_t value) { | |
61 eh_frame_buffer_.AddAll( | |
62 Vector<byte>(reinterpret_cast<byte*>(&value), sizeof(value))); | |
63 } | |
64 | |
65 void WriteInt32(uint32_t value) { | |
66 eh_frame_buffer_.AddAll( | |
67 Vector<byte>(reinterpret_cast<byte*>(&value), sizeof(value))); | |
68 } | |
69 | |
70 void WriteULEB128(uint32_t value); | |
71 | |
72 void PatchInt32(int base_offset, uint32_t value) { | |
73 DCHECK_EQ(ReadUnalignedUInt32(eh_frame_buffer_.begin() + base_offset), | |
74 kInt32Placeholder); | |
75 MemCopy(eh_frame_buffer_.begin() + base_offset, &value, sizeof(value)); | |
76 } | |
77 | |
78 void WriteFDEHeader(); | |
79 | |
80 int eh_frame_offset() const { return eh_frame_buffer_.length(); } | |
81 | |
82 private: | |
83 static const byte kNop = 0x00; | |
84 static const byte kAdvanceLoc1 = 0x02; | |
85 static const byte kAdvanceLoc2 = 0x03; | |
86 static const byte kAdvanceLoc4 = 0x04; | |
87 static const byte kSameValue = 0x08; | |
88 static const byte kDefCFA = 0x0c; | |
89 static const byte kDefCFARegister = 0x0d; | |
90 static const byte kDefCFAOffset = 0x0e; | |
rmcilroy
2016/06/30 15:23:11
This could be enums (enum class DwarfOpcode: byte)
Stefano Sanfilippo
2016/07/04 18:21:15
Done.
| |
91 static const uint32_t kInt32Placeholder = 0xdeadc0de; | |
rmcilroy
2016/06/30 15:23:11
newlines between groups
Stefano Sanfilippo
2016/07/04 18:21:14
Done.
| |
92 static const int kEhFrameTerminatorSize = 4; | |
93 static const int kLocationTag = 1; | |
94 static const int kSavedRegisterTag = 2; | |
rmcilroy
2016/06/30 15:23:11
this should be 1 << 1 to make it clear its a bit f
Stefano Sanfilippo
2016/07/04 18:21:15
It's not a bit field, the 2 MSBs are used as opcod
| |
95 static const int kLocationMask = 0x3f; | |
96 static const int kLocationMaskSize = 6; | |
97 static const int kSavedRegisterMask = 0x3f; | |
98 static const int kSavedRegisterMaskSize = 6; | |
rmcilroy
2016/06/30 15:23:11
group tags with masks
Stefano Sanfilippo
2016/07/04 18:21:14
Done.
| |
99 static const int kFDEOffset; | |
100 static const int kProcedureAddressOffset; | |
101 static const int kProcedureSizeOffset; | |
102 #ifdef ENABLE_DISASSEMBLER | |
103 static const int kFDEDirectivesOffset; | |
104 | |
105 static void DumpDWARFDirectives(std::ostream& stream, // NOLINT | |
106 const byte* begin, const byte* end); | |
107 #endif | |
108 | |
109 int last_pc_offset_; | |
110 #if DEBUG | |
111 bool eh_frame_finalised_; | |
rmcilroy
2016/06/30 15:23:11
no need to make this debug only, setting a bool is
Stefano Sanfilippo
2016/07/04 18:21:14
Fine, done.
| |
112 #endif | |
113 Register base_register_; | |
114 int base_offset_; | |
115 List<byte> eh_frame_buffer_; | |
rmcilroy
2016/06/30 15:23:11
Why list and not vector?
Stefano Sanfilippo
2016/07/04 18:21:14
I assumed V8 APIs took priority, replaced with std
| |
116 }; | |
14 | 117 |
15 class EhFrameHdr final { | 118 class EhFrameHdr final { |
16 public: | 119 public: |
17 static const int kRecordSize = 20; | 120 static const int kRecordSize = 20; |
18 static const int kCIESize; | |
19 | 121 |
20 explicit EhFrameHdr(Code* code); | 122 static EhFrameHdr MakeDummy(); |
rmcilroy
2016/06/30 15:23:11
below constructor. Also, how about Empty instead o
Stefano Sanfilippo
2016/07/04 18:21:14
Moved.
*Empty* is fine for me, renamed.
| |
123 EhFrameHdr(int code_size, int eh_frame_size); | |
21 | 124 |
22 int32_t offset_to_eh_frame() const { return offset_to_eh_frame_; } | 125 int32_t offset_to_eh_frame() const { return offset_to_eh_frame_; } |
23 uint32_t lut_entries_number() const { return lut_entries_number_; } | 126 uint32_t lut_entries_number() const { return lut_entries_number_; } |
24 int32_t offset_to_procedure() const { return offset_to_procedure_; } | 127 int32_t offset_to_procedure() const { return offset_to_procedure_; } |
25 int32_t offset_to_fde() const { return offset_to_fde_; } | 128 int32_t offset_to_fde() const { return offset_to_fde_; } |
26 | 129 |
27 private: | 130 private: |
131 static const byte kPcRel = 0x10; | |
132 static const byte kDataRel = 0x30; | |
133 static const byte kUData4 = 0x03; | |
134 static const byte kSData4 = 0x0b; | |
135 static const int kEhFrameHdrVersion = 1; | |
136 static const int kFDEVersionSize = 1; | |
137 static const int kFDEEncodingSpecifiersSize = 3; | |
138 | |
139 EhFrameHdr() {} | |
140 | |
28 uint8_t version_; | 141 uint8_t version_; |
29 uint8_t eh_frame_ptr_encoding_; | 142 uint8_t eh_frame_ptr_encoding_; |
30 uint8_t lut_size_encoding_; | 143 uint8_t lut_size_encoding_; |
31 uint8_t lut_entries_encoding_; | 144 uint8_t lut_entries_encoding_; |
32 int32_t offset_to_eh_frame_; | 145 int32_t offset_to_eh_frame_; |
33 uint32_t lut_entries_number_; | 146 uint32_t lut_entries_number_; |
34 int32_t offset_to_procedure_; | 147 int32_t offset_to_procedure_; |
35 int32_t offset_to_fde_; | 148 int32_t offset_to_fde_; |
36 }; | 149 }; |
37 | 150 |
38 } // namespace internal | 151 } // namespace internal |
39 } // namespace v8 | 152 } // namespace v8 |
40 | 153 |
41 #endif | 154 #endif |
OLD | NEW |