authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-12 14:26:21-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-12 14:26:21-04:00
loga75753338657b85588fe6c54a40fecac0584b336
tree9d0e1f367a172d04284b808c629394b4e45d7a98
parent178d69191ba008dffd70d2854df09cec556b59dd

fix zig fmt on windows

closes #1069

10 files changed, 161 insertions(+), 120 deletions(-)

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