Try weak symbols for all linux syscall! wrappers
This commit is contained in:
parent
7a15f026f2
commit
a035626eb5
2 changed files with 8 additions and 17 deletions
|
@ -29,7 +29,7 @@ mod imp {
|
|||
// A weak symbol allows interposition, e.g. for perf measurements that want to
|
||||
// disable randomness for consistency. Otherwise, we'll try a raw syscall.
|
||||
// (`getrandom` was added in glibc 2.25, musl 1.1.20, android API level 28)
|
||||
weak_syscall! {
|
||||
syscall! {
|
||||
fn getrandom(
|
||||
buffer: *mut libc::c_void,
|
||||
length: libc::size_t,
|
||||
|
|
|
@ -92,26 +92,17 @@ macro_rules! syscall {
|
|||
// (not paths).
|
||||
use libc::*;
|
||||
|
||||
syscall(
|
||||
concat_idents!(SYS_, $name),
|
||||
$($arg_name as c_long),*
|
||||
) as $ret
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/// Use a weak symbol from libc when possible, allowing `LD_PRELOAD` interposition,
|
||||
/// but if it's not found just use a raw syscall.
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
macro_rules! weak_syscall {
|
||||
(fn $name:ident($($arg_name:ident: $t:ty),*) -> $ret:ty) => (
|
||||
unsafe fn $name($($arg_name:$t),*) -> $ret {
|
||||
weak! { fn $name($($t),*) -> $ret }
|
||||
|
||||
// Use a weak symbol from libc when possible, allowing `LD_PRELOAD`
|
||||
// interposition, but if it's not found just use a raw syscall.
|
||||
if let Some(fun) = $name.get() {
|
||||
fun($($arg_name),*)
|
||||
} else {
|
||||
syscall! { fn $name($($arg_name:$t),*) -> $ret }
|
||||
$name($($arg_name),*)
|
||||
syscall(
|
||||
concat_idents!(SYS_, $name),
|
||||
$($arg_name as c_long),*
|
||||
) as $ret
|
||||
}
|
||||
}
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue