std.os.execve: handle EBADEXEC and EBADARCH

Observed on aarch64-macos when trying to execute an x86_64-macos
binary.
This commit is contained in:
Andrew Kelley 2021-12-02 21:24:37 -08:00
parent f3edff439e
commit dfa8ab1dc9

View File

@ -1533,6 +1533,32 @@ pub fn execveZ(
child_argv: [*:null]const ?[*:0]const u8,
envp: [*:null]const ?[*:0]const u8,
) ExecveError {
if (comptime builtin.target.isDarwin()) {
// Darwin gets its own branch because it has BADEXEC and BADARCH
// which are beyond posix.
switch (errno(system.execve(path, child_argv, envp))) {
.SUCCESS => unreachable,
.FAULT => unreachable,
.@"2BIG" => return error.SystemResources,
.MFILE => return error.ProcessFdQuotaExceeded,
.NAMETOOLONG => return error.NameTooLong,
.NFILE => return error.SystemFdQuotaExceeded,
.NOMEM => return error.SystemResources,
.ACCES => return error.AccessDenied,
.PERM => return error.AccessDenied,
.INVAL => return error.InvalidExe,
.NOEXEC => return error.InvalidExe,
.BADEXEC => return error.InvalidExe,
.BADARCH => return error.InvalidExe,
.IO => return error.FileSystem,
.LOOP => return error.FileSystem,
.ISDIR => return error.IsDir,
.NOENT => return error.FileNotFound,
.NOTDIR => return error.NotDir,
.TXTBSY => return error.FileBusy,
else => |err| return unexpectedErrno(err),
}
}
switch (errno(system.execve(path, child_argv, envp))) {
.SUCCESS => unreachable,
.FAULT => unreachable,