Skip to content

Commit 354cfe9

Browse files
committed
Add error.InvalidExe to CreateProcessW error set and handle it in ChildProcess.spawnWindows
1 parent b362cbb commit 354cfe9

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

lib/std/child_process.zig

+3-2
Original file line numberDiff line numberDiff line change
@@ -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

+19
Original file line numberDiff line numberDiff line change
@@ -1569,6 +1569,7 @@ pub const CreateProcessError = error{
15691569
AccessDenied,
15701570
InvalidName,
15711571
NameTooLong,
1572+
InvalidExe,
15721573
Unexpected,
15731574
};
15741575

@@ -1603,6 +1604,24 @@ 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 in ReactOS:
1608+
// https://doxygen.reactos.org/d8/d68/doserrmap_8h_source.html
1609+
.INVALID_STARTING_CODESEG,
1610+
.INVALID_STACKSEG,
1611+
.INVALID_MODULETYPE,
1612+
.INVALID_EXE_SIGNATURE,
1613+
.EXE_MARKED_INVALID,
1614+
.BAD_EXE_FORMAT,
1615+
.ITERATED_DATA_EXCEEDS_64k,
1616+
.INVALID_MINALLOCSIZE,
1617+
.DYNLINK_FROM_INVALID_RING,
1618+
.IOPL_NOT_ENABLED,
1619+
.INVALID_SEGDPL,
1620+
.AUTODATASEG_EXCEEDS_64k,
1621+
.RING2SEG_MUST_BE_MOVABLE,
1622+
.RELOC_CHAIN_XEEDS_SEGLIM,
1623+
.INFLOOP_IN_RELOC_CHAIN,
1624+
=> return error.InvalidExe,
16061625
else => |err| return unexpectedError(err),
16071626
}
16081627
}

0 commit comments

Comments
 (0)