Chromium Code Reviews| 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/macro-assembler.h" |
| 9 | 9 |
| 10 namespace v8 { | 10 namespace v8 { |
| 11 namespace internal { | 11 namespace internal { |
| 12 | 12 |
| 13 class Code; | 13 class EhFrameWriter { |
| 14 public: | |
| 15 enum DwarfOpcodes : byte { | |
|
rmcilroy
2016/07/05 10:56:12
enum class please
Stefano Sanfilippo
2016/07/05 16:02:13
Done.
| |
| 16 kNop = 0x00, | |
| 17 kAdvanceLoc1 = 0x02, | |
| 18 kAdvanceLoc2 = 0x03, | |
| 19 kAdvanceLoc4 = 0x04, | |
| 20 kSameValue = 0x08, | |
| 21 kDefCfa = 0x0c, | |
| 22 kDefCfaRegister = 0x0d, | |
| 23 kDefCfaOffset = 0x0e, | |
| 24 kOffsetExtendedSf = 0x11, | |
| 25 }; | |
| 26 | |
| 27 enum DwarfEncodingSpecifiers : byte { | |
|
rmcilroy
2016/07/05 10:56:13
ditto
Stefano Sanfilippo
2016/07/05 16:02:14
These need to be | combinable though, static_cast<
rmcilroy
2016/07/06 13:59:30
OK, enum is fine in that case.
| |
| 28 kUData4 = 0x03, | |
| 29 kSData4 = 0x0b, | |
| 30 kPcRel = 0x10, | |
| 31 kDataRel = 0x30, | |
| 32 kOmit = 0xff, | |
| 33 }; | |
| 34 | |
| 35 static const uint32_t kInt32Placeholder = 0xdeadc0de; | |
| 36 | |
| 37 static const int kLocationTag = 1; | |
| 38 static const int kSavedRegisterTag = 2; | |
|
rmcilroy
2016/07/05 10:56:13
Move SavedRegisterTag below the location mask / ma
Stefano Sanfilippo
2016/07/05 16:02:13
Done.
| |
| 39 static const int kLocationMask = 0x3f; | |
| 40 static const int kLocationMaskSize = 6; | |
| 41 static const int kSavedRegisterMask = 0x3f; | |
| 42 static const int kSavedRegisterMaskSize = 6; | |
| 43 | |
| 44 static const int kProcedureAddressOffsetInFde = 2 * kInt32Size; | |
| 45 static const int kProcedureSizeOffsetInFde = 3 * kInt32Size; | |
| 46 static const int kTerminatorSize = 4; | |
|
rmcilroy
2016/07/05 10:56:12
kFdeTerminatorSize ? also put in it's own block (
Stefano Sanfilippo
2016/07/05 16:02:13
Done the moving. About the name, the terminator te
rmcilroy
2016/07/06 13:59:30
SGTM
| |
| 47 | |
| 48 static const int kInitialStateOffsetInCIE = 19; | |
| 49 | |
| 50 static const int kDataAlignmentFactor; | |
|
rmcilroy
2016/07/05 10:56:13
This should all be private, none ofthese fields or
Stefano Sanfilippo
2016/07/05 16:02:14
The encoding specifiers are used in the EhFrameHdr
rmcilroy
2016/07/06 13:59:30
These shouldn't be part of EhFrameWriter in that c
Stefano Sanfilippo
2016/07/06 16:54:49
As discussed, I have uploaded a patchset with the
| |
| 51 | |
| 52 EhFrameWriter(); | |
| 53 | |
| 54 void AdvanceLocation(int pc_offset); | |
| 55 | |
| 56 // The <base_address> is the one to which all <offset>s in SaveRegisterToStack | |
| 57 // directives are relative. It is given by <base_register> + <base_offset>. | |
| 58 void SetBaseAddressRegister(Register base_register); | |
| 59 void SetBaseAddressOffset(int base_offset); | |
| 60 void IncreaseBaseAddressOffset(int base_delta) { | |
| 61 SetBaseAddressOffset(base_offset_ + base_delta); | |
| 62 } | |
| 63 void SetBaseAddressRegisterAndOffset(Register base_register, int base_offset); | |
| 64 | |
| 65 // Offset relative to <base address>, positive offsets go in the direction | |
| 66 // of stack growth (downwards on all architectures we support). | |
| 67 void RegisterSavedToStack(Register name, int offset) { | |
| 68 RegisterSavedToStack(RegisterToDwarfCode(name), offset); | |
| 69 } | |
| 70 | |
| 71 void RegisterSavedToStack(Register name) { | |
| 72 RegisterSavedToStack(name, base_offset_); | |
| 73 } | |
| 74 | |
| 75 void RegisterIsValid(Register name); | |
| 76 | |
| 77 void Finish(int code_size); | |
| 78 | |
| 79 // Remember to call Finish() before GetEhFrame(). | |
| 80 // | |
| 81 // The EhFrameWriter instance owns the buffer pointed by | |
| 82 // CodeDesc::unwinding_info, and must outlive any use of the CodeDesc. | |
| 83 void GetEhFrame(CodeDesc* desc); | |
| 84 | |
| 85 int last_pc_offset() const { return last_pc_offset_; } | |
| 86 Register base_register() const { return base_register_; } | |
| 87 int base_offset() const { return base_offset_; } | |
| 88 | |
| 89 #ifdef ENABLE_DISASSEMBLER | |
| 90 static void DisassembleToStream(std::ostream& stream, // NOLINT | |
| 91 const byte* start, const byte* end); | |
| 92 #endif | |
| 93 | |
| 94 protected: | |
|
rmcilroy
2016/07/05 10:56:13
This should all be private - you've already made E
Stefano Sanfilippo
2016/07/05 16:02:14
Done.
| |
| 95 static uint32_t DecodeULEB128(const byte* encoded, int* encoded_size); | |
| 96 | |
|
rmcilroy
2016/07/05 10:56:13
nit - remove newline (and group common blocks (e.g
Stefano Sanfilippo
2016/07/05 16:02:13
Done.
| |
| 97 static int32_t DecodeSLEB128(const byte* encoded, int* encoded_size); | |
| 98 | |
| 99 void WriteByte(byte value) { eh_frame_buffer_.push_back(value); } | |
| 100 | |
| 101 void WriteBytes(const byte* start, int size) { | |
| 102 eh_frame_buffer_.insert(eh_frame_buffer_.end(), start, start + size); | |
| 103 } | |
| 104 | |
| 105 void WriteInt16(uint16_t value) { | |
| 106 WriteBytes(reinterpret_cast<const byte*>(&value), sizeof(value)); | |
| 107 } | |
| 108 | |
| 109 void WriteInt32(uint32_t value) { | |
| 110 WriteBytes(reinterpret_cast<const byte*>(&value), sizeof(value)); | |
| 111 } | |
| 112 | |
| 113 void WriteSLEB128(int32_t value); | |
| 114 | |
| 115 void WriteULEB128(uint32_t value); | |
| 116 | |
| 117 void PatchInt32(int base_offset, uint32_t value) { | |
| 118 DCHECK_EQ(ReadUnalignedUInt32(eh_frame_buffer_.data() + base_offset), | |
| 119 kInt32Placeholder); | |
| 120 DCHECK_LT(base_offset + kInt32Size, eh_frame_offset()); | |
| 121 WriteUnalignedUInt32(eh_frame_buffer_.data() + base_offset, value); | |
| 122 } | |
| 123 | |
| 124 void WriteFDEHeader(); | |
|
rmcilroy
2016/07/05 10:56:13
Short comments for these more complex functions
Stefano Sanfilippo
2016/07/05 16:02:13
Done.
rmcilroy
2016/07/06 13:59:30
Still no comments?
Stefano Sanfilippo
2016/07/06 16:54:49
Sorry, they came in a later patchset.
| |
| 125 | |
| 126 void WriteCIE(); | |
| 127 | |
| 128 void WriteInitialState(); | |
|
rmcilroy
2016/07/05 10:56:13
WriteInitialStateInCIE ?
Stefano Sanfilippo
2016/07/05 16:02:14
Done.
| |
| 129 | |
| 130 void WriteReturnAddressRegisterCode(); | |
|
rmcilroy
2016/07/05 10:56:13
This should just be "Register GetReturnAddressRegi
Stefano Sanfilippo
2016/07/05 16:02:14
The problem is that x64 rip is a pseudoregister wi
| |
| 131 | |
| 132 void Align(); | |
|
rmcilroy
2016/07/05 10:56:13
WritePaddingTo8ByteAlign
Stefano Sanfilippo
2016/07/05 16:02:13
Done.
| |
| 133 | |
| 134 // Internal version that directly accepts a DWARF register code, needed for | |
| 135 // handling pseudoregisters on some platforms, such as x64. | |
| 136 void RegisterSavedToStack(int register_code, int offset); | |
| 137 | |
| 138 int eh_frame_offset() const { | |
| 139 return static_cast<int>(eh_frame_buffer_.size()); | |
| 140 } | |
| 141 | |
| 142 int fde_offset() const { return cie_size_; } | |
| 143 | |
| 144 int procedure_address_offset() const { | |
| 145 return fde_offset() + kProcedureAddressOffsetInFde; | |
| 146 } | |
| 147 | |
| 148 int procedure_size_offset() const { | |
| 149 return fde_offset() + kProcedureSizeOffsetInFde; | |
| 150 } | |
| 151 | |
| 152 private: | |
| 153 #ifdef ENABLE_DISASSEMBLER | |
| 154 static void DumpDWARFDirectives(std::ostream& stream, // NOLINT | |
| 155 const byte* begin, const byte* end); | |
| 156 #endif | |
| 157 | |
| 158 static const char* DwarfRegisterCodeToString(int code); | |
| 159 static int RegisterToDwarfCode(Register name); | |
| 160 | |
| 161 int last_pc_offset_; | |
| 162 bool eh_frame_finalised_; | |
| 163 Register base_register_; | |
| 164 int base_offset_; | |
| 165 std::vector<byte> eh_frame_buffer_; | |
| 166 int cie_size_; | |
|
rmcilroy
2016/07/05 10:56:13
nit - move cie_size_ to be first field
Stefano Sanfilippo
2016/07/05 16:02:14
Done.
| |
| 167 | |
| 168 friend class EhFrameWriterInternals; // For unit tests. | |
|
rmcilroy
2016/07/05 10:56:13
Rename this class to EhFrameWriteTest and remove c
Stefano Sanfilippo
2016/07/05 16:02:14
Removed the friend altogether, since the internals
| |
| 169 }; | |
| 14 | 170 |
| 15 class EhFrameHdr final { | 171 class EhFrameHdr final { |
| 16 public: | 172 public: |
| 17 static const int kRecordSize = 20; | 173 static const int kRecordSize = 20; |
| 18 static const int kCIESize; | |
| 19 | 174 |
| 20 explicit EhFrameHdr(Code* code); | 175 EhFrameHdr(int code_size, int eh_frame_size, int cie_size); |
| 176 static EhFrameHdr CreateEmptyHeader(); | |
| 21 | 177 |
| 22 int32_t offset_to_eh_frame() const { return offset_to_eh_frame_; } | 178 int32_t offset_to_eh_frame() const { return offset_to_eh_frame_; } |
| 23 uint32_t lut_entries_number() const { return lut_entries_number_; } | 179 uint32_t lut_entries_number() const { return lut_entries_number_; } |
| 24 int32_t offset_to_procedure() const { return offset_to_procedure_; } | 180 int32_t offset_to_procedure() const { return offset_to_procedure_; } |
| 25 int32_t offset_to_fde() const { return offset_to_fde_; } | 181 int32_t offset_to_fde() const { return offset_to_fde_; } |
| 26 | 182 |
| 27 private: | 183 private: |
| 184 static const int kEhFrameHdrVersion = 1; | |
| 185 | |
| 186 EhFrameHdr() {} | |
| 187 | |
| 28 uint8_t version_; | 188 uint8_t version_; |
| 29 uint8_t eh_frame_ptr_encoding_; | 189 uint8_t eh_frame_ptr_encoding_; |
| 30 uint8_t lut_size_encoding_; | 190 uint8_t lut_size_encoding_; |
| 31 uint8_t lut_entries_encoding_; | 191 uint8_t lut_entries_encoding_; |
| 32 int32_t offset_to_eh_frame_; | 192 int32_t offset_to_eh_frame_; |
| 33 uint32_t lut_entries_number_; | 193 uint32_t lut_entries_number_; |
| 34 int32_t offset_to_procedure_; | 194 int32_t offset_to_procedure_; |
| 35 int32_t offset_to_fde_; | 195 int32_t offset_to_fde_; |
| 36 }; | 196 }; |
| 37 | 197 |
| 38 } // namespace internal | 198 } // namespace internal |
| 39 } // namespace v8 | 199 } // namespace v8 |
| 40 | 200 |
| 41 #endif | 201 #endif |
| OLD | NEW |