authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-12-02 21:24:37-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-12-02 21:24:37-08:00
logdfa8ab1dc9825c0c3b0433037cbb0123027ea93e
treebff9a2066f70a10b82b2887a6d55a72ebefd8ab0
parentf3edff439e2dd8e4055d21507b352141cd5b1718

std.os.execve: handle EBADEXEC and EBADARCH

Observed on aarch64-macos when trying to execute an x86_64-macos binary.

1 files changed, 26 insertions(+), 0 deletions(-)

lib/std/os.zig+26
......@@ -1533,6 +1533,32 @@ pub fn execveZ(
15331533 child_argv: [*:null]const ?[*:0]const u8,
15341534 envp: [*:null]const ?[*:0]const u8,
15351535) ExecveError {
1536 if (comptime builtin.target.isDarwin()) {
1537 // Darwin gets its own branch because it has BADEXEC and BADARCH
1538 // which are beyond posix.
1539 switch (errno(system.execve(path, child_argv, envp))) {
1540 .SUCCESS => unreachable,
1541 .FAULT => unreachable,
1542 .@"2BIG" => return error.SystemResources,
1543 .MFILE => return error.ProcessFdQuotaExceeded,
1544 .NAMETOOLONG => return error.NameTooLong,
1545 .NFILE => return error.SystemFdQuotaExceeded,
1546 .NOMEM => return error.SystemResources,
1547 .ACCES => return error.AccessDenied,
1548 .PERM => return error.AccessDenied,
1549 .INVAL => return error.InvalidExe,
1550 .NOEXEC => return error.InvalidExe,
1551 .BADEXEC => return error.InvalidExe,
1552 .BADARCH => return error.InvalidExe,
1553 .IO => return error.FileSystem,
1554 .LOOP => return error.FileSystem,
1555 .ISDIR => return error.IsDir,
1556 .NOENT => return error.FileNotFound,
1557 .NOTDIR => return error.NotDir,
1558 .TXTBSY => return error.FileBusy,
1559 else => |err| return unexpectedErrno(err),
1560 }
1561 }
15361562 switch (errno(system.execve(path, child_argv, envp))) {
15371563 .SUCCESS => unreachable,
15381564 .FAULT => unreachable,