Update ion, update libc
This commit is contained in:
parent
1395eaecf4
commit
58e7685cd3
|
@ -6,3 +6,4 @@ build = "build.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
redox_syscall = { path = "../../syscall/" }
|
redox_syscall = { path = "../../syscall/" }
|
||||||
|
spin = "*"
|
||||||
|
|
|
@ -8,12 +8,33 @@ pub unsafe extern fn strlen(ptr: *const c_char) -> size_t {
|
||||||
i
|
i
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern crate spin;
|
||||||
|
use core::cell::Cell;
|
||||||
|
use self::spin::Mutex;
|
||||||
|
|
||||||
|
/// The randomness state.
|
||||||
|
///
|
||||||
|
/// This is updated when a new random integer is read.
|
||||||
|
static STATE: Mutex<[u64; 2]> = Mutex::new([0xBADF00D1, 0xDEADBEEF]);
|
||||||
|
|
||||||
|
/// Get a pseudorandom integer.
|
||||||
|
///
|
||||||
|
/// Note that this is full-cycle, so apply a modulo when true equidistribution is needed.
|
||||||
pub unsafe extern fn random() -> u64 {
|
pub unsafe extern fn random() -> u64 {
|
||||||
let rand;
|
// Fetch the state.
|
||||||
asm!("rdrand rax"
|
let mut state = STATE.lock();
|
||||||
: "={rax}"(rand)
|
|
||||||
:
|
// Store the first and second part.
|
||||||
:
|
let mut x = state[0];
|
||||||
: "intel", "volatile");
|
let y = state[1];
|
||||||
rand
|
|
||||||
|
// Put the second part into the first slot.
|
||||||
|
state[0] = y;
|
||||||
|
// Twist the first slot.
|
||||||
|
x ^= x << 23;
|
||||||
|
// Update the second slot.
|
||||||
|
state[1] = x ^ y ^ (x >> 17) ^ (y >> 26);
|
||||||
|
|
||||||
|
// Generate the final integer.
|
||||||
|
state[1].wrapping_add(y)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
#![no_std]
|
#![no_std]
|
||||||
#![allow(non_camel_case_types)]
|
#![allow(non_camel_case_types)]
|
||||||
#![feature(asm)]
|
#![feature(asm)]
|
||||||
|
#![feature(const_fn)]
|
||||||
#![feature(naked_functions)]
|
#![feature(naked_functions)]
|
||||||
|
#![feature(thread_local)]
|
||||||
|
|
||||||
#![cfg_attr(stdbuild, feature(no_std, core, core_slice_ext, staged_api, custom_attribute, cfg_target_vendor))]
|
#![cfg_attr(stdbuild, feature(no_std, core, core_slice_ext, staged_api, custom_attribute, cfg_target_vendor))]
|
||||||
#![cfg_attr(stdbuild, no_std)]
|
#![cfg_attr(stdbuild, no_std)]
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit fad8108a164732ff63950b49ac78d76bb3834a87
|
Subproject commit e594412a99c87daa619f09a673b288beecd275ca
|
Loading…
Reference in a new issue