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 // This is the transformation and adjustment for all executables. | 5 // This is the transformation and adjustment for all executables. |
6 // The executable type is determined by ParseDetectedExecutable function. | 6 // The executable type is determined by ParseDetectedExecutable function. |
7 | 7 |
8 #ifndef COURGETTE_WIN32_X86_GENERATOR_H_ | 8 #ifndef COURGETTE_WIN32_X86_GENERATOR_H_ |
9 #define COURGETTE_WIN32_X86_GENERATOR_H_ | 9 #define COURGETTE_WIN32_X86_GENERATOR_H_ |
10 | 10 |
| 11 #include <memory> |
| 12 |
11 #include "base/logging.h" | 13 #include "base/logging.h" |
12 #include "base/macros.h" | 14 #include "base/macros.h" |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "courgette/assembly_program.h" | 15 #include "courgette/assembly_program.h" |
15 #include "courgette/ensemble.h" | 16 #include "courgette/ensemble.h" |
16 #include "courgette/program_detector.h" | 17 #include "courgette/program_detector.h" |
17 | 18 |
18 namespace courgette { | 19 namespace courgette { |
19 | 20 |
20 class PatchGeneratorX86_32 : public TransformationPatchGenerator { | 21 class PatchGeneratorX86_32 : public TransformationPatchGenerator { |
21 public: | 22 public: |
22 PatchGeneratorX86_32(Element* old_element, | 23 PatchGeneratorX86_32(Element* old_element, |
23 Element* new_element, | 24 Element* new_element, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 // serializing them. | 56 // serializing them. |
56 Status Transform(SourceStreamSet* corrected_parameters, | 57 Status Transform(SourceStreamSet* corrected_parameters, |
57 SinkStreamSet* old_transformed_element, | 58 SinkStreamSet* old_transformed_element, |
58 SinkStreamSet* new_transformed_element) { | 59 SinkStreamSet* new_transformed_element) { |
59 // Don't expect any corrected parameters. | 60 // Don't expect any corrected parameters. |
60 if (!corrected_parameters->Empty()) | 61 if (!corrected_parameters->Empty()) |
61 return C_GENERAL_ERROR; | 62 return C_GENERAL_ERROR; |
62 | 63 |
63 // Generate old version of program using |corrected_parameters|. | 64 // Generate old version of program using |corrected_parameters|. |
64 // TODO(sra): refactor to use same code from patcher_. | 65 // TODO(sra): refactor to use same code from patcher_. |
65 scoped_ptr<AssemblyProgram> old_program; | 66 std::unique_ptr<AssemblyProgram> old_program; |
66 Status old_parse_status = | 67 Status old_parse_status = |
67 ParseDetectedExecutable(old_element_->region().start(), | 68 ParseDetectedExecutable(old_element_->region().start(), |
68 old_element_->region().length(), | 69 old_element_->region().length(), |
69 &old_program); | 70 &old_program); |
70 if (old_parse_status != C_OK) { | 71 if (old_parse_status != C_OK) { |
71 LOG(ERROR) << "Cannot parse an executable " << old_element_->Name(); | 72 LOG(ERROR) << "Cannot parse an executable " << old_element_->Name(); |
72 return old_parse_status; | 73 return old_parse_status; |
73 } | 74 } |
74 | 75 |
75 // TODO(huangs): Move the block below to right before |new_program| gets | 76 // TODO(huangs): Move the block below to right before |new_program| gets |
76 // used, so we can reduce Courgette-gen peak memory. | 77 // used, so we can reduce Courgette-gen peak memory. |
77 scoped_ptr<AssemblyProgram> new_program; | 78 std::unique_ptr<AssemblyProgram> new_program; |
78 Status new_parse_status = | 79 Status new_parse_status = |
79 ParseDetectedExecutable(new_element_->region().start(), | 80 ParseDetectedExecutable(new_element_->region().start(), |
80 new_element_->region().length(), | 81 new_element_->region().length(), |
81 &new_program); | 82 &new_program); |
82 if (new_parse_status != C_OK) { | 83 if (new_parse_status != C_OK) { |
83 LOG(ERROR) << "Cannot parse an executable " << new_element_->Name(); | 84 LOG(ERROR) << "Cannot parse an executable " << new_element_->Name(); |
84 return new_parse_status; | 85 return new_parse_status; |
85 } | 86 } |
86 | 87 |
87 scoped_ptr<EncodedProgram> old_encoded; | 88 std::unique_ptr<EncodedProgram> old_encoded; |
88 Status old_encode_status = Encode(*old_program, &old_encoded); | 89 Status old_encode_status = Encode(*old_program, &old_encoded); |
89 if (old_encode_status != C_OK) | 90 if (old_encode_status != C_OK) |
90 return old_encode_status; | 91 return old_encode_status; |
91 | 92 |
92 Status old_write_status = | 93 Status old_write_status = |
93 WriteEncodedProgram(old_encoded.get(), old_transformed_element); | 94 WriteEncodedProgram(old_encoded.get(), old_transformed_element); |
94 | 95 |
95 old_encoded.reset(); | 96 old_encoded.reset(); |
96 | 97 |
97 if (old_write_status != C_OK) | 98 if (old_write_status != C_OK) |
98 return old_write_status; | 99 return old_write_status; |
99 | 100 |
100 Status adjust_status = Adjust(*old_program, new_program.get()); | 101 Status adjust_status = Adjust(*old_program, new_program.get()); |
101 old_program.reset(); | 102 old_program.reset(); |
102 if (adjust_status != C_OK) | 103 if (adjust_status != C_OK) |
103 return adjust_status; | 104 return adjust_status; |
104 | 105 |
105 scoped_ptr<EncodedProgram> new_encoded; | 106 std::unique_ptr<EncodedProgram> new_encoded; |
106 Status new_encode_status = Encode(*new_program, &new_encoded); | 107 Status new_encode_status = Encode(*new_program, &new_encoded); |
107 if (new_encode_status != C_OK) | 108 if (new_encode_status != C_OK) |
108 return new_encode_status; | 109 return new_encode_status; |
109 | 110 |
110 new_program.reset(); | 111 new_program.reset(); |
111 | 112 |
112 Status new_write_status = | 113 Status new_write_status = |
113 WriteEncodedProgram(new_encoded.get(), new_transformed_element); | 114 WriteEncodedProgram(new_encoded.get(), new_transformed_element); |
114 return new_write_status; | 115 return new_write_status; |
115 } | 116 } |
116 | 117 |
117 Status Reform(SourceStreamSet* transformed_element, | 118 Status Reform(SourceStreamSet* transformed_element, |
118 SinkStream* reformed_element) { | 119 SinkStream* reformed_element) { |
119 return TransformationPatchGenerator::Reform(transformed_element, | 120 return TransformationPatchGenerator::Reform(transformed_element, |
120 reformed_element); | 121 reformed_element); |
121 } | 122 } |
122 | 123 |
123 private: | 124 private: |
124 virtual ~PatchGeneratorX86_32() { } | 125 virtual ~PatchGeneratorX86_32() { } |
125 | 126 |
126 ExecutableType kind_; | 127 ExecutableType kind_; |
127 | 128 |
128 DISALLOW_COPY_AND_ASSIGN(PatchGeneratorX86_32); | 129 DISALLOW_COPY_AND_ASSIGN(PatchGeneratorX86_32); |
129 }; | 130 }; |
130 | 131 |
131 } // namespace courgette | 132 } // namespace courgette |
132 | 133 |
133 #endif // COURGETTE_WIN32_X86_GENERATOR_H_ | 134 #endif // COURGETTE_WIN32_X86_GENERATOR_H_ |
OLD | NEW |