2020-08-20 02:40:15 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
// Copyright (c) 2015-2020 Zig Contributors
|
|
|
|
// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
|
|
|
|
// The MIT license requires this copyright notice to be included in all copies
|
|
|
|
// and substantial portions of the software.
|
2019-05-25 17:07:44 +00:00
|
|
|
// This file provides the system interface functions for Linux matching those
|
|
|
|
// that are provided by libc, whether or not libc is linked. The following
|
|
|
|
// abstractions are made:
|
|
|
|
// * Work around kernel bugs and limitations. For example, see sendmmsg.
|
|
|
|
// * Implement all the syscalls in the same way that libc functions will
|
|
|
|
// provide `rename` when only the `renameat` syscall exists.
|
|
|
|
// * Does not support POSIX thread cancellation.
|
2019-03-02 21:46:04 +00:00
|
|
|
const std = @import("../std.zig");
|
2020-03-03 17:01:17 +00:00
|
|
|
const builtin = std.builtin;
|
2019-05-25 17:07:44 +00:00
|
|
|
const assert = std.debug.assert;
|
|
|
|
const maxInt = std.math.maxInt;
|
|
|
|
const elf = std.elf;
|
|
|
|
const vdso = @import("linux/vdso.zig");
|
|
|
|
const dl = @import("../dynamic_library.zig");
|
|
|
|
|
2019-05-29 22:55:42 +00:00
|
|
|
pub usingnamespace switch (builtin.arch) {
|
2019-11-30 15:13:33 +00:00
|
|
|
.i386 => @import("linux/i386.zig"),
|
2019-05-25 17:07:44 +00:00
|
|
|
.x86_64 => @import("linux/x86_64.zig"),
|
|
|
|
.aarch64 => @import("linux/arm64.zig"),
|
2019-08-28 15:41:49 +00:00
|
|
|
.arm => @import("linux/arm-eabi.zig"),
|
2019-07-18 19:03:21 +00:00
|
|
|
.riscv64 => @import("linux/riscv64.zig"),
|
2020-08-17 08:07:57 +00:00
|
|
|
.sparcv9 => @import("linux/sparc64.zig"),
|
2020-04-21 16:42:21 +00:00
|
|
|
.mips, .mipsel => @import("linux/mips.zig"),
|
2020-06-04 00:37:14 +00:00
|
|
|
.powerpc64, .powerpc64le => @import("linux/powerpc64.zig"),
|
2019-05-25 17:07:44 +00:00
|
|
|
else => struct {},
|
|
|
|
};
|
2019-05-29 22:55:42 +00:00
|
|
|
pub usingnamespace @import("bits.zig");
|
2019-05-26 17:17:34 +00:00
|
|
|
pub const tls = @import("linux/tls.zig");
|
2020-08-22 19:08:01 +00:00
|
|
|
pub const BPF = @import("linux/bpf.zig");
|
2020-09-19 14:18:04 +00:00
|
|
|
pub usingnamespace @import("linux/io_uring.zig");
|
2019-05-25 17:07:44 +00:00
|
|
|
|
|
|
|
/// Set by startup code, used by `getauxval`.
|
|
|
|
pub var elf_aux_maybe: ?[*]std.elf.Auxv = null;
|
|
|
|
|
|
|
|
/// See `std.elf` for the constants.
|
|
|
|
pub fn getauxval(index: usize) usize {
|
|
|
|
const auxv = elf_aux_maybe orelse return 0;
|
|
|
|
var i: usize = 0;
|
|
|
|
while (auxv[i].a_type != std.elf.AT_NULL) : (i += 1) {
|
|
|
|
if (auxv[i].a_type == index)
|
|
|
|
return auxv[i].a_un.a_val;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-11-02 11:11:07 +00:00
|
|
|
// Some architectures (and some syscalls) require 64bit parameters to be passed
|
|
|
|
// in a even-aligned register pair.
|
2020-12-09 11:54:26 +00:00
|
|
|
const require_aligned_register_pair =
|
2020-03-03 17:01:17 +00:00
|
|
|
std.Target.current.cpu.arch.isMIPS() or
|
|
|
|
std.Target.current.cpu.arch.isARM() or
|
|
|
|
std.Target.current.cpu.arch.isThumb();
|
2020-03-03 16:19:40 +00:00
|
|
|
|
2020-11-02 11:11:07 +00:00
|
|
|
// Split a 64bit value into a {LSB,MSB} pair.
|
|
|
|
fn splitValue64(val: u64) [2]u32 {
|
|
|
|
switch (builtin.endian) {
|
|
|
|
.Little => return [2]u32{
|
|
|
|
@truncate(u32, val),
|
|
|
|
@truncate(u32, val >> 32),
|
|
|
|
},
|
|
|
|
.Big => return [2]u32{
|
|
|
|
@truncate(u32, val >> 32),
|
|
|
|
@truncate(u32, val),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-25 17:07:44 +00:00
|
|
|
/// Get the errno from a syscall return value, or 0 for no error.
|
|
|
|
pub fn getErrno(r: usize) u12 {
|
|
|
|
const signed_r = @bitCast(isize, r);
|
|
|
|
return if (signed_r > -4096 and signed_r < 0) @intCast(u12, -signed_r) else 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn dup2(old: i32, new: i32) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
if (@hasField(SYS, "dup2")) {
|
|
|
|
return syscall2(.dup2, @bitCast(usize, @as(isize, old)), @bitCast(usize, @as(isize, new)));
|
2019-05-25 17:07:44 +00:00
|
|
|
} else {
|
|
|
|
if (old == new) {
|
|
|
|
if (std.debug.runtime_safety) {
|
2020-03-02 12:30:53 +00:00
|
|
|
const rc = syscall2(.fcntl, @bitCast(usize, @as(isize, old)), F_GETFD);
|
2019-05-25 17:07:44 +00:00
|
|
|
if (@bitCast(isize, rc) < 0) return rc;
|
|
|
|
}
|
|
|
|
return @intCast(usize, old);
|
|
|
|
} else {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall3(.dup3, @bitCast(usize, @as(isize, old)), @bitCast(usize, @as(isize, new)), 0);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn dup3(old: i32, new: i32, flags: u32) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall3(.dup3, @bitCast(usize, @as(isize, old)), @bitCast(usize, @as(isize, new)), flags);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2019-12-17 20:43:49 +00:00
|
|
|
pub fn chdir(path: [*:0]const u8) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall1(.chdir, @ptrToInt(path));
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2020-01-15 08:11:54 +00:00
|
|
|
pub fn fchdir(fd: fd_t) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall1(.fchdir, @bitCast(usize, @as(isize, fd)));
|
2020-01-15 08:11:54 +00:00
|
|
|
}
|
|
|
|
|
2019-12-17 20:43:49 +00:00
|
|
|
pub fn chroot(path: [*:0]const u8) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall1(.chroot, @ptrToInt(path));
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2019-12-17 20:43:49 +00:00
|
|
|
pub fn execve(path: [*:0]const u8, argv: [*:null]const ?[*:0]const u8, envp: [*:null]const ?[*:0]const u8) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall3(.execve, @ptrToInt(path), @ptrToInt(argv), @ptrToInt(envp));
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn fork() usize {
|
2020-11-27 16:02:22 +00:00
|
|
|
if (comptime builtin.arch.isSPARC()) {
|
|
|
|
return syscall_fork();
|
|
|
|
} else if (@hasField(SYS, "fork")) {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall0(.fork);
|
2019-05-25 17:07:44 +00:00
|
|
|
} else {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall2(.clone, SIGCHLD, 0);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// 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 {
|
2020-03-02 12:30:53 +00:00
|
|
|
return @call(.{ .modifier = .always_inline }, syscall0, .{.vfork});
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2019-07-14 07:06:20 +00:00
|
|
|
pub fn futimens(fd: i32, times: *const [2]timespec) usize {
|
|
|
|
return utimensat(fd, null, times, 0);
|
|
|
|
}
|
|
|
|
|
2019-12-17 20:43:49 +00:00
|
|
|
pub fn utimensat(dirfd: i32, path: ?[*:0]const u8, times: *const [2]timespec, flags: u32) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall4(.utimensat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(times), flags);
|
2019-07-14 07:06:20 +00:00
|
|
|
}
|
|
|
|
|
2020-11-03 04:03:38 +00:00
|
|
|
pub fn fallocate(fd: i32, mode: i32, offset: u64, length: u64) usize {
|
2020-11-01 09:49:08 +00:00
|
|
|
if (@sizeOf(usize) == 4) {
|
2020-11-03 04:03:38 +00:00
|
|
|
const offset_halves = splitValue64(offset);
|
|
|
|
const length_halves = splitValue64(length);
|
2020-11-01 09:49:08 +00:00
|
|
|
return syscall6(
|
|
|
|
.fallocate,
|
|
|
|
@bitCast(usize, @as(isize, fd)),
|
|
|
|
@bitCast(usize, @as(isize, mode)),
|
2020-11-03 04:03:38 +00:00
|
|
|
offset_halves[0],
|
|
|
|
offset_halves[1],
|
|
|
|
length_halves[0],
|
|
|
|
length_halves[1],
|
2020-11-01 09:49:08 +00:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return syscall4(
|
|
|
|
.fallocate,
|
|
|
|
@bitCast(usize, @as(isize, fd)),
|
|
|
|
@bitCast(usize, @as(isize, mode)),
|
|
|
|
offset,
|
2020-11-03 04:03:38 +00:00
|
|
|
length,
|
2020-11-01 09:49:08 +00:00
|
|
|
);
|
|
|
|
}
|
2020-10-31 11:39:33 +00:00
|
|
|
}
|
|
|
|
|
2019-05-25 17:07:44 +00:00
|
|
|
pub fn futex_wait(uaddr: *const i32, futex_op: u32, val: i32, timeout: ?*timespec) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall4(.futex, @ptrToInt(uaddr), futex_op, @bitCast(u32, val), @ptrToInt(timeout));
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn futex_wake(uaddr: *const i32, futex_op: u32, val: i32) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall3(.futex, @ptrToInt(uaddr), futex_op, @bitCast(u32, val));
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn getcwd(buf: [*]u8, size: usize) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall2(.getcwd, @ptrToInt(buf), size);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2019-07-08 21:52:28 +00:00
|
|
|
pub fn getdents(fd: i32, dirp: [*]u8, len: usize) usize {
|
|
|
|
return syscall3(
|
2020-03-02 12:30:53 +00:00
|
|
|
.getdents,
|
2019-11-07 04:25:57 +00:00
|
|
|
@bitCast(usize, @as(isize, fd)),
|
2019-07-08 21:52:28 +00:00
|
|
|
@ptrToInt(dirp),
|
|
|
|
std.math.min(len, maxInt(c_int)),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn getdents64(fd: i32, dirp: [*]u8, len: usize) usize {
|
|
|
|
return syscall3(
|
2020-03-02 12:30:53 +00:00
|
|
|
.getdents64,
|
2019-11-07 04:25:57 +00:00
|
|
|
@bitCast(usize, @as(isize, fd)),
|
2019-07-08 21:52:28 +00:00
|
|
|
@ptrToInt(dirp),
|
|
|
|
std.math.min(len, maxInt(c_int)),
|
|
|
|
);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn inotify_init1(flags: u32) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall1(.inotify_init1, flags);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2019-12-17 20:43:49 +00:00
|
|
|
pub fn inotify_add_watch(fd: i32, pathname: [*:0]const u8, mask: u32) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall3(.inotify_add_watch, @bitCast(usize, @as(isize, fd)), @ptrToInt(pathname), mask);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn inotify_rm_watch(fd: i32, wd: i32) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall2(.inotify_rm_watch, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, wd)));
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2019-12-17 20:43:49 +00:00
|
|
|
pub fn readlink(noalias path: [*:0]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
if (@hasField(SYS, "readlink")) {
|
|
|
|
return syscall3(.readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);
|
2019-05-25 17:07:44 +00:00
|
|
|
} else {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall4(.readlinkat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-17 20:43:49 +00:00
|
|
|
pub fn readlinkat(dirfd: i32, noalias path: [*:0]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall4(.readlinkat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2019-12-17 20:43:49 +00:00
|
|
|
pub fn mkdir(path: [*:0]const u8, mode: u32) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
if (@hasField(SYS, "mkdir")) {
|
|
|
|
return syscall2(.mkdir, @ptrToInt(path), mode);
|
2019-05-25 17:07:44 +00:00
|
|
|
} else {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall3(.mkdirat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), mode);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-17 20:43:49 +00:00
|
|
|
pub fn mkdirat(dirfd: i32, path: [*:0]const u8, mode: u32) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall3(.mkdirat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), mode);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2019-12-17 20:43:49 +00:00
|
|
|
pub fn mount(special: [*:0]const u8, dir: [*:0]const u8, fstype: [*:0]const u8, flags: u32, data: usize) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall5(.mount, @ptrToInt(special), @ptrToInt(dir), @ptrToInt(fstype), flags, data);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2019-12-17 20:43:49 +00:00
|
|
|
pub fn umount(special: [*:0]const u8) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall2(.umount2, @ptrToInt(special), 0);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2019-12-17 20:43:49 +00:00
|
|
|
pub fn umount2(special: [*:0]const u8, flags: u32) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall2(.umount2, @ptrToInt(special), flags);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2019-09-25 19:57:13 +00:00
|
|
|
pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, offset: u64) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
if (@hasField(SYS, "mmap2")) {
|
2019-09-27 16:18:38 +00:00
|
|
|
// Make sure the offset is also specified in multiples of page size
|
|
|
|
if ((offset & (MMAP2_UNIT - 1)) != 0)
|
2019-11-07 04:25:57 +00:00
|
|
|
return @bitCast(usize, @as(isize, -EINVAL));
|
2019-09-27 16:18:38 +00:00
|
|
|
|
|
|
|
return syscall6(
|
2020-03-02 12:30:53 +00:00
|
|
|
.mmap2,
|
2019-09-27 16:18:38 +00:00
|
|
|
@ptrToInt(address),
|
|
|
|
length,
|
|
|
|
prot,
|
|
|
|
flags,
|
2019-11-07 04:25:57 +00:00
|
|
|
@bitCast(usize, @as(isize, fd)),
|
2019-09-27 16:18:38 +00:00
|
|
|
@truncate(usize, offset / MMAP2_UNIT),
|
|
|
|
);
|
2019-08-28 22:55:22 +00:00
|
|
|
} else {
|
2019-09-27 16:18:38 +00:00
|
|
|
return syscall6(
|
2020-03-02 12:30:53 +00:00
|
|
|
.mmap,
|
2019-09-27 16:18:38 +00:00
|
|
|
@ptrToInt(address),
|
|
|
|
length,
|
|
|
|
prot,
|
|
|
|
flags,
|
2019-11-07 04:25:57 +00:00
|
|
|
@bitCast(usize, @as(isize, fd)),
|
2019-09-27 16:18:38 +00:00
|
|
|
offset,
|
|
|
|
);
|
2019-08-28 22:55:22 +00:00
|
|
|
}
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2019-05-26 23:56:37 +00:00
|
|
|
pub fn mprotect(address: [*]const u8, length: usize, protection: usize) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall3(.mprotect, @ptrToInt(address), length, protection);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2019-05-26 23:56:37 +00:00
|
|
|
pub fn munmap(address: [*]const u8, length: usize) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall2(.munmap, @ptrToInt(address), length);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2019-10-29 06:19:22 +00:00
|
|
|
pub fn poll(fds: [*]pollfd, n: nfds_t, timeout: i32) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
if (@hasField(SYS, "poll")) {
|
|
|
|
return syscall3(.poll, @ptrToInt(fds), n, @bitCast(u32, timeout));
|
2019-10-29 06:19:22 +00:00
|
|
|
} else {
|
2020-11-20 19:26:04 +00:00
|
|
|
return syscall5(
|
2020-03-02 12:30:53 +00:00
|
|
|
.ppoll,
|
2019-10-29 06:19:22 +00:00
|
|
|
@ptrToInt(fds),
|
|
|
|
n,
|
|
|
|
@ptrToInt(if (timeout >= 0)
|
|
|
|
×pec{
|
2019-10-30 16:49:37 +00:00
|
|
|
.tv_sec = @divTrunc(timeout, 1000),
|
|
|
|
.tv_nsec = @rem(timeout, 1000) * 1000000,
|
2019-10-29 06:19:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
null),
|
|
|
|
0,
|
|
|
|
NSIG / 8,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-20 19:26:04 +00:00
|
|
|
pub fn ppoll(fds: [*]pollfd, n: nfds_t, timeout: ?*timespec, sigmask: ?*const sigset_t) usize {
|
|
|
|
return syscall5(.ppoll, @ptrToInt(fds), n, @ptrToInt(timeout), @ptrToInt(sigmask), NSIG / 8);
|
|
|
|
}
|
|
|
|
|
2019-05-25 17:07:44 +00:00
|
|
|
pub fn read(fd: i32, buf: [*]u8, count: usize) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall3(.read, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: u64) usize {
|
2020-11-02 11:11:07 +00:00
|
|
|
const offset_halves = splitValue64(offset);
|
2019-09-01 14:10:36 +00:00
|
|
|
return syscall5(
|
2020-03-02 12:30:53 +00:00
|
|
|
.preadv,
|
2019-11-07 04:25:57 +00:00
|
|
|
@bitCast(usize, @as(isize, fd)),
|
2019-09-01 14:10:36 +00:00
|
|
|
@ptrToInt(iov),
|
|
|
|
count,
|
2020-11-02 11:11:07 +00:00
|
|
|
offset_halves[0],
|
|
|
|
offset_halves[1],
|
2019-09-01 14:10:36 +00:00
|
|
|
);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2019-05-20 13:25:11 +00:00
|
|
|
pub fn preadv2(fd: i32, iov: [*]const iovec, count: usize, offset: u64, flags: kernel_rwf) usize {
|
2020-11-02 11:11:07 +00:00
|
|
|
const offset_halves = splitValue64(offset);
|
2019-09-01 14:10:36 +00:00
|
|
|
return syscall6(
|
2020-03-02 12:30:53 +00:00
|
|
|
.preadv2,
|
2019-11-07 04:25:57 +00:00
|
|
|
@bitCast(usize, @as(isize, fd)),
|
2019-09-01 14:10:36 +00:00
|
|
|
@ptrToInt(iov),
|
|
|
|
count,
|
2020-11-02 11:11:07 +00:00
|
|
|
offset_halves[0],
|
|
|
|
offset_halves[1],
|
2019-09-10 17:00:35 +00:00
|
|
|
flags,
|
2019-09-01 14:10:36 +00:00
|
|
|
);
|
2019-05-20 13:25:11 +00:00
|
|
|
}
|
|
|
|
|
2019-05-25 17:07:44 +00:00
|
|
|
pub fn readv(fd: i32, iov: [*]const iovec, count: usize) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall3(.readv, @bitCast(usize, @as(isize, fd)), @ptrToInt(iov), count);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn writev(fd: i32, iov: [*]const iovec_const, count: usize) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall3(.writev, @bitCast(usize, @as(isize, fd)), @ptrToInt(iov), count);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64) usize {
|
2020-11-02 11:11:07 +00:00
|
|
|
const offset_halves = splitValue64(offset);
|
2019-09-01 14:10:36 +00:00
|
|
|
return syscall5(
|
2020-03-02 12:30:53 +00:00
|
|
|
.pwritev,
|
2019-11-07 04:25:57 +00:00
|
|
|
@bitCast(usize, @as(isize, fd)),
|
2019-09-01 14:10:36 +00:00
|
|
|
@ptrToInt(iov),
|
|
|
|
count,
|
2020-11-02 11:11:07 +00:00
|
|
|
offset_halves[0],
|
|
|
|
offset_halves[1],
|
2019-09-01 14:10:36 +00:00
|
|
|
);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2019-05-20 13:25:11 +00:00
|
|
|
pub fn pwritev2(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64, flags: kernel_rwf) usize {
|
2020-11-02 11:11:07 +00:00
|
|
|
const offset_halves = splitValue64(offset);
|
2019-09-01 14:10:36 +00:00
|
|
|
return syscall6(
|
2020-03-02 12:30:53 +00:00
|
|
|
.pwritev2,
|
2019-11-07 04:25:57 +00:00
|
|
|
@bitCast(usize, @as(isize, fd)),
|
2019-09-01 14:10:36 +00:00
|
|
|
@ptrToInt(iov),
|
|
|
|
count,
|
2020-11-02 11:11:07 +00:00
|
|
|
offset_halves[0],
|
|
|
|
offset_halves[1],
|
2019-09-10 17:00:35 +00:00
|
|
|
flags,
|
2019-09-01 14:10:36 +00:00
|
|
|
);
|
2019-05-20 13:25:11 +00:00
|
|
|
}
|
|
|
|
|
2019-12-17 20:43:49 +00:00
|
|
|
pub fn rmdir(path: [*:0]const u8) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
if (@hasField(SYS, "rmdir")) {
|
|
|
|
return syscall1(.rmdir, @ptrToInt(path));
|
2019-05-25 17:07:44 +00:00
|
|
|
} else {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall3(.unlinkat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), AT_REMOVEDIR);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-17 20:43:49 +00:00
|
|
|
pub fn symlink(existing: [*:0]const u8, new: [*:0]const u8) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
if (@hasField(SYS, "symlink")) {
|
|
|
|
return syscall2(.symlink, @ptrToInt(existing), @ptrToInt(new));
|
2019-05-25 17:07:44 +00:00
|
|
|
} else {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall3(.symlinkat, @ptrToInt(existing), @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(new));
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-17 20:43:49 +00:00
|
|
|
pub fn symlinkat(existing: [*:0]const u8, newfd: i32, newpath: [*:0]const u8) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall3(.symlinkat, @ptrToInt(existing), @bitCast(usize, @as(isize, newfd)), @ptrToInt(newpath));
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2020-03-03 07:03:22 +00:00
|
|
|
pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: u64) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
if (@hasField(SYS, "pread64")) {
|
2020-11-02 11:11:07 +00:00
|
|
|
const offset_halves = splitValue64(offset);
|
2020-03-03 16:19:40 +00:00
|
|
|
if (require_aligned_register_pair) {
|
|
|
|
return syscall6(
|
2020-03-02 12:30:53 +00:00
|
|
|
.pread64,
|
2020-03-03 16:19:40 +00:00
|
|
|
@bitCast(usize, @as(isize, fd)),
|
|
|
|
@ptrToInt(buf),
|
|
|
|
count,
|
|
|
|
0,
|
2020-11-02 11:11:07 +00:00
|
|
|
offset_halves[0],
|
|
|
|
offset_halves[1],
|
2020-03-03 16:19:40 +00:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return syscall5(
|
2020-03-02 12:30:53 +00:00
|
|
|
.pread64,
|
2020-03-03 16:19:40 +00:00
|
|
|
@bitCast(usize, @as(isize, fd)),
|
|
|
|
@ptrToInt(buf),
|
|
|
|
count,
|
2020-11-02 11:11:07 +00:00
|
|
|
offset_halves[0],
|
|
|
|
offset_halves[1],
|
2020-03-03 16:19:40 +00:00
|
|
|
);
|
|
|
|
}
|
2020-03-03 07:03:22 +00:00
|
|
|
} else {
|
2020-03-11 19:03:36 +00:00
|
|
|
return syscall4(
|
2020-03-02 12:30:53 +00:00
|
|
|
.pread,
|
2020-03-11 19:03:36 +00:00
|
|
|
@bitCast(usize, @as(isize, fd)),
|
|
|
|
@ptrToInt(buf),
|
|
|
|
count,
|
|
|
|
offset,
|
|
|
|
);
|
2020-03-03 07:03:22 +00:00
|
|
|
}
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2019-12-17 20:43:49 +00:00
|
|
|
pub fn access(path: [*:0]const u8, mode: u32) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
if (@hasField(SYS, "access")) {
|
|
|
|
return syscall2(.access, @ptrToInt(path), mode);
|
2019-05-30 14:28:33 +00:00
|
|
|
} else {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall4(.faccessat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), mode, 0);
|
2019-05-30 14:28:33 +00:00
|
|
|
}
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2019-12-17 20:43:49 +00:00
|
|
|
pub fn faccessat(dirfd: i32, path: [*:0]const u8, mode: u32, flags: u32) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall4(.faccessat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), mode, flags);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn pipe(fd: *[2]i32) usize {
|
2020-10-24 14:33:40 +00:00
|
|
|
if (comptime (builtin.arch.isMIPS() or builtin.arch.isSPARC())) {
|
2019-10-03 13:32:47 +00:00
|
|
|
return syscall_pipe(fd);
|
2020-03-02 12:30:53 +00:00
|
|
|
} else if (@hasField(SYS, "pipe")) {
|
|
|
|
return syscall1(.pipe, @ptrToInt(fd));
|
2019-05-25 17:07:44 +00:00
|
|
|
} else {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall2(.pipe2, @ptrToInt(fd), 0);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn pipe2(fd: *[2]i32, flags: u32) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall2(.pipe2, @ptrToInt(fd), flags);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn write(fd: i32, buf: [*]const u8, count: usize) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall3(.write, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2020-03-11 19:56:43 +00:00
|
|
|
pub fn ftruncate(fd: i32, length: u64) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
if (@hasField(SYS, "ftruncate64")) {
|
2020-11-02 11:11:07 +00:00
|
|
|
const length_halves = splitValue64(length);
|
2020-03-11 19:56:43 +00:00
|
|
|
if (require_aligned_register_pair) {
|
|
|
|
return syscall4(
|
2020-03-02 12:30:53 +00:00
|
|
|
.ftruncate64,
|
2020-03-11 19:56:43 +00:00
|
|
|
@bitCast(usize, @as(isize, fd)),
|
|
|
|
0,
|
2020-11-02 11:11:07 +00:00
|
|
|
length_halves[0],
|
|
|
|
length_halves[1],
|
2020-03-11 19:56:43 +00:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return syscall3(
|
2020-03-02 12:30:53 +00:00
|
|
|
.ftruncate64,
|
2020-03-11 19:56:43 +00:00
|
|
|
@bitCast(usize, @as(isize, fd)),
|
2020-11-02 11:11:07 +00:00
|
|
|
length_halves[0],
|
|
|
|
length_halves[1],
|
2020-03-11 19:56:43 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return syscall2(
|
2020-03-02 12:30:53 +00:00
|
|
|
.ftruncate,
|
2020-03-11 19:56:43 +00:00
|
|
|
@bitCast(usize, @as(isize, fd)),
|
|
|
|
@truncate(usize, length),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-25 23:59:39 +00:00
|
|
|
pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: u64) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
if (@hasField(SYS, "pwrite64")) {
|
2020-11-02 11:11:07 +00:00
|
|
|
const offset_halves = splitValue64(offset);
|
|
|
|
|
2020-03-11 19:03:36 +00:00
|
|
|
if (require_aligned_register_pair) {
|
|
|
|
return syscall6(
|
2020-03-02 12:30:53 +00:00
|
|
|
.pwrite64,
|
2020-03-11 19:03:36 +00:00
|
|
|
@bitCast(usize, @as(isize, fd)),
|
|
|
|
@ptrToInt(buf),
|
|
|
|
count,
|
|
|
|
0,
|
2020-11-02 11:11:07 +00:00
|
|
|
offset_halves[0],
|
|
|
|
offset_halves[1],
|
2020-03-11 19:03:36 +00:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return syscall5(
|
2020-03-02 12:30:53 +00:00
|
|
|
.pwrite64,
|
2020-03-11 19:03:36 +00:00
|
|
|
@bitCast(usize, @as(isize, fd)),
|
|
|
|
@ptrToInt(buf),
|
|
|
|
count,
|
2020-11-02 11:11:07 +00:00
|
|
|
offset_halves[0],
|
|
|
|
offset_halves[1],
|
2020-03-11 19:03:36 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return syscall4(
|
2020-03-02 12:30:53 +00:00
|
|
|
.pwrite,
|
2020-03-11 19:03:36 +00:00
|
|
|
@bitCast(usize, @as(isize, fd)),
|
|
|
|
@ptrToInt(buf),
|
|
|
|
count,
|
|
|
|
offset,
|
|
|
|
);
|
|
|
|
}
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2019-12-17 20:43:49 +00:00
|
|
|
pub fn rename(old: [*:0]const u8, new: [*:0]const u8) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
if (@hasField(SYS, "rename")) {
|
|
|
|
return syscall2(.rename, @ptrToInt(old), @ptrToInt(new));
|
|
|
|
} else if (@hasField(SYS, "renameat")) {
|
|
|
|
return syscall4(.renameat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(old), @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(new));
|
2019-05-25 17:07:44 +00:00
|
|
|
} else {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall5(.renameat2, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(old), @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(new), 0);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn renameat(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const u8) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
if (@hasField(SYS, "renameat")) {
|
2019-05-25 17:07:44 +00:00
|
|
|
return syscall4(
|
2020-03-02 12:30:53 +00:00
|
|
|
.renameat,
|
2019-11-07 04:25:57 +00:00
|
|
|
@bitCast(usize, @as(isize, oldfd)),
|
zig build system: correctly handle multiple output artifacts
Previously the zig build system incorrectly assumed that the only build
artifact was a binary. Now, when you enable the cache, only the output
dir is printed to stdout, and the zig build system iterates over the
files in that directory, copying them to the output directory.
To support this change:
* Add `std.os.renameat`, `std.os.renameatZ`, and `std.os.renameatW`.
* Fix `std.os.linux.renameat` not compiling due to typos.
* Deprecate `std.fs.updateFile` and `std.fs.updateFileMode`.
* Add `std.fs.Dir.updateFile`, which supports using open directory
handles for both the source and destination paths, as well as an
options parameter which allows overriding the mode.
* Update `std.fs.AtomicFile` to support operating based on an open
directory handle. Instead of `std.fs.AtomicFile.init`, use
`std.fs.Dir.atomicFile`.
* `std.fs.AtomicFile` deinit() better handles the situation when the
rename fails but the temporary file still exists, by still
attempting to remove the temporary file.
* `std.fs.Dir.openFileWindows` is moved to `std.os.windows.OpenFileW`.
* `std.os.RenameError` gains the error codes `NoDevice`,
`SharingViolation`, and `PipeBusy` which have been observed from
Windows.
Closes #4733
2020-03-14 01:06:07 +00:00
|
|
|
@ptrToInt(oldpath),
|
2019-11-07 04:25:57 +00:00
|
|
|
@bitCast(usize, @as(isize, newfd)),
|
zig build system: correctly handle multiple output artifacts
Previously the zig build system incorrectly assumed that the only build
artifact was a binary. Now, when you enable the cache, only the output
dir is printed to stdout, and the zig build system iterates over the
files in that directory, copying them to the output directory.
To support this change:
* Add `std.os.renameat`, `std.os.renameatZ`, and `std.os.renameatW`.
* Fix `std.os.linux.renameat` not compiling due to typos.
* Deprecate `std.fs.updateFile` and `std.fs.updateFileMode`.
* Add `std.fs.Dir.updateFile`, which supports using open directory
handles for both the source and destination paths, as well as an
options parameter which allows overriding the mode.
* Update `std.fs.AtomicFile` to support operating based on an open
directory handle. Instead of `std.fs.AtomicFile.init`, use
`std.fs.Dir.atomicFile`.
* `std.fs.AtomicFile` deinit() better handles the situation when the
rename fails but the temporary file still exists, by still
attempting to remove the temporary file.
* `std.fs.Dir.openFileWindows` is moved to `std.os.windows.OpenFileW`.
* `std.os.RenameError` gains the error codes `NoDevice`,
`SharingViolation`, and `PipeBusy` which have been observed from
Windows.
Closes #4733
2020-03-14 01:06:07 +00:00
|
|
|
@ptrToInt(newpath),
|
2019-05-25 17:07:44 +00:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return syscall5(
|
2020-03-02 12:30:53 +00:00
|
|
|
.renameat2,
|
2019-11-07 04:25:57 +00:00
|
|
|
@bitCast(usize, @as(isize, oldfd)),
|
zig build system: correctly handle multiple output artifacts
Previously the zig build system incorrectly assumed that the only build
artifact was a binary. Now, when you enable the cache, only the output
dir is printed to stdout, and the zig build system iterates over the
files in that directory, copying them to the output directory.
To support this change:
* Add `std.os.renameat`, `std.os.renameatZ`, and `std.os.renameatW`.
* Fix `std.os.linux.renameat` not compiling due to typos.
* Deprecate `std.fs.updateFile` and `std.fs.updateFileMode`.
* Add `std.fs.Dir.updateFile`, which supports using open directory
handles for both the source and destination paths, as well as an
options parameter which allows overriding the mode.
* Update `std.fs.AtomicFile` to support operating based on an open
directory handle. Instead of `std.fs.AtomicFile.init`, use
`std.fs.Dir.atomicFile`.
* `std.fs.AtomicFile` deinit() better handles the situation when the
rename fails but the temporary file still exists, by still
attempting to remove the temporary file.
* `std.fs.Dir.openFileWindows` is moved to `std.os.windows.OpenFileW`.
* `std.os.RenameError` gains the error codes `NoDevice`,
`SharingViolation`, and `PipeBusy` which have been observed from
Windows.
Closes #4733
2020-03-14 01:06:07 +00:00
|
|
|
@ptrToInt(oldpath),
|
2019-11-07 04:25:57 +00:00
|
|
|
@bitCast(usize, @as(isize, newfd)),
|
zig build system: correctly handle multiple output artifacts
Previously the zig build system incorrectly assumed that the only build
artifact was a binary. Now, when you enable the cache, only the output
dir is printed to stdout, and the zig build system iterates over the
files in that directory, copying them to the output directory.
To support this change:
* Add `std.os.renameat`, `std.os.renameatZ`, and `std.os.renameatW`.
* Fix `std.os.linux.renameat` not compiling due to typos.
* Deprecate `std.fs.updateFile` and `std.fs.updateFileMode`.
* Add `std.fs.Dir.updateFile`, which supports using open directory
handles for both the source and destination paths, as well as an
options parameter which allows overriding the mode.
* Update `std.fs.AtomicFile` to support operating based on an open
directory handle. Instead of `std.fs.AtomicFile.init`, use
`std.fs.Dir.atomicFile`.
* `std.fs.AtomicFile` deinit() better handles the situation when the
rename fails but the temporary file still exists, by still
attempting to remove the temporary file.
* `std.fs.Dir.openFileWindows` is moved to `std.os.windows.OpenFileW`.
* `std.os.RenameError` gains the error codes `NoDevice`,
`SharingViolation`, and `PipeBusy` which have been observed from
Windows.
Closes #4733
2020-03-14 01:06:07 +00:00
|
|
|
@ptrToInt(newpath),
|
2019-05-25 17:07:44 +00:00
|
|
|
0,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-17 20:43:49 +00:00
|
|
|
pub fn renameat2(oldfd: i32, oldpath: [*:0]const u8, newfd: i32, newpath: [*:0]const u8, flags: u32) usize {
|
2019-05-25 17:07:44 +00:00
|
|
|
return syscall5(
|
2020-03-02 12:30:53 +00:00
|
|
|
.renameat2,
|
2019-11-07 04:25:57 +00:00
|
|
|
@bitCast(usize, @as(isize, oldfd)),
|
2019-05-25 17:07:44 +00:00
|
|
|
@ptrToInt(oldpath),
|
2019-11-07 04:25:57 +00:00
|
|
|
@bitCast(usize, @as(isize, newfd)),
|
2019-05-25 17:07:44 +00:00
|
|
|
@ptrToInt(newpath),
|
|
|
|
flags,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-05-02 18:14:46 +00:00
|
|
|
pub fn open(path: [*:0]const u8, flags: u32, perm: mode_t) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
if (@hasField(SYS, "open")) {
|
|
|
|
return syscall3(.open, @ptrToInt(path), flags, perm);
|
2019-05-30 14:28:33 +00:00
|
|
|
} else {
|
|
|
|
return syscall4(
|
2020-03-02 12:30:53 +00:00
|
|
|
.openat,
|
2019-11-07 04:25:57 +00:00
|
|
|
@bitCast(usize, @as(isize, AT_FDCWD)),
|
2019-05-30 14:28:33 +00:00
|
|
|
@ptrToInt(path),
|
|
|
|
flags,
|
|
|
|
perm,
|
|
|
|
);
|
|
|
|
}
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2020-05-02 18:14:46 +00:00
|
|
|
pub fn create(path: [*:0]const u8, perm: mode_t) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall2(.creat, @ptrToInt(path), perm);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2020-05-02 18:14:46 +00:00
|
|
|
pub fn openat(dirfd: i32, path: [*:0]const u8, flags: u32, mode: mode_t) usize {
|
2019-05-25 17:07:44 +00:00
|
|
|
// dirfd could be negative, for example AT_FDCWD is -100
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall4(.openat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), flags, mode);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// See also `clone` (from the arch-specific include)
|
|
|
|
pub fn clone5(flags: usize, child_stack_ptr: usize, parent_tid: *i32, child_tid: *i32, newtls: usize) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall5(.clone, flags, child_stack_ptr, @ptrToInt(parent_tid), @ptrToInt(child_tid), newtls);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// See also `clone` (from the arch-specific include)
|
|
|
|
pub fn clone2(flags: u32, child_stack_ptr: usize) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall2(.clone, flags, child_stack_ptr);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn close(fd: i32) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall1(.close, @bitCast(usize, @as(isize, fd)));
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Can only be called on 32 bit systems. For 64 bit see `lseek`.
|
|
|
|
pub fn llseek(fd: i32, offset: u64, result: ?*u64, whence: usize) usize {
|
2020-11-02 11:11:07 +00:00
|
|
|
// NOTE: The offset parameter splitting is independent from the target
|
|
|
|
// endianness.
|
2019-05-25 17:07:44 +00:00
|
|
|
return syscall5(
|
2020-03-02 12:30:53 +00:00
|
|
|
._llseek,
|
2019-11-07 04:25:57 +00:00
|
|
|
@bitCast(usize, @as(isize, fd)),
|
2019-05-25 17:07:44 +00:00
|
|
|
@truncate(usize, offset >> 32),
|
|
|
|
@truncate(usize, offset),
|
|
|
|
@ptrToInt(result),
|
|
|
|
whence,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Can only be called on 64 bit systems. For 32 bit see `llseek`.
|
|
|
|
pub fn lseek(fd: i32, offset: i64, whence: usize) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall3(.lseek, @bitCast(usize, @as(isize, fd)), @bitCast(usize, offset), whence);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn exit(status: i32) noreturn {
|
2020-03-02 12:30:53 +00:00
|
|
|
_ = syscall1(.exit, @bitCast(usize, @as(isize, status)));
|
2019-05-25 17:07:44 +00:00
|
|
|
unreachable;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn exit_group(status: i32) noreturn {
|
2020-03-02 12:30:53 +00:00
|
|
|
_ = syscall1(.exit_group, @bitCast(usize, @as(isize, status)));
|
2019-05-25 17:07:44 +00:00
|
|
|
unreachable;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn getrandom(buf: [*]u8, count: usize, flags: u32) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall3(.getrandom, @ptrToInt(buf), count, flags);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2019-12-22 01:25:45 +00:00
|
|
|
pub fn kill(pid: pid_t, sig: i32) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall2(.kill, @bitCast(usize, @as(isize, pid)), @bitCast(usize, @as(isize, sig)));
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2019-12-22 01:17:11 +00:00
|
|
|
pub fn tkill(tid: pid_t, sig: i32) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall2(.tkill, @bitCast(usize, @as(isize, tid)), @bitCast(usize, @as(isize, sig)));
|
2019-12-22 01:17:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn tgkill(tgid: pid_t, tid: pid_t, sig: i32) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall2(.tgkill, @bitCast(usize, @as(isize, tgid)), @bitCast(usize, @as(isize, tid)), @bitCast(usize, @as(isize, sig)));
|
2019-12-22 01:17:11 +00:00
|
|
|
}
|
|
|
|
|
2019-12-17 20:43:49 +00:00
|
|
|
pub fn unlink(path: [*:0]const u8) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
if (@hasField(SYS, "unlink")) {
|
|
|
|
return syscall1(.unlink, @ptrToInt(path));
|
2019-05-25 17:07:44 +00:00
|
|
|
} else {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall3(.unlinkat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), 0);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-17 20:43:49 +00:00
|
|
|
pub fn unlinkat(dirfd: i32, path: [*:0]const u8, flags: u32) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall3(.unlinkat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), flags);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2019-12-22 01:25:45 +00:00
|
|
|
pub fn waitpid(pid: pid_t, status: *u32, flags: u32) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall4(.wait4, @bitCast(usize, @as(isize, pid)), @ptrToInt(status), flags, 0);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2020-03-16 10:39:18 +00:00
|
|
|
pub fn fcntl(fd: fd_t, cmd: i32, arg: usize) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall3(.fcntl, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, cmd)), arg);
|
2020-03-16 10:39:18 +00:00
|
|
|
}
|
|
|
|
|
2020-04-03 04:57:02 +00:00
|
|
|
pub fn flock(fd: fd_t, operation: i32) usize {
|
|
|
|
return syscall2(.flock, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, operation)));
|
|
|
|
}
|
|
|
|
|
2019-05-25 17:07:44 +00:00
|
|
|
var vdso_clock_gettime = @ptrCast(?*const c_void, init_vdso_clock_gettime);
|
|
|
|
|
|
|
|
// We must follow the C calling convention when we call into the VDSO
|
2020-05-04 15:49:27 +00:00
|
|
|
const vdso_clock_gettime_ty = fn (i32, *timespec) callconv(.C) usize;
|
2019-05-25 17:07:44 +00:00
|
|
|
|
|
|
|
pub fn clock_gettime(clk_id: i32, tp: *timespec) usize {
|
2019-09-25 07:30:44 +00:00
|
|
|
if (@hasDecl(@This(), "VDSO_CGT_SYM")) {
|
2019-05-25 17:07:44 +00:00
|
|
|
const ptr = @atomicLoad(?*const c_void, &vdso_clock_gettime, .Unordered);
|
|
|
|
if (ptr) |fn_ptr| {
|
|
|
|
const f = @ptrCast(vdso_clock_gettime_ty, fn_ptr);
|
|
|
|
const rc = f(clk_id, tp);
|
|
|
|
switch (rc) {
|
2019-11-07 04:25:57 +00:00
|
|
|
0, @bitCast(usize, @as(isize, -EINVAL)) => return rc,
|
2019-05-25 17:07:44 +00:00
|
|
|
else => {},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall2(.clock_gettime, @bitCast(usize, @as(isize, clk_id)), @ptrToInt(tp));
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2020-01-06 20:34:50 +00:00
|
|
|
fn init_vdso_clock_gettime(clk: i32, ts: *timespec) callconv(.C) usize {
|
2019-05-25 17:07:44 +00:00
|
|
|
const ptr = @intToPtr(?*const c_void, vdso.lookup(VDSO_CGT_VER, VDSO_CGT_SYM));
|
|
|
|
// Note that we may not have a VDSO at all, update the stub address anyway
|
|
|
|
// so that clock_gettime will fall back on the good old (and slow) syscall
|
2019-11-12 22:45:37 +00:00
|
|
|
@atomicStore(?*const c_void, &vdso_clock_gettime, ptr, .Monotonic);
|
2019-05-25 17:07:44 +00:00
|
|
|
// Call into the VDSO if available
|
|
|
|
if (ptr) |fn_ptr| {
|
|
|
|
const f = @ptrCast(vdso_clock_gettime_ty, fn_ptr);
|
|
|
|
return f(clk, ts);
|
|
|
|
}
|
2019-11-07 04:25:57 +00:00
|
|
|
return @bitCast(usize, @as(isize, -ENOSYS));
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn clock_getres(clk_id: i32, tp: *timespec) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall2(.clock_getres, @bitCast(usize, @as(isize, clk_id)), @ptrToInt(tp));
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn clock_settime(clk_id: i32, tp: *const timespec) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall2(.clock_settime, @bitCast(usize, @as(isize, clk_id)), @ptrToInt(tp));
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn gettimeofday(tv: *timeval, tz: *timezone) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall2(.gettimeofday, @ptrToInt(tv), @ptrToInt(tz));
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn settimeofday(tv: *const timeval, tz: *const timezone) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall2(.settimeofday, @ptrToInt(tv), @ptrToInt(tz));
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn nanosleep(req: *const timespec, rem: ?*timespec) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall2(.nanosleep, @ptrToInt(req), @ptrToInt(rem));
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2020-09-03 13:08:37 +00:00
|
|
|
pub fn setuid(uid: uid_t) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
if (@hasField(SYS, "setuid32")) {
|
|
|
|
return syscall1(.setuid32, uid);
|
2019-09-01 09:54:57 +00:00
|
|
|
} else {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall1(.setuid, uid);
|
2019-09-01 09:54:57 +00:00
|
|
|
}
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2020-09-03 13:08:37 +00:00
|
|
|
pub fn setgid(gid: gid_t) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
if (@hasField(SYS, "setgid32")) {
|
|
|
|
return syscall1(.setgid32, gid);
|
2019-09-01 09:54:57 +00:00
|
|
|
} else {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall1(.setgid, gid);
|
2019-09-01 09:54:57 +00:00
|
|
|
}
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2020-09-03 13:08:37 +00:00
|
|
|
pub fn setreuid(ruid: uid_t, euid: uid_t) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
if (@hasField(SYS, "setreuid32")) {
|
|
|
|
return syscall2(.setreuid32, ruid, euid);
|
2019-09-01 09:54:57 +00:00
|
|
|
} else {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall2(.setreuid, ruid, euid);
|
2019-09-01 09:54:57 +00:00
|
|
|
}
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2020-09-03 13:08:37 +00:00
|
|
|
pub fn setregid(rgid: gid_t, egid: gid_t) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
if (@hasField(SYS, "setregid32")) {
|
|
|
|
return syscall2(.setregid32, rgid, egid);
|
2019-09-01 09:54:57 +00:00
|
|
|
} else {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall2(.setregid, rgid, egid);
|
2019-09-01 09:54:57 +00:00
|
|
|
}
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2020-09-03 13:08:37 +00:00
|
|
|
pub fn getuid() uid_t {
|
2020-03-02 12:30:53 +00:00
|
|
|
if (@hasField(SYS, "getuid32")) {
|
2020-12-23 09:16:27 +00:00
|
|
|
return @intCast(uid_t, syscall0(.getuid32));
|
2019-09-01 09:54:57 +00:00
|
|
|
} else {
|
2020-12-23 09:16:27 +00:00
|
|
|
return @intCast(uid_t, syscall0(.getuid));
|
2019-09-01 09:54:57 +00:00
|
|
|
}
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2020-09-03 13:08:37 +00:00
|
|
|
pub fn getgid() gid_t {
|
2020-03-02 12:30:53 +00:00
|
|
|
if (@hasField(SYS, "getgid32")) {
|
2020-12-23 09:16:27 +00:00
|
|
|
return @intCast(gid_t, syscall0(.getgid32));
|
2019-09-01 09:54:57 +00:00
|
|
|
} else {
|
2020-12-23 09:16:27 +00:00
|
|
|
return @intCast(gid_t, syscall0(.getgid));
|
2019-09-01 09:54:57 +00:00
|
|
|
}
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2020-09-03 13:08:37 +00:00
|
|
|
pub fn geteuid() uid_t {
|
2020-03-02 12:30:53 +00:00
|
|
|
if (@hasField(SYS, "geteuid32")) {
|
2020-12-23 09:16:27 +00:00
|
|
|
return @intCast(uid_t, syscall0(.geteuid32));
|
2019-09-01 09:54:57 +00:00
|
|
|
} else {
|
2020-12-23 09:16:27 +00:00
|
|
|
return @intCast(uid_t, syscall0(.geteuid));
|
2019-09-01 09:54:57 +00:00
|
|
|
}
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2020-09-03 13:08:37 +00:00
|
|
|
pub fn getegid() gid_t {
|
2020-03-02 12:30:53 +00:00
|
|
|
if (@hasField(SYS, "getegid32")) {
|
2020-12-23 09:16:27 +00:00
|
|
|
return @intCast(gid_t, syscall0(.getegid32));
|
2019-09-01 09:54:57 +00:00
|
|
|
} else {
|
2020-12-23 09:16:27 +00:00
|
|
|
return @intCast(gid_t, syscall0(.getegid));
|
2019-09-01 09:54:57 +00:00
|
|
|
}
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2020-09-03 13:08:37 +00:00
|
|
|
pub fn seteuid(euid: uid_t) usize {
|
2020-09-03 13:16:26 +00:00
|
|
|
// We use setresuid here instead of setreuid to ensure that the saved uid
|
|
|
|
// is not changed. This is what musl and recent glibc versions do as well.
|
|
|
|
//
|
|
|
|
// The setresuid(2) man page says that if -1 is passed the corresponding
|
|
|
|
// id will not be changed. Since uid_t is unsigned, this wraps around to the
|
|
|
|
// max value in C.
|
2020-10-18 00:04:53 +00:00
|
|
|
comptime assert(@typeInfo(uid_t) == .Int and @typeInfo(uid_t).Int.signedness == .unsigned);
|
2020-09-03 13:16:26 +00:00
|
|
|
return setresuid(std.math.maxInt(uid_t), euid, std.math.maxInt(uid_t));
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2020-09-03 13:08:37 +00:00
|
|
|
pub fn setegid(egid: gid_t) usize {
|
2020-09-03 13:16:26 +00:00
|
|
|
// We use setresgid here instead of setregid to ensure that the saved uid
|
|
|
|
// is not changed. This is what musl and recent glibc versions do as well.
|
|
|
|
//
|
|
|
|
// The setresgid(2) man page says that if -1 is passed the corresponding
|
|
|
|
// id will not be changed. Since gid_t is unsigned, this wraps around to the
|
|
|
|
// max value in C.
|
2020-10-18 00:04:53 +00:00
|
|
|
comptime assert(@typeInfo(uid_t) == .Int and @typeInfo(uid_t).Int.signedness == .unsigned);
|
2020-09-03 13:16:26 +00:00
|
|
|
return setresgid(std.math.maxInt(gid_t), egid, std.math.maxInt(gid_t));
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2020-09-03 13:08:37 +00:00
|
|
|
pub fn getresuid(ruid: *uid_t, euid: *uid_t, suid: *uid_t) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
if (@hasField(SYS, "getresuid32")) {
|
|
|
|
return syscall3(.getresuid32, @ptrToInt(ruid), @ptrToInt(euid), @ptrToInt(suid));
|
2019-09-01 09:54:57 +00:00
|
|
|
} else {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall3(.getresuid, @ptrToInt(ruid), @ptrToInt(euid), @ptrToInt(suid));
|
2019-09-01 09:54:57 +00:00
|
|
|
}
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2020-09-03 13:08:37 +00:00
|
|
|
pub fn getresgid(rgid: *gid_t, egid: *gid_t, sgid: *gid_t) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
if (@hasField(SYS, "getresgid32")) {
|
|
|
|
return syscall3(.getresgid32, @ptrToInt(rgid), @ptrToInt(egid), @ptrToInt(sgid));
|
2019-09-01 09:54:57 +00:00
|
|
|
} else {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall3(.getresgid, @ptrToInt(rgid), @ptrToInt(egid), @ptrToInt(sgid));
|
2019-09-01 09:54:57 +00:00
|
|
|
}
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2020-09-03 13:08:37 +00:00
|
|
|
pub fn setresuid(ruid: uid_t, euid: uid_t, suid: uid_t) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
if (@hasField(SYS, "setresuid32")) {
|
|
|
|
return syscall3(.setresuid32, ruid, euid, suid);
|
2019-09-01 09:54:57 +00:00
|
|
|
} else {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall3(.setresuid, ruid, euid, suid);
|
2019-09-01 09:54:57 +00:00
|
|
|
}
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2020-09-03 13:08:37 +00:00
|
|
|
pub fn setresgid(rgid: gid_t, egid: gid_t, sgid: gid_t) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
if (@hasField(SYS, "setresgid32")) {
|
|
|
|
return syscall3(.setresgid32, rgid, egid, sgid);
|
2019-09-01 09:54:57 +00:00
|
|
|
} else {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall3(.setresgid, rgid, egid, sgid);
|
2019-09-01 09:54:57 +00:00
|
|
|
}
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2020-09-03 13:08:37 +00:00
|
|
|
pub fn getgroups(size: usize, list: *gid_t) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
if (@hasField(SYS, "getgroups32")) {
|
|
|
|
return syscall2(.getgroups32, size, @ptrToInt(list));
|
2019-09-01 09:54:57 +00:00
|
|
|
} else {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall2(.getgroups, size, @ptrToInt(list));
|
2019-09-01 09:54:57 +00:00
|
|
|
}
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2020-09-03 13:08:37 +00:00
|
|
|
pub fn setgroups(size: usize, list: *const gid_t) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
if (@hasField(SYS, "setgroups32")) {
|
|
|
|
return syscall2(.setgroups32, size, @ptrToInt(list));
|
2019-09-01 09:54:57 +00:00
|
|
|
} else {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall2(.setgroups, size, @ptrToInt(list));
|
2019-09-01 09:54:57 +00:00
|
|
|
}
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2019-12-22 01:25:45 +00:00
|
|
|
pub fn getpid() pid_t {
|
2020-03-02 12:30:53 +00:00
|
|
|
return @bitCast(pid_t, @truncate(u32, syscall0(.getpid)));
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2019-12-22 01:25:45 +00:00
|
|
|
pub fn gettid() pid_t {
|
2020-03-02 12:30:53 +00:00
|
|
|
return @bitCast(pid_t, @truncate(u32, syscall0(.gettid)));
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2019-12-22 01:03:03 +00:00
|
|
|
pub fn sigprocmask(flags: u32, noalias set: ?*const sigset_t, noalias oldset: ?*sigset_t) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall4(.rt_sigprocmask, flags, @ptrToInt(set), @ptrToInt(oldset), NSIG / 8);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2020-12-12 12:57:25 +00:00
|
|
|
pub fn sigaction(sig: u6, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) usize {
|
2019-05-25 17:07:44 +00:00
|
|
|
assert(sig >= 1);
|
|
|
|
assert(sig != SIGKILL);
|
|
|
|
assert(sig != SIGSTOP);
|
2019-10-01 13:57:38 +00:00
|
|
|
|
2020-12-12 12:57:25 +00:00
|
|
|
var ksa: k_sigaction = undefined;
|
|
|
|
var oldksa: k_sigaction = undefined;
|
|
|
|
const mask_size = @sizeOf(@TypeOf(ksa.mask));
|
|
|
|
|
|
|
|
if (act) |new| {
|
|
|
|
const restorer_fn = if ((new.flags & SA_SIGINFO) != 0) restore_rt else restore;
|
|
|
|
ksa = k_sigaction{
|
2020-12-12 15:44:10 +00:00
|
|
|
.handler = new.handler.handler,
|
2020-12-12 12:57:25 +00:00
|
|
|
.flags = new.flags | SA_RESTORER,
|
|
|
|
.mask = undefined,
|
|
|
|
.restorer = @ptrCast(fn () callconv(.C) void, restorer_fn),
|
|
|
|
};
|
|
|
|
@memcpy(@ptrCast([*]u8, &ksa.mask), @ptrCast([*]const u8, &new.mask), mask_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
const ksa_arg = if (act != null) @ptrToInt(&ksa) else 0;
|
|
|
|
const oldksa_arg = if (oact != null) @ptrToInt(&oldksa) else 0;
|
|
|
|
|
2020-10-24 12:58:01 +00:00
|
|
|
const result = switch (builtin.arch) {
|
|
|
|
// The sparc version of rt_sigaction needs the restorer function to be passed as an argument too.
|
2020-12-12 12:57:25 +00:00
|
|
|
.sparc, .sparcv9 => syscall5(.rt_sigaction, sig, ksa_arg, oldksa_arg, @ptrToInt(ksa.restorer), mask_size),
|
|
|
|
else => syscall4(.rt_sigaction, sig, ksa_arg, oldksa_arg, mask_size),
|
2020-10-24 12:58:01 +00:00
|
|
|
};
|
2020-12-12 12:57:25 +00:00
|
|
|
if (getErrno(result) != 0) return result;
|
|
|
|
|
2019-05-25 17:07:44 +00:00
|
|
|
if (oact) |old| {
|
2020-12-12 15:44:10 +00:00
|
|
|
old.handler.handler = oldksa.handler;
|
|
|
|
old.flags = @truncate(c_uint, oldksa.flags);
|
2020-12-12 12:57:25 +00:00
|
|
|
@memcpy(@ptrCast([*]u8, &old.mask), @ptrCast([*]const u8, &oldksa.mask), mask_size);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
2020-12-12 12:57:25 +00:00
|
|
|
|
2019-05-25 17:07:44 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-09-03 15:09:55 +00:00
|
|
|
const usize_bits = @typeInfo(usize).Int.bits;
|
|
|
|
|
2019-05-25 17:07:44 +00:00
|
|
|
pub fn sigaddset(set: *sigset_t, sig: u6) void {
|
|
|
|
const s = sig - 1;
|
2020-07-22 21:26:27 +00:00
|
|
|
// shift in musl: s&8*sizeof *set->__bits-1
|
2020-09-03 15:09:55 +00:00
|
|
|
const shift = @intCast(u5, s & (usize_bits - 1));
|
2020-07-22 21:26:27 +00:00
|
|
|
const val = @intCast(u32, 1) << shift;
|
2020-09-03 15:09:55 +00:00
|
|
|
(set.*)[@intCast(usize, s) / usize_bits] |= val;
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn sigismember(set: *const sigset_t, sig: u6) bool {
|
|
|
|
const s = sig - 1;
|
2020-09-03 15:09:55 +00:00
|
|
|
return ((set.*)[@intCast(usize, s) / usize_bits] & (@intCast(usize, 1) << (s & (usize_bits - 1)))) != 0;
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn getsockname(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize {
|
2019-11-30 15:13:33 +00:00
|
|
|
if (builtin.arch == .i386) {
|
|
|
|
return socketcall(SC_getsockname, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len) });
|
|
|
|
}
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall3(.getsockname, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len));
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn getpeername(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize {
|
2019-11-30 15:13:33 +00:00
|
|
|
if (builtin.arch == .i386) {
|
|
|
|
return socketcall(SC_getpeername, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len) });
|
|
|
|
}
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall3(.getpeername, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len));
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn socket(domain: u32, socket_type: u32, protocol: u32) usize {
|
2019-11-30 15:13:33 +00:00
|
|
|
if (builtin.arch == .i386) {
|
|
|
|
return socketcall(SC_socket, &[3]usize{ domain, socket_type, protocol });
|
|
|
|
}
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall3(.socket, domain, socket_type, protocol);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn setsockopt(fd: i32, level: u32, optname: u32, optval: [*]const u8, optlen: socklen_t) usize {
|
2019-11-30 15:13:33 +00:00
|
|
|
if (builtin.arch == .i386) {
|
|
|
|
return socketcall(SC_setsockopt, &[5]usize{ @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @intCast(usize, optlen) });
|
|
|
|
}
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall5(.setsockopt, @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @intCast(usize, optlen));
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn getsockopt(fd: i32, level: u32, optname: u32, noalias optval: [*]u8, noalias optlen: *socklen_t) usize {
|
2019-11-30 15:13:33 +00:00
|
|
|
if (builtin.arch == .i386) {
|
|
|
|
return socketcall(SC_getsockopt, &[5]usize{ @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @ptrToInt(optlen) });
|
|
|
|
}
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall5(.getsockopt, @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @ptrToInt(optlen));
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn sendmsg(fd: i32, msg: *msghdr_const, flags: u32) usize {
|
2019-11-30 15:13:33 +00:00
|
|
|
if (builtin.arch == .i386) {
|
|
|
|
return socketcall(SC_sendmsg, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags });
|
|
|
|
}
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall3(.sendmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize {
|
2019-12-09 20:56:19 +00:00
|
|
|
if (@typeInfo(usize).Int.bits > @typeInfo(@TypeOf(mmsghdr(undefined).msg_len)).Int.bits) {
|
2019-05-25 17:07:44 +00:00
|
|
|
// workaround kernel brokenness:
|
|
|
|
// if adding up all iov_len overflows a i32 then split into multiple calls
|
|
|
|
// see https://www.openwall.com/lists/musl/2014/06/07/5
|
|
|
|
const kvlen = if (vlen > IOV_MAX) IOV_MAX else vlen; // matches kernel
|
|
|
|
var next_unsent: usize = 0;
|
|
|
|
for (msgvec[0..kvlen]) |*msg, i| {
|
|
|
|
var size: i32 = 0;
|
|
|
|
const msg_iovlen = @intCast(usize, msg.msg_hdr.msg_iovlen); // kernel side this is treated as unsigned
|
|
|
|
for (msg.msg_hdr.msg_iov[0..msg_iovlen]) |iov, j| {
|
|
|
|
if (iov.iov_len > std.math.maxInt(i32) or @addWithOverflow(i32, size, @intCast(i32, iov.iov_len), &size)) {
|
|
|
|
// batch-send all messages up to the current message
|
|
|
|
if (next_unsent < i) {
|
|
|
|
const batch_size = i - next_unsent;
|
2020-03-02 12:30:53 +00:00
|
|
|
const r = syscall4(.sendmmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(&msgvec[next_unsent]), batch_size, flags);
|
2019-05-25 17:07:44 +00:00
|
|
|
if (getErrno(r) != 0) return next_unsent;
|
|
|
|
if (r < batch_size) return next_unsent + r;
|
|
|
|
}
|
|
|
|
// send current message as own packet
|
|
|
|
const r = sendmsg(fd, &msg.msg_hdr, flags);
|
|
|
|
if (getErrno(r) != 0) return r;
|
|
|
|
// Linux limits the total bytes sent by sendmsg to INT_MAX, so this cast is safe.
|
|
|
|
msg.msg_len = @intCast(u32, r);
|
|
|
|
next_unsent = i + 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (next_unsent < kvlen or next_unsent == 0) { // want to make sure at least one syscall occurs (e.g. to trigger MSG_EOR)
|
|
|
|
const batch_size = kvlen - next_unsent;
|
2020-03-02 12:30:53 +00:00
|
|
|
const r = syscall4(.sendmmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(&msgvec[next_unsent]), batch_size, flags);
|
2019-05-25 17:07:44 +00:00
|
|
|
if (getErrno(r) != 0) return r;
|
|
|
|
return next_unsent + r;
|
|
|
|
}
|
|
|
|
return kvlen;
|
|
|
|
}
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall4(.sendmmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msgvec), vlen, flags);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn connect(fd: i32, addr: *const c_void, len: socklen_t) usize {
|
2019-11-30 15:13:33 +00:00
|
|
|
if (builtin.arch == .i386) {
|
|
|
|
return socketcall(SC_connect, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), len });
|
|
|
|
}
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall3(.connect, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), len);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn recvmsg(fd: i32, msg: *msghdr, flags: u32) usize {
|
2019-11-30 15:13:33 +00:00
|
|
|
if (builtin.arch == .i386) {
|
|
|
|
return socketcall(SC_recvmsg, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags });
|
|
|
|
}
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall3(.recvmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn recvfrom(fd: i32, noalias buf: [*]u8, len: usize, flags: u32, noalias addr: ?*sockaddr, noalias alen: ?*socklen_t) usize {
|
2019-11-30 15:13:33 +00:00
|
|
|
if (builtin.arch == .i386) {
|
|
|
|
return socketcall(SC_recvfrom, &[6]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen) });
|
|
|
|
}
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall6(.recvfrom, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen));
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn shutdown(fd: i32, how: i32) usize {
|
2019-11-30 15:13:33 +00:00
|
|
|
if (builtin.arch == .i386) {
|
|
|
|
return socketcall(SC_shutdown, &[2]usize{ @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, how)) });
|
|
|
|
}
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall2(.shutdown, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, how)));
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn bind(fd: i32, addr: *const sockaddr, len: socklen_t) usize {
|
2019-11-30 15:13:33 +00:00
|
|
|
if (builtin.arch == .i386) {
|
|
|
|
return socketcall(SC_bind, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @intCast(usize, len) });
|
|
|
|
}
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall3(.bind, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @intCast(usize, len));
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn listen(fd: i32, backlog: u32) usize {
|
2019-11-30 15:13:33 +00:00
|
|
|
if (builtin.arch == .i386) {
|
|
|
|
return socketcall(SC_listen, &[2]usize{ @bitCast(usize, @as(isize, fd)), backlog });
|
|
|
|
}
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall2(.listen, @bitCast(usize, @as(isize, fd)), backlog);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn sendto(fd: i32, buf: [*]const u8, len: usize, flags: u32, addr: ?*const sockaddr, alen: socklen_t) usize {
|
2019-11-30 15:13:33 +00:00
|
|
|
if (builtin.arch == .i386) {
|
|
|
|
return socketcall(SC_sendto, &[6]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @intCast(usize, alen) });
|
|
|
|
}
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall6(.sendto, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @intCast(usize, alen));
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2020-03-03 07:03:22 +00:00
|
|
|
pub fn sendfile(outfd: i32, infd: i32, offset: ?*i64, count: usize) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
if (@hasField(SYS, "sendfile64")) {
|
2020-03-03 07:03:22 +00:00
|
|
|
return syscall4(
|
2020-03-02 12:30:53 +00:00
|
|
|
.sendfile64,
|
2020-03-03 07:03:22 +00:00
|
|
|
@bitCast(usize, @as(isize, outfd)),
|
|
|
|
@bitCast(usize, @as(isize, infd)),
|
|
|
|
@ptrToInt(offset),
|
|
|
|
count,
|
|
|
|
);
|
2020-01-10 10:03:56 +00:00
|
|
|
} else {
|
2020-03-03 07:03:22 +00:00
|
|
|
return syscall4(
|
2020-03-02 12:30:53 +00:00
|
|
|
.sendfile,
|
2020-03-03 07:03:22 +00:00
|
|
|
@bitCast(usize, @as(isize, outfd)),
|
|
|
|
@bitCast(usize, @as(isize, infd)),
|
|
|
|
@ptrToInt(offset),
|
|
|
|
count,
|
|
|
|
);
|
2020-01-10 10:03:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-25 17:07:44 +00:00
|
|
|
pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) usize {
|
2019-11-30 15:13:33 +00:00
|
|
|
if (builtin.arch == .i386) {
|
|
|
|
return socketcall(SC_socketpair, &[4]usize{ @intCast(usize, domain), @intCast(usize, socket_type), @intCast(usize, protocol), @ptrToInt(&fd[0]) });
|
|
|
|
}
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall4(.socketpair, @intCast(usize, domain), @intCast(usize, socket_type), @intCast(usize, protocol), @ptrToInt(&fd[0]));
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2020-10-27 07:00:35 +00:00
|
|
|
pub fn accept(fd: i32, noalias addr: ?*sockaddr, noalias len: ?*socklen_t) usize {
|
2019-11-30 15:13:33 +00:00
|
|
|
if (builtin.arch == .i386) {
|
|
|
|
return socketcall(SC_accept, &[4]usize{ fd, addr, len, 0 });
|
|
|
|
}
|
2019-05-25 17:07:44 +00:00
|
|
|
return accept4(fd, addr, len, 0);
|
|
|
|
}
|
|
|
|
|
2020-10-27 07:00:35 +00:00
|
|
|
pub fn accept4(fd: i32, noalias addr: ?*sockaddr, noalias len: ?*socklen_t, flags: u32) usize {
|
2019-11-30 15:13:33 +00:00
|
|
|
if (builtin.arch == .i386) {
|
|
|
|
return socketcall(SC_accept4, &[4]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len), flags });
|
|
|
|
}
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall4(.accept4, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len), flags);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2020-11-04 14:55:36 +00:00
|
|
|
pub fn fstat(fd: i32, stat_buf: *kernel_stat) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
if (@hasField(SYS, "fstat64")) {
|
|
|
|
return syscall2(.fstat64, @bitCast(usize, @as(isize, fd)), @ptrToInt(stat_buf));
|
2019-08-29 08:34:05 +00:00
|
|
|
} else {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall2(.fstat, @bitCast(usize, @as(isize, fd)), @ptrToInt(stat_buf));
|
2019-08-29 08:34:05 +00:00
|
|
|
}
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2020-11-04 14:55:36 +00:00
|
|
|
pub fn stat(pathname: [*:0]const u8, statbuf: *kernel_stat) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
if (@hasField(SYS, "stat64")) {
|
|
|
|
return syscall2(.stat64, @ptrToInt(pathname), @ptrToInt(statbuf));
|
2019-08-29 08:34:05 +00:00
|
|
|
} else {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall2(.stat, @ptrToInt(pathname), @ptrToInt(statbuf));
|
2019-08-29 08:34:05 +00:00
|
|
|
}
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2020-11-04 14:55:36 +00:00
|
|
|
pub fn lstat(pathname: [*:0]const u8, statbuf: *kernel_stat) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
if (@hasField(SYS, "lstat64")) {
|
|
|
|
return syscall2(.lstat64, @ptrToInt(pathname), @ptrToInt(statbuf));
|
2019-08-29 08:34:05 +00:00
|
|
|
} else {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall2(.lstat, @ptrToInt(pathname), @ptrToInt(statbuf));
|
2019-08-29 08:34:05 +00:00
|
|
|
}
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2020-11-04 14:55:36 +00:00
|
|
|
pub fn fstatat(dirfd: i32, path: [*:0]const u8, stat_buf: *kernel_stat, flags: u32) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
if (@hasField(SYS, "fstatat64")) {
|
|
|
|
return syscall4(.fstatat64, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags);
|
2020-11-08 15:34:44 +00:00
|
|
|
} else if (@hasField(SYS, "newfstatat")) {
|
|
|
|
return syscall4(.newfstatat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags);
|
2019-08-29 08:34:05 +00:00
|
|
|
} else {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall4(.fstatat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags);
|
2019-08-29 08:34:05 +00:00
|
|
|
}
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2019-10-12 12:55:02 +00:00
|
|
|
pub fn statx(dirfd: i32, path: [*]const u8, flags: u32, mask: u32, statx_buf: *Statx) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
if (@hasField(SYS, "statx")) {
|
2019-10-12 12:55:02 +00:00
|
|
|
return syscall5(
|
2020-03-02 12:30:53 +00:00
|
|
|
.statx,
|
2019-11-07 04:25:57 +00:00
|
|
|
@bitCast(usize, @as(isize, dirfd)),
|
2019-10-12 12:55:02 +00:00
|
|
|
@ptrToInt(path),
|
|
|
|
flags,
|
|
|
|
mask,
|
|
|
|
@ptrToInt(statx_buf),
|
|
|
|
);
|
|
|
|
}
|
2019-11-07 04:25:57 +00:00
|
|
|
return @bitCast(usize, @as(isize, -ENOSYS));
|
2019-10-12 12:55:02 +00:00
|
|
|
}
|
|
|
|
|
2019-12-17 20:43:49 +00:00
|
|
|
pub fn listxattr(path: [*:0]const u8, list: [*]u8, size: usize) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall3(.listxattr, @ptrToInt(path), @ptrToInt(list), size);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2019-12-17 20:43:49 +00:00
|
|
|
pub fn llistxattr(path: [*:0]const u8, list: [*]u8, size: usize) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall3(.llistxattr, @ptrToInt(path), @ptrToInt(list), size);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn flistxattr(fd: usize, list: [*]u8, size: usize) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall3(.flistxattr, fd, @ptrToInt(list), size);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2019-12-17 20:43:49 +00:00
|
|
|
pub fn getxattr(path: [*:0]const u8, name: [*:0]const u8, value: [*]u8, size: usize) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall4(.getxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2019-12-17 20:43:49 +00:00
|
|
|
pub fn lgetxattr(path: [*:0]const u8, name: [*:0]const u8, value: [*]u8, size: usize) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall4(.lgetxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2019-12-17 20:43:49 +00:00
|
|
|
pub fn fgetxattr(fd: usize, name: [*:0]const u8, value: [*]u8, size: usize) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall4(.lgetxattr, fd, @ptrToInt(name), @ptrToInt(value), size);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2019-12-17 20:43:49 +00:00
|
|
|
pub fn setxattr(path: [*:0]const u8, name: [*:0]const u8, value: *const void, size: usize, flags: usize) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall5(.setxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size, flags);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2019-12-17 20:43:49 +00:00
|
|
|
pub fn lsetxattr(path: [*:0]const u8, name: [*:0]const u8, value: *const void, size: usize, flags: usize) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall5(.lsetxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size, flags);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2019-12-17 20:43:49 +00:00
|
|
|
pub fn fsetxattr(fd: usize, name: [*:0]const u8, value: *const void, size: usize, flags: usize) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall5(.fsetxattr, fd, @ptrToInt(name), @ptrToInt(value), size, flags);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2019-12-17 20:43:49 +00:00
|
|
|
pub fn removexattr(path: [*:0]const u8, name: [*:0]const u8) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall2(.removexattr, @ptrToInt(path), @ptrToInt(name));
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2019-12-17 20:43:49 +00:00
|
|
|
pub fn lremovexattr(path: [*:0]const u8, name: [*:0]const u8) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall2(.lremovexattr, @ptrToInt(path), @ptrToInt(name));
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2019-12-17 20:43:49 +00:00
|
|
|
pub fn fremovexattr(fd: usize, name: [*:0]const u8) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall2(.fremovexattr, fd, @ptrToInt(name));
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2019-11-07 21:32:20 +00:00
|
|
|
pub fn sched_yield() usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall0(.sched_yield);
|
2019-11-07 21:32:20 +00:00
|
|
|
}
|
|
|
|
|
2019-12-22 01:25:45 +00:00
|
|
|
pub fn sched_getaffinity(pid: pid_t, size: usize, set: *cpu_set_t) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
const rc = syscall3(.sched_getaffinity, @bitCast(usize, @as(isize, pid)), size, @ptrToInt(set));
|
2019-05-25 17:07:44 +00:00
|
|
|
if (@bitCast(isize, rc) < 0) return rc;
|
|
|
|
if (rc < size) @memset(@ptrCast([*]u8, set) + rc, 0, size - rc);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn epoll_create() usize {
|
|
|
|
return epoll_create1(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn epoll_create1(flags: usize) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall1(.epoll_create1, flags);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2019-05-30 14:28:33 +00:00
|
|
|
pub fn epoll_ctl(epoll_fd: i32, op: u32, fd: i32, ev: ?*epoll_event) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall4(.epoll_ctl, @bitCast(usize, @as(isize, epoll_fd)), @intCast(usize, op), @bitCast(usize, @as(isize, fd)), @ptrToInt(ev));
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn epoll_wait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32) usize {
|
2019-05-30 14:28:33 +00:00
|
|
|
return epoll_pwait(epoll_fd, events, maxevents, timeout, null);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2020-11-20 19:26:04 +00:00
|
|
|
pub fn epoll_pwait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32, sigmask: ?*const sigset_t) usize {
|
2019-05-25 17:07:44 +00:00
|
|
|
return syscall6(
|
2020-03-02 12:30:53 +00:00
|
|
|
.epoll_pwait,
|
2019-11-07 04:25:57 +00:00
|
|
|
@bitCast(usize, @as(isize, epoll_fd)),
|
2019-05-25 17:07:44 +00:00
|
|
|
@ptrToInt(events),
|
|
|
|
@intCast(usize, maxevents),
|
2019-11-07 04:25:57 +00:00
|
|
|
@bitCast(usize, @as(isize, timeout)),
|
2019-05-25 17:07:44 +00:00
|
|
|
@ptrToInt(sigmask),
|
|
|
|
@sizeOf(sigset_t),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn eventfd(count: u32, flags: u32) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall2(.eventfd2, count, flags);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn timerfd_create(clockid: i32, flags: u32) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall2(.timerfd_create, @bitCast(usize, @as(isize, clockid)), flags);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub const itimerspec = extern struct {
|
|
|
|
it_interval: timespec,
|
|
|
|
it_value: timespec,
|
|
|
|
};
|
|
|
|
|
|
|
|
pub fn timerfd_gettime(fd: i32, curr_value: *itimerspec) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall2(.timerfd_gettime, @bitCast(usize, @as(isize, fd)), @ptrToInt(curr_value));
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn timerfd_settime(fd: i32, flags: u32, new_value: *const itimerspec, old_value: ?*itimerspec) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall4(.timerfd_settime, @bitCast(usize, @as(isize, fd)), flags, @ptrToInt(new_value), @ptrToInt(old_value));
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn unshare(flags: usize) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall1(.unshare, flags);
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn capget(hdrp: *cap_user_header_t, datap: *cap_user_data_t) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall2(.capget, @ptrToInt(hdrp), @ptrToInt(datap));
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn capset(hdrp: *cap_user_header_t, datap: *const cap_user_data_t) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall2(.capset, @ptrToInt(hdrp), @ptrToInt(datap));
|
2019-05-28 13:22:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall2(.sigaltstack, @ptrToInt(ss), @ptrToInt(old_ss));
|
2019-05-25 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2019-09-12 01:21:00 +00:00
|
|
|
pub fn uname(uts: *utsname) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall1(.uname, @ptrToInt(uts));
|
2019-09-12 01:21:00 +00:00
|
|
|
}
|
|
|
|
|
2019-05-20 13:25:47 +00:00
|
|
|
pub fn io_uring_setup(entries: u32, p: *io_uring_params) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall2(.io_uring_setup, entries, @ptrToInt(p));
|
2019-05-20 13:25:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn io_uring_enter(fd: i32, to_submit: u32, min_complete: u32, flags: u32, sig: ?*sigset_t) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall6(.io_uring_enter, @bitCast(usize, @as(isize, fd)), to_submit, min_complete, flags, @ptrToInt(sig), NSIG / 8);
|
2019-05-20 13:25:47 +00:00
|
|
|
}
|
|
|
|
|
2020-03-30 10:24:08 +00:00
|
|
|
pub fn io_uring_register(fd: i32, opcode: IORING_REGISTER, arg: ?*const c_void, nr_args: u32) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall4(.io_uring_register, @bitCast(usize, @as(isize, fd)), @enumToInt(opcode), @ptrToInt(arg), nr_args);
|
2019-05-20 13:25:47 +00:00
|
|
|
}
|
|
|
|
|
2019-12-31 18:33:23 +00:00
|
|
|
pub fn memfd_create(name: [*:0]const u8, flags: u32) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall2(.memfd_create, @ptrToInt(name), flags);
|
2019-11-14 00:25:19 +00:00
|
|
|
}
|
|
|
|
|
2019-12-06 01:29:23 +00:00
|
|
|
pub fn getrusage(who: i32, usage: *rusage) usize {
|
2020-03-02 12:30:53 +00:00
|
|
|
return syscall2(.getrusage, @bitCast(usize, @as(isize, who)), @ptrToInt(usage));
|
2019-12-06 01:29:23 +00:00
|
|
|
}
|
|
|
|
|
2020-01-30 06:36:28 +00:00
|
|
|
pub fn tcgetattr(fd: fd_t, termios_p: *termios) usize {
|
2020-06-02 19:28:46 +00:00
|
|
|
return syscall3(.ioctl, @bitCast(usize, @as(isize, fd)), TCGETS, @ptrToInt(termios_p));
|
2020-01-30 06:36:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn tcsetattr(fd: fd_t, optional_action: TCSA, termios_p: *const termios) usize {
|
2020-06-02 19:28:46 +00:00
|
|
|
return syscall3(.ioctl, @bitCast(usize, @as(isize, fd)), TCSETS + @enumToInt(optional_action), @ptrToInt(termios_p));
|
2020-01-30 06:36:28 +00:00
|
|
|
}
|
|
|
|
|
2020-06-02 19:28:46 +00:00
|
|
|
pub fn ioctl(fd: fd_t, request: u32, arg: usize) usize {
|
|
|
|
return syscall3(.ioctl, @bitCast(usize, @as(isize, fd)), request, arg);
|
2020-04-20 19:34:37 +00:00
|
|
|
}
|
|
|
|
|
2020-08-17 23:19:57 +00:00
|
|
|
pub fn signalfd(fd: fd_t, mask: *const sigset_t, flags: u32) usize {
|
|
|
|
return syscall4(.signalfd4, @bitCast(usize, @as(isize, fd)), @ptrToInt(mask), NSIG / 8, flags);
|
2020-07-22 21:26:27 +00:00
|
|
|
}
|
|
|
|
|
2020-08-11 19:49:43 +00:00
|
|
|
pub fn copy_file_range(fd_in: fd_t, off_in: ?*i64, fd_out: fd_t, off_out: ?*i64, len: usize, flags: u32) usize {
|
|
|
|
return syscall6(
|
|
|
|
.copy_file_range,
|
|
|
|
@bitCast(usize, @as(isize, fd_in)),
|
|
|
|
@ptrToInt(off_in),
|
|
|
|
@bitCast(usize, @as(isize, fd_out)),
|
|
|
|
@ptrToInt(off_out),
|
|
|
|
len,
|
|
|
|
flags,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-08-21 01:54:41 +00:00
|
|
|
pub fn bpf(cmd: BPF.Cmd, attr: *BPF.Attr, size: u32) usize {
|
2020-08-19 05:03:51 +00:00
|
|
|
return syscall3(.bpf, @enumToInt(cmd), @ptrToInt(attr), size);
|
|
|
|
}
|
|
|
|
|
2020-09-02 22:16:40 +00:00
|
|
|
pub fn sync() void {
|
|
|
|
_ = syscall0(.sync);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn syncfs(fd: fd_t) usize {
|
|
|
|
return syscall1(.syncfs, @bitCast(usize, @as(isize, fd)));
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn fsync(fd: fd_t) usize {
|
|
|
|
return syscall1(.fsync, @bitCast(usize, @as(isize, fd)));
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn fdatasync(fd: fd_t) usize {
|
|
|
|
return syscall1(.fdatasync, @bitCast(usize, @as(isize, fd)));
|
|
|
|
}
|
|
|
|
|
2020-09-10 23:34:10 +00:00
|
|
|
pub fn prctl(option: i32, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize {
|
|
|
|
return syscall5(.prctl, @bitCast(usize, @as(isize, option)), arg2, arg3, arg4, arg5);
|
|
|
|
}
|
|
|
|
|
2020-10-01 22:20:32 +00:00
|
|
|
pub fn getrlimit(resource: rlimit_resource, rlim: *rlimit) usize {
|
|
|
|
// use prlimit64 to have 64 bit limits on 32 bit platforms
|
|
|
|
return prlimit(0, resource, null, rlim);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn setrlimit(resource: rlimit_resource, rlim: *const rlimit) usize {
|
|
|
|
// use prlimit64 to have 64 bit limits on 32 bit platforms
|
|
|
|
return prlimit(0, resource, rlim, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn prlimit(pid: pid_t, resource: rlimit_resource, new_limit: ?*const rlimit, old_limit: ?*rlimit) usize {
|
|
|
|
return syscall4(
|
|
|
|
.prlimit64,
|
|
|
|
@bitCast(usize, @as(isize, pid)),
|
|
|
|
@bitCast(usize, @as(isize, @enumToInt(resource))),
|
|
|
|
@ptrToInt(new_limit),
|
2020-10-27 14:37:28 +00:00
|
|
|
@ptrToInt(old_limit),
|
2020-10-01 22:20:32 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-12-18 22:38:38 +00:00
|
|
|
pub fn madvise(address: [*]u8, len: usize, advice: u32) usize {
|
|
|
|
return syscall3(.madvise, @ptrToInt(address), len, advice);
|
|
|
|
}
|
|
|
|
|
2019-05-24 23:36:09 +00:00
|
|
|
test "" {
|
2020-02-25 06:52:27 +00:00
|
|
|
if (builtin.os.tag == .linux) {
|
2019-03-02 21:46:04 +00:00
|
|
|
_ = @import("linux/test.zig");
|
2018-04-22 17:36:26 +00:00
|
|
|
}
|
2017-11-10 23:12:46 +00:00
|
|
|
}
|