Skip to content

Commit a035626

Browse files
committed
Try weak symbols for all linux syscall! wrappers
1 parent 7a15f02 commit a035626

File tree

2 files changed

+8
-17
lines changed

2 files changed

+8
-17
lines changed

library/std/src/sys/unix/rand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ mod imp {
2929
// A weak symbol allows interposition, e.g. for perf measurements that want to
3030
// disable randomness for consistency. Otherwise, we'll try a raw syscall.
3131
// (`getrandom` was added in glibc 2.25, musl 1.1.20, android API level 28)
32-
weak_syscall! {
32+
syscall! {
3333
fn getrandom(
3434
buffer: *mut libc::c_void,
3535
length: libc::size_t,

library/std/src/sys/unix/weak.rs

+7-16
Original file line numberDiff line numberDiff line change
@@ -92,26 +92,17 @@ macro_rules! syscall {
9292
// (not paths).
9393
use libc::*;
9494

95-
syscall(
96-
concat_idents!(SYS_, $name),
97-
$($arg_name as c_long),*
98-
) as $ret
99-
}
100-
)
101-
}
102-
103-
/// Use a weak symbol from libc when possible, allowing `LD_PRELOAD` interposition,
104-
/// but if it's not found just use a raw syscall.
105-
#[cfg(any(target_os = "linux", target_os = "android"))]
106-
macro_rules! weak_syscall {
107-
(fn $name:ident($($arg_name:ident: $t:ty),*) -> $ret:ty) => (
108-
unsafe fn $name($($arg_name:$t),*) -> $ret {
10995
weak! { fn $name($($t),*) -> $ret }
96+
97+
// Use a weak symbol from libc when possible, allowing `LD_PRELOAD`
98+
// interposition, but if it's not found just use a raw syscall.
11099
if let Some(fun) = $name.get() {
111100
fun($($arg_name),*)
112101
} else {
113-
syscall! { fn $name($($arg_name:$t),*) -> $ret }
114-
$name($($arg_name),*)
102+
syscall(
103+
concat_idents!(SYS_, $name),
104+
$($arg_name as c_long),*
105+
) as $ret
115106
}
116107
}
117108
)

0 commit comments

Comments
 (0)