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

Side by Side Diff: courgette/disassembler_elf_32_x86.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 (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_ELF_32_X86_H_ 5 #ifndef COURGETTE_DISASSEMBLER_ELF_32_X86_H_
6 #define COURGETTE_DISASSEMBLER_ELF_32_X86_H_ 6 #define COURGETTE_DISASSEMBLER_ELF_32_X86_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 class DisassemblerElf32X86 : public DisassemblerElf32 { 21 class DisassemblerElf32X86 : public DisassemblerElf32 {
21 public: 22 public:
22 class TypedRVAX86 : public TypedRVA { 23 class TypedRVAX86 : public TypedRVA {
23 public: 24 public:
24 explicit TypedRVAX86(RVA rva) : TypedRVA(rva) { 25 explicit TypedRVAX86(RVA rva) : TypedRVA(rva) { }
25 }
26 26
27 CheckBool ComputeRelativeTarget(const uint8_t* op_pointer) override { 27 ~TypedRVAX86() override { }
28 set_relative_target(Read32LittleEndian(op_pointer) + 4);
29 return true;
30 }
31 28
29 // TypedRVA interfaces.
30 CheckBool ComputeRelativeTarget(const uint8_t* op_pointer) override;
32 CheckBool EmitInstruction(AssemblyProgram* program, 31 CheckBool EmitInstruction(AssemblyProgram* program,
33 RVA target_rva) override { 32 RVA target_rva) override;
34 return program->EmitRel32(program->FindOrMakeRel32Label(target_rva)); 33 uint16_t op_size() const override;
35 }
36
37 uint16_t op_size() const override { return 4; }
38 }; 34 };
39 35
40 explicit DisassemblerElf32X86(const void* start, size_t length); 36 DisassemblerElf32X86(const void* start, size_t length);
41 37
42 virtual ExecutableType kind() { return EXE_ELF_32_X86; } 38 ~DisassemblerElf32X86() override { };
43 39
44 virtual e_machine_values ElfEM() { return EM_386; } 40 // DisassemblerElf32 interfaces.
41 ExecutableType kind() const override { return EXE_ELF_32_X86; }
42 e_machine_values ElfEM() const override { return EM_386; }
45 43
46 protected: 44 protected:
47 virtual CheckBool RelToRVA(Elf32_Rel rel, RVA* result) 45 // DisassemblerElf32 interfaces.
48 const WARN_UNUSED_RESULT; 46 CheckBool RelToRVA(Elf32_Rel rel, RVA* result)
49 47 const WARN_UNUSED_RESULT override;
50 virtual CheckBool ParseRelocationSection( 48 CheckBool ParseRelocationSection(
51 const Elf32_Shdr *section_header, 49 const Elf32_Shdr* section_header,
52 AssemblyProgram* program) WARN_UNUSED_RESULT; 50 AssemblyProgram* program) WARN_UNUSED_RESULT override;
53 51 CheckBool ParseRel32RelocsFromSection(
54 virtual CheckBool ParseRel32RelocsFromSection( 52 const Elf32_Shdr* section) WARN_UNUSED_RESULT override;
55 const Elf32_Shdr* section) WARN_UNUSED_RESULT;
56 53
57 #if COURGETTE_HISTOGRAM_TARGETS 54 #if COURGETTE_HISTOGRAM_TARGETS
58 std::map<RVA, int> rel32_target_rvas_; 55 std::map<RVA, int> rel32_target_rvas_;
59 #endif 56 #endif
60 57
61 DISALLOW_COPY_AND_ASSIGN(DisassemblerElf32X86); 58 DISALLOW_COPY_AND_ASSIGN(DisassemblerElf32X86);
62 }; 59 };
63 60
64 } // namespace courgette 61 } // namespace courgette
65 62
66 #endif // COURGETTE_DISASSEMBLER_ELF_32_X86_H_ 63 #endif // COURGETTE_DISASSEMBLER_ELF_32_X86_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698