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

Side by Side Diff: courgette/disassembler_elf_32_arm.h

Issue 2462993003: [Courgette] Refactor: Add and use Instruction*Receptor classes; call ParseFile() in 2 passes. (Closed)
Patch Set: Fix comments. Created 4 years, 1 month 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/disassembler_elf_32.cc ('k') | courgette/disassembler_elf_32_arm.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_ELF_32_ARM_H_ 5 #ifndef COURGETTE_DISASSEMBLER_ELF_32_ARM_H_
6 #define COURGETTE_DISASSEMBLER_ELF_32_ARM_H_ 6 #define COURGETTE_DISASSEMBLER_ELF_32_ARM_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <map> 11 #include <map>
12 12
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "courgette/disassembler_elf_32.h" 14 #include "courgette/disassembler_elf_32.h"
15 #include "courgette/types_elf.h" 15 #include "courgette/types_elf.h"
16 16
17 namespace courgette { 17 namespace courgette {
18 18
19 class AssemblyProgram; 19 class AssemblyProgram;
20 class InstructionReceptor;
20 21
21 enum ARM_RVA { 22 enum ARM_RVA {
22 ARM_OFF8, 23 ARM_OFF8,
23 ARM_OFF11, 24 ARM_OFF11,
24 ARM_OFF24, 25 ARM_OFF24,
25 ARM_OFF25, 26 ARM_OFF25,
26 ARM_OFF21, 27 ARM_OFF21,
27 }; 28 };
28 29
29 class DisassemblerElf32ARM : public DisassemblerElf32 { 30 class DisassemblerElf32ARM : public DisassemblerElf32 {
30 public: 31 public:
31 // Returns true if a valid executable is detected using only quick checks. 32 // Returns true if a valid executable is detected using only quick checks.
32 static bool QuickDetect(const uint8_t* start, size_t length) { 33 static bool QuickDetect(const uint8_t* start, size_t length) {
33 return DisassemblerElf32::QuickDetect(start, length, EM_ARM); 34 return DisassemblerElf32::QuickDetect(start, length, EM_ARM);
34 } 35 }
35 36
36 class TypedRVAARM : public TypedRVA { 37 class TypedRVAARM : public TypedRVA {
37 public: 38 public:
38 TypedRVAARM(ARM_RVA type, RVA rva) : TypedRVA(rva), type_(type) { } 39 TypedRVAARM(ARM_RVA type, RVA rva) : TypedRVA(rva), type_(type) { }
39 ~TypedRVAARM() override { } 40 ~TypedRVAARM() override { }
40 41
41 // TypedRVA interfaces. 42 // TypedRVA interfaces.
42 CheckBool ComputeRelativeTarget(const uint8_t* op_pointer) override; 43 CheckBool ComputeRelativeTarget(const uint8_t* op_pointer) override;
43 CheckBool EmitInstruction(AssemblyProgram* program, 44 CheckBool EmitInstruction(Label* label,
44 Label* label) override; 45 InstructionReceptor* receptor) override;
45 uint16_t op_size() const override; 46 uint16_t op_size() const override;
46 47
47 uint16_t c_op() const { return c_op_; } 48 uint16_t c_op() const { return c_op_; }
48 49
49 private: 50 private:
50 ARM_RVA type_; 51 ARM_RVA type_;
51 uint16_t c_op_; // Set by ComputeRelativeTarget(). 52 uint16_t c_op_; // Set by ComputeRelativeTarget().
52 const uint8_t* arm_op_; 53 const uint8_t* arm_op_;
53 }; 54 };
54 55
(...skipping 24 matching lines...) Expand all
79 static CheckBool Decompress(ARM_RVA type, 80 static CheckBool Decompress(ARM_RVA type,
80 uint16_t c_op, 81 uint16_t c_op,
81 uint32_t addr, 82 uint32_t addr,
82 uint32_t* arm_op /* out */); 83 uint32_t* arm_op /* out */);
83 84
84 protected: 85 protected:
85 // DisassemblerElf32 interfaces. 86 // DisassemblerElf32 interfaces.
86 CheckBool RelToRVA(Elf32_Rel rel, 87 CheckBool RelToRVA(Elf32_Rel rel,
87 RVA* result) const override WARN_UNUSED_RESULT; 88 RVA* result) const override WARN_UNUSED_RESULT;
88 CheckBool ParseRelocationSection(const Elf32_Shdr* section_header, 89 CheckBool ParseRelocationSection(const Elf32_Shdr* section_header,
89 AssemblyProgram* program) 90 InstructionReceptor* receptor) const override
90 override WARN_UNUSED_RESULT; 91 WARN_UNUSED_RESULT;
91 CheckBool ParseRel32RelocsFromSection(const Elf32_Shdr* section) 92 CheckBool ParseRel32RelocsFromSection(const Elf32_Shdr* section)
92 override WARN_UNUSED_RESULT; 93 override WARN_UNUSED_RESULT;
93 94
94 #if COURGETTE_HISTOGRAM_TARGETS 95 #if COURGETTE_HISTOGRAM_TARGETS
95 std::map<RVA, int> rel32_target_rvas_; 96 std::map<RVA, int> rel32_target_rvas_;
96 #endif 97 #endif
97 98
99 private:
98 DISALLOW_COPY_AND_ASSIGN(DisassemblerElf32ARM); 100 DISALLOW_COPY_AND_ASSIGN(DisassemblerElf32ARM);
99 }; 101 };
100 102
101 } // namespace courgette 103 } // namespace courgette
102 104
103 #endif // COURGETTE_DISASSEMBLER_ELF_32_ARM_H_ 105 #endif // COURGETTE_DISASSEMBLER_ELF_32_ARM_H_
OLDNEW
« no previous file with comments | « courgette/disassembler_elf_32.cc ('k') | courgette/disassembler_elf_32_arm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698