oscall 0.0.2

Low-level cross-platform interface to operating system services: files, memory mapping, networking and more, with no libc on Linux
Documentation
//! arm (EABI): `svc 0`, number in `r7`, arguments in `r0`..`r5`.
//!
//! `r7` is the Thumb frame pointer, which inline assembly may not name as an
//! operand: the number travels in another register and `r7` is saved around
//! the call.

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; r7
            // is restored before the block ends.
            unsafe {
                asm!(
                    "mov {saved}, r7",
                    "mov r7, {nr}",
                    "svc 0",
                    "mov r7, {saved}",
                    nr = in(reg) nr,
                    saved = out(reg) _,
                    $(in($reg) $arg,)*
                    lateout("r0") ret,
                    options(nostack, preserves_flags),
                );
            }
            ret
        }
    };
}

define!(syscall0);
define!(syscall1, a in "r0");
define!(syscall2, a in "r0", b in "r1");
define!(syscall3, a in "r0", b in "r1", c in "r2");
define!(syscall4, a in "r0", b in "r1", c in "r2", d in "r3");
define!(syscall5, a in "r0", b in "r1", c in "r2", d in "r3", e in "r4");
define!(syscall6, a in "r0", b in "r1", c in "r2", d in "r3", e in "r4", f in "r5");