| ... | @@ -88,7 +88,7 @@ pub fn loadSymbols(allocator: &mem.Allocator, in: &io.FileInStream) !SymbolTable | ... | @@ -88,7 +88,7 @@ pub fn loadSymbols(allocator: &mem.Allocator, in: &io.FileInStream) !SymbolTable |
| 88 | try file.seekTo(0); | 88 | try file.seekTo(0); |
| 89 | | 89 | |
| 90 | var hdr: MachHeader64 = undefined; | 90 | var hdr: MachHeader64 = undefined; |
| 91 | try readNoEof(in, &hdr); | 91 | try readOneNoEof(in, MachHeader64, &hdr); |
| 92 | if (hdr.magic != MH_MAGIC_64) return error.MissingDebugInfo; | 92 | if (hdr.magic != MH_MAGIC_64) return error.MissingDebugInfo; |
| 93 | const is_pie = MH_PIE == (hdr.flags & MH_PIE); | 93 | const is_pie = MH_PIE == (hdr.flags & MH_PIE); |
| 94 | | 94 | |
| ... | @@ -97,7 +97,7 @@ pub fn loadSymbols(allocator: &mem.Allocator, in: &io.FileInStream) !SymbolTable | ... | @@ -97,7 +97,7 @@ pub fn loadSymbols(allocator: &mem.Allocator, in: &io.FileInStream) !SymbolTable |
| 97 | while (ncmd != 0) : (ncmd -= 1) { | 97 | while (ncmd != 0) : (ncmd -= 1) { |
| 98 | try file.seekTo(pos); | 98 | try file.seekTo(pos); |
| 99 | var lc: LoadCommand = undefined; | 99 | var lc: LoadCommand = undefined; |
| 100 | try readNoEof(in, &lc); | 100 | try readOneNoEof(in, LoadCommand, &lc); |
| 101 | if (lc.cmd == LC_SYMTAB) break; | 101 | if (lc.cmd == LC_SYMTAB) break; |
| 102 | pos += lc.cmdsize; | 102 | pos += lc.cmdsize; |
| 103 | } else { | 103 | } else { |
| ... | @@ -105,12 +105,12 @@ pub fn loadSymbols(allocator: &mem.Allocator, in: &io.FileInStream) !SymbolTable | ... | @@ -105,12 +105,12 @@ pub fn loadSymbols(allocator: &mem.Allocator, in: &io.FileInStream) !SymbolTable |
| 105 | } | 105 | } |
| 106 | | 106 | |
| 107 | var cmd: SymtabCommand = undefined; | 107 | var cmd: SymtabCommand = undefined; |
| 108 | try readNoEof(in, &cmd); | 108 | try readOneNoEof(in, SymtabCommand, &cmd); |
| 109 | | 109 | |
| 110 | try file.seekTo(cmd.symoff); | 110 | try file.seekTo(cmd.symoff); |
| 111 | var syms = try allocator.alloc(Nlist64, cmd.nsyms); | 111 | var syms = try allocator.alloc(Nlist64, cmd.nsyms); |
| 112 | defer allocator.free(syms); | 112 | defer allocator.free(syms); |
| 113 | try readNoEof(in, syms); | 113 | try readNoEof(in, Nlist64, syms); |
| 114 | | 114 | |
| 115 | try file.seekTo(cmd.stroff); | 115 | try file.seekTo(cmd.stroff); |
| 116 | var strings = try allocator.alloc(u8, cmd.strsize); | 116 | var strings = try allocator.alloc(u8, cmd.strsize); |
| ... | @@ -158,18 +158,11 @@ pub fn loadSymbols(allocator: &mem.Allocator, in: &io.FileInStream) !SymbolTable | ... | @@ -158,18 +158,11 @@ pub fn loadSymbols(allocator: &mem.Allocator, in: &io.FileInStream) !SymbolTable |
| 158 | }; | 158 | }; |
| 159 | } | 159 | } |
| 160 | | 160 | |
| 161 | fn readNoEof(in: &io.FileInStream, sink: var) !void { | 161 | fn readNoEof(in: &io.FileInStream, comptime T: type, result: []T) !void { |
| 162 | if (@typeOf(sink) == []Nlist64) { | 162 | return in.stream.readNoEof(([]u8)(result)); |
| 163 | const T = @typeOf(sink[0]); | 163 | } |
| 164 | const len = @sizeOf(T) * sink.len; | 164 | fn readOneNoEof(in: &io.FileInStream, comptime T: type, result: &T) !void { |
| 165 | const bytes = @ptrCast(&u8, &sink[0]); | 165 | return readNoEof(in, T, result[0..1]); |
| 166 | return in.stream.readNoEof(bytes[0..len]); | | |
| 167 | } else { | | |
| 168 | const T = @typeOf(*sink); | | |
| 169 | const len = @sizeOf(T); | | |
| 170 | const bytes = @ptrCast(&u8, sink); | | |
| 171 | return in.stream.readNoEof(bytes[0..len]); | | |
| 172 | } | | |
| 173 | } | 166 | } |
| 174 | | 167 | |
| 175 | fn isSymbol(sym: &const Nlist64) bool { | 168 | fn isSymbol(sym: &const Nlist64) bool { |