Merge branch 'bunnie-dev' into main

This commit is contained in:
bunnie 2022-01-10 17:13:53 +08:00
commit f9cc193a53
5 changed files with 18 additions and 10 deletions

View file

@ -67,13 +67,14 @@ static LOCAL_RNG_STATE: AtomicU64 = AtomicU64::new(2);
#[cfg(not(test))]
fn generate_pid_key() -> [u8; 16] {
use ::rand::prelude::*;
use rand_chacha::ChaCha8Rng;
use rand_chacha::rand_core::SeedableRng;
use rand_chacha::rand_core::RngCore;
let mut process_key = [0u8; 16];
let mut rng = ChaCha8Rng::seed_from_u64(LOCAL_RNG_STATE.load(Ordering::SeqCst) + xous_kernel::TESTING_RNG_SEED.load(core::sync::atomic::Ordering::SeqCst));
for b in process_key.iter_mut() {
*b = rng.gen();
*b = rng.next_u32() as u8;
}
LOCAL_RNG_STATE.store(rng.next_u64(), Ordering::SeqCst);
process_key

View file

@ -5,8 +5,9 @@ use core::sync::atomic::Ordering;
use crate::arch::hosted::LOCAL_RNG_STATE;
pub fn get_u32() -> u32 {
use ::rand::prelude::*;
use rand_chacha::ChaCha8Rng;
use rand_chacha::rand_core::RngCore;
use rand_chacha::rand_core::SeedableRng;
let mut rng = ChaCha8Rng::seed_from_u64(LOCAL_RNG_STATE.load(Ordering::SeqCst));
let r = rng.next_u32();

View file

@ -1,5 +1,6 @@
use rand::prelude::*;
use rand_chacha::ChaCha8Rng;
use rand_chacha::rand_core::RngCore;
use rand_chacha::rand_core::SeedableRng;
use crate::*;
use core::sync::atomic::{AtomicU64, Ordering};
use std::collections::{BTreeSet, HashSet};
@ -13,10 +14,12 @@ static RNG_LOCAL_STATE: AtomicU64 = AtomicU64::new(3);
fn gen_key(dictname: &str, keynum: usize, lower_size_bound: usize, upper_size_bound: usize) -> (String, Vec::<u8>) {
let mut rng = ChaCha8Rng::seed_from_u64(RNG_LOCAL_STATE.load(Ordering::SeqCst) + xous::TESTING_RNG_SEED.load(core::sync::atomic::Ordering::SeqCst));
// we want roughly half our keys to be in the small bin, and half in the large bin
let keylen = if rng.gen_bool(0.5) {
rng.gen_range(lower_size_bound..VPAGE_SIZE)
let keylen = if rng.next_u32() < (u32::MAX / 2) {
((rng.next_u64() as usize) % (VPAGE_SIZE - lower_size_bound)) + lower_size_bound
//rng.gen_range(lower_size_bound..VPAGE_SIZE) // older API used to minimize crate count
} else {
rng.gen_range(VPAGE_SIZE..upper_size_bound)
((rng.next_u64() as usize) % (upper_size_bound - VPAGE_SIZE)) + VPAGE_SIZE
//rng.gen_range(VPAGE_SIZE..upper_size_bound) // older API used to minimize crate count
};
// record the owning dictionary name & length with the key. This isn't mandatory for a key name,
// but it helps the test checking program check things.

View file

@ -47,7 +47,7 @@ impl Susres {
// different and have a lot of overhead; it seems like the system goes into a form of deadlock
// during boot when all the hosted mode servers try to connect. This isn't an issue on real hardware.
#[cfg(not(any(target_os = "none", target_os = "xous")))]
pub fn new(xns: &xous_names::XousNames, cb_discriminant: u32, cid: CID) -> Result<Self, xous::Error> {
pub fn new(_ordering: Option<SuspendOrder>, xns: &xous_names::XousNames, cb_discriminant: u32, cid: CID) -> Result<Self, xous::Error> {
REFCOUNT.store(REFCOUNT.load(Ordering::Relaxed) + 1, Ordering::Relaxed);
Ok(Susres {
conn: 0,

View file

@ -467,8 +467,9 @@ mod implementation {
// a stub to try to avoid breaking hosted mode for as long as possible.
#[cfg(not(any(target_os = "none", target_os = "xous")))]
mod implementation {
use rand::prelude::*;
use rand_chacha::ChaCha8Rng;
use rand_chacha::rand_core::SeedableRng;
use rand_chacha::rand_core::RngCore;
use crate::api::{HealthTests, TrngBuf, TrngErrors};
pub struct Trng {
@ -502,7 +503,9 @@ mod implementation {
}
self.msgcount += 1;
let mut data = [0; 1024];
self.rng.fill(&mut data);
for d in data.iter_mut() {
*d = self.rng.next_u32();
}
TrngBuf {
data,
len,