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

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: Sync. 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
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) { }
33 34
35 ~TypedRVAARM() override { }
36
37 // TypedRVA interfaces.
38 CheckBool ComputeRelativeTarget(const uint8_t* op_pointer) override;
39 CheckBool EmitInstruction(AssemblyProgram* program,
40 RVA target_rva) override;
41 uint16_t op_size() const override;
42
34 uint16_t c_op() const { return c_op_; } 43 uint16_t c_op() const { return c_op_; }
35 44
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: 45 private:
44 ARM_RVA type_; 46 ARM_RVA type_;
45 47 uint16_t c_op_; // Set by ComputeRelativeTarget().
46 uint16_t c_op_; // set by ComputeRelativeTarget()
47 const uint8_t* arm_op_; 48 const uint8_t* arm_op_;
48 }; 49 };
49 50
50 explicit DisassemblerElf32ARM(const void* start, size_t length); 51 DisassemblerElf32ARM(const void* start, size_t length);
51 52
52 virtual ExecutableType kind() { return EXE_ELF_32_ARM; } 53 ~DisassemblerElf32ARM() override { };
53 54
54 virtual e_machine_values ElfEM() { return EM_ARM; } 55 // DisassemblerElf32 interfaces.
56 ExecutableType kind() const override { return EXE_ELF_32_ARM; }
57 e_machine_values ElfEM() const override { return EM_ARM; }
55 58
59 // Takes an ARM or thumb opcode |arm_op| of specified |type| and located at
60 // |rva|, extracts the instruction-relative target RVA into |*addr| and
61 // encodes the corresponding Courgette opcode as |*c_op|.
62 //
63 // Details on ARM opcodes, and target RVA extraction are taken from
64 // "ARM Architecture Reference Manual", section A4.1.5 and
65 // "Thumb-2 supplement", section 4.6.12.
66 // ARM_OFF24 is for the ARM opcode. The rest are for thumb opcodes.
56 static CheckBool Compress(ARM_RVA type, 67 static CheckBool Compress(ARM_RVA type,
57 uint32_t arm_op, 68 uint32_t arm_op,
58 RVA rva, 69 RVA rva,
59 uint16_t* c_op /* out */, 70 uint16_t* c_op /* out */,
60 uint32_t* addr /* out */); 71 uint32_t* addr /* out */);
61 72
73 // Inverts the process in Compress() method. Takes Courgette op |c_op| and
74 // relative address |addr| to reconstruct the original ARM or thumb op
75 // |*arm_op|.
62 static CheckBool Decompress(ARM_RVA type, 76 static CheckBool Decompress(ARM_RVA type,
63 uint16_t c_op, 77 uint16_t c_op,
64 uint32_t addr, 78 uint32_t addr,
65 uint32_t* arm_op /* out */); 79 uint32_t* arm_op /* out */);
66 80
67 protected: 81 protected:
68 82 // DisassemblerElf32 interfaces.
69 virtual CheckBool RelToRVA(Elf32_Rel rel, RVA* result) 83 CheckBool RelToRVA(Elf32_Rel rel, RVA* result)
70 const WARN_UNUSED_RESULT; 84 const WARN_UNUSED_RESULT override;
71 85 CheckBool ParseRelocationSection(
72 virtual CheckBool ParseRelocationSection( 86 const Elf32_Shdr* section_header,
73 const Elf32_Shdr *section_header, 87 AssemblyProgram* program) WARN_UNUSED_RESULT override;
74 AssemblyProgram* program) WARN_UNUSED_RESULT; 88 CheckBool ParseRel32RelocsFromSection(
75 89 const Elf32_Shdr* section) WARN_UNUSED_RESULT override;
76 virtual CheckBool ParseRel32RelocsFromSection(
77 const Elf32_Shdr* section) WARN_UNUSED_RESULT;
78 90
79 #if COURGETTE_HISTOGRAM_TARGETS 91 #if COURGETTE_HISTOGRAM_TARGETS
80 std::map<RVA, int> rel32_target_rvas_; 92 std::map<RVA, int> rel32_target_rvas_;
81 #endif 93 #endif
82 94
83 DISALLOW_COPY_AND_ASSIGN(DisassemblerElf32ARM); 95 DISALLOW_COPY_AND_ASSIGN(DisassemblerElf32ARM);
84 }; 96 };
85 97
86 } // namespace courgette 98 } // namespace courgette
87 99
88 #endif // COURGETTE_DISASSEMBLER_ELF_32_ARM_H_ 100 #endif // COURGETTE_DISASSEMBLER_ELF_32_ARM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698