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

Side by Side Diff: courgette/disassembler_elf_32_arm.h

Issue 1676683002: [Courgette] Clean up Disassembler; fix ELF Memory leaks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Wrap #include <iostream> under #if COURGETTE_HISTOGRAM_TARGETS. Created 4 years, 9 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/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>
12
11 #include "base/macros.h" 13 #include "base/macros.h"
12 #include "courgette/disassembler_elf_32.h" 14 #include "courgette/disassembler_elf_32.h"
13 #include "courgette/memory_allocator.h"
14 #include "courgette/types_elf.h" 15 #include "courgette/types_elf.h"
15 16
16 namespace courgette { 17 namespace courgette {
17 18
18 class AssemblyProgram; 19 class AssemblyProgram;
19 20
20 enum ARM_RVA { 21 enum ARM_RVA {
21 ARM_OFF8, 22 ARM_OFF8,
22 ARM_OFF11, 23 ARM_OFF11,
23 ARM_OFF24, 24 ARM_OFF24,
24 ARM_OFF25, 25 ARM_OFF25,
25 ARM_OFF21, 26 ARM_OFF21,
26 }; 27 };
27 28
28 class DisassemblerElf32ARM : public DisassemblerElf32 { 29 class DisassemblerElf32ARM : public DisassemblerElf32 {
29 public: 30 public:
30 class TypedRVAARM : public TypedRVA { 31 class TypedRVAARM : public TypedRVA {
31 public: 32 public:
32 TypedRVAARM(ARM_RVA type, RVA rva) : TypedRVA(rva), type_(type) { } 33 TypedRVAARM(ARM_RVA type, RVA rva) : TypedRVA(rva), type_(type) { }
34 ~TypedRVAARM() override { }
35
36 // TypedRVA interfaces.
37 CheckBool ComputeRelativeTarget(const uint8_t* op_pointer) override;
38 CheckBool EmitInstruction(AssemblyProgram* program,
39 RVA target_rva) override;
40 uint16_t op_size() const override;
33 41
34 uint16_t c_op() const { return c_op_; } 42 uint16_t c_op() const { return c_op_; }
35 43
36 virtual CheckBool ComputeRelativeTarget(const uint8_t* op_pointer);
37
38 virtual CheckBool EmitInstruction(AssemblyProgram* program,
39 RVA target_rva);
40
41 virtual uint16_t op_size() const;
42
43 private: 44 private:
44 ARM_RVA type_; 45 ARM_RVA type_;
45 46 uint16_t c_op_; // Set by ComputeRelativeTarget().
46 uint16_t c_op_; // set by ComputeRelativeTarget()
47 const uint8_t* arm_op_; 47 const uint8_t* arm_op_;
48 }; 48 };
49 49
50 explicit DisassemblerElf32ARM(const void* start, size_t length); 50 DisassemblerElf32ARM(const void* start, size_t length);
51 51
52 virtual ExecutableType kind() { return EXE_ELF_32_ARM; } 52 ~DisassemblerElf32ARM() override { }
53 53
54 virtual e_machine_values ElfEM() { return EM_ARM; } 54 // DisassemblerElf32 interfaces.
55 ExecutableType kind() const override { return EXE_ELF_32_ARM; }
56 e_machine_values ElfEM() const override { return EM_ARM; }
55 57
58 // Takes an ARM or thumb opcode |arm_op| of specified |type| and located at
59 // |rva|, extracts the instruction-relative target RVA into |*addr| and
60 // encodes the corresponding Courgette opcode as |*c_op|.
61 //
62 // Details on ARM opcodes, and target RVA extraction are taken from
63 // "ARM Architecture Reference Manual", section A4.1.5 and
64 // "Thumb-2 supplement", section 4.6.12.
65 // ARM_OFF24 is for the ARM opcode. The rest are for thumb opcodes.
56 static CheckBool Compress(ARM_RVA type, 66 static CheckBool Compress(ARM_RVA type,
57 uint32_t arm_op, 67 uint32_t arm_op,
58 RVA rva, 68 RVA rva,
59 uint16_t* c_op /* out */, 69 uint16_t* c_op /* out */,
60 uint32_t* addr /* out */); 70 uint32_t* addr /* out */);
61 71
72 // Inverse for Compress(). Takes Courgette op |c_op| and relative address
73 // |addr| to reconstruct the original ARM or thumb op |*arm_op|.
62 static CheckBool Decompress(ARM_RVA type, 74 static CheckBool Decompress(ARM_RVA type,
63 uint16_t c_op, 75 uint16_t c_op,
64 uint32_t addr, 76 uint32_t addr,
65 uint32_t* arm_op /* out */); 77 uint32_t* arm_op /* out */);
66 78
67 protected: 79 protected:
68 80 // DisassemblerElf32 interfaces.
69 virtual CheckBool RelToRVA(Elf32_Rel rel, RVA* result) 81 CheckBool RelToRVA(Elf32_Rel rel,
70 const WARN_UNUSED_RESULT; 82 RVA* result) const override WARN_UNUSED_RESULT;
71 83 CheckBool ParseRelocationSection(const Elf32_Shdr* section_header,
72 virtual CheckBool ParseRelocationSection( 84 AssemblyProgram* program)
73 const Elf32_Shdr *section_header, 85 override WARN_UNUSED_RESULT;
74 AssemblyProgram* program) WARN_UNUSED_RESULT; 86 CheckBool ParseRel32RelocsFromSection(const Elf32_Shdr* section)
75 87 override WARN_UNUSED_RESULT;
76 virtual CheckBool ParseRel32RelocsFromSection(
77 const Elf32_Shdr* section) WARN_UNUSED_RESULT;
78 88
79 #if COURGETTE_HISTOGRAM_TARGETS 89 #if COURGETTE_HISTOGRAM_TARGETS
80 std::map<RVA, int> rel32_target_rvas_; 90 std::map<RVA, int> rel32_target_rvas_;
81 #endif 91 #endif
82 92
83 DISALLOW_COPY_AND_ASSIGN(DisassemblerElf32ARM); 93 DISALLOW_COPY_AND_ASSIGN(DisassemblerElf32ARM);
84 }; 94 };
85 95
86 } // namespace courgette 96 } // namespace courgette
87 97
88 #endif // COURGETTE_DISASSEMBLER_ELF_32_ARM_H_ 98 #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