| 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 |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "courgette/courgette.h" | 15 #include "courgette/courgette.h" |
| 16 #include "courgette/image_utils.h" | 16 #include "courgette/image_utils.h" |
| 17 #include "courgette/instruction_utils.h" |
| 17 #include "courgette/memory_allocator.h" | 18 #include "courgette/memory_allocator.h" |
| 18 #include "courgette/types_elf.h" | 19 #include "courgette/types_elf.h" |
| 19 | 20 |
| 20 namespace courgette { | 21 namespace courgette { |
| 21 | 22 |
| 22 // Stream indexes. | 23 // Stream indexes. |
| 23 const int kStreamMisc = 0; | 24 const int kStreamMisc = 0; |
| 24 const int kStreamOps = 1; | 25 const int kStreamOps = 1; |
| 25 const int kStreamBytes = 2; | 26 const int kStreamBytes = 2; |
| 26 const int kStreamAbs32Indexes = 3; | 27 const int kStreamAbs32Indexes = 3; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 CheckBool WriteTo(SinkStreamSet* streams) WARN_UNUSED_RESULT; | 74 CheckBool WriteTo(SinkStreamSet* streams) WARN_UNUSED_RESULT; |
| 74 | 75 |
| 75 // Using an EncodedProgram to generate a byte stream: | 76 // Using an EncodedProgram to generate a byte stream: |
| 76 // | 77 // |
| 77 // (4) Deserializes a fresh EncodedProgram from a set of streams. | 78 // (4) Deserializes a fresh EncodedProgram from a set of streams. |
| 78 bool ReadFrom(SourceStreamSet* streams); | 79 bool ReadFrom(SourceStreamSet* streams); |
| 79 | 80 |
| 80 // (5) Assembles the 'binary assembly language' into final file. | 81 // (5) Assembles the 'binary assembly language' into final file. |
| 81 CheckBool AssembleTo(SinkStream* buffer) WARN_UNUSED_RESULT; | 82 CheckBool AssembleTo(SinkStream* buffer) WARN_UNUSED_RESULT; |
| 82 | 83 |
| 84 // Calls |gen| to extract all instructions, which are then encoded and stored. |
| 85 CheckBool GenerateInstructions(ExecutableType exe_type, |
| 86 const InstructionGenerator& gen); |
| 87 |
| 83 private: | 88 private: |
| 84 // Binary assembly language operations. | 89 // Binary assembly language operations. |
| 85 // These are part of the patch format. Reusing an existing value will | 90 // These are part of the patch format. Reusing an existing value will |
| 86 // break backwards compatibility. | 91 // break backwards compatibility. |
| 87 enum OP { | 92 enum OP { |
| 88 ORIGIN = 0, // ORIGIN <rva> - set address for subsequent assembly. | 93 ORIGIN = 0, // ORIGIN <rva> - set address for subsequent assembly. |
| 89 COPY = 1, // COPY <count> <bytes> - copy bytes to output. | 94 COPY = 1, // COPY <count> <bytes> - copy bytes to output. |
| 90 COPY1 = 2, // COPY1 <byte> - same as COPY 1 <byte>. | 95 COPY1 = 2, // COPY1 <byte> - same as COPY 1 <byte>. |
| 91 REL32 = 3, // REL32 <index> - emit rel32 encoded reference to address at | 96 REL32 = 3, // REL32 <index> - emit rel32 encoded reference to address at |
| 92 // address table offset <index> | 97 // address table offset <index> |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 }; | 158 }; |
| 154 | 159 |
| 155 // Deserializes program from a stream set to |*output|. Returns C_OK if | 160 // Deserializes program from a stream set to |*output|. Returns C_OK if |
| 156 // successful, otherwise assigns |*output| to null and returns an error status. | 161 // successful, otherwise assigns |*output| to null and returns an error status. |
| 157 Status ReadEncodedProgram(SourceStreamSet* source, | 162 Status ReadEncodedProgram(SourceStreamSet* source, |
| 158 std::unique_ptr<EncodedProgram>* output); | 163 std::unique_ptr<EncodedProgram>* output); |
| 159 | 164 |
| 160 } // namespace courgette | 165 } // namespace courgette |
| 161 | 166 |
| 162 #endif // COURGETTE_ENCODED_PROGRAM_H_ | 167 #endif // COURGETTE_ENCODED_PROGRAM_H_ |
| OLD | NEW |