macro_rules! syscall {
    ($nr:ident$(, $args:expr)* $(,)?) => { ... };
}
Expand description

Make a syscall, and return the result as a Result<usize, i32>.

This returns Ok(retval) on success, and Err(errno) on error. It’s essentially equivalent to decode_raw_result(syscall_raw!(...)).

Tip: If you’re not in a #![no_std] crate, you can do something like syscall!(SETRESUID, 0, 0, 0).map_err(std::io::Error::from_raw_os_error) to get an io::Result<usize>, which is easier to work with.

Example

let pid = unsafe { syscall!(GETPID).unwrap() };
assert_eq!(pid as u32, std::process::id());

Safety

Making syscalls is wildly unsafe! Read the man pages carefully, and consider architecture-specific differences (syscall_args64! may help with this).