mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +00:00
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.
This commit is contained in:
parent
1553c8eae7
commit
6f64c8b693
2 changed files with 16 additions and 11 deletions
|
|
@ -2052,10 +2052,10 @@ fn dirOpenFileWindows(
|
||||||
const sub_path_w_array = try windows.sliceToPrefixedFileW(dir.handle, sub_path);
|
const sub_path_w_array = try windows.sliceToPrefixedFileW(dir.handle, sub_path);
|
||||||
const sub_path_w = sub_path_w_array.span();
|
const sub_path_w = sub_path_w_array.span();
|
||||||
const dir_handle = if (std.fs.path.isAbsoluteWindowsWtf16(sub_path_w)) null else dir.handle;
|
const dir_handle = if (std.fs.path.isAbsoluteWindowsWtf16(sub_path_w)) null else dir.handle;
|
||||||
return dirOpenFileWindowsInner(t, dir_handle, sub_path_w, flags);
|
return dirOpenFileWtf16(t, dir_handle, sub_path_w, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dirOpenFileWindowsInner(
|
pub fn dirOpenFileWtf16(
|
||||||
t: *Threaded,
|
t: *Threaded,
|
||||||
dir_handle: ?windows.HANDLE,
|
dir_handle: ?windows.HANDLE,
|
||||||
sub_path_w: [:0]const u16,
|
sub_path_w: [:0]const u16,
|
||||||
|
|
@ -2800,7 +2800,7 @@ fn openSelfExe(userdata: ?*anyopaque, flags: Io.File.OpenFlags) Io.File.OpenSelf
|
||||||
const image_path_unicode_string = &windows.peb().ProcessParameters.ImagePathName;
|
const image_path_unicode_string = &windows.peb().ProcessParameters.ImagePathName;
|
||||||
const image_path_name = image_path_unicode_string.Buffer.?[0 .. image_path_unicode_string.Length / 2 :0];
|
const image_path_name = image_path_unicode_string.Buffer.?[0 .. image_path_unicode_string.Length / 2 :0];
|
||||||
const prefixed_path_w = try windows.wToPrefixedFileW(null, image_path_name);
|
const prefixed_path_w = try windows.wToPrefixedFileW(null, image_path_name);
|
||||||
return dirOpenFileWindowsInner(t, null, prefixed_path_w.span(), flags);
|
return dirOpenFileWtf16(t, null, prefixed_path_w.span(), flags);
|
||||||
},
|
},
|
||||||
else => @panic("TODO implement openSelfExe"),
|
else => @panic("TODO implement openSelfExe"),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -297,7 +297,19 @@ const Module = struct {
|
||||||
// a binary is produced with -gdwarf, since the section names are longer than 8 bytes.
|
// a binary is produced with -gdwarf, since the section names are longer than 8 bytes.
|
||||||
const mapped_file: ?DebugInfo.MappedFile = mapped: {
|
const mapped_file: ?DebugInfo.MappedFile = mapped: {
|
||||||
if (!coff_obj.strtabRequired()) break :mapped null;
|
if (!coff_obj.strtabRequired()) break :mapped null;
|
||||||
const coff_file = Io.File.openSelfExe(io, .{}) catch |err| switch (err) {
|
var name_buffer: [windows.PATH_MAX_WIDE + 4:0]u16 = undefined;
|
||||||
|
name_buffer[0..4].* = .{ '\\', '?', '?', '\\' }; // openFileAbsoluteW requires the prefix to be present
|
||||||
|
const process_handle = windows.GetCurrentProcess();
|
||||||
|
const len = windows.kernel32.GetModuleFileNameExW(
|
||||||
|
process_handle,
|
||||||
|
module.handle,
|
||||||
|
name_buffer[4..],
|
||||||
|
windows.PATH_MAX_WIDE,
|
||||||
|
);
|
||||||
|
if (len == 0) return error.MissingDebugInfo;
|
||||||
|
const name_w = name_buffer[0 .. len + 4 :0];
|
||||||
|
var threaded: Io.Threaded = .init_single_threaded;
|
||||||
|
const coff_file = threaded.dirOpenFileWtf16(null, name_w, .{}) catch |err| switch (err) {
|
||||||
error.Canceled => |e| return e,
|
error.Canceled => |e| return e,
|
||||||
error.Unexpected => |e| return e,
|
error.Unexpected => |e| return e,
|
||||||
error.FileNotFound => return error.MissingDebugInfo,
|
error.FileNotFound => return error.MissingDebugInfo,
|
||||||
|
|
@ -327,12 +339,6 @@ const Module = struct {
|
||||||
error.SystemFdQuotaExceeded,
|
error.SystemFdQuotaExceeded,
|
||||||
error.FileLocksNotSupported,
|
error.FileLocksNotSupported,
|
||||||
error.FileBusy,
|
error.FileBusy,
|
||||||
error.InputOutput,
|
|
||||||
error.NotSupported,
|
|
||||||
error.FileSystem,
|
|
||||||
error.NotLink,
|
|
||||||
error.UnrecognizedVolume,
|
|
||||||
error.UnknownName,
|
|
||||||
=> return error.ReadFailed,
|
=> return error.ReadFailed,
|
||||||
};
|
};
|
||||||
errdefer coff_file.close(io);
|
errdefer coff_file.close(io);
|
||||||
|
|
@ -352,7 +358,6 @@ const Module = struct {
|
||||||
errdefer windows.CloseHandle(section_handle);
|
errdefer windows.CloseHandle(section_handle);
|
||||||
var coff_len: usize = 0;
|
var coff_len: usize = 0;
|
||||||
var section_view_ptr: ?[*]const u8 = null;
|
var section_view_ptr: ?[*]const u8 = null;
|
||||||
const process_handle = windows.GetCurrentProcess();
|
|
||||||
const map_section_rc = windows.ntdll.NtMapViewOfSection(
|
const map_section_rc = windows.ntdll.NtMapViewOfSection(
|
||||||
section_handle,
|
section_handle,
|
||||||
process_handle,
|
process_handle,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue