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

Side by Side Diff: courgette/disassembler_elf_32.cc

Issue 1969543002: Unified usage of vector<unique_ptr<T>> (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 #include "courgette/disassembler_elf_32.h" 5 #include "courgette/disassembler_elf_32.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "courgette/assembly_program.h" 10 #include "courgette/assembly_program.h"
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 for (RVA rva : rvas) { 266 for (RVA rva : rvas) {
267 FileOffset file_offset = RVAToFileOffset(rva); 267 FileOffset file_offset = RVAToFileOffset(rva);
268 if (file_offset == kNoFileOffset) 268 if (file_offset == kNoFileOffset)
269 return false; 269 return false;
270 file_offsets->push_back(file_offset); 270 file_offsets->push_back(file_offset);
271 } 271 }
272 return true; 272 return true;
273 } 273 }
274 274
275 CheckBool DisassemblerElf32::RVAsToFileOffsets( 275 CheckBool DisassemblerElf32::RVAsToFileOffsets(
276 ScopedVector<TypedRVA>* typed_rvas) { 276 std::vector<std::unique_ptr<TypedRVA>>* typed_rvas) {
277 for (TypedRVA* typed_rva : *typed_rvas) { 277 for (auto& typed_rva : *typed_rvas) {
278 FileOffset file_offset = RVAToFileOffset(typed_rva->rva()); 278 FileOffset file_offset = RVAToFileOffset(typed_rva->rva());
279 if (file_offset == kNoFileOffset) 279 if (file_offset == kNoFileOffset)
280 return false; 280 return false;
281 typed_rva->set_file_offset(file_offset); 281 typed_rva->set_file_offset(file_offset);
282 } 282 }
283 return true; 283 return true;
284 } 284 }
285 285
286 CheckBool DisassemblerElf32::ParseFile(AssemblyProgram* program) { 286 CheckBool DisassemblerElf32::ParseFile(AssemblyProgram* program) {
287 // Walk all the bytes in the file, whether or not in a section. 287 // Walk all the bytes in the file, whether or not in a section.
(...skipping 10 matching lines...) Expand all
298 298
299 if (!RVAsToFileOffsets(&rel32_locations_)) 299 if (!RVAsToFileOffsets(&rel32_locations_))
300 return false; 300 return false;
301 std::sort(rel32_locations_.begin(), 301 std::sort(rel32_locations_.begin(),
302 rel32_locations_.end(), 302 rel32_locations_.end(),
303 TypedRVA::IsLessThanByFileOffset); 303 TypedRVA::IsLessThanByFileOffset);
304 304
305 std::vector<FileOffset>::iterator current_abs_offset = abs_offsets.begin(); 305 std::vector<FileOffset>::iterator current_abs_offset = abs_offsets.begin();
306 std::vector<FileOffset>::iterator end_abs_offset = abs_offsets.end(); 306 std::vector<FileOffset>::iterator end_abs_offset = abs_offsets.end();
307 307
308 ScopedVector<TypedRVA>::iterator current_rel = rel32_locations_.begin(); 308 auto current_rel = rel32_locations_.begin();
huangs 2016/05/11 04:49:23 More consistent to keep at std::vector<std::uniqe_
etiennep 2016/05/11 18:19:12 Done.
309 ScopedVector<TypedRVA>::iterator end_rel = rel32_locations_.end(); 309 auto end_rel = rel32_locations_.end();
310 310
311 // Visit section headers ordered by file offset. 311 // Visit section headers ordered by file offset.
312 for (Elf32_Half section_id : section_header_file_offset_order_) { 312 for (Elf32_Half section_id : section_header_file_offset_order_) {
313 const Elf32_Shdr* section_header = SectionHeader(section_id); 313 const Elf32_Shdr* section_header = SectionHeader(section_id);
314 314
315 if (section_header->sh_type == SHT_NOBITS) 315 if (section_header->sh_type == SHT_NOBITS)
316 continue; 316 continue;
317 317
318 if (!ParseSimpleRegion(file_offset, section_header->sh_offset, program)) 318 if (!ParseSimpleRegion(file_offset, section_header->sh_offset, program))
319 return false; 319 return false;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 return false; 367 return false;
368 368
369 // Make certain we consume all of the relocations as expected 369 // Make certain we consume all of the relocations as expected
370 return (current_abs_offset == end_abs_offset); 370 return (current_abs_offset == end_abs_offset);
371 } 371 }
372 372
373 CheckBool DisassemblerElf32::ParseProgbitsSection( 373 CheckBool DisassemblerElf32::ParseProgbitsSection(
374 const Elf32_Shdr* section_header, 374 const Elf32_Shdr* section_header,
375 std::vector<FileOffset>::iterator* current_abs_offset, 375 std::vector<FileOffset>::iterator* current_abs_offset,
376 std::vector<FileOffset>::iterator end_abs_offset, 376 std::vector<FileOffset>::iterator end_abs_offset,
377 ScopedVector<TypedRVA>::iterator* current_rel, 377 std::vector<std::unique_ptr<TypedRVA>>::iterator* current_rel,
378 ScopedVector<TypedRVA>::iterator end_rel, 378 std::vector<std::unique_ptr<TypedRVA>>::iterator end_rel,
379 AssemblyProgram* program) { 379 AssemblyProgram* program) {
380 // Walk all the bytes in the file, whether or not in a section. 380 // Walk all the bytes in the file, whether or not in a section.
381 FileOffset file_offset = section_header->sh_offset; 381 FileOffset file_offset = section_header->sh_offset;
382 FileOffset section_end = section_header->sh_offset + section_header->sh_size; 382 FileOffset section_end = section_header->sh_offset + section_header->sh_size;
383 383
384 Elf32_Addr origin = section_header->sh_addr; 384 Elf32_Addr origin = section_header->sh_addr;
385 FileOffset origin_offset = section_header->sh_offset; 385 FileOffset origin_offset = section_header->sh_offset;
386 if (!program->EmitOriginInstruction(origin)) 386 if (!program->EmitOriginInstruction(origin))
387 return false; 387 return false;
388 388
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 if (!ParseRel32RelocsFromSection(section_header)) 548 if (!ParseRel32RelocsFromSection(section_header))
549 return false; 549 return false;
550 } 550 }
551 if (!found_rel32) 551 if (!found_rel32)
552 VLOG(1) << "Warning: Found no rel32 addresses. Missing .text section?"; 552 VLOG(1) << "Warning: Found no rel32 addresses. Missing .text section?";
553 553
554 return true; 554 return true;
555 } 555 }
556 556
557 } // namespace courgette 557 } // namespace courgette
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698