OLD | NEW |
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 "base/basictypes.h" | 8 #include <stddef.h> |
| 9 #include <stdint.h> |
| 10 |
| 11 #include "base/macros.h" |
9 #include "courgette/disassembler_elf_32.h" | 12 #include "courgette/disassembler_elf_32.h" |
10 #include "courgette/memory_allocator.h" | 13 #include "courgette/memory_allocator.h" |
11 #include "courgette/types_elf.h" | 14 #include "courgette/types_elf.h" |
12 | 15 |
13 namespace courgette { | 16 namespace courgette { |
14 | 17 |
15 class AssemblyProgram; | 18 class AssemblyProgram; |
16 | 19 |
17 class DisassemblerElf32X86 : public DisassemblerElf32 { | 20 class DisassemblerElf32X86 : public DisassemblerElf32 { |
18 public: | 21 public: |
19 class TypedRVAX86 : public TypedRVA { | 22 class TypedRVAX86 : public TypedRVA { |
20 public: | 23 public: |
21 explicit TypedRVAX86(RVA rva) : TypedRVA(rva) { | 24 explicit TypedRVAX86(RVA rva) : TypedRVA(rva) { |
22 } | 25 } |
23 | 26 |
24 CheckBool ComputeRelativeTarget(const uint8* op_pointer) override { | 27 CheckBool ComputeRelativeTarget(const uint8_t* op_pointer) override { |
25 set_relative_target(Read32LittleEndian(op_pointer) + 4); | 28 set_relative_target(Read32LittleEndian(op_pointer) + 4); |
26 return true; | 29 return true; |
27 } | 30 } |
28 | 31 |
29 CheckBool EmitInstruction(AssemblyProgram* program, | 32 CheckBool EmitInstruction(AssemblyProgram* program, |
30 RVA target_rva) override { | 33 RVA target_rva) override { |
31 return program->EmitRel32(program->FindOrMakeRel32Label(target_rva)); | 34 return program->EmitRel32(program->FindOrMakeRel32Label(target_rva)); |
32 } | 35 } |
33 | 36 |
34 uint16 op_size() const override { return 4; } | 37 uint16_t op_size() const override { return 4; } |
35 }; | 38 }; |
36 | 39 |
37 explicit DisassemblerElf32X86(const void* start, size_t length); | 40 explicit DisassemblerElf32X86(const void* start, size_t length); |
38 | 41 |
39 virtual ExecutableType kind() { return EXE_ELF_32_X86; } | 42 virtual ExecutableType kind() { return EXE_ELF_32_X86; } |
40 | 43 |
41 virtual e_machine_values ElfEM() { return EM_386; } | 44 virtual e_machine_values ElfEM() { return EM_386; } |
42 | 45 |
43 protected: | 46 protected: |
44 virtual CheckBool RelToRVA(Elf32_Rel rel, RVA* result) | 47 virtual CheckBool RelToRVA(Elf32_Rel rel, RVA* result) |
45 const WARN_UNUSED_RESULT; | 48 const WARN_UNUSED_RESULT; |
46 | 49 |
47 virtual CheckBool ParseRelocationSection( | 50 virtual CheckBool ParseRelocationSection( |
48 const Elf32_Shdr *section_header, | 51 const Elf32_Shdr *section_header, |
49 AssemblyProgram* program) WARN_UNUSED_RESULT; | 52 AssemblyProgram* program) WARN_UNUSED_RESULT; |
50 | 53 |
51 virtual CheckBool ParseRel32RelocsFromSection( | 54 virtual CheckBool ParseRel32RelocsFromSection( |
52 const Elf32_Shdr* section) WARN_UNUSED_RESULT; | 55 const Elf32_Shdr* section) WARN_UNUSED_RESULT; |
53 | 56 |
54 #if COURGETTE_HISTOGRAM_TARGETS | 57 #if COURGETTE_HISTOGRAM_TARGETS |
55 std::map<RVA, int> rel32_target_rvas_; | 58 std::map<RVA, int> rel32_target_rvas_; |
56 #endif | 59 #endif |
57 | 60 |
58 DISALLOW_COPY_AND_ASSIGN(DisassemblerElf32X86); | 61 DISALLOW_COPY_AND_ASSIGN(DisassemblerElf32X86); |
59 }; | 62 }; |
60 | 63 |
61 } // namespace courgette | 64 } // namespace courgette |
62 | 65 |
63 #endif // COURGETTE_DISASSEMBLER_ELF_32_X86_H_ | 66 #endif // COURGETTE_DISASSEMBLER_ELF_32_X86_H_ |
OLD | NEW |