Update ion, update libc

This commit is contained in:
Jeremy Soller 2016-11-15 08:21:04 -07:00
parent 1395eaecf4
commit 58e7685cd3
4 changed files with 32 additions and 8 deletions

View file

@ -6,3 +6,4 @@ build = "build.rs"
[dependencies]
redox_syscall = { path = "../../syscall/" }
spin = "*"

View file

@ -8,12 +8,33 @@ pub unsafe extern fn strlen(ptr: *const c_char) -> size_t {
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 {
let rand;
asm!("rdrand rax"
: "={rax}"(rand)
:
:
: "intel", "volatile");
rand
// Fetch the state.
let mut state = STATE.lock();
// Store the first and second part.
let mut x = state[0];
let y = state[1];
// 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)
}

View file

@ -1,7 +1,9 @@
#![no_std]
#![allow(non_camel_case_types)]
#![feature(asm)]
#![feature(const_fn)]
#![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, no_std)]

@ -1 +1 @@
Subproject commit fad8108a164732ff63950b49ac78d76bb3834a87
Subproject commit e594412a99c87daa619f09a673b288beecd275ca