Skip to content

Commit 452947c

Browse files
committed
Revert "linux: try to use libc getrandom to allow interposition"
This measures the performance impact of that PR. - Revert "Use syscall! for copy_file_range too" - Revert "Try weak symbols for all linux syscall! wrappers" - Revert "linux: try to use libc getrandom to allow interposition"
1 parent 25a6910 commit 452947c

File tree

3 files changed

+18
-35
lines changed

3 files changed

+18
-35
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -445,15 +445,15 @@ pub(super) fn copy_regular_files(reader: RawFd, writer: RawFd, max_len: u64) ->
445445
// We store the availability in a global to avoid unnecessary syscalls
446446
static HAS_COPY_FILE_RANGE: AtomicBool = AtomicBool::new(true);
447447

448-
syscall! {
449-
fn copy_file_range(
450-
fd_in: libc::c_int,
451-
off_in: *mut libc::loff_t,
452-
fd_out: libc::c_int,
453-
off_out: *mut libc::loff_t,
454-
len: libc::size_t,
455-
flags: libc::c_uint
456-
) -> libc::ssize_t
448+
unsafe fn copy_file_range(
449+
fd_in: libc::c_int,
450+
off_in: *mut libc::loff_t,
451+
fd_out: libc::c_int,
452+
off_out: *mut libc::loff_t,
453+
len: libc::size_t,
454+
flags: libc::c_uint,
455+
) -> libc::c_long {
456+
libc::syscall(libc::SYS_copy_file_range, fd_in, off_in, fd_out, off_out, len, flags)
457457
}
458458

459459
let has_copy_file_range = HAS_COPY_FILE_RANGE.load(Ordering::Relaxed);

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

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,10 @@ mod imp {
2525
use crate::io::Read;
2626

2727
#[cfg(any(target_os = "linux", target_os = "android"))]
28-
fn getrandom(buf: &mut [u8]) -> libc::ssize_t {
29-
// A weak symbol allows interposition, e.g. for perf measurements that want to
30-
// disable randomness for consistency. Otherwise, we'll try a raw syscall.
31-
// (`getrandom` was added in glibc 2.25, musl 1.1.20, android API level 28)
32-
syscall! {
33-
fn getrandom(
34-
buffer: *mut libc::c_void,
35-
length: libc::size_t,
36-
flags: libc::c_uint
37-
) -> libc::ssize_t
28+
fn getrandom(buf: &mut [u8]) -> libc::c_long {
29+
unsafe {
30+
libc::syscall(libc::SYS_getrandom, buf.as_mut_ptr(), buf.len(), libc::GRND_NONBLOCK)
3831
}
39-
40-
unsafe { getrandom(buf.as_mut_ptr().cast(), buf.len(), libc::GRND_NONBLOCK) }
4132
}
4233

4334
#[cfg(not(any(target_os = "linux", target_os = "android")))]

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

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ unsafe fn fetch(name: &str) -> usize {
100100
libc::dlsym(libc::RTLD_DEFAULT, name.as_ptr()) as usize
101101
}
102102

103-
#[cfg(not(any(target_os = "linux", target_os = "android")))]
103+
#[cfg(not(target_os = "linux"))]
104104
macro_rules! syscall {
105105
(fn $name:ident($($arg_name:ident: $t:ty),*) -> $ret:ty) => (
106106
unsafe fn $name($($arg_name: $t),*) -> $ret {
@@ -118,26 +118,18 @@ macro_rules! syscall {
118118
)
119119
}
120120

121-
#[cfg(any(target_os = "linux", target_os = "android"))]
121+
#[cfg(target_os = "linux")]
122122
macro_rules! syscall {
123123
(fn $name:ident($($arg_name:ident: $t:ty),*) -> $ret:ty) => (
124124
unsafe fn $name($($arg_name:$t),*) -> $ret {
125125
// This looks like a hack, but concat_idents only accepts idents
126126
// (not paths).
127127
use libc::*;
128128

129-
weak! { fn $name($($t),*) -> $ret }
130-
131-
// Use a weak symbol from libc when possible, allowing `LD_PRELOAD`
132-
// interposition, but if it's not found just use a raw syscall.
133-
if let Some(fun) = $name.get() {
134-
fun($($arg_name),*)
135-
} else {
136-
syscall(
137-
concat_idents!(SYS_, $name),
138-
$($arg_name),*
139-
) as $ret
140-
}
129+
syscall(
130+
concat_idents!(SYS_, $name),
131+
$($arg_name as c_long),*
132+
) as $ret
141133
}
142134
)
143135
}

0 commit comments

Comments
 (0)