authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-10-28 08:47:39-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-10-29 06:20:52-07:00
log6f64c8b693446a6f8d170bb09324e5c5e506ce6f
tree620a2126901c6d92536012ec6599c0b96759d313
parent1553c8eae7d830cb793e78c3e52ad816fa8efd23

std.debug.SelfInfo.Windows: less invasive change

restores code closer to master branch in hopes of avoiding a regression that was introduced when this was based on openSelfExe rather than GetModuleFileNameExW.

2 files changed, 16 insertions(+), 11 deletions(-)

lib/std/Io/Threaded.zig+3-3
...@@ -2052,10 +2052,10 @@ fn dirOpenFileWindows(...@@ -2052,10 +2052,10 @@ fn dirOpenFileWindows(
2052 const sub_path_w_array = try windows.sliceToPrefixedFileW(dir.handle, sub_path);2052 const sub_path_w_array = try windows.sliceToPrefixedFileW(dir.handle, sub_path);
2053 const sub_path_w = sub_path_w_array.span();2053 const sub_path_w = sub_path_w_array.span();
2054 const dir_handle = if (std.fs.path.isAbsoluteWindowsWtf16(sub_path_w)) null else dir.handle;2054 const dir_handle = if (std.fs.path.isAbsoluteWindowsWtf16(sub_path_w)) null else dir.handle;
2055 return dirOpenFileWindowsInner(t, dir_handle, sub_path_w, flags);2055 return dirOpenFileWtf16(t, dir_handle, sub_path_w, flags);
2056}2056}
20572057
2058fn dirOpenFileWindowsInner(2058pub fn dirOpenFileWtf16(
2059 t: *Threaded,2059 t: *Threaded,
2060 dir_handle: ?windows.HANDLE,2060 dir_handle: ?windows.HANDLE,
2061 sub_path_w: [:0]const u16,2061 sub_path_w: [:0]const u16,
...@@ -2800,7 +2800,7 @@ fn openSelfExe(userdata: ?*anyopaque, flags: Io.File.OpenFlags) Io.File.OpenSelf...@@ -2800,7 +2800,7 @@ fn openSelfExe(userdata: ?*anyopaque, flags: Io.File.OpenFlags) Io.File.OpenSelf
2800 const image_path_unicode_string = &windows.peb().ProcessParameters.ImagePathName;2800 const image_path_unicode_string = &windows.peb().ProcessParameters.ImagePathName;
2801 const image_path_name = image_path_unicode_string.Buffer.?[0 .. image_path_unicode_string.Length / 2 :0];2801 const image_path_name = image_path_unicode_string.Buffer.?[0 .. image_path_unicode_string.Length / 2 :0];
2802 const prefixed_path_w = try windows.wToPrefixedFileW(null, image_path_name);2802 const prefixed_path_w = try windows.wToPrefixedFileW(null, image_path_name);
2803 return dirOpenFileWindowsInner(t, null, prefixed_path_w.span(), flags);2803 return dirOpenFileWtf16(t, null, prefixed_path_w.span(), flags);
2804 },2804 },
2805 else => @panic("TODO implement openSelfExe"),2805 else => @panic("TODO implement openSelfExe"),
2806 }2806 }
lib/std/debug/SelfInfo/Windows.zig+13-8
...@@ -297,7 +297,19 @@ const Module = struct {...@@ -297,7 +297,19 @@ const Module = struct {
297 // a binary is produced with -gdwarf, since the section names are longer than 8 bytes.297 // a binary is produced with -gdwarf, since the section names are longer than 8 bytes.
298 const mapped_file: ?DebugInfo.MappedFile = mapped: {298 const mapped_file: ?DebugInfo.MappedFile = mapped: {
299 if (!coff_obj.strtabRequired()) break :mapped null;299 if (!coff_obj.strtabRequired()) break :mapped null;
300 const coff_file = Io.File.openSelfExe(io, .{}) catch |err| switch (err) {300 var name_buffer: [windows.PATH_MAX_WIDE + 4:0]u16 = undefined;
301 name_buffer[0..4].* = .{ '\\', '?', '?', '\\' }; // openFileAbsoluteW requires the prefix to be present
302 const process_handle = windows.GetCurrentProcess();
303 const len = windows.kernel32.GetModuleFileNameExW(
304 process_handle,
305 module.handle,
306 name_buffer[4..],
307 windows.PATH_MAX_WIDE,
308 );
309 if (len == 0) return error.MissingDebugInfo;
310 const name_w = name_buffer[0 .. len + 4 :0];
311 var threaded: Io.Threaded = .init_single_threaded;
312 const coff_file = threaded.dirOpenFileWtf16(null, name_w, .{}) catch |err| switch (err) {
301 error.Canceled => |e| return e,313 error.Canceled => |e| return e,
302 error.Unexpected => |e| return e,314 error.Unexpected => |e| return e,
303 error.FileNotFound => return error.MissingDebugInfo,315 error.FileNotFound => return error.MissingDebugInfo,
...@@ -327,12 +339,6 @@ const Module = struct {...@@ -327,12 +339,6 @@ const Module = struct {
327 error.SystemFdQuotaExceeded,339 error.SystemFdQuotaExceeded,
328 error.FileLocksNotSupported,340 error.FileLocksNotSupported,
329 error.FileBusy,341 error.FileBusy,
330 error.InputOutput,
331 error.NotSupported,
332 error.FileSystem,
333 error.NotLink,
334 error.UnrecognizedVolume,
335 error.UnknownName,
336 => return error.ReadFailed,342 => return error.ReadFailed,
337 };343 };
338 errdefer coff_file.close(io);344 errdefer coff_file.close(io);
...@@ -352,7 +358,6 @@ const Module = struct {...@@ -352,7 +358,6 @@ const Module = struct {
352 errdefer windows.CloseHandle(section_handle);358 errdefer windows.CloseHandle(section_handle);
353 var coff_len: usize = 0;359 var coff_len: usize = 0;
354 var section_view_ptr: ?[*]const u8 = null;360 var section_view_ptr: ?[*]const u8 = null;
355 const process_handle = windows.GetCurrentProcess();
356 const map_section_rc = windows.ntdll.NtMapViewOfSection(361 const map_section_rc = windows.ntdll.NtMapViewOfSection(
357 section_handle,362 section_handle,
358 process_handle,363 process_handle,