add seed setting from the XOUS_SEED environment variable

This commit is contained in:
bunnie 2021-12-27 12:29:29 +08:00
parent dd14dfc4c6
commit 1fab068296
2 changed files with 17 additions and 1 deletions

View file

@ -25,6 +25,16 @@ lazy_static::lazy_static! {
.unwrap_or_else(|_| SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 0))
};
static ref PROCESS_KEY: ProcessKey = {
// piggy back a seed initialization on top of the PROCESS_KEY initialization
let seed = match std::env::var("XOUS_SEED") {
Ok(s) => {
s.parse::<u64>().unwrap_or(0u64)
}
Err(_) => 0u64
};
crate::TESTING_RNG_SEED.store(seed, core::sync::atomic::Ordering::SeqCst);
// resume with PROCESS_KEY initialization
std::env::var("XOUS_PROCESS_KEY")
.map(|s| {
let mut base = ProcessKey([0u8; 16]);

View file

@ -42,8 +42,14 @@ pub const PDDB_LEN: u32 = EC_REGION_LOC - PDDB_LOC;
#[cfg(all(any(windows, unix), not(feature = "processes-as-threads")))]
use core::sync::atomic::AtomicU64;
// Secretly, you can change this by setting the XOUS_SEED environment variable.
// I don't lke environment variables because where do you document features like this?
// But, this was the most expedient way to get all the threads in Hosted mode to pick up a seed.
// The code that reads the varable this is all the way over in xous-rs\src\arch\hosted\mod.rs#29, and
// it's glommed onto some other static process initialization code because I don't fully understand
// what's going on over there.
#[cfg(all(any(windows, unix), not(feature = "processes-as-threads")))]
pub const TESTING_RNG_SEED: AtomicU64 = AtomicU64::new(0); // 0, 1, 2, 3, 4, 7, 8 "works"; 5 "oom"; 6 "key space oom"
pub static TESTING_RNG_SEED: AtomicU64 = AtomicU64::new(0);
pub mod exceptions;
pub use exceptions::*;