From 452947c316da414fa1759aeed051377d70fd1cad Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Tue, 24 Nov 2020 15:56:35 -0500 Subject: [PATCH] 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" --- library/std/src/sys/unix/kernel_copy.rs | 18 +++++++++--------- library/std/src/sys/unix/rand.rs | 15 +++------------ library/std/src/sys/unix/weak.rs | 20 ++++++-------------- 3 files changed, 18 insertions(+), 35 deletions(-) diff --git a/library/std/src/sys/unix/kernel_copy.rs b/library/std/src/sys/unix/kernel_copy.rs index 1dc16ef099367..ac2fcfcb53f72 100644 --- a/library/std/src/sys/unix/kernel_copy.rs +++ b/library/std/src/sys/unix/kernel_copy.rs @@ -445,15 +445,15 @@ pub(super) fn copy_regular_files(reader: RawFd, writer: RawFd, max_len: u64) -> // We store the availability in a global to avoid unnecessary syscalls static HAS_COPY_FILE_RANGE: AtomicBool = AtomicBool::new(true); - syscall! { - fn copy_file_range( - fd_in: libc::c_int, - off_in: *mut libc::loff_t, - fd_out: libc::c_int, - off_out: *mut libc::loff_t, - len: libc::size_t, - flags: libc::c_uint - ) -> libc::ssize_t + unsafe fn copy_file_range( + fd_in: libc::c_int, + off_in: *mut libc::loff_t, + fd_out: libc::c_int, + off_out: *mut libc::loff_t, + len: libc::size_t, + flags: libc::c_uint, + ) -> libc::c_long { + libc::syscall(libc::SYS_copy_file_range, fd_in, off_in, fd_out, off_out, len, flags) } let has_copy_file_range = HAS_COPY_FILE_RANGE.load(Ordering::Relaxed); diff --git a/library/std/src/sys/unix/rand.rs b/library/std/src/sys/unix/rand.rs index 38ddb41700c4b..eed6fbf13b7d2 100644 --- a/library/std/src/sys/unix/rand.rs +++ b/library/std/src/sys/unix/rand.rs @@ -25,19 +25,10 @@ mod imp { use crate::io::Read; #[cfg(any(target_os = "linux", target_os = "android"))] - fn getrandom(buf: &mut [u8]) -> libc::ssize_t { - // 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) - syscall! { - fn getrandom( - buffer: *mut libc::c_void, - length: libc::size_t, - flags: libc::c_uint - ) -> libc::ssize_t + fn getrandom(buf: &mut [u8]) -> libc::c_long { + unsafe { + libc::syscall(libc::SYS_getrandom, buf.as_mut_ptr(), buf.len(), libc::GRND_NONBLOCK) } - - unsafe { getrandom(buf.as_mut_ptr().cast(), buf.len(), libc::GRND_NONBLOCK) } } #[cfg(not(any(target_os = "linux", target_os = "android")))] diff --git a/library/std/src/sys/unix/weak.rs b/library/std/src/sys/unix/weak.rs index e93a4972caa3e..cc3f8dbbce750 100644 --- a/library/std/src/sys/unix/weak.rs +++ b/library/std/src/sys/unix/weak.rs @@ -100,7 +100,7 @@ unsafe fn fetch(name: &str) -> usize { libc::dlsym(libc::RTLD_DEFAULT, name.as_ptr()) as usize } -#[cfg(not(any(target_os = "linux", target_os = "android")))] +#[cfg(not(target_os = "linux"))] macro_rules! syscall { (fn $name:ident($($arg_name:ident: $t:ty),*) -> $ret:ty) => ( unsafe fn $name($($arg_name: $t),*) -> $ret { @@ -118,7 +118,7 @@ macro_rules! syscall { ) } -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(target_os = "linux")] macro_rules! syscall { (fn $name:ident($($arg_name:ident: $t:ty),*) -> $ret:ty) => ( unsafe fn $name($($arg_name:$t),*) -> $ret { @@ -126,18 +126,10 @@ macro_rules! syscall { // (not paths). use libc::*; - 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( - concat_idents!(SYS_, $name), - $($arg_name),* - ) as $ret - } + syscall( + concat_idents!(SYS_, $name), + $($arg_name as c_long),* + ) as $ret } ) }