Auto merge of #24526 - klutzy:getrandom-fix, r=alexcrichton
Fixes #21538.
This commit is contained in:
commit
c6b8d96abd
@ -97,25 +97,24 @@ fn getrandom_next_u64() -> u64 {
|
||||
target_arch = "powerpc")))]
|
||||
fn is_getrandom_available() -> bool {
|
||||
use sync::atomic::{AtomicBool, ATOMIC_BOOL_INIT, Ordering};
|
||||
use sync::{Once, ONCE_INIT};
|
||||
|
||||
static GETRANDOM_CHECKED: AtomicBool = ATOMIC_BOOL_INIT;
|
||||
static GETRANDOM_AVAILABLE: AtomicBool = ATOMIC_BOOL_INIT;
|
||||
static CHECKER: Once = ONCE_INIT;
|
||||
static AVAILABLE: AtomicBool = ATOMIC_BOOL_INIT;
|
||||
|
||||
if !GETRANDOM_CHECKED.load(Ordering::Relaxed) {
|
||||
CHECKER.call_once(|| {
|
||||
let mut buf: [u8; 0] = [];
|
||||
let result = getrandom(&mut buf);
|
||||
let available = if result == -1 {
|
||||
let err = errno() as libc::c_int;
|
||||
err != libc::ENOSYS
|
||||
let err = io::Error::last_os_error().raw_os_error();
|
||||
err != Some(libc::ENOSYS)
|
||||
} else {
|
||||
true
|
||||
};
|
||||
GETRANDOM_AVAILABLE.store(available, Ordering::Relaxed);
|
||||
GETRANDOM_CHECKED.store(true, Ordering::Relaxed);
|
||||
available
|
||||
} else {
|
||||
GETRANDOM_AVAILABLE.load(Ordering::Relaxed)
|
||||
}
|
||||
AVAILABLE.store(available, Ordering::Relaxed);
|
||||
});
|
||||
|
||||
AVAILABLE.load(Ordering::Relaxed)
|
||||
}
|
||||
|
||||
#[cfg(not(all(target_os = "linux",
|
||||
|
Loading…
Reference in New Issue
Block a user