@@ -24,7 +24,6 @@ const UT = DW.UT;
24
24
const assert = std .debug .assert ;
25
25
const cast = std .math .cast ;
26
26
const maxInt = std .math .maxInt ;
27
- const MemoryAccessor = std .debug .MemoryAccessor ;
28
27
const Path = std .Build .Cache .Path ;
29
28
const FixedBufferReader = std .debug .FixedBufferReader ;
30
29
const ArrayList = std .ArrayList ;
@@ -349,29 +348,9 @@ pub const ExceptionFrameHeader = struct {
349
348
};
350
349
}
351
350
352
- fn isValidPtr (
353
- self : ExceptionFrameHeader ,
354
- comptime T : type ,
355
- ptr : usize ,
356
- ma : * MemoryAccessor ,
357
- eh_frame_len : ? usize ,
358
- ) bool {
359
- if (eh_frame_len ) | len | {
360
- return ptr >= self .eh_frame_ptr and ptr <= self .eh_frame_ptr + len - @sizeOf (T );
361
- } else {
362
- return ma .load (T , ptr ) != null ;
363
- }
364
- }
365
-
366
- /// Find an entry by binary searching the eh_frame_hdr section.
367
- ///
368
- /// Since the length of the eh_frame section (`eh_frame_len`) may not be known by the caller,
369
- /// MemoryAccessor will be used to verify readability of the header entries.
370
- /// If `eh_frame_len` is provided, then these checks can be skipped.
371
351
pub fn findEntry (
372
352
self : ExceptionFrameHeader ,
373
- ma : * MemoryAccessor ,
374
- eh_frame_len : ? usize ,
353
+ eh_frame_len : usize ,
375
354
eh_frame_hdr_ptr : usize ,
376
355
pc : usize ,
377
356
cie : * CommonInformationEntry ,
@@ -421,8 +400,7 @@ pub const ExceptionFrameHeader = struct {
421
400
422
401
if (fde_ptr < self .eh_frame_ptr ) return bad ();
423
402
424
- // Even if eh_frame_len is not specified, all ranges accssed are checked via MemoryAccessor
425
- const eh_frame = @as ([* ]const u8 , @ptrFromInt (self .eh_frame_ptr ))[0 .. eh_frame_len orelse maxInt (u32 )];
403
+ const eh_frame = @as ([* ]const u8 , @ptrFromInt (self .eh_frame_ptr ))[0.. eh_frame_len ];
426
404
427
405
const fde_offset = fde_ptr - self .eh_frame_ptr ;
428
406
var eh_frame_fbr : FixedBufferReader = .{
@@ -431,15 +409,13 @@ pub const ExceptionFrameHeader = struct {
431
409
.endian = native_endian ,
432
410
};
433
411
434
- const fde_entry_header = try EntryHeader .read (& eh_frame_fbr , if (eh_frame_len == null ) ma else null , .eh_frame );
435
- if (fde_entry_header .entry_bytes .len > 0 and ! self .isValidPtr (u8 , @intFromPtr (& fde_entry_header .entry_bytes [fde_entry_header .entry_bytes .len - 1 ]), ma , eh_frame_len )) return bad ();
412
+ const fde_entry_header = try EntryHeader .read (& eh_frame_fbr , .eh_frame );
436
413
if (fde_entry_header .type != .fde ) return bad ();
437
414
438
415
// CIEs always come before FDEs (the offset is a subtraction), so we can assume this memory is readable
439
416
const cie_offset = fde_entry_header .type .fde ;
440
417
try eh_frame_fbr .seekTo (cie_offset );
441
- const cie_entry_header = try EntryHeader .read (& eh_frame_fbr , if (eh_frame_len == null ) ma else null , .eh_frame );
442
- if (cie_entry_header .entry_bytes .len > 0 and ! self .isValidPtr (u8 , @intFromPtr (& cie_entry_header .entry_bytes [cie_entry_header .entry_bytes .len - 1 ]), ma , eh_frame_len )) return bad ();
418
+ const cie_entry_header = try EntryHeader .read (& eh_frame_fbr , .eh_frame );
443
419
if (cie_entry_header .type != .cie ) return bad ();
444
420
445
421
cie .* = try CommonInformationEntry .parse (
@@ -486,15 +462,11 @@ pub const EntryHeader = struct {
486
462
487
463
/// Reads a header for either an FDE or a CIE, then advances the fbr to the position after the trailing structure.
488
464
/// `fbr` must be a FixedBufferReader backed by either the .eh_frame or .debug_frame sections.
489
- pub fn read (
490
- fbr : * FixedBufferReader ,
491
- opt_ma : ? * MemoryAccessor ,
492
- dwarf_section : Section.Id ,
493
- ) ! EntryHeader {
465
+ pub fn read (fbr : * FixedBufferReader , dwarf_section : Section.Id ) ! EntryHeader {
494
466
assert (dwarf_section == .eh_frame or dwarf_section == .debug_frame );
495
467
496
468
const length_offset = fbr .pos ;
497
- const unit_header = try readUnitHeader (fbr , opt_ma );
469
+ const unit_header = try readUnitHeader (fbr );
498
470
const unit_length = cast (usize , unit_header .unit_length ) orelse return bad ();
499
471
if (unit_length == 0 ) return .{
500
472
.length_offset = length_offset ,
@@ -506,10 +478,7 @@ pub const EntryHeader = struct {
506
478
const end_offset = start_offset + unit_length ;
507
479
defer fbr .pos = end_offset ;
508
480
509
- const id = try if (opt_ma ) | ma |
510
- fbr .readAddressChecked (unit_header .format , ma )
511
- else
512
- fbr .readAddress (unit_header .format );
481
+ const id = try fbr .readAddress (unit_header .format );
513
482
const entry_bytes = fbr .buf [fbr .pos .. end_offset ];
514
483
const cie_id : u64 = switch (dwarf_section ) {
515
484
.eh_frame = > CommonInformationEntry .eh_id ,
@@ -856,7 +825,7 @@ fn scanAllFunctions(di: *Dwarf, allocator: Allocator) ScanError!void {
856
825
while (this_unit_offset < fbr .buf .len ) {
857
826
try fbr .seekTo (this_unit_offset );
858
827
859
- const unit_header = try readUnitHeader (& fbr , null );
828
+ const unit_header = try readUnitHeader (& fbr );
860
829
if (unit_header .unit_length == 0 ) return ;
861
830
const next_offset = unit_header .header_length + unit_header .unit_length ;
862
831
@@ -1045,7 +1014,7 @@ fn scanAllCompileUnits(di: *Dwarf, allocator: Allocator) ScanError!void {
1045
1014
while (this_unit_offset < fbr .buf .len ) {
1046
1015
try fbr .seekTo (this_unit_offset );
1047
1016
1048
- const unit_header = try readUnitHeader (& fbr , null );
1017
+ const unit_header = try readUnitHeader (& fbr );
1049
1018
if (unit_header .unit_length == 0 ) return ;
1050
1019
const next_offset = unit_header .header_length + unit_header .unit_length ;
1051
1020
@@ -1427,7 +1396,7 @@ fn runLineNumberProgram(d: *Dwarf, gpa: Allocator, compile_unit: *CompileUnit) !
1427
1396
};
1428
1397
try fbr .seekTo (line_info_offset );
1429
1398
1430
- const unit_header = try readUnitHeader (& fbr , null );
1399
+ const unit_header = try readUnitHeader (& fbr );
1431
1400
if (unit_header .unit_length == 0 ) return missing ();
1432
1401
1433
1402
const next_offset = unit_header .header_length + unit_header .unit_length ;
@@ -1815,7 +1784,7 @@ pub fn scanCieFdeInfo(di: *Dwarf, allocator: Allocator, base_address: usize) !vo
1815
1784
if (di .section (frame_section )) | section_data | {
1816
1785
var fbr : FixedBufferReader = .{ .buf = section_data , .endian = di .endian };
1817
1786
while (fbr .pos < fbr .buf .len ) {
1818
- const entry_header = try EntryHeader .read (& fbr , null , frame_section );
1787
+ const entry_header = try EntryHeader .read (& fbr , frame_section );
1819
1788
switch (entry_header .type ) {
1820
1789
.cie = > {
1821
1790
const cie = try CommonInformationEntry .parse (
@@ -1988,8 +1957,8 @@ const UnitHeader = struct {
1988
1957
unit_length : u64 ,
1989
1958
};
1990
1959
1991
- fn readUnitHeader (fbr : * FixedBufferReader , opt_ma : ? * MemoryAccessor ) ScanError ! UnitHeader {
1992
- return switch (try if ( opt_ma ) | ma | fbr . readIntChecked ( u32 , ma ) else fbr .readInt (u32 )) {
1960
+ fn readUnitHeader (fbr : * FixedBufferReader ) ScanError ! UnitHeader {
1961
+ return switch (try fbr .readInt (u32 )) {
1993
1962
0... 0xfffffff0 - 1 = > | unit_length | .{
1994
1963
.format = .@"32" ,
1995
1964
.header_length = 4 ,
@@ -1999,7 +1968,7 @@ fn readUnitHeader(fbr: *FixedBufferReader, opt_ma: ?*MemoryAccessor) ScanError!U
1999
1968
0xffffffff = > .{
2000
1969
.format = .@"64" ,
2001
1970
.header_length = 12 ,
2002
- .unit_length = try if ( opt_ma ) | ma | fbr . readIntChecked ( u64 , ma ) else fbr .readInt (u64 ),
1971
+ .unit_length = try fbr .readInt (u64 ),
2003
1972
},
2004
1973
};
2005
1974
}
0 commit comments