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