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 {...@@ -966,7 +966,7 @@ pub const ChildProcess = struct {
966 defer self.allocator.free(cmd_line_w);966 defer self.allocator.free(cmd_line_w);
967967
968 windowsCreateProcess(app_path_w.ptr, cmd_line_w.ptr, envp_ptr, cwd_w_ptr, &siStartInfo, &piProcInfo) catch |no_path_err| {968 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
971 const PATH: [:0]const u16 = std.os.getenvW(unicode.utf8ToUtf16LeStringLiteral("PATH")) orelse &[_:0]u16{};971 const PATH: [:0]const u16 = std.os.getenvW(unicode.utf8ToUtf16LeStringLiteral("PATH")) orelse &[_:0]u16{};
972 const PATHEXT: [:0]const u16 = std.os.getenvW(unicode.utf8ToUtf16LeStringLiteral("PATHEXT")) orelse &[_:0]u16{};972 const PATHEXT: [:0]const u16 = std.os.getenvW(unicode.utf8ToUtf16LeStringLiteral("PATHEXT")) orelse &[_:0]u16{};
...@@ -991,7 +991,7 @@ pub const ChildProcess = struct {...@@ -991,7 +991,7 @@ pub const ChildProcess = struct {
991 if (windowsCreateProcess(path_no_ext.ptr, cmd_line_w.ptr, envp_ptr, cwd_w_ptr, &siStartInfo, &piProcInfo)) |_| {991 if (windowsCreateProcess(path_no_ext.ptr, cmd_line_w.ptr, envp_ptr, cwd_w_ptr, &siStartInfo, &piProcInfo)) |_| {
992 break :retry;992 break :retry;
993 } else |err| switch (err) {993 } else |err| switch (err) {
994 error.FileNotFound, error.AccessDenied => {},994 error.FileNotFound, error.AccessDenied, error.InvalidExe => {},
995 else => return err,995 else => return err,
996 }996 }
997997
...@@ -1007,6 +1007,7 @@ pub const ChildProcess = struct {...@@ -1007,6 +1007,7 @@ pub const ChildProcess = struct {
1007 } else |err| switch (err) {1007 } else |err| switch (err) {
1008 error.FileNotFound => continue,1008 error.FileNotFound => continue,
1009 error.AccessDenied => continue,1009 error.AccessDenied => continue,
1010 error.InvalidExe => continue,
1010 else => return err,1011 else => return err,
1011 }1012 }
1012 }1013 }
lib/std/os/windows.zig+22
...@@ -1569,6 +1569,7 @@ pub const CreateProcessError = error{...@@ -1569,6 +1569,7 @@ pub const CreateProcessError = error{
1569 AccessDenied,1569 AccessDenied,
1570 InvalidName,1570 InvalidName,
1571 NameTooLong,1571 NameTooLong,
1572 InvalidExe,
1572 Unexpected,1573 Unexpected,
1573};1574};
15741575
...@@ -1603,6 +1604,27 @@ pub fn CreateProcessW(...@@ -1603,6 +1604,27 @@ pub fn CreateProcessW(
1603 .INVALID_PARAMETER => unreachable,1604 .INVALID_PARAMETER => unreachable,
1604 .INVALID_NAME => return error.InvalidName,1605 .INVALID_NAME => return error.InvalidName,
1605 .FILENAME_EXCED_RANGE => return error.NameTooLong,1606 .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,
1606 else => |err| return unexpectedError(err),1628 else => |err| return unexpectedError(err),
1607 }1629 }
1608 }1630 }