@@ -67,6 +67,7 @@ class LinearExecutable::Loader
67
67
bool load_object_page_header (ObjectPageHeader *hdr);
68
68
bool load_fixup_record_offsets (void );
69
69
bool load_fixup_record_table (void );
70
+ bool load_fixup_record_pages (size_t oi);
70
71
71
72
public:
72
73
LinearExecutable *load (istream *is, const std::string &name);
@@ -396,12 +397,11 @@ LinearExecutable::Loader::load_fixup_record_offsets (void)
396
397
}
397
398
398
399
bool
399
- LinearExecutable::Loader::load_fixup_record_table ( void )
400
+ LinearExecutable::Loader::load_fixup_record_pages ( size_t oi )
400
401
{
401
402
Fixup fixup;
402
403
ObjectHeader *obj;
403
404
size_t n;
404
- size_t oi;
405
405
size_t offset;
406
406
size_t end;
407
407
uint8_t addr_flags;
@@ -412,103 +412,114 @@ LinearExecutable::Loader::load_fixup_record_table (void)
412
412
uint8_t obj_index;
413
413
istream *is = this ->is ;
414
414
415
- this -> le -> fixups . resize ( this ->le ->objects . size ()) ;
415
+ obj = & this ->le ->objects [oi] ;
416
416
417
- for (oi = 0 ; oi < this ->le ->objects .size (); oi++)
417
+ for (n = obj->first_page_index ;
418
+ n < obj->first_page_index + obj->page_count ; n++)
418
419
{
419
- obj = &this ->le ->objects [oi];
420
+ offset = this ->header_offset
421
+ + this ->le ->header .fixup_record_table_offset
422
+ + this ->fixup_record_offsets [n];
423
+ end = offset
424
+ + this ->fixup_record_offsets [n + 1 ]
425
+ - this ->fixup_record_offsets [n];
426
+
427
+ is->seekg (offset);
420
428
421
- for (n = obj->first_page_index ;
422
- n < obj->first_page_index + obj->page_count ; n++)
429
+ while (offset < end)
423
430
{
424
- offset = this ->header_offset
425
- + this ->le ->header .fixup_record_table_offset
426
- + this ->fixup_record_offsets [n];
427
- end = offset
428
- + this ->fixup_record_offsets [n + 1 ]
429
- - this ->fixup_record_offsets [n];
431
+ if (end - offset < 2 )
432
+ return false ;
430
433
431
- is->seekg (offset);
434
+ read_u8 (is, &addr_flags);
435
+ read_u8 (is, &reloc_flags);
432
436
433
- while (offset < end)
437
+ if (!is->good ())
438
+ return false ;
439
+
440
+ if ((addr_flags & 0x20 ) != 0 )
434
441
{
435
- if (end - offset < 2 )
436
- return false ;
442
+ cerr << " Fixup lists not supported.\n " ;
443
+ return false ;
444
+ }
445
+
446
+ if ((addr_flags & 0xf ) != 0x7 ) /* 32-bit offset */
447
+ {
448
+ cerr << " Unsupported fixup type " << std::hex << std::showbase
449
+ << (addr_flags & 0xf ) << " .\n " ;
450
+ return false ;
451
+ }
437
452
438
- read_u8 (is, &addr_flags);
439
- read_u8 (is, &reloc_flags);
453
+ if ((reloc_flags & 0x3 ) != 0x0 ) /* internal ref */
454
+ {
455
+ cerr << " Unsupported reloc type " << std::hex << std::showbase
456
+ << (reloc_flags & 0x03 ) << " .\n " ;
457
+ }
440
458
441
- if (!is->good ())
442
- return false ;
459
+ offset += 2 ;
443
460
444
- if ((addr_flags & 0x20 ) != 0 )
445
- {
446
- cerr << " Fixup lists not supported.\n " ;
447
- return false ;
448
- }
449
-
450
- if ((addr_flags & 0xf ) != 0x7 ) /* 32-bit offset */
451
- {
452
- cerr << " Unsupported fixup type " << std::hex << std::showbase
453
- << (addr_flags & 0xf ) << " .\n " ;
454
- return false ;
455
- }
456
-
457
- if ((reloc_flags & 0x3 ) != 0x0 ) /* internal ref */
458
- {
459
- cerr << " Unsupported reloc type " << std::hex << std::showbase
460
- << (reloc_flags & 0x03 ) << " .\n " ;
461
- }
461
+ if (end - offset < 3 )
462
+ return false ;
462
463
463
- offset += 2 ;
464
+ read_le<int16_t > (is, &src_off);
465
+ read_u8 (is, &obj_index);
464
466
465
- if (end - offset < 3 )
466
- return false ;
467
+ if (!is->good ())
468
+ return false ;
469
+
470
+ if (obj_index < 1 || obj_index > this ->le ->objects .size ())
471
+ return false ;
467
472
468
- read_le<int16_t > (is, &src_off);
469
- read_u8 (is, &obj_index);
473
+ obj_index--;
470
474
471
- if (!is->good ())
475
+ offset += 3 ;
476
+
477
+ if ((reloc_flags & 0x10 ) != 0 ) /* 32-bit offset */
478
+ {
479
+ if (end - offset < 4 )
472
480
return false ;
473
481
474
- if (obj_index < 1 || obj_index > this ->le ->objects .size ())
482
+ read_le<uint32_t > (is, &dst_off_32);
483
+ offset += 4 ;
484
+ }
485
+ else /* 16-bit offset */
486
+ {
487
+ if (end - offset < 2 )
475
488
return false ;
476
489
477
- obj_index--;
490
+ read_le<uint16_t > (is, &dst_off_16);
491
+ dst_off_32 = dst_off_16;
492
+ offset += 2 ;
493
+ }
478
494
479
- offset += 3 ;
495
+ if (!is->good ())
496
+ return false ;
480
497
481
- if ((reloc_flags & 0x10 ) != 0 ) /* 32-bit offset */
482
- {
483
- if (end - offset < 4 )
484
- return false ;
498
+ fixup.offset = (n - obj->first_page_index )
499
+ * this ->le ->header .page_size
500
+ + src_off;
501
+ fixup.address = this ->le ->objects [obj_index].base_address
502
+ + dst_off_32;
485
503
486
- read_le<uint32_t > (is, &dst_off_32);
487
- offset += 4 ;
488
- }
489
- else /* 16-bit offset */
490
- {
491
- if (end - offset < 2 )
492
- return false ;
504
+ this ->le ->fixups [oi][fixup.offset ] = fixup;
505
+ this ->le ->fixup_addresses .insert (fixup.address );
506
+ }
507
+ }
493
508
494
- read_le<uint16_t > (is, &dst_off_16);
495
- dst_off_32 = dst_off_16;
496
- offset += 2 ;
497
- }
509
+ return true ;
510
+ }
498
511
499
- if (!is->good ())
500
- return false ;
512
+ bool
513
+ LinearExecutable::Loader::load_fixup_record_table (void )
514
+ {
515
+ size_t oi;
501
516
502
- fixup.offset = (n - obj->first_page_index )
503
- * this ->le ->header .page_size
504
- + src_off;
505
- fixup.address = this ->le ->objects [obj_index].base_address
506
- + dst_off_32;
517
+ this ->le ->fixups .resize (this ->le ->objects .size ());
507
518
508
- this ->le ->fixups [oi][fixup. offset ] = fixup;
509
- this -> le -> fixup_addresses . insert (fixup. address );
510
- }
511
- }
519
+ for (oi = 0 ; oi < this ->le ->objects . size (); oi++)
520
+ {
521
+ if (! load_fixup_record_pages (oi))
522
+ return false ;
512
523
}
513
524
514
525
return true ;
0 commit comments