OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium 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 COURGETTE_ENCODED_PROGRAM_H_ | 5 #ifndef COURGETTE_ENCODED_PROGRAM_H_ |
6 #define COURGETTE_ENCODED_PROGRAM_H_ | 6 #define COURGETTE_ENCODED_PROGRAM_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 class EncodedProgram { | 43 class EncodedProgram { |
44 public: | 44 public: |
45 EncodedProgram(); | 45 EncodedProgram(); |
46 ~EncodedProgram(); | 46 ~EncodedProgram(); |
47 | 47 |
48 // Generating an EncodedProgram: | 48 // Generating an EncodedProgram: |
49 // | 49 // |
50 // (1) The image base can be specified at any time. | 50 // (1) The image base can be specified at any time. |
51 void set_image_base(uint64_t base) { image_base_ = base; } | 51 void set_image_base(uint64_t base) { image_base_ = base; } |
52 | 52 |
53 // (2) Address tables and indexes defined first. | 53 // (2) Address tables and indexes imported first. |
54 CheckBool DefineLabels(const RVAToLabel& abs32_labels, | |
55 const RVAToLabel& rel32_labels) WARN_UNUSED_RESULT; | |
56 | 54 |
| 55 CheckBool ImportLabels(const LabelManager& abs32_label_manager, |
| 56 const LabelManager& rel32_label_manager) |
| 57 WARN_UNUSED_RESULT; |
57 | 58 |
58 // (3) Add instructions in the order needed to generate bytes of file. | 59 // (3) Add instructions in the order needed to generate bytes of file. |
59 // NOTE: If any of these methods ever fail, the EncodedProgram instance | 60 // NOTE: If any of these methods ever fail, the EncodedProgram instance |
60 // has failed and should be discarded. | 61 // has failed and should be discarded. |
61 CheckBool AddOrigin(RVA rva) WARN_UNUSED_RESULT; | 62 CheckBool AddOrigin(RVA rva) WARN_UNUSED_RESULT; |
62 CheckBool AddCopy(size_t count, const void* bytes) WARN_UNUSED_RESULT; | 63 CheckBool AddCopy(size_t count, const void* bytes) WARN_UNUSED_RESULT; |
63 CheckBool AddRel32(int label_index) WARN_UNUSED_RESULT; | 64 CheckBool AddRel32(int label_index) WARN_UNUSED_RESULT; |
64 CheckBool AddRel32ARM(uint16_t op, int label_index) WARN_UNUSED_RESULT; | 65 CheckBool AddRel32ARM(uint16_t op, int label_index) WARN_UNUSED_RESULT; |
65 CheckBool AddAbs32(int label_index) WARN_UNUSED_RESULT; | 66 CheckBool AddAbs32(int label_index) WARN_UNUSED_RESULT; |
66 CheckBool AddAbs64(int label_index) WARN_UNUSED_RESULT; | 67 CheckBool AddAbs64(int label_index) WARN_UNUSED_RESULT; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 LAST_ARM = 0x5FFF, | 108 LAST_ARM = 0x5FFF, |
108 }; | 109 }; |
109 | 110 |
110 typedef NoThrowBuffer<RVA> RvaVector; | 111 typedef NoThrowBuffer<RVA> RvaVector; |
111 typedef NoThrowBuffer<size_t> SizeTVector; | 112 typedef NoThrowBuffer<size_t> SizeTVector; |
112 typedef NoThrowBuffer<uint32_t> UInt32Vector; | 113 typedef NoThrowBuffer<uint32_t> UInt32Vector; |
113 typedef NoThrowBuffer<uint8_t> UInt8Vector; | 114 typedef NoThrowBuffer<uint8_t> UInt8Vector; |
114 typedef NoThrowBuffer<OP> OPVector; | 115 typedef NoThrowBuffer<OP> OPVector; |
115 | 116 |
116 void DebuggingSummary(); | 117 void DebuggingSummary(); |
| 118 |
| 119 // Helper for ImportLabels(). |
| 120 static CheckBool WriteRvasToList(const LabelManager& label_manager, |
| 121 RvaVector* rvas); |
| 122 |
| 123 // Helper for ImportLabels(). |
| 124 static void FillUnassignedRvaSlots(RvaVector* rvas); |
| 125 |
117 CheckBool GeneratePeRelocations(SinkStream* buffer, | 126 CheckBool GeneratePeRelocations(SinkStream* buffer, |
118 uint8_t type) WARN_UNUSED_RESULT; | 127 uint8_t type) WARN_UNUSED_RESULT; |
119 CheckBool GenerateElfRelocations(Elf32_Word pending_elf_relocation_table, | 128 CheckBool GenerateElfRelocations(Elf32_Word pending_elf_relocation_table, |
120 SinkStream *buffer) WARN_UNUSED_RESULT; | 129 SinkStream *buffer) WARN_UNUSED_RESULT; |
121 | 130 |
122 // Decodes and evaluates courgette ops for ARM rel32 addresses. | 131 // Decodes and evaluates courgette ops for ARM rel32 addresses. |
123 CheckBool EvaluateRel32ARM(OP op, size_t& ix_rel32_ix, RVA& current_rva, | 132 CheckBool EvaluateRel32ARM(OP op, size_t& ix_rel32_ix, RVA& current_rva, |
124 SinkStream* output); | 133 SinkStream* output); |
125 | 134 |
126 // Binary assembly language tables. | 135 // Binary assembly language tables. |
(...skipping 15 matching lines...) Expand all Loading... |
142 }; | 151 }; |
143 | 152 |
144 // Deserializes program from a stream set to |*output|. Returns C_OK if | 153 // Deserializes program from a stream set to |*output|. Returns C_OK if |
145 // successful, otherwise assigns |*output| to null and returns an error status. | 154 // successful, otherwise assigns |*output| to null and returns an error status. |
146 Status ReadEncodedProgram(SourceStreamSet* source, | 155 Status ReadEncodedProgram(SourceStreamSet* source, |
147 std::unique_ptr<EncodedProgram>* output); | 156 std::unique_ptr<EncodedProgram>* output); |
148 | 157 |
149 } // namespace courgette | 158 } // namespace courgette |
150 | 159 |
151 #endif // COURGETTE_ENCODED_PROGRAM_H_ | 160 #endif // COURGETTE_ENCODED_PROGRAM_H_ |
OLD | NEW |