Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 11 pull requests #79167

Merged
merged 28 commits into from
Nov 18, 2020
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9feb567
Updated the list of white-listed target features for x86
DevJPM Oct 25, 2020
cd95e93
Removed movbe from run-time-detect
DevJPM Oct 25, 2020
3daa93f
Updated documentation, x86 feature detection testing, and removed LLV…
DevJPM Oct 26, 2020
909c894
stability: More precise location for deprecation lint on macros
petrochenkov Nov 12, 2020
55d7f73
Tighten the bounds on atomic Ordering in std::sys::unix::weak
thomcc Nov 14, 2020
72b83af
Re-enable LLVM 9 target features with LLVM 9 being the minimum now
DevJPM Nov 15, 2020
c82a258
Turn top-level comments into module docs in MIR visitor
camelid Nov 15, 2020
dcc194c
instrument `QueryNormalizer::fold_ty`
lcnr Nov 16, 2020
7a15f02
linux: try to use libc getrandom to allow interposition
cuviper Nov 5, 2020
a035626
Try weak symbols for all linux syscall! wrappers
cuviper Nov 5, 2020
cd22381
Use syscall! for copy_file_range too
cuviper Nov 5, 2020
d701bf9
Enable AVX512 *epi64 variants by updating stdarch
vertexclique Nov 17, 2020
d17874f
bootstrap: use the same version number for rustc and cargo
pietroalbini Nov 17, 2020
9bbc4c1
add trailing_zeros and leading_zeros to non zero types
andjo403 Nov 17, 2020
95eff66
Fix handling of panic calls
camelid Nov 17, 2020
bdaa76c
Fix typo in `std::io::Write` docs
wchargin Nov 17, 2020
88584d5
change error for `LayoutErr::SizeOverflow`
lcnr Nov 18, 2020
c7e9029
Rollup merge of #78361 - DevJPM:master, r=workingjubilee
m-ou-se Nov 18, 2020
61134aa
Rollup merge of #78785 - cuviper:weak-getrandom, r=m-ou-se
m-ou-se Nov 18, 2020
92dcf6d
Rollup merge of #78999 - petrochenkov:deprid, r=eddyb
m-ou-se Nov 18, 2020
ad6fd9b
Rollup merge of #79039 - thomcc:weakly-relaxing, r=Amanieu
m-ou-se Nov 18, 2020
f85c3f7
Rollup merge of #79079 - camelid:mir-visit-docs, r=matthewjasper
m-ou-se Nov 18, 2020
126d88b
Rollup merge of #79114 - andjo403:nonzero_leading_trailing_zeros, r=m…
m-ou-se Nov 18, 2020
e2addb4
Rollup merge of #79131 - vertexclique:stdarch-update, r=Amanieu
m-ou-se Nov 18, 2020
83fcbd5
Rollup merge of #79133 - pietroalbini:simplify-stage0, r=Mark-Simulacrum
m-ou-se Nov 18, 2020
20fbe22
Rollup merge of #79145 - camelid:clippy-fix-panics, r=flip1995
m-ou-se Nov 18, 2020
5a9104f
Rollup merge of #79151 - wchargin:wchargin-io-write-docs, r=jyn514
m-ou-se Nov 18, 2020
43d13e2
Rollup merge of #79158 - lcnr:lazy-norm-coerce, r=oli-obk
m-ou-se Nov 18, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
linux: try to use libc getrandom to allow interposition
We'll try to use a weak `getrandom` symbol first, because that allows
things like `LD_PRELOAD` interposition. For example, perf measurements
might want to disable randomness to get reproducible results. If the
weak symbol is not found, we fall back to a raw `SYS_getrandom` call.
  • Loading branch information
cuviper committed Nov 16, 2020

Verified

This commit was signed with the committer’s verified signature.
GoldsteinE Max “Goldstein” Siling
commit 7a15f026f2666a16255904879028acdd5513c766
15 changes: 12 additions & 3 deletions library/std/src/sys/unix/rand.rs
Original file line number Diff line number Diff line change
@@ -25,10 +25,19 @@ mod imp {
use crate::io::Read;

#[cfg(any(target_os = "linux", target_os = "android"))]
fn getrandom(buf: &mut [u8]) -> libc::c_long {
unsafe {
libc::syscall(libc::SYS_getrandom, buf.as_mut_ptr(), buf.len(), libc::GRND_NONBLOCK)
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)
weak_syscall! {
fn getrandom(
buffer: *mut libc::c_void,
length: libc::size_t,
flags: libc::c_uint
) -> libc::ssize_t
}

unsafe { getrandom(buf.as_mut_ptr().cast(), buf.len(), libc::GRND_NONBLOCK) }
}

#[cfg(not(any(target_os = "linux", target_os = "android")))]
21 changes: 19 additions & 2 deletions library/std/src/sys/unix/weak.rs
Original file line number Diff line number Diff line change
@@ -66,7 +66,7 @@ unsafe fn fetch(name: &str) -> usize {
libc::dlsym(libc::RTLD_DEFAULT, name.as_ptr()) as usize
}

#[cfg(not(target_os = "linux"))]
#[cfg(not(any(target_os = "linux", target_os = "android")))]
macro_rules! syscall {
(fn $name:ident($($arg_name:ident: $t:ty),*) -> $ret:ty) => (
unsafe fn $name($($arg_name: $t),*) -> $ret {
@@ -84,7 +84,7 @@ macro_rules! syscall {
)
}

#[cfg(target_os = "linux")]
#[cfg(any(target_os = "linux", target_os = "android"))]
macro_rules! syscall {
(fn $name:ident($($arg_name:ident: $t:ty),*) -> $ret:ty) => (
unsafe fn $name($($arg_name:$t),*) -> $ret {
@@ -99,3 +99,20 @@ macro_rules! syscall {
}
)
}

/// 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 }
if let Some(fun) = $name.get() {
fun($($arg_name),*)
} else {
syscall! { fn $name($($arg_name:$t),*) -> $ret }
$name($($arg_name),*)
}
}
)
}