| author | |
| committer | |
| log | a75753338657b85588fe6c54a40fecac0584b336 |
| tree | 9d0e1f367a172d04284b808c629394b4e45d7a98 |
| parent | 178d69191ba008dffd70d2854df09cec556b59dd |
closes #106910 files changed, 161 insertions(+), 120 deletions(-)
std/coff.zig+23-29| ... | ... | @@ -8,9 +8,9 @@ const ArrayList = std.ArrayList; |
| 8 | 8 | |
| 9 | 9 | // CoffHeader.machine values |
| 10 | 10 | // see https://msdn.microsoft.com/en-us/library/windows/desktop/ms680313(v=vs.85).aspx |
| 11 | const IMAGE_FILE_MACHINE_I386 = 0x014c; | |
| 12 | const IMAGE_FILE_MACHINE_IA64 = 0x0200; | |
| 13 | const IMAGE_FILE_MACHINE_AMD64 = 0x8664; | |
| 11 | const IMAGE_FILE_MACHINE_I386 = 0x014c; | |
| 12 | const IMAGE_FILE_MACHINE_IA64 = 0x0200; | |
| 13 | const IMAGE_FILE_MACHINE_AMD64 = 0x8664; | |
| 14 | 14 | |
| 15 | 15 | // OptionalHeader.magic values |
| 16 | 16 | // see https://msdn.microsoft.com/en-us/library/windows/desktop/ms680339(v=vs.85).aspx |
| ... | ... | @@ -20,7 +20,7 @@ const IMAGE_NT_OPTIONAL_HDR64_MAGIC = 0x20b; |
| 20 | 20 | const IMAGE_NUMBEROF_DIRECTORY_ENTRIES = 16; |
| 21 | 21 | const DEBUG_DIRECTORY = 6; |
| 22 | 22 | |
| 23 | pub const CoffError = error { | |
| 23 | pub const CoffError = error{ | |
| 24 | 24 | InvalidPEMagic, |
| 25 | 25 | InvalidPEHeader, |
| 26 | 26 | InvalidMachine, |
| ... | ... | @@ -56,24 +56,21 @@ pub const Coff = struct { |
| 56 | 56 | |
| 57 | 57 | var pe_header_magic: [4]u8 = undefined; |
| 58 | 58 | try in.readNoEof(pe_header_magic[0..]); |
| 59 | if (!mem.eql(u8, pe_header_magic, []u8{'P', 'E', 0, 0})) | |
| 59 | if (!mem.eql(u8, pe_header_magic, []u8{ 'P', 'E', 0, 0 })) | |
| 60 | 60 | return error.InvalidPEHeader; |
| 61 | 61 | |
| 62 | self.coff_header = CoffHeader { | |
| 62 | self.coff_header = CoffHeader{ | |
| 63 | 63 | .machine = try in.readIntLe(u16), |
| 64 | .number_of_sections = try in.readIntLe(u16), | |
| 65 | .timedate_stamp = try in.readIntLe(u32), | |
| 66 | .pointer_to_symbol_table = try in.readIntLe(u32), | |
| 67 | .number_of_symbols = try in.readIntLe(u32), | |
| 68 | .size_of_optional_header = try in.readIntLe(u16), | |
| 69 | .characteristics = try in.readIntLe(u16), | |
| 64 | .number_of_sections = try in.readIntLe(u16), | |
| 65 | .timedate_stamp = try in.readIntLe(u32), | |
| 66 | .pointer_to_symbol_table = try in.readIntLe(u32), | |
| 67 | .number_of_symbols = try in.readIntLe(u32), | |
| 68 | .size_of_optional_header = try in.readIntLe(u16), | |
| 69 | .characteristics = try in.readIntLe(u16), | |
| 70 | 70 | }; |
| 71 | 71 | |
| 72 | 72 | switch (self.coff_header.machine) { |
| 73 | IMAGE_FILE_MACHINE_I386, | |
| 74 | IMAGE_FILE_MACHINE_AMD64, | |
| 75 | IMAGE_FILE_MACHINE_IA64 | |
| 76 | => {}, | |
| 73 | IMAGE_FILE_MACHINE_I386, IMAGE_FILE_MACHINE_AMD64, IMAGE_FILE_MACHINE_IA64 => {}, | |
| 77 | 74 | else => return error.InvalidMachine, |
| 78 | 75 | } |
| 79 | 76 | |
| ... | ... | @@ -89,11 +86,9 @@ pub const Coff = struct { |
| 89 | 86 | var skip_size: u16 = undefined; |
| 90 | 87 | if (self.pe_header.magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC) { |
| 91 | 88 | skip_size = 2 * @sizeOf(u8) + 8 * @sizeOf(u16) + 18 * @sizeOf(u32); |
| 92 | } | |
| 93 | else if (self.pe_header.magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC) { | |
| 89 | } else if (self.pe_header.magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC) { | |
| 94 | 90 | skip_size = 2 * @sizeOf(u8) + 8 * @sizeOf(u16) + 12 * @sizeOf(u32) + 5 * @sizeOf(u64); |
| 95 | } | |
| 96 | else | |
| 91 | } else | |
| 97 | 92 | return error.InvalidPEMagic; |
| 98 | 93 | |
| 99 | 94 | try self.in_file.seekForward(skip_size); |
| ... | ... | @@ -103,7 +98,7 @@ pub const Coff = struct { |
| 103 | 98 | return error.InvalidPEHeader; |
| 104 | 99 | |
| 105 | 100 | for (self.pe_header.data_directory) |*data_dir| { |
| 106 | data_dir.* = OptionalHeader.DataDirectory { | |
| 101 | data_dir.* = OptionalHeader.DataDirectory{ | |
| 107 | 102 | .virtual_address = try in.readIntLe(u32), |
| 108 | 103 | .size = try in.readIntLe(u32), |
| 109 | 104 | }; |
| ... | ... | @@ -114,7 +109,7 @@ pub const Coff = struct { |
| 114 | 109 | try self.loadSections(); |
| 115 | 110 | const header = (self.getSection(".rdata") orelse return error.MissingCoffSection).header; |
| 116 | 111 | |
| 117 | // The linker puts a chunk that contains the .pdb path right after the | |
| 112 | // The linker puts a chunk that contains the .pdb path right after the | |
| 118 | 113 | // debug_directory. |
| 119 | 114 | const debug_dir = &self.pe_header.data_directory[DEBUG_DIRECTORY]; |
| 120 | 115 | const file_offset = debug_dir.virtual_address - header.virtual_address + header.pointer_to_raw_data; |
| ... | ... | @@ -159,10 +154,10 @@ pub const Coff = struct { |
| 159 | 154 | var i: u16 = 0; |
| 160 | 155 | while (i < self.coff_header.number_of_sections) : (i += 1) { |
| 161 | 156 | try in.readNoEof(name[0..]); |
| 162 | try self.sections.append(Section { | |
| 163 | .header = SectionHeader { | |
| 157 | try self.sections.append(Section{ | |
| 158 | .header = SectionHeader{ | |
| 164 | 159 | .name = name, |
| 165 | .misc = SectionHeader.Misc { .physical_address = try in.readIntLe(u32) }, | |
| 160 | .misc = SectionHeader.Misc{ .physical_address = try in.readIntLe(u32) }, | |
| 166 | 161 | .virtual_address = try in.readIntLe(u32), |
| 167 | 162 | .size_of_raw_data = try in.readIntLe(u32), |
| 168 | 163 | .pointer_to_raw_data = try in.readIntLe(u32), |
| ... | ... | @@ -184,7 +179,6 @@ pub const Coff = struct { |
| 184 | 179 | } |
| 185 | 180 | return null; |
| 186 | 181 | } |
| 187 | ||
| 188 | 182 | }; |
| 189 | 183 | |
| 190 | 184 | const CoffHeader = struct { |
| ... | ... | @@ -194,13 +188,13 @@ const CoffHeader = struct { |
| 194 | 188 | pointer_to_symbol_table: u32, |
| 195 | 189 | number_of_symbols: u32, |
| 196 | 190 | size_of_optional_header: u16, |
| 197 | characteristics: u16 | |
| 191 | characteristics: u16, | |
| 198 | 192 | }; |
| 199 | 193 | |
| 200 | 194 | const OptionalHeader = struct { |
| 201 | 195 | const DataDirectory = struct { |
| 202 | 196 | virtual_address: u32, |
| 203 | size: u32 | |
| 197 | size: u32, | |
| 204 | 198 | }; |
| 205 | 199 | |
| 206 | 200 | magic: u16, |
| ... | ... | @@ -214,7 +208,7 @@ pub const Section = struct { |
| 214 | 208 | const SectionHeader = struct { |
| 215 | 209 | const Misc = union { |
| 216 | 210 | physical_address: u32, |
| 217 | virtual_size: u32 | |
| 211 | virtual_size: u32, | |
| 218 | 212 | }; |
| 219 | 213 | |
| 220 | 214 | name: [8]u8, |
std/crypto/x25519.zig+1-1| ... | ... | @@ -115,7 +115,7 @@ pub const X25519 = struct { |
| 115 | 115 | return !zerocmp(u8, out); |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | pub fn createPublicKey(public_key: [] u8, private_key: []const u8) bool { | |
| 118 | pub fn createPublicKey(public_key: []u8, private_key: []const u8) bool { | |
| 119 | 119 | var base_point = []u8{9} ++ []u8{0} ** 31; |
| 120 | 120 | return create(public_key, private_key, base_point); |
| 121 | 121 | } |
std/debug/index.zig+12-11| ... | ... | @@ -242,9 +242,12 @@ pub fn writeCurrentStackTrace(out_stream: var, debug_info: *DebugInfo, tty_color |
| 242 | 242 | } |
| 243 | 243 | } |
| 244 | 244 | |
| 245 | pub fn writeCurrentStackTraceWindows(out_stream: var, debug_info: *DebugInfo, | |
| 246 | tty_color: bool, start_addr: ?usize) !void | |
| 247 | { | |
| 245 | pub fn writeCurrentStackTraceWindows( | |
| 246 | out_stream: var, | |
| 247 | debug_info: *DebugInfo, | |
| 248 | tty_color: bool, | |
| 249 | start_addr: ?usize, | |
| 250 | ) !void { | |
| 248 | 251 | var addr_buf: [1024]usize = undefined; |
| 249 | 252 | const casted_len = @intCast(u32, addr_buf.len); // TODO shouldn't need this cast |
| 250 | 253 | const n = windows.RtlCaptureStackBackTrace(0, casted_len, @ptrCast(**c_void, &addr_buf), null); |
| ... | ... | @@ -391,7 +394,7 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres |
| 391 | 394 | break :subsections null; |
| 392 | 395 | } |
| 393 | 396 | }; |
| 394 | ||
| 397 | ||
| 395 | 398 | if (tty_color) { |
| 396 | 399 | setTtyColor(TtyColor.White); |
| 397 | 400 | if (opt_line_info) |li| { |
| ... | ... | @@ -438,7 +441,7 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres |
| 438 | 441 | } |
| 439 | 442 | } |
| 440 | 443 | |
| 441 | const TtyColor = enum{ | |
| 444 | const TtyColor = enum { | |
| 442 | 445 | Red, |
| 443 | 446 | Green, |
| 444 | 447 | Cyan, |
| ... | ... | @@ -465,18 +468,16 @@ fn setTtyColor(tty_color: TtyColor) void { |
| 465 | 468 | // TODO handle errors |
| 466 | 469 | switch (tty_color) { |
| 467 | 470 | TtyColor.Red => { |
| 468 | _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_RED|windows.FOREGROUND_INTENSITY); | |
| 471 | _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_RED | windows.FOREGROUND_INTENSITY); | |
| 469 | 472 | }, |
| 470 | 473 | TtyColor.Green => { |
| 471 | _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_GREEN|windows.FOREGROUND_INTENSITY); | |
| 474 | _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_GREEN | windows.FOREGROUND_INTENSITY); | |
| 472 | 475 | }, |
| 473 | 476 | TtyColor.Cyan => { |
| 474 | _ = windows.SetConsoleTextAttribute(stderr_file.handle, | |
| 475 | windows.FOREGROUND_GREEN|windows.FOREGROUND_BLUE|windows.FOREGROUND_INTENSITY); | |
| 477 | _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_GREEN | windows.FOREGROUND_BLUE | windows.FOREGROUND_INTENSITY); | |
| 476 | 478 | }, |
| 477 | 479 | TtyColor.White, TtyColor.Bold => { |
| 478 | _ = windows.SetConsoleTextAttribute(stderr_file.handle, | |
| 479 | windows.FOREGROUND_RED|windows.FOREGROUND_GREEN|windows.FOREGROUND_BLUE|windows.FOREGROUND_INTENSITY); | |
| 480 | _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_RED | windows.FOREGROUND_GREEN | windows.FOREGROUND_BLUE | windows.FOREGROUND_INTENSITY); | |
| 480 | 481 | }, |
| 481 | 482 | TtyColor.Dim => { |
| 482 | 483 | _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_INTENSITY); |
std/event/fs.zig+8-7| ... | ... | @@ -119,7 +119,7 @@ pub async fn pwriteWindows(loop: *Loop, fd: os.FileHandle, data: []const u8, off |
| 119 | 119 | }, |
| 120 | 120 | }; |
| 121 | 121 | // TODO only call create io completion port once per fd |
| 122 | _ = try os.windowsCreateIoCompletionPort(fd, loop.os_data.io_port, undefined, undefined); | |
| 122 | _ = windows.CreateIoCompletionPort(fd, loop.os_data.io_port, undefined, undefined); | |
| 123 | 123 | loop.beginOneEvent(); |
| 124 | 124 | errdefer loop.finishOneEvent(); |
| 125 | 125 | |
| ... | ... | @@ -251,7 +251,7 @@ pub async fn preadWindows(loop: *Loop, fd: os.FileHandle, data: []u8, offset: u6 |
| 251 | 251 | }, |
| 252 | 252 | }; |
| 253 | 253 | // TODO only call create io completion port once per fd |
| 254 | _ = try os.windowsCreateIoCompletionPort(fd, loop.os_data.io_port, undefined, undefined); | |
| 254 | _ = windows.CreateIoCompletionPort(fd, loop.os_data.io_port, undefined, undefined); | |
| 255 | 255 | loop.beginOneEvent(); |
| 256 | 256 | errdefer loop.finishOneEvent(); |
| 257 | 257 | |
| ... | ... | @@ -264,12 +264,13 @@ pub async fn preadWindows(loop: *Loop, fd: os.FileHandle, data: []u8, offset: u6 |
| 264 | 264 | var bytes_transferred: windows.DWORD = undefined; |
| 265 | 265 | if (windows.GetOverlappedResult(fd, &resume_node.base.overlapped, &bytes_transferred, windows.FALSE) == 0) { |
| 266 | 266 | const err = windows.GetLastError(); |
| 267 | return switch (err) { | |
| 267 | switch (err) { | |
| 268 | 268 | windows.ERROR.IO_PENDING => unreachable, |
| 269 | windows.ERROR.OPERATION_ABORTED => error.OperationAborted, | |
| 270 | windows.ERROR.BROKEN_PIPE => error.BrokenPipe, | |
| 271 | else => os.unexpectedErrorWindows(err), | |
| 272 | }; | |
| 269 | windows.ERROR.OPERATION_ABORTED => return error.OperationAborted, | |
| 270 | windows.ERROR.BROKEN_PIPE => return error.BrokenPipe, | |
| 271 | windows.ERROR.HANDLE_EOF => return usize(bytes_transferred), | |
| 272 | else => return os.unexpectedErrorWindows(err), | |
| 273 | } | |
| 273 | 274 | } |
| 274 | 275 | return usize(bytes_transferred); |
| 275 | 276 | } |
std/event/loop.zig+5-5| ... | ... | @@ -29,7 +29,7 @@ pub const Loop = struct { |
| 29 | 29 | handle: promise, |
| 30 | 30 | overlapped: Overlapped, |
| 31 | 31 | |
| 32 | const overlapped_init = switch (builtin.os) { | |
| 32 | pub const overlapped_init = switch (builtin.os) { | |
| 33 | 33 | builtin.Os.windows => windows.OVERLAPPED{ |
| 34 | 34 | .Internal = 0, |
| 35 | 35 | .InternalHigh = 0, |
| ... | ... | @@ -39,7 +39,7 @@ pub const Loop = struct { |
| 39 | 39 | }, |
| 40 | 40 | else => {}, |
| 41 | 41 | }; |
| 42 | const Overlapped = @typeOf(overlapped_init); | |
| 42 | pub const Overlapped = @typeOf(overlapped_init); | |
| 43 | 43 | |
| 44 | 44 | pub const Id = enum { |
| 45 | 45 | Basic, |
| ... | ... | @@ -415,6 +415,7 @@ pub const Loop = struct { |
| 415 | 415 | .base = ResumeNode{ |
| 416 | 416 | .id = ResumeNode.Id.Basic, |
| 417 | 417 | .handle = @handle(), |
| 418 | .overlapped = ResumeNode.overlapped_init, | |
| 418 | 419 | }, |
| 419 | 420 | }; |
| 420 | 421 | try self.linuxAddFd(fd, &resume_node.base, flags); |
| ... | ... | @@ -697,11 +698,10 @@ pub const Loop = struct { |
| 697 | 698 | const overlapped = while (true) { |
| 698 | 699 | var nbytes: windows.DWORD = undefined; |
| 699 | 700 | var overlapped: ?*windows.OVERLAPPED = undefined; |
| 700 | switch (os.windowsGetQueuedCompletionStatus(self.os_data.io_port, &nbytes, &completion_key, | |
| 701 | &overlapped, windows.INFINITE)) | |
| 702 | { | |
| 701 | switch (os.windowsGetQueuedCompletionStatus(self.os_data.io_port, &nbytes, &completion_key, &overlapped, windows.INFINITE)) { | |
| 703 | 702 | os.WindowsWaitResult.Aborted => return, |
| 704 | 703 | os.WindowsWaitResult.Normal => {}, |
| 704 | os.WindowsWaitResult.EOF => {}, | |
| 705 | 705 | os.WindowsWaitResult.Cancelled => continue, |
| 706 | 706 | } |
| 707 | 707 | if (overlapped) |o| break o; |
std/event/tcp.zig+1| ... | ... | @@ -32,6 +32,7 @@ pub const Server = struct { |
| 32 | 32 | .listen_resume_node = event.Loop.ResumeNode{ |
| 33 | 33 | .id = event.Loop.ResumeNode.Id.Basic, |
| 34 | 34 | .handle = undefined, |
| 35 | .overlapped = event.Loop.ResumeNode.overlapped_init, | |
| 35 | 36 | }, |
| 36 | 37 | }; |
| 37 | 38 | } |
std/os/child_process.zig+10-2| ... | ... | @@ -658,8 +658,16 @@ fn windowsCreateProcess(app_name: [*]u16, cmd_line: [*]u16, envp_ptr: ?[*]u16, c |
| 658 | 658 | // environment variables to programs that were not, which seems unlikely. |
| 659 | 659 | // More investigation is needed. |
| 660 | 660 | if (windows.CreateProcessW( |
| 661 | app_name, cmd_line, null, null, windows.TRUE, windows.CREATE_UNICODE_ENVIRONMENT, | |
| 662 | @ptrCast(?*c_void, envp_ptr), cwd_ptr, lpStartupInfo, lpProcessInformation, | |
| 661 | app_name, | |
| 662 | cmd_line, | |
| 663 | null, | |
| 664 | null, | |
| 665 | windows.TRUE, | |
| 666 | windows.CREATE_UNICODE_ENVIRONMENT, | |
| 667 | @ptrCast(?*c_void, envp_ptr), | |
| 668 | cwd_ptr, | |
| 669 | lpStartupInfo, | |
| 670 | lpProcessInformation, | |
| 663 | 671 | ) == 0) { |
| 664 | 672 | const err = windows.GetLastError(); |
| 665 | 673 | switch (err) { |
std/os/windows/kernel32.zig-1| ... | ... | @@ -206,7 +206,6 @@ pub const FILE_NOTIFY_CHANGE_DIR_NAME = 2; |
| 206 | 206 | pub const FILE_NOTIFY_CHANGE_FILE_NAME = 1; |
| 207 | 207 | pub const FILE_NOTIFY_CHANGE_ATTRIBUTES = 4; |
| 208 | 208 | |
| 209 | ||
| 210 | 209 | pub const CONSOLE_SCREEN_BUFFER_INFO = extern struct { |
| 211 | 210 | dwSize: COORD, |
| 212 | 211 | dwCursorPosition: COORD, |
std/os/windows/util.zig+3-1| ... | ... | @@ -223,7 +223,7 @@ pub fn windowsFindFirstFile( |
| 223 | 223 | dir_path: []const u8, |
| 224 | 224 | find_file_data: *windows.WIN32_FIND_DATAW, |
| 225 | 225 | ) !windows.HANDLE { |
| 226 | const dir_path_w = try sliceToPrefixedSuffixedFileW(dir_path, []u16{'\\', '*', 0}); | |
| 226 | const dir_path_w = try sliceToPrefixedSuffixedFileW(dir_path, []u16{ '\\', '*', 0 }); | |
| 227 | 227 | const handle = windows.FindFirstFileW(&dir_path_w, find_file_data); |
| 228 | 228 | |
| 229 | 229 | if (handle == windows.INVALID_HANDLE_VALUE) { |
| ... | ... | @@ -278,6 +278,7 @@ pub const WindowsWaitResult = enum { |
| 278 | 278 | Normal, |
| 279 | 279 | Aborted, |
| 280 | 280 | Cancelled, |
| 281 | EOF, | |
| 281 | 282 | }; |
| 282 | 283 | |
| 283 | 284 | pub fn windowsGetQueuedCompletionStatus(completion_port: windows.HANDLE, bytes_transferred_count: *windows.DWORD, lpCompletionKey: *usize, lpOverlapped: *?*windows.OVERLAPPED, dwMilliseconds: windows.DWORD) WindowsWaitResult { |
| ... | ... | @@ -286,6 +287,7 @@ pub fn windowsGetQueuedCompletionStatus(completion_port: windows.HANDLE, bytes_t |
| 286 | 287 | switch (err) { |
| 287 | 288 | windows.ERROR.ABANDONED_WAIT_0 => return WindowsWaitResult.Aborted, |
| 288 | 289 | windows.ERROR.OPERATION_ABORTED => return WindowsWaitResult.Cancelled, |
| 290 | windows.ERROR.HANDLE_EOF => return WindowsWaitResult.EOF, | |
| 289 | 291 | else => { |
| 290 | 292 | if (std.debug.runtime_safety) { |
| 291 | 293 | std.debug.panic("unexpected error: {}\n", err); |
std/pdb.zig+98-63| ... | ... | @@ -64,19 +64,35 @@ pub const ModInfo = packed struct { |
| 64 | 64 | }; |
| 65 | 65 | |
| 66 | 66 | pub const SectionMapHeader = packed struct { |
| 67 | Count: u16, /// Number of segment descriptors | |
| 68 | LogCount: u16, /// Number of logical segment descriptors | |
| 67 | /// Number of segment descriptors | |
| 68 | Count: u16, | |
| 69 | ||
| 70 | /// Number of logical segment descriptors | |
| 71 | LogCount: u16, | |
| 69 | 72 | }; |
| 70 | 73 | |
| 71 | 74 | pub const SectionMapEntry = packed struct { |
| 72 | Flags: u16 , /// See the SectionMapEntryFlags enum below. | |
| 73 | Ovl: u16 , /// Logical overlay number | |
| 74 | Group: u16 , /// Group index into descriptor array. | |
| 75 | Frame: u16 , | |
| 76 | SectionName: u16 , /// Byte index of segment / group name in string table, or 0xFFFF. | |
| 77 | ClassName: u16 , /// Byte index of class in string table, or 0xFFFF. | |
| 78 | Offset: u32 , /// Byte offset of the logical segment within physical segment. If group is set in flags, this is the offset of the group. | |
| 79 | SectionLength: u32 , /// Byte count of the segment or group. | |
| 75 | /// See the SectionMapEntryFlags enum below. | |
| 76 | Flags: u16, | |
| 77 | ||
| 78 | /// Logical overlay number | |
| 79 | Ovl: u16, | |
| 80 | ||
| 81 | /// Group index into descriptor array. | |
| 82 | Group: u16, | |
| 83 | Frame: u16, | |
| 84 | ||
| 85 | /// Byte index of segment / group name in string table, or 0xFFFF. | |
| 86 | SectionName: u16, | |
| 87 | ||
| 88 | /// Byte index of class in string table, or 0xFFFF. | |
| 89 | ClassName: u16, | |
| 90 | ||
| 91 | /// Byte offset of the logical segment within physical segment. If group is set in flags, this is the offset of the group. | |
| 92 | Offset: u32, | |
| 93 | ||
| 94 | /// Byte count of the segment or group. | |
| 95 | SectionLength: u32, | |
| 80 | 96 | }; |
| 81 | 97 | |
| 82 | 98 | pub const StreamType = enum(u16) { |
| ... | ... | @@ -290,13 +306,13 @@ pub const SymbolKind = packed enum(u16) { |
| 290 | 306 | pub const TypeIndex = u32; |
| 291 | 307 | |
| 292 | 308 | pub const ProcSym = packed struct { |
| 293 | Parent: u32 , | |
| 294 | End: u32 , | |
| 295 | Next: u32 , | |
| 296 | CodeSize: u32 , | |
| 297 | DbgStart: u32 , | |
| 298 | DbgEnd: u32 , | |
| 299 | FunctionType: TypeIndex , | |
| 309 | Parent: u32, | |
| 310 | End: u32, | |
| 311 | Next: u32, | |
| 312 | CodeSize: u32, | |
| 313 | DbgStart: u32, | |
| 314 | DbgEnd: u32, | |
| 315 | FunctionType: TypeIndex, | |
| 300 | 316 | CodeOffset: u32, |
| 301 | 317 | Segment: u16, |
| 302 | 318 | Flags: ProcSymFlags, |
| ... | ... | @@ -315,25 +331,34 @@ pub const ProcSymFlags = packed struct { |
| 315 | 331 | HasOptimizedDebugInfo: bool, |
| 316 | 332 | }; |
| 317 | 333 | |
| 318 | pub const SectionContrSubstreamVersion = enum(u32) { | |
| 319 | Ver60 = 0xeffe0000 + 19970605, | |
| 320 | V2 = 0xeffe0000 + 20140516 | |
| 334 | pub const SectionContrSubstreamVersion = enum(u32) { | |
| 335 | Ver60 = 0xeffe0000 + 19970605, | |
| 336 | V2 = 0xeffe0000 + 20140516, | |
| 321 | 337 | }; |
| 322 | 338 | |
| 323 | 339 | pub const RecordPrefix = packed struct { |
| 324 | RecordLen: u16, /// Record length, starting from &RecordKind. | |
| 325 | RecordKind: SymbolKind, /// Record kind enum (SymRecordKind or TypeRecordKind) | |
| 340 | /// Record length, starting from &RecordKind. | |
| 341 | RecordLen: u16, | |
| 342 | ||
| 343 | /// Record kind enum (SymRecordKind or TypeRecordKind) | |
| 344 | RecordKind: SymbolKind, | |
| 326 | 345 | }; |
| 327 | 346 | |
| 328 | 347 | pub const LineFragmentHeader = packed struct { |
| 329 | RelocOffset: u32, /// Code offset of line contribution. | |
| 330 | RelocSegment: u16, /// Code segment of line contribution. | |
| 348 | /// Code offset of line contribution. | |
| 349 | RelocOffset: u32, | |
| 350 | ||
| 351 | /// Code segment of line contribution. | |
| 352 | RelocSegment: u16, | |
| 331 | 353 | Flags: LineFlags, |
| 332 | CodeSize: u32, /// Code size of this line contribution. | |
| 354 | ||
| 355 | /// Code size of this line contribution. | |
| 356 | CodeSize: u32, | |
| 333 | 357 | }; |
| 334 | 358 | |
| 335 | 359 | pub const LineFlags = packed struct { |
| 336 | LF_HaveColumns: bool, /// CV_LINES_HAVE_COLUMNS | |
| 360 | /// CV_LINES_HAVE_COLUMNS | |
| 361 | LF_HaveColumns: bool, | |
| 337 | 362 | unused: u15, |
| 338 | 363 | }; |
| 339 | 364 | |
| ... | ... | @@ -348,12 +373,14 @@ pub const LineBlockFragmentHeader = packed struct { |
| 348 | 373 | /// table of the actual name. |
| 349 | 374 | NameIndex: u32, |
| 350 | 375 | NumLines: u32, |
| 351 | BlockSize: u32, /// code size of block, in bytes | |
| 352 | }; | |
| 353 | 376 | |
| 377 | /// code size of block, in bytes | |
| 378 | BlockSize: u32, | |
| 379 | }; | |
| 354 | 380 | |
| 355 | 381 | pub const LineNumberEntry = packed struct { |
| 356 | Offset: u32, /// Offset to start of code bytes for line number | |
| 382 | /// Offset to start of code bytes for line number | |
| 383 | Offset: u32, | |
| 357 | 384 | Flags: u32, |
| 358 | 385 | |
| 359 | 386 | /// TODO runtime crash when I make the actual type of Flags this |
| ... | ... | @@ -371,42 +398,53 @@ pub const ColumnNumberEntry = packed struct { |
| 371 | 398 | |
| 372 | 399 | /// Checksum bytes follow. |
| 373 | 400 | pub const FileChecksumEntryHeader = packed struct { |
| 374 | FileNameOffset: u32, /// Byte offset of filename in global string table. | |
| 375 | ChecksumSize: u8, /// Number of bytes of checksum. | |
| 376 | ChecksumKind: u8, /// FileChecksumKind | |
| 401 | /// Byte offset of filename in global string table. | |
| 402 | FileNameOffset: u32, | |
| 403 | ||
| 404 | /// Number of bytes of checksum. | |
| 405 | ChecksumSize: u8, | |
| 406 | ||
| 407 | /// FileChecksumKind | |
| 408 | ChecksumKind: u8, | |
| 377 | 409 | }; |
| 378 | 410 | |
| 379 | 411 | pub const DebugSubsectionKind = packed enum(u32) { |
| 380 | None = 0, | |
| 381 | Symbols = 0xf1, | |
| 382 | Lines = 0xf2, | |
| 383 | StringTable = 0xf3, | |
| 384 | FileChecksums = 0xf4, | |
| 385 | FrameData = 0xf5, | |
| 386 | InlineeLines = 0xf6, | |
| 387 | CrossScopeImports = 0xf7, | |
| 388 | CrossScopeExports = 0xf8, | |
| 389 | ||
| 390 | // These appear to relate to .Net assembly info. | |
| 391 | ILLines = 0xf9, | |
| 392 | FuncMDTokenMap = 0xfa, | |
| 393 | TypeMDTokenMap = 0xfb, | |
| 394 | MergedAssemblyInput = 0xfc, | |
| 395 | ||
| 396 | CoffSymbolRVA = 0xfd, | |
| 412 | None = 0, | |
| 413 | Symbols = 0xf1, | |
| 414 | Lines = 0xf2, | |
| 415 | StringTable = 0xf3, | |
| 416 | FileChecksums = 0xf4, | |
| 417 | FrameData = 0xf5, | |
| 418 | InlineeLines = 0xf6, | |
| 419 | CrossScopeImports = 0xf7, | |
| 420 | CrossScopeExports = 0xf8, | |
| 421 | ||
| 422 | // These appear to relate to .Net assembly info. | |
| 423 | ILLines = 0xf9, | |
| 424 | FuncMDTokenMap = 0xfa, | |
| 425 | TypeMDTokenMap = 0xfb, | |
| 426 | MergedAssemblyInput = 0xfc, | |
| 427 | ||
| 428 | CoffSymbolRVA = 0xfd, | |
| 397 | 429 | }; |
| 398 | 430 | |
| 399 | ||
| 400 | 431 | pub const DebugSubsectionHeader = packed struct { |
| 401 | Kind: DebugSubsectionKind, /// codeview::DebugSubsectionKind enum | |
| 402 | Length: u32, /// number of bytes occupied by this record. | |
| 403 | }; | |
| 432 | /// codeview::DebugSubsectionKind enum | |
| 433 | Kind: DebugSubsectionKind, | |
| 404 | 434 | |
| 435 | /// number of bytes occupied by this record. | |
| 436 | Length: u32, | |
| 437 | }; | |
| 405 | 438 | |
| 406 | 439 | pub const PDBStringTableHeader = packed struct { |
| 407 | Signature: u32, /// PDBStringTableSignature | |
| 408 | HashVersion: u32, /// 1 or 2 | |
| 409 | ByteSize: u32, /// Number of bytes of names buffer. | |
| 440 | /// PDBStringTableSignature | |
| 441 | Signature: u32, | |
| 442 | ||
| 443 | /// 1 or 2 | |
| 444 | HashVersion: u32, | |
| 445 | ||
| 446 | /// Number of bytes of names buffer. | |
| 447 | ByteSize: u32, | |
| 410 | 448 | }; |
| 411 | 449 | |
| 412 | 450 | pub const Pdb = struct { |
| ... | ... | @@ -456,7 +494,7 @@ const Msf = struct { |
| 456 | 494 | switch (superblock.BlockSize) { |
| 457 | 495 | // llvm only supports 4096 but we can handle any of these values |
| 458 | 496 | 512, 1024, 2048, 4096 => {}, |
| 459 | else => return error.InvalidDebugInfo | |
| 497 | else => return error.InvalidDebugInfo, | |
| 460 | 498 | } |
| 461 | 499 | |
| 462 | 500 | if (superblock.NumBlocks * superblock.BlockSize != try file.getEndPos()) |
| ... | ... | @@ -536,7 +574,6 @@ const SuperBlock = packed struct { |
| 536 | 574 | /// The number of ulittle32_t’s in this array is given by |
| 537 | 575 | /// ceil(NumDirectoryBytes / BlockSize). |
| 538 | 576 | BlockMapAddr: u32, |
| 539 | ||
| 540 | 577 | }; |
| 541 | 578 | |
| 542 | 579 | const MsfStream = struct { |
| ... | ... | @@ -552,14 +589,12 @@ const MsfStream = struct { |
| 552 | 589 | pub const Stream = io.InStream(Error); |
| 553 | 590 | |
| 554 | 591 | fn init(block_size: u32, block_count: u32, pos: usize, file: os.File, allocator: *mem.Allocator) !MsfStream { |
| 555 | var stream = MsfStream { | |
| 592 | var stream = MsfStream{ | |
| 556 | 593 | .in_file = file, |
| 557 | 594 | .pos = 0, |
| 558 | 595 | .blocks = try allocator.alloc(u32, block_count), |
| 559 | 596 | .block_size = block_size, |
| 560 | .stream = Stream { | |
| 561 | .readFn = readFn, | |
| 562 | }, | |
| 597 | .stream = Stream{ .readFn = readFn }, | |
| 563 | 598 | }; |
| 564 | 599 | |
| 565 | 600 | var file_stream = io.FileInStream.init(file); |
| ... | ... | @@ -597,7 +632,7 @@ const MsfStream = struct { |
| 597 | 632 | |
| 598 | 633 | var size: usize = 0; |
| 599 | 634 | for (buffer) |*byte| { |
| 600 | byte.* = try in.readByte(); | |
| 635 | byte.* = try in.readByte(); | |
| 601 | 636 | |
| 602 | 637 | offset += 1; |
| 603 | 638 | size += 1; |