From 178d69191ba008dffd70d2854df09cec556b59dd Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 12 Sep 2018 13:55:02 -0400 Subject: windows: std.fs functions support concurrent ops when reading and writing the same file descriptors --- std/event/loop.zig | 46 +++++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 15 deletions(-) (limited to 'std/event/loop.zig') diff --git a/std/event/loop.zig b/std/event/loop.zig index 733112549d..6cd22ff69e 100644 --- a/std/event/loop.zig +++ b/std/event/loop.zig @@ -27,6 +27,19 @@ pub const Loop = struct { pub const ResumeNode = struct { id: Id, handle: promise, + overlapped: Overlapped, + + const overlapped_init = switch (builtin.os) { + builtin.Os.windows => windows.OVERLAPPED{ + .Internal = 0, + .InternalHigh = 0, + .Offset = 0, + .OffsetHigh = 0, + .hEvent = null, + }, + else => {}, + }; + const Overlapped = @typeOf(overlapped_init); pub const Id = enum { Basic, @@ -101,6 +114,7 @@ pub const Loop = struct { .final_resume_node = ResumeNode{ .id = ResumeNode.Id.Stop, .handle = undefined, + .overlapped = ResumeNode.overlapped_init, }, }; const extra_thread_count = thread_count - 1; @@ -153,6 +167,7 @@ pub const Loop = struct { .base = ResumeNode{ .id = ResumeNode.Id.EventFd, .handle = undefined, + .overlapped = ResumeNode.overlapped_init, }, .eventfd = try os.linuxEventFd(1, posix.EFD_CLOEXEC | posix.EFD_NONBLOCK), .epoll_op = posix.EPOLL_CTL_ADD, @@ -225,6 +240,7 @@ pub const Loop = struct { .base = ResumeNode{ .id = ResumeNode.Id.EventFd, .handle = undefined, + .overlapped = ResumeNode.overlapped_init, }, // this one is for sending events .kevent = posix.Kevent{ @@ -311,6 +327,7 @@ pub const Loop = struct { .base = ResumeNode{ .id = ResumeNode.Id.EventFd, .handle = undefined, + .overlapped = ResumeNode.overlapped_init, }, // this one is for sending events .completion_key = @ptrToInt(&eventfd_node.data.base), @@ -325,8 +342,8 @@ pub const Loop = struct { var i: usize = 0; while (i < extra_thread_index) : (i += 1) { while (true) { - const overlapped = @intToPtr(?*windows.OVERLAPPED, 0x1); - os.windowsPostQueuedCompletionStatus(self.os_data.io_port, undefined, @ptrToInt(&self.final_resume_node), overlapped) catch continue; + const overlapped = &self.final_resume_node.overlapped; + os.windowsPostQueuedCompletionStatus(self.os_data.io_port, undefined, undefined, overlapped) catch continue; break; } } @@ -413,6 +430,7 @@ pub const Loop = struct { .base = ResumeNode{ .id = ResumeNode.Id.Basic, .handle = @handle(), + .overlapped = ResumeNode.overlapped_init, }, .kev = undefined, }; @@ -489,15 +507,11 @@ pub const Loop = struct { }; }, builtin.Os.windows => { - // this value is never dereferenced but we need it to be non-null so that - // the consumer code can decide whether to read the completion key. - // it has to do this for normal I/O, so we match that behavior here. - const overlapped = @intToPtr(?*windows.OVERLAPPED, 0x1); os.windowsPostQueuedCompletionStatus( self.os_data.io_port, undefined, - eventfd_node.completion_key, - overlapped, + undefined, + &eventfd_node.base.overlapped, ) catch { self.next_tick_queue.unget(next_tick_node); self.available_eventfd_resume_nodes.push(resume_stack_node); @@ -606,8 +620,8 @@ pub const Loop = struct { var i: usize = 0; while (i < self.extra_threads.len + 1) : (i += 1) { while (true) { - const overlapped = @intToPtr(?*windows.OVERLAPPED, 0x1); - os.windowsPostQueuedCompletionStatus(self.os_data.io_port, undefined, @ptrToInt(&self.final_resume_node), overlapped) catch continue; + const overlapped = &self.final_resume_node.overlapped; + os.windowsPostQueuedCompletionStatus(self.os_data.io_port, undefined, undefined, overlapped) catch continue; break; } } @@ -680,17 +694,19 @@ pub const Loop = struct { }, builtin.Os.windows => { var completion_key: usize = undefined; - while (true) { + const overlapped = while (true) { var nbytes: windows.DWORD = undefined; var overlapped: ?*windows.OVERLAPPED = undefined; - switch (os.windowsGetQueuedCompletionStatus(self.os_data.io_port, &nbytes, &completion_key, &overlapped, windows.INFINITE)) { + switch (os.windowsGetQueuedCompletionStatus(self.os_data.io_port, &nbytes, &completion_key, + &overlapped, windows.INFINITE)) + { os.WindowsWaitResult.Aborted => return, os.WindowsWaitResult.Normal => {}, os.WindowsWaitResult.Cancelled => continue, } - if (overlapped != null) break; - } - const resume_node = @intToPtr(*ResumeNode, completion_key); + if (overlapped) |o| break o; + } else unreachable; // TODO else unreachable should not be necessary + const resume_node = @fieldParentPtr(ResumeNode, "overlapped", overlapped); const handle = resume_node.handle; const resume_node_id = resume_node.id; switch (resume_node_id) { -- cgit v1.2.3 From a75753338657b85588fe6c54a40fecac0584b336 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 12 Sep 2018 14:26:21 -0400 Subject: fix zig fmt on windows closes #1069 --- std/coff.zig | 52 +++++++------- std/crypto/x25519.zig | 2 +- std/debug/index.zig | 23 ++++--- std/event/fs.zig | 15 +++-- std/event/loop.zig | 10 +-- std/event/tcp.zig | 1 + std/os/child_process.zig | 12 +++- std/os/windows/kernel32.zig | 1 - std/os/windows/util.zig | 4 +- std/pdb.zig | 161 +++++++++++++++++++++++++++----------------- 10 files changed, 161 insertions(+), 120 deletions(-) (limited to 'std/event/loop.zig') diff --git a/std/coff.zig b/std/coff.zig index 379fd1af42..bf5a93ef30 100644 --- a/std/coff.zig +++ b/std/coff.zig @@ -8,9 +8,9 @@ const ArrayList = std.ArrayList; // CoffHeader.machine values // see https://msdn.microsoft.com/en-us/library/windows/desktop/ms680313(v=vs.85).aspx -const IMAGE_FILE_MACHINE_I386 = 0x014c; -const IMAGE_FILE_MACHINE_IA64 = 0x0200; -const IMAGE_FILE_MACHINE_AMD64 = 0x8664; +const IMAGE_FILE_MACHINE_I386 = 0x014c; +const IMAGE_FILE_MACHINE_IA64 = 0x0200; +const IMAGE_FILE_MACHINE_AMD64 = 0x8664; // OptionalHeader.magic values // 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; const IMAGE_NUMBEROF_DIRECTORY_ENTRIES = 16; const DEBUG_DIRECTORY = 6; -pub const CoffError = error { +pub const CoffError = error{ InvalidPEMagic, InvalidPEHeader, InvalidMachine, @@ -56,24 +56,21 @@ pub const Coff = struct { var pe_header_magic: [4]u8 = undefined; try in.readNoEof(pe_header_magic[0..]); - if (!mem.eql(u8, pe_header_magic, []u8{'P', 'E', 0, 0})) + if (!mem.eql(u8, pe_header_magic, []u8{ 'P', 'E', 0, 0 })) return error.InvalidPEHeader; - self.coff_header = CoffHeader { + self.coff_header = CoffHeader{ .machine = try in.readIntLe(u16), - .number_of_sections = try in.readIntLe(u16), - .timedate_stamp = try in.readIntLe(u32), - .pointer_to_symbol_table = try in.readIntLe(u32), - .number_of_symbols = try in.readIntLe(u32), - .size_of_optional_header = try in.readIntLe(u16), - .characteristics = try in.readIntLe(u16), + .number_of_sections = try in.readIntLe(u16), + .timedate_stamp = try in.readIntLe(u32), + .pointer_to_symbol_table = try in.readIntLe(u32), + .number_of_symbols = try in.readIntLe(u32), + .size_of_optional_header = try in.readIntLe(u16), + .characteristics = try in.readIntLe(u16), }; switch (self.coff_header.machine) { - IMAGE_FILE_MACHINE_I386, - IMAGE_FILE_MACHINE_AMD64, - IMAGE_FILE_MACHINE_IA64 - => {}, + IMAGE_FILE_MACHINE_I386, IMAGE_FILE_MACHINE_AMD64, IMAGE_FILE_MACHINE_IA64 => {}, else => return error.InvalidMachine, } @@ -89,11 +86,9 @@ pub const Coff = struct { var skip_size: u16 = undefined; if (self.pe_header.magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC) { skip_size = 2 * @sizeOf(u8) + 8 * @sizeOf(u16) + 18 * @sizeOf(u32); - } - else if (self.pe_header.magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC) { + } else if (self.pe_header.magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC) { skip_size = 2 * @sizeOf(u8) + 8 * @sizeOf(u16) + 12 * @sizeOf(u32) + 5 * @sizeOf(u64); - } - else + } else return error.InvalidPEMagic; try self.in_file.seekForward(skip_size); @@ -103,7 +98,7 @@ pub const Coff = struct { return error.InvalidPEHeader; for (self.pe_header.data_directory) |*data_dir| { - data_dir.* = OptionalHeader.DataDirectory { + data_dir.* = OptionalHeader.DataDirectory{ .virtual_address = try in.readIntLe(u32), .size = try in.readIntLe(u32), }; @@ -114,7 +109,7 @@ pub const Coff = struct { try self.loadSections(); const header = (self.getSection(".rdata") orelse return error.MissingCoffSection).header; - // The linker puts a chunk that contains the .pdb path right after the + // The linker puts a chunk that contains the .pdb path right after the // debug_directory. const debug_dir = &self.pe_header.data_directory[DEBUG_DIRECTORY]; const file_offset = debug_dir.virtual_address - header.virtual_address + header.pointer_to_raw_data; @@ -159,10 +154,10 @@ pub const Coff = struct { var i: u16 = 0; while (i < self.coff_header.number_of_sections) : (i += 1) { try in.readNoEof(name[0..]); - try self.sections.append(Section { - .header = SectionHeader { + try self.sections.append(Section{ + .header = SectionHeader{ .name = name, - .misc = SectionHeader.Misc { .physical_address = try in.readIntLe(u32) }, + .misc = SectionHeader.Misc{ .physical_address = try in.readIntLe(u32) }, .virtual_address = try in.readIntLe(u32), .size_of_raw_data = try in.readIntLe(u32), .pointer_to_raw_data = try in.readIntLe(u32), @@ -184,7 +179,6 @@ pub const Coff = struct { } return null; } - }; const CoffHeader = struct { @@ -194,13 +188,13 @@ const CoffHeader = struct { pointer_to_symbol_table: u32, number_of_symbols: u32, size_of_optional_header: u16, - characteristics: u16 + characteristics: u16, }; const OptionalHeader = struct { const DataDirectory = struct { virtual_address: u32, - size: u32 + size: u32, }; magic: u16, @@ -214,7 +208,7 @@ pub const Section = struct { const SectionHeader = struct { const Misc = union { physical_address: u32, - virtual_size: u32 + virtual_size: u32, }; name: [8]u8, diff --git a/std/crypto/x25519.zig b/std/crypto/x25519.zig index 41b2ff0959..bf78511f9a 100644 --- a/std/crypto/x25519.zig +++ b/std/crypto/x25519.zig @@ -115,7 +115,7 @@ pub const X25519 = struct { return !zerocmp(u8, out); } - pub fn createPublicKey(public_key: [] u8, private_key: []const u8) bool { + pub fn createPublicKey(public_key: []u8, private_key: []const u8) bool { var base_point = []u8{9} ++ []u8{0} ** 31; return create(public_key, private_key, base_point); } diff --git a/std/debug/index.zig b/std/debug/index.zig index 8db7c75d2c..14e8b9197a 100644 --- a/std/debug/index.zig +++ b/std/debug/index.zig @@ -242,9 +242,12 @@ pub fn writeCurrentStackTrace(out_stream: var, debug_info: *DebugInfo, tty_color } } -pub fn writeCurrentStackTraceWindows(out_stream: var, debug_info: *DebugInfo, - tty_color: bool, start_addr: ?usize) !void -{ +pub fn writeCurrentStackTraceWindows( + out_stream: var, + debug_info: *DebugInfo, + tty_color: bool, + start_addr: ?usize, +) !void { var addr_buf: [1024]usize = undefined; const casted_len = @intCast(u32, addr_buf.len); // TODO shouldn't need this cast 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 break :subsections null; } }; - + if (tty_color) { setTtyColor(TtyColor.White); if (opt_line_info) |li| { @@ -438,7 +441,7 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres } } -const TtyColor = enum{ +const TtyColor = enum { Red, Green, Cyan, @@ -465,18 +468,16 @@ fn setTtyColor(tty_color: TtyColor) void { // TODO handle errors switch (tty_color) { TtyColor.Red => { - _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_RED|windows.FOREGROUND_INTENSITY); + _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_RED | windows.FOREGROUND_INTENSITY); }, TtyColor.Green => { - _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_GREEN|windows.FOREGROUND_INTENSITY); + _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_GREEN | windows.FOREGROUND_INTENSITY); }, TtyColor.Cyan => { - _ = windows.SetConsoleTextAttribute(stderr_file.handle, - windows.FOREGROUND_GREEN|windows.FOREGROUND_BLUE|windows.FOREGROUND_INTENSITY); + _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_GREEN | windows.FOREGROUND_BLUE | windows.FOREGROUND_INTENSITY); }, TtyColor.White, TtyColor.Bold => { - _ = windows.SetConsoleTextAttribute(stderr_file.handle, - windows.FOREGROUND_RED|windows.FOREGROUND_GREEN|windows.FOREGROUND_BLUE|windows.FOREGROUND_INTENSITY); + _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_RED | windows.FOREGROUND_GREEN | windows.FOREGROUND_BLUE | windows.FOREGROUND_INTENSITY); }, TtyColor.Dim => { _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_INTENSITY); diff --git a/std/event/fs.zig b/std/event/fs.zig index c13a940a36..5635471212 100644 --- a/std/event/fs.zig +++ b/std/event/fs.zig @@ -119,7 +119,7 @@ pub async fn pwriteWindows(loop: *Loop, fd: os.FileHandle, data: []const u8, off }, }; // TODO only call create io completion port once per fd - _ = try os.windowsCreateIoCompletionPort(fd, loop.os_data.io_port, undefined, undefined); + _ = windows.CreateIoCompletionPort(fd, loop.os_data.io_port, undefined, undefined); loop.beginOneEvent(); errdefer loop.finishOneEvent(); @@ -251,7 +251,7 @@ pub async fn preadWindows(loop: *Loop, fd: os.FileHandle, data: []u8, offset: u6 }, }; // TODO only call create io completion port once per fd - _ = try os.windowsCreateIoCompletionPort(fd, loop.os_data.io_port, undefined, undefined); + _ = windows.CreateIoCompletionPort(fd, loop.os_data.io_port, undefined, undefined); loop.beginOneEvent(); errdefer loop.finishOneEvent(); @@ -264,12 +264,13 @@ pub async fn preadWindows(loop: *Loop, fd: os.FileHandle, data: []u8, offset: u6 var bytes_transferred: windows.DWORD = undefined; if (windows.GetOverlappedResult(fd, &resume_node.base.overlapped, &bytes_transferred, windows.FALSE) == 0) { const err = windows.GetLastError(); - return switch (err) { + switch (err) { windows.ERROR.IO_PENDING => unreachable, - windows.ERROR.OPERATION_ABORTED => error.OperationAborted, - windows.ERROR.BROKEN_PIPE => error.BrokenPipe, - else => os.unexpectedErrorWindows(err), - }; + windows.ERROR.OPERATION_ABORTED => return error.OperationAborted, + windows.ERROR.BROKEN_PIPE => return error.BrokenPipe, + windows.ERROR.HANDLE_EOF => return usize(bytes_transferred), + else => return os.unexpectedErrorWindows(err), + } } return usize(bytes_transferred); } diff --git a/std/event/loop.zig b/std/event/loop.zig index 6cd22ff69e..e87e928049 100644 --- a/std/event/loop.zig +++ b/std/event/loop.zig @@ -29,7 +29,7 @@ pub const Loop = struct { handle: promise, overlapped: Overlapped, - const overlapped_init = switch (builtin.os) { + pub const overlapped_init = switch (builtin.os) { builtin.Os.windows => windows.OVERLAPPED{ .Internal = 0, .InternalHigh = 0, @@ -39,7 +39,7 @@ pub const Loop = struct { }, else => {}, }; - const Overlapped = @typeOf(overlapped_init); + pub const Overlapped = @typeOf(overlapped_init); pub const Id = enum { Basic, @@ -415,6 +415,7 @@ pub const Loop = struct { .base = ResumeNode{ .id = ResumeNode.Id.Basic, .handle = @handle(), + .overlapped = ResumeNode.overlapped_init, }, }; try self.linuxAddFd(fd, &resume_node.base, flags); @@ -697,11 +698,10 @@ pub const Loop = struct { const overlapped = while (true) { var nbytes: windows.DWORD = undefined; var overlapped: ?*windows.OVERLAPPED = undefined; - switch (os.windowsGetQueuedCompletionStatus(self.os_data.io_port, &nbytes, &completion_key, - &overlapped, windows.INFINITE)) - { + switch (os.windowsGetQueuedCompletionStatus(self.os_data.io_port, &nbytes, &completion_key, &overlapped, windows.INFINITE)) { os.WindowsWaitResult.Aborted => return, os.WindowsWaitResult.Normal => {}, + os.WindowsWaitResult.EOF => {}, os.WindowsWaitResult.Cancelled => continue, } if (overlapped) |o| break o; diff --git a/std/event/tcp.zig b/std/event/tcp.zig index 491acab39d..69b143dda0 100644 --- a/std/event/tcp.zig +++ b/std/event/tcp.zig @@ -32,6 +32,7 @@ pub const Server = struct { .listen_resume_node = event.Loop.ResumeNode{ .id = event.Loop.ResumeNode.Id.Basic, .handle = undefined, + .overlapped = event.Loop.ResumeNode.overlapped_init, }, }; } diff --git a/std/os/child_process.zig b/std/os/child_process.zig index a8f307f3b6..8b76a3cb9e 100644 --- a/std/os/child_process.zig +++ b/std/os/child_process.zig @@ -658,8 +658,16 @@ fn windowsCreateProcess(app_name: [*]u16, cmd_line: [*]u16, envp_ptr: ?[*]u16, c // environment variables to programs that were not, which seems unlikely. // More investigation is needed. if (windows.CreateProcessW( - app_name, cmd_line, null, null, windows.TRUE, windows.CREATE_UNICODE_ENVIRONMENT, - @ptrCast(?*c_void, envp_ptr), cwd_ptr, lpStartupInfo, lpProcessInformation, + app_name, + cmd_line, + null, + null, + windows.TRUE, + windows.CREATE_UNICODE_ENVIRONMENT, + @ptrCast(?*c_void, envp_ptr), + cwd_ptr, + lpStartupInfo, + lpProcessInformation, ) == 0) { const err = windows.GetLastError(); switch (err) { diff --git a/std/os/windows/kernel32.zig b/std/os/windows/kernel32.zig index 1a7b28eac2..94b339fa6e 100644 --- a/std/os/windows/kernel32.zig +++ b/std/os/windows/kernel32.zig @@ -206,7 +206,6 @@ pub const FILE_NOTIFY_CHANGE_DIR_NAME = 2; pub const FILE_NOTIFY_CHANGE_FILE_NAME = 1; pub const FILE_NOTIFY_CHANGE_ATTRIBUTES = 4; - pub const CONSOLE_SCREEN_BUFFER_INFO = extern struct { dwSize: COORD, dwCursorPosition: COORD, diff --git a/std/os/windows/util.zig b/std/os/windows/util.zig index 2a1a82a963..6534d16f5e 100644 --- a/std/os/windows/util.zig +++ b/std/os/windows/util.zig @@ -223,7 +223,7 @@ pub fn windowsFindFirstFile( dir_path: []const u8, find_file_data: *windows.WIN32_FIND_DATAW, ) !windows.HANDLE { - const dir_path_w = try sliceToPrefixedSuffixedFileW(dir_path, []u16{'\\', '*', 0}); + const dir_path_w = try sliceToPrefixedSuffixedFileW(dir_path, []u16{ '\\', '*', 0 }); const handle = windows.FindFirstFileW(&dir_path_w, find_file_data); if (handle == windows.INVALID_HANDLE_VALUE) { @@ -278,6 +278,7 @@ pub const WindowsWaitResult = enum { Normal, Aborted, Cancelled, + EOF, }; 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 switch (err) { windows.ERROR.ABANDONED_WAIT_0 => return WindowsWaitResult.Aborted, windows.ERROR.OPERATION_ABORTED => return WindowsWaitResult.Cancelled, + windows.ERROR.HANDLE_EOF => return WindowsWaitResult.EOF, else => { if (std.debug.runtime_safety) { std.debug.panic("unexpected error: {}\n", err); diff --git a/std/pdb.zig b/std/pdb.zig index 907eddff04..3bb6c9d58d 100644 --- a/std/pdb.zig +++ b/std/pdb.zig @@ -64,19 +64,35 @@ pub const ModInfo = packed struct { }; pub const SectionMapHeader = packed struct { - Count: u16, /// Number of segment descriptors - LogCount: u16, /// Number of logical segment descriptors + /// Number of segment descriptors + Count: u16, + + /// Number of logical segment descriptors + LogCount: u16, }; pub const SectionMapEntry = packed struct { - Flags: u16 , /// See the SectionMapEntryFlags enum below. - Ovl: u16 , /// Logical overlay number - Group: u16 , /// Group index into descriptor array. - Frame: u16 , - SectionName: u16 , /// Byte index of segment / group name in string table, or 0xFFFF. - ClassName: u16 , /// Byte index of class in string table, or 0xFFFF. - Offset: u32 , /// Byte offset of the logical segment within physical segment. If group is set in flags, this is the offset of the group. - SectionLength: u32 , /// Byte count of the segment or group. + /// See the SectionMapEntryFlags enum below. + Flags: u16, + + /// Logical overlay number + Ovl: u16, + + /// Group index into descriptor array. + Group: u16, + Frame: u16, + + /// Byte index of segment / group name in string table, or 0xFFFF. + SectionName: u16, + + /// Byte index of class in string table, or 0xFFFF. + ClassName: u16, + + /// Byte offset of the logical segment within physical segment. If group is set in flags, this is the offset of the group. + Offset: u32, + + /// Byte count of the segment or group. + SectionLength: u32, }; pub const StreamType = enum(u16) { @@ -290,13 +306,13 @@ pub const SymbolKind = packed enum(u16) { pub const TypeIndex = u32; pub const ProcSym = packed struct { - Parent: u32 , - End: u32 , - Next: u32 , - CodeSize: u32 , - DbgStart: u32 , - DbgEnd: u32 , - FunctionType: TypeIndex , + Parent: u32, + End: u32, + Next: u32, + CodeSize: u32, + DbgStart: u32, + DbgEnd: u32, + FunctionType: TypeIndex, CodeOffset: u32, Segment: u16, Flags: ProcSymFlags, @@ -315,25 +331,34 @@ pub const ProcSymFlags = packed struct { HasOptimizedDebugInfo: bool, }; -pub const SectionContrSubstreamVersion = enum(u32) { - Ver60 = 0xeffe0000 + 19970605, - V2 = 0xeffe0000 + 20140516 +pub const SectionContrSubstreamVersion = enum(u32) { + Ver60 = 0xeffe0000 + 19970605, + V2 = 0xeffe0000 + 20140516, }; pub const RecordPrefix = packed struct { - RecordLen: u16, /// Record length, starting from &RecordKind. - RecordKind: SymbolKind, /// Record kind enum (SymRecordKind or TypeRecordKind) + /// Record length, starting from &RecordKind. + RecordLen: u16, + + /// Record kind enum (SymRecordKind or TypeRecordKind) + RecordKind: SymbolKind, }; pub const LineFragmentHeader = packed struct { - RelocOffset: u32, /// Code offset of line contribution. - RelocSegment: u16, /// Code segment of line contribution. + /// Code offset of line contribution. + RelocOffset: u32, + + /// Code segment of line contribution. + RelocSegment: u16, Flags: LineFlags, - CodeSize: u32, /// Code size of this line contribution. + + /// Code size of this line contribution. + CodeSize: u32, }; pub const LineFlags = packed struct { - LF_HaveColumns: bool, /// CV_LINES_HAVE_COLUMNS + /// CV_LINES_HAVE_COLUMNS + LF_HaveColumns: bool, unused: u15, }; @@ -348,12 +373,14 @@ pub const LineBlockFragmentHeader = packed struct { /// table of the actual name. NameIndex: u32, NumLines: u32, - BlockSize: u32, /// code size of block, in bytes -}; + /// code size of block, in bytes + BlockSize: u32, +}; pub const LineNumberEntry = packed struct { - Offset: u32, /// Offset to start of code bytes for line number + /// Offset to start of code bytes for line number + Offset: u32, Flags: u32, /// TODO runtime crash when I make the actual type of Flags this @@ -371,42 +398,53 @@ pub const ColumnNumberEntry = packed struct { /// Checksum bytes follow. pub const FileChecksumEntryHeader = packed struct { - FileNameOffset: u32, /// Byte offset of filename in global string table. - ChecksumSize: u8, /// Number of bytes of checksum. - ChecksumKind: u8, /// FileChecksumKind + /// Byte offset of filename in global string table. + FileNameOffset: u32, + + /// Number of bytes of checksum. + ChecksumSize: u8, + + /// FileChecksumKind + ChecksumKind: u8, }; pub const DebugSubsectionKind = packed enum(u32) { - None = 0, - Symbols = 0xf1, - Lines = 0xf2, - StringTable = 0xf3, - FileChecksums = 0xf4, - FrameData = 0xf5, - InlineeLines = 0xf6, - CrossScopeImports = 0xf7, - CrossScopeExports = 0xf8, - - // These appear to relate to .Net assembly info. - ILLines = 0xf9, - FuncMDTokenMap = 0xfa, - TypeMDTokenMap = 0xfb, - MergedAssemblyInput = 0xfc, - - CoffSymbolRVA = 0xfd, + None = 0, + Symbols = 0xf1, + Lines = 0xf2, + StringTable = 0xf3, + FileChecksums = 0xf4, + FrameData = 0xf5, + InlineeLines = 0xf6, + CrossScopeImports = 0xf7, + CrossScopeExports = 0xf8, + + // These appear to relate to .Net assembly info. + ILLines = 0xf9, + FuncMDTokenMap = 0xfa, + TypeMDTokenMap = 0xfb, + MergedAssemblyInput = 0xfc, + + CoffSymbolRVA = 0xfd, }; - pub const DebugSubsectionHeader = packed struct { - Kind: DebugSubsectionKind, /// codeview::DebugSubsectionKind enum - Length: u32, /// number of bytes occupied by this record. -}; + /// codeview::DebugSubsectionKind enum + Kind: DebugSubsectionKind, + /// number of bytes occupied by this record. + Length: u32, +}; pub const PDBStringTableHeader = packed struct { - Signature: u32, /// PDBStringTableSignature - HashVersion: u32, /// 1 or 2 - ByteSize: u32, /// Number of bytes of names buffer. + /// PDBStringTableSignature + Signature: u32, + + /// 1 or 2 + HashVersion: u32, + + /// Number of bytes of names buffer. + ByteSize: u32, }; pub const Pdb = struct { @@ -456,7 +494,7 @@ const Msf = struct { switch (superblock.BlockSize) { // llvm only supports 4096 but we can handle any of these values 512, 1024, 2048, 4096 => {}, - else => return error.InvalidDebugInfo + else => return error.InvalidDebugInfo, } if (superblock.NumBlocks * superblock.BlockSize != try file.getEndPos()) @@ -536,7 +574,6 @@ const SuperBlock = packed struct { /// The number of ulittle32_t’s in this array is given by /// ceil(NumDirectoryBytes / BlockSize). BlockMapAddr: u32, - }; const MsfStream = struct { @@ -552,14 +589,12 @@ const MsfStream = struct { pub const Stream = io.InStream(Error); fn init(block_size: u32, block_count: u32, pos: usize, file: os.File, allocator: *mem.Allocator) !MsfStream { - var stream = MsfStream { + var stream = MsfStream{ .in_file = file, .pos = 0, .blocks = try allocator.alloc(u32, block_count), .block_size = block_size, - .stream = Stream { - .readFn = readFn, - }, + .stream = Stream{ .readFn = readFn }, }; var file_stream = io.FileInStream.init(file); @@ -597,7 +632,7 @@ const MsfStream = struct { var size: usize = 0; for (buffer) |*byte| { - byte.* = try in.readByte(); + byte.* = try in.readByte(); offset += 1; size += 1; -- cgit v1.2.3