OLD | NEW |
---|---|
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 #include "courgette/disassembler_elf_32.h" | 5 #include "courgette/disassembler_elf_32.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
401 return ParseSimpleRegion(file_offset, section_end, program); | 401 return ParseSimpleRegion(file_offset, section_end, program); |
402 } | 402 } |
403 | 403 |
404 CheckBool DisassemblerElf32::ParseSimpleRegion( | 404 CheckBool DisassemblerElf32::ParseSimpleRegion( |
405 size_t start_file_offset, | 405 size_t start_file_offset, |
406 size_t end_file_offset, | 406 size_t end_file_offset, |
407 AssemblyProgram* program) { | 407 AssemblyProgram* program) { |
408 | 408 |
409 const uint8* start = OffsetToPointer(start_file_offset); | 409 const uint8* start = OffsetToPointer(start_file_offset); |
410 const uint8* end = OffsetToPointer(end_file_offset); | 410 const uint8* end = OffsetToPointer(end_file_offset); |
411 const uint32 len = end - start; // Works because vars are byte pointers | |
Ben Chan
2013/08/09 20:58:39
nit: two spaces between comment
(note: generally,
paulgazz
2013/08/09 23:23:31
Done spaces.
Regarding ptrdiff_t: the underlying
| |
411 | 412 |
412 const uint8* p = start; | 413 // Callers don't guarantee start < end |
414 if (start >= end) return true; | |
413 | 415 |
414 while (p < end) { | 416 if (!program->EmitBytesInstruction(start, len)) |
415 if (!program->EmitByteInstruction(*p)) | 417 return false; |
416 return false; | |
417 ++p; | |
418 } | |
419 | 418 |
420 return true; | 419 return true; |
421 } | 420 } |
422 | 421 |
423 CheckBool DisassemblerElf32::ParseAbs32Relocs() { | 422 CheckBool DisassemblerElf32::ParseAbs32Relocs() { |
424 abs32_locations_.clear(); | 423 abs32_locations_.clear(); |
425 | 424 |
426 // Loop through sections for relocation sections | 425 // Loop through sections for relocation sections |
427 for (int section_id = 0; section_id < SectionHeaderCount(); section_id++) { | 426 for (int section_id = 0; section_id < SectionHeaderCount(); section_id++) { |
428 const Elf32_Shdr *section_header = SectionHeader(section_id); | 427 const Elf32_Shdr *section_header = SectionHeader(section_id); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
497 return false; | 496 return false; |
498 } | 497 } |
499 | 498 |
500 std::sort(rel32_locations_.begin(), | 499 std::sort(rel32_locations_.begin(), |
501 rel32_locations_.end(), | 500 rel32_locations_.end(), |
502 TypedRVA::IsLessThan); | 501 TypedRVA::IsLessThan); |
503 return true; | 502 return true; |
504 } | 503 } |
505 | 504 |
506 } // namespace courgette | 505 } // namespace courgette |
OLD | NEW |