From acefcdbca58efd97bf5346eb7dae22c49efa1a3d Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 2 Oct 2018 14:08:32 -0400 Subject: [PATCH] add std.os.linux.vfork and std.os.linux.exit_group --- std/os/index.zig | 29 ++++++++++++++++++----------- std/os/linux/index.zig | 14 ++++++++++++++ 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/std/os/index.zig b/std/os/index.zig index 40219b9cf..b1356f8ed 100644 --- a/std/os/index.zig +++ b/std/os/index.zig @@ -634,18 +634,25 @@ pub const PosixExecveError = error{ fn posixExecveErrnoToErr(err: usize) PosixExecveError { assert(err > 0); - return switch (err) { + switch (err) { posix.EFAULT => unreachable, - posix.E2BIG, posix.EMFILE, posix.ENAMETOOLONG, posix.ENFILE, posix.ENOMEM => error.SystemResources, - posix.EACCES, posix.EPERM => error.AccessDenied, - posix.EINVAL, posix.ENOEXEC => error.InvalidExe, - posix.EIO, posix.ELOOP => error.FileSystem, - posix.EISDIR => error.IsDir, - posix.ENOENT => error.FileNotFound, - posix.ENOTDIR => error.NotDir, - posix.ETXTBSY => error.FileBusy, - else => unexpectedErrorPosix(err), - }; + posix.E2BIG => return error.SystemResources, + posix.EMFILE => return error.SystemResources, + posix.ENAMETOOLONG => return error.SystemResources, + posix.ENFILE => return error.SystemResources, + posix.ENOMEM => return error.SystemResources, + posix.EACCES => return error.AccessDenied, + posix.EPERM => return error.AccessDenied, + posix.EINVAL => return error.InvalidExe, + posix.ENOEXEC => return error.InvalidExe, + posix.EIO => return error.FileSystem, + posix.ELOOP => return error.FileSystem, + posix.EISDIR => return error.IsDir, + posix.ENOENT => return error.FileNotFound, + posix.ENOTDIR => return error.NotDir, + posix.ETXTBSY => return error.FileBusy, + else => return unexpectedErrorPosix(err), + } } pub var linux_aux_raw = []usize{0} ** 38; diff --git a/std/os/linux/index.zig b/std/os/linux/index.zig index e00c664af..8819aa21c 100644 --- a/std/os/linux/index.zig +++ b/std/os/linux/index.zig @@ -719,6 +719,15 @@ pub fn fork() usize { return syscall0(SYS_fork); } +/// This must be inline, and inline call the syscall function, because if the +/// child does a return it will clobber the parent's stack. +/// It is advised to avoid this function and use clone instead, because +/// the compiler is not aware of how vfork affects control flow and you may +/// see different results in optimized builds. +pub inline fn vfork() usize { + return @inlineCall(syscall0, SYS_vfork); +} + pub fn futex_wait(uaddr: usize, futex_op: u32, val: i32, timeout: ?*timespec) usize { return syscall4(SYS_futex, uaddr, futex_op, @bitCast(u32, val), @ptrToInt(timeout)); } @@ -883,6 +892,11 @@ pub fn exit(status: i32) noreturn { unreachable; } +pub fn exit_group(status: i32) noreturn { + _ = syscall1(SYS_exit_group, @bitCast(usize, isize(status))); + unreachable; +} + pub fn getrandom(buf: [*]u8, count: usize, flags: u32) usize { return syscall3(SYS_getrandom, @ptrToInt(buf), count, @intCast(usize, flags)); }