std/sys/pal/unix/weak/syscall.rs
1use super::weak;
2
3pub(crate) macro syscall {
4    (
5        fn $name:ident($($param:ident : $t:ty),* $(,)?) -> $ret:ty;
6    ) => (
7        unsafe fn $name($($param: $t),*) -> $ret {
8            weak!(fn $name($($param: $t),*) -> $ret;);
9
10            // Use a weak symbol from libc when possible, allowing `LD_PRELOAD`
11            // interposition, but if it's not found just use a raw syscall.
12            if let Some(fun) = $name.get() {
13                unsafe { fun($($param),*) }
14            } else {
15                unsafe { libc::syscall(libc::${concat(SYS_, $name)}, $($param),*) as $ret }
16            }
17        }
18    )
19}