zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit dfa8ab1dc9825c0c3b0433037cbb0123027ea93e (tree)
parent f3edff439e2dd8e4055d21507b352141cd5b1718
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Thu,  2 Dec 2021 21:24:37 -0800

std.os.execve: handle EBADEXEC and EBADARCH

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

Diffstat:
Mlib/std/os.zig | 26++++++++++++++++++++++++++
1 file changed, 26 insertions(+), 0 deletions(-)

diff --git a/lib/std/os.zig b/lib/std/os.zig @@ -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,