macro_rules! syscall {
([ro] $sysno:expr, $arg0:expr, $arg1:expr, $arg2:expr, $arg3:expr, $arg4:expr, $arg5:expr $(,)?) => { ... };
([ro] $sysno:expr, $arg0:expr, $arg1:expr, $arg2:expr, $arg3:expr, $arg4:expr $(,)?) => { ... };
([ro] $sysno:expr, $arg0:expr, $arg1:expr, $arg2:expr, $arg3:expr $(,)?) => { ... };
([ro] $sysno:expr, $arg0:expr, $arg1:expr, $arg2:expr $(,)?) => { ... };
([ro] $sysno:expr, $arg0:expr, $arg1:expr $(,)?) => { ... };
([!] $sysno:expr, $arg0:expr $(,)?) => { ... };
([ro] $sysno:expr, $arg0:expr $(,)?) => { ... };
([ro] $sysno:expr $(,)?) => { ... };
($sysno:expr, $arg0:expr, $arg1:expr, $arg2:expr, $arg3:expr, $arg4:expr, $arg5:expr $(,)?) => { ... };
($sysno:expr, $arg0:expr, $arg1:expr, $arg2:expr, $arg3:expr, $arg4:expr $(,)?) => { ... };
($sysno:expr, $arg0:expr, $arg1:expr, $arg2:expr, $arg3:expr $(,)?) => { ... };
($sysno:expr, $arg0:expr, $arg1:expr, $arg2:expr $(,)?) => { ... };
($sysno:expr, $arg0:expr, $arg1:expr $(,)?) => { ... };
($sysno:expr, $arg0:expr $(,)?) => { ... };
($sysno:expr $(,)?) => { ... };
}Available on (Linux or Android) and (x86-64 and little-endian and 64-bit, or AArch64 and 64-bit, or ARM and 32-bit, or x86 and little-endian and 32-bit), or Linux and (x86-64 and little-endian and 32-bit, or RISC-V RV64 and little-endian and 64-bit, or RISC-V RV32 and little-endian and 32-bit, or MIPS and 32-bit, or MIPS-64 and 64-bit, or s390x and big-endian and 64-bit, or LoongArch LA64 and little-endian and 64-bit, or PowerPC and big-endian and 32-bit, or PowerPC-64 and 64-bit) only.
Expand description
Make a syscall and returns a Result<usize, Errno>
Accept a Sysno as the first parameter and a variable number of arguments (0 to 6).
It calls syscallN under the hood where N is the number of arguments.
The are two variations:
[ro]: use the_readonlyversion ofsyscallN.[!]: use the_noreturnversion ofsyscall1(useful forexit).
Use the previous tags if you what are you doing, otherwise you can omit them.
ยงExample
use linux_syscalls::{Errno, Sysno, syscall};
let mut buf: [u8; 1024] = [0; 1024];
let buf = loop {
match unsafe { syscall!(Sysno::read, 0, buf.as_mut_ptr(), buf.len()) } {
Ok(n) => break &buf[..n],
Err(Errno::EINTR) => (),
Err(err) => return Err(err),
}
};
// [ro] because write do not change the memory.
unsafe { syscall!([ro] Sysno::write, 1, buf.as_ptr(), buf.len())? };
// [!] because exit do not return.
unsafe { syscall!([!] Sysno::exit, 0) };