Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(563)

Side by Side Diff: courgette/disassembler.h

Issue 2854113002: [Courgette] Reduce AssemblyProgram to reduce Courgette-apply RAM floor and disk churn. (Closed)
Patch Set: Update courgette_fuzzer in libfuzzer. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « courgette/courgette_tool.cc ('k') | courgette/disassembler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_DISASSEMBLER_H_ 5 #ifndef COURGETTE_DISASSEMBLER_H_
6 #define COURGETTE_DISASSEMBLER_H_ 6 #define COURGETTE_DISASSEMBLER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "courgette/courgette.h" 14 #include "courgette/courgette.h"
15 #include "courgette/image_utils.h" 15 #include "courgette/image_utils.h"
16 #include "courgette/instruction_utils.h" 16 #include "courgette/instruction_utils.h"
17 17
18 namespace courgette { 18 namespace courgette {
19 19
20 class AssemblyProgram; 20 class AssemblyProgram;
21 class EncodedProgram;
21 22
22 class Disassembler : public AddressTranslator { 23 class Disassembler : public AddressTranslator {
23 public: 24 public:
24 // Visitor/adaptor to translate RVA to target RVA for abs32. 25 // Visitor/adaptor to translate RVA to target RVA for abs32.
25 class RvaVisitor_Abs32 : public VectorRvaVisitor<RVA> { 26 class RvaVisitor_Abs32 : public VectorRvaVisitor<RVA> {
26 public: 27 public:
27 RvaVisitor_Abs32(const std::vector<RVA>& rva_locations, 28 RvaVisitor_Abs32(const std::vector<RVA>& rva_locations,
28 const AddressTranslator& translator); 29 const AddressTranslator& translator);
29 ~RvaVisitor_Abs32() override { } 30 ~RvaVisitor_Abs32() override { }
30 31
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 // because we may remove rel32 Labels along the way. As a result the matching 85 // because we may remove rel32 Labels along the way. As a result the matching
85 // rel32 addresses become unused. Removing them saves space. 86 // rel32 addresses become unused. Removing them saves space.
86 virtual void RemoveUnusedRel32Locations(AssemblyProgram* program) = 0; 87 virtual void RemoveUnusedRel32Locations(AssemblyProgram* program) = 0;
87 88
88 // Extracts structural data from the main image. Returns true if the image 89 // Extracts structural data from the main image. Returns true if the image
89 // appears to be a valid executable of the expected type, or false otherwise. 90 // appears to be a valid executable of the expected type, or false otherwise.
90 // This needs to be called before Disassemble(). 91 // This needs to be called before Disassemble().
91 virtual bool ParseHeader() = 0; 92 virtual bool ParseHeader() = 0;
92 93
93 // Extracts and stores references from the main image. Returns a new 94 // Extracts and stores references from the main image. Returns a new
94 // AssemblyProgram initialized using data parsed from the main image and 95 // AssemblyProgram with initialized Labels, or null on failure.
95 // |annotate_labels|, or null on failure. 96 std::unique_ptr<AssemblyProgram> CreateProgram(bool annotate);
96 std::unique_ptr<AssemblyProgram> Disassemble(bool annotate_labels); 97
98 // Goes through the entire program (with the help of |program|), computes all
99 // instructions, and stores them into |encoded|.
100 Status DisassembleAndEncode(AssemblyProgram* program,
101 EncodedProgram* encoded);
97 102
98 // ok() may always be called but returns true only after ParseHeader() 103 // ok() may always be called but returns true only after ParseHeader()
99 // succeeds. 104 // succeeds.
100 bool ok() const { return failure_reason_ == nullptr; } 105 bool ok() const { return failure_reason_ == nullptr; }
101 106
102 // Returns the length of the image. May reduce after ParseHeader(). 107 // Returns the length of the image. May reduce after ParseHeader().
103 size_t length() const { return length_; } 108 size_t length() const { return length_; }
104 const uint8_t* start() const { return start_; } 109 const uint8_t* start() const { return start_; }
105 const uint8_t* end() const { return end_; } 110 const uint8_t* end() const { return end_; }
106 111
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 size_t length_; // In current memory. 143 size_t length_; // In current memory.
139 const uint8_t* start_; // In current memory, base for 'file offsets'. 144 const uint8_t* start_; // In current memory, base for 'file offsets'.
140 const uint8_t* end_; // In current memory. 145 const uint8_t* end_; // In current memory.
141 146
142 DISALLOW_COPY_AND_ASSIGN(Disassembler); 147 DISALLOW_COPY_AND_ASSIGN(Disassembler);
143 }; 148 };
144 149
145 } // namespace courgette 150 } // namespace courgette
146 151
147 #endif // COURGETTE_DISASSEMBLER_H_ 152 #endif // COURGETTE_DISASSEMBLER_H_
OLDNEW
« no previous file with comments | « courgette/courgette_tool.cc ('k') | courgette/disassembler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698