From 1fab0682964d979eed08a40d8f8f157027489772 Mon Sep 17 00:00:00 2001 From: bunnie Date: Mon, 27 Dec 2021 12:29:29 +0800 Subject: [PATCH] add seed setting from the XOUS_SEED environment variable --- xous-rs/src/arch/hosted/mod.rs | 10 ++++++++++ xous-rs/src/definitions.rs | 8 +++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/xous-rs/src/arch/hosted/mod.rs b/xous-rs/src/arch/hosted/mod.rs index 8ceb6071d..e263f78c5 100644 --- a/xous-rs/src/arch/hosted/mod.rs +++ b/xous-rs/src/arch/hosted/mod.rs @@ -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::().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]); diff --git a/xous-rs/src/definitions.rs b/xous-rs/src/definitions.rs index f39068d70..e56f108f8 100644 --- a/xous-rs/src/definitions.rs +++ b/xous-rs/src/definitions.rs @@ -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::*;