authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2022-12-16 22:14:33-08:00
committergravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2022-12-17 03:36:45-08:00
log5843b7987e705ec01d07cd98a7f7bb10aa579587
tree8a674a778f34a041c24de8018df53d6244d6929b
parentb362cbbc9fb4ab09c6a52948476d3d7dff27d795

Add error.InvalidExe to CreateProcessW error set and handle it in ChildProcess.spawnWindows


2 files changed, 25 insertions(+), 2 deletions(-)

lib/std/child_process.zig+3-2
......@@ -966,7 +966,7 @@ pub const ChildProcess = struct {
966966 defer self.allocator.free(cmd_line_w);
967967
968968 windowsCreateProcess(app_path_w.ptr, cmd_line_w.ptr, envp_ptr, cwd_w_ptr, &siStartInfo, &piProcInfo) catch |no_path_err| {
969 if (no_path_err != error.FileNotFound) return no_path_err;
969 if (no_path_err != error.FileNotFound and no_path_err != error.InvalidExe) return no_path_err;
970970
971971 const PATH: [:0]const u16 = std.os.getenvW(unicode.utf8ToUtf16LeStringLiteral("PATH")) orelse &[_:0]u16{};
972972 const PATHEXT: [:0]const u16 = std.os.getenvW(unicode.utf8ToUtf16LeStringLiteral("PATHEXT")) orelse &[_:0]u16{};
......@@ -991,7 +991,7 @@ pub const ChildProcess = struct {
991991 if (windowsCreateProcess(path_no_ext.ptr, cmd_line_w.ptr, envp_ptr, cwd_w_ptr, &siStartInfo, &piProcInfo)) |_| {
992992 break :retry;
993993 } else |err| switch (err) {
994 error.FileNotFound, error.AccessDenied => {},
994 error.FileNotFound, error.AccessDenied, error.InvalidExe => {},
995995 else => return err,
996996 }
997997
......@@ -1007,6 +1007,7 @@ pub const ChildProcess = struct {
10071007 } else |err| switch (err) {
10081008 error.FileNotFound => continue,
10091009 error.AccessDenied => continue,
1010 error.InvalidExe => continue,
10101011 else => return err,
10111012 }
10121013 }
lib/std/os/windows.zig+22
......@@ -1569,6 +1569,7 @@ pub const CreateProcessError = error{
15691569 AccessDenied,
15701570 InvalidName,
15711571 NameTooLong,
1572 InvalidExe,
15721573 Unexpected,
15731574};
15741575
......@@ -1603,6 +1604,27 @@ pub fn CreateProcessW(
16031604 .INVALID_PARAMETER => unreachable,
16041605 .INVALID_NAME => return error.InvalidName,
16051606 .FILENAME_EXCED_RANGE => return error.NameTooLong,
1607 // These are all the system errors that are mapped to ENOEXEC by
1608 // the undocumented _dosmaperr (old CRT) or __acrt_errno_map_os_error
1609 // (newer CRT) functions. Their code can be found in crt/src/dosmap.c (old SDK)
1610 // or urt/misc/errno.cpp (newer SDK) in the Windows SDK.
1611 .BAD_FORMAT,
1612 .INVALID_STARTING_CODESEG, // MIN_EXEC_ERROR in errno.cpp
1613 .INVALID_STACKSEG,
1614 .INVALID_MODULETYPE,
1615 .INVALID_EXE_SIGNATURE,
1616 .EXE_MARKED_INVALID,
1617 .BAD_EXE_FORMAT,
1618 .ITERATED_DATA_EXCEEDS_64k,
1619 .INVALID_MINALLOCSIZE,
1620 .DYNLINK_FROM_INVALID_RING,
1621 .IOPL_NOT_ENABLED,
1622 .INVALID_SEGDPL,
1623 .AUTODATASEG_EXCEEDS_64k,
1624 .RING2SEG_MUST_BE_MOVABLE,
1625 .RELOC_CHAIN_XEEDS_SEGLIM,
1626 .INFLOOP_IN_RELOC_CHAIN, // MAX_EXEC_ERROR in errno.cpp
1627 => return error.InvalidExe,
16061628 else => |err| return unexpectedError(err),
16071629 }
16081630 }