Macro scall::syscall_nofail
source · [−]macro_rules! syscall_nofail {
($nr:ident) => { ... };
($nr:ident, $a1:expr) => { ... };
($nr:ident, $a1:expr, $a2:expr) => { ... };
($nr:ident, $a1:expr, $a2:expr, $a3:expr) => { ... };
($nr:ident, $a1:expr, $a2:expr, $a3:expr, $a4:expr) => { ... };
($nr:ident, $a1:expr, $a2:expr, $a3:expr, $a4:expr, $a5:expr) => { ... };
($nr:ident, $a1:expr, $a2:expr, $a3:expr, $a4:expr, $a5:expr, $a6:expr) => { ... };
($nr:ident, $a1:expr, $a2:expr, $a3:expr, $a4:expr, $a5:expr, $a6:expr, $a7:expr) => { ... };
($nr:ident, $($args:expr,)*) => { ... };
}
Expand description
Make a syscall that should never fail (or for which the result should be completely ignored).
Assuming that the syscall won’t fail saves the overhead involved with checking for errors, so
this macro may see minor performance boosts over syscall!
.
This macro will return the result of the syscall as a usize
. It is assumed that either:
- The syscall will never fail (like
sync()
,sched_yield()
, orgetpid()
). In this case the result can be used safely. - The result will be ignored (like
close()
often is).
Note: If the syscall fails, the value returned by this function is completely
unspecified and should be immediately discarded. On some platforms, it may even be a value
that otherwise looks like an ordinary return value for this function. Do NOT use this macro
to call syscalls like open()
which can easily fail for a variety of reasons and whose
results must be checked carefully.
Example usage:
unsafe {
// getpid() will never fail
let pid = syscall_nofail!(GETPID);
// Completely ignore the result of close()
// (In reality, a valid file descriptor would be used here)
syscall_nofail!(CLOSE, -1i32);
}
Safety
See syscall!
. Also, make sure that one of the 2 conditions described above is satisfied.