oscall 0.1.0

Low-level cross-platform interface to operating system services: files, memory mapping, networking and more, with no libc on Linux
Documentation
//! x86_64: `syscall`, number in `rax`, arguments in `rdi rsi rdx r10 r8 r9`.
//! The instruction itself clobbers `rcx` and `r11`.

use core::arch::asm;

macro_rules! define {
    ($name:ident $(, $arg:ident in $reg:tt)*) => {
        /// # Safety
        ///
        /// The system call and its arguments must be valid: see `syscall!`.
        #[inline]
        pub(crate) unsafe fn $name(nr: usize $(, $arg: usize)*) -> usize {
            let ret;
            // SAFETY: the caller upholds the system call's own contract; the
            // registers the kernel clobbers are declared.
            unsafe {
                asm!(
                    "syscall",
                    inlateout("rax") nr => ret,
                    $(in($reg) $arg,)*
                    lateout("rcx") _,
                    lateout("r11") _,
                    options(nostack, preserves_flags),
                );
            }
            ret
        }
    };
}

define!(syscall0);
define!(syscall1, a in "rdi");
define!(syscall2, a in "rdi", b in "rsi");
define!(syscall3, a in "rdi", b in "rsi", c in "rdx");
define!(syscall4, a in "rdi", b in "rsi", c in "rdx", d in "r10");
define!(syscall5, a in "rdi", b in "rsi", c in "rdx", d in "r10", e in "r8");
define!(syscall6, a in "rdi", b in "rsi", c in "rdx", d in "r10", e in "r8", f in "r9");