diff --git a/crates/private/tests/root-task/ring-test-harness/src/lib.rs b/crates/private/tests/root-task/ring-test-harness/src/lib.rs index a6415ff4a..7f4bb1da5 100644 --- a/crates/private/tests/root-task/ring-test-harness/src/lib.rs +++ b/crates/private/tests/root-task/ring-test-harness/src/lib.rs @@ -9,11 +9,6 @@ #![feature(cfg_target_thread_local)] #![feature(thread_local)] -use core::cell::RefCell; - -use rand::rngs::SmallRng; -use rand::{RngCore, SeedableRng}; - use sel4_newlib as _; use sel4_root_task::root_task; use sel4_test_harness::run_test_main; @@ -24,35 +19,45 @@ const HEAP_SIZE: usize = 256 * 1024 * 1024; #[root_task(heap_size = HEAP_SIZE)] fn main(_bootinfo: &sel4::BootInfo) -> ! { - seed_insecure_dummy_rng(0); + init(); run_test_main(); sel4::BootInfo::init_thread_tcb().tcb_suspend().unwrap(); unreachable!() } -#[cfg(not(target_thread_local))] -compile_error!(""); +fn init() { + dummy_custom_getrandom::seed_dummy_custom_getrandom(0); +} + +mod dummy_custom_getrandom { + use core::cell::RefCell; -#[thread_local] -static RNG: RefCell> = RefCell::new(None); + use rand::rngs::SmallRng; + use rand::{RngCore, SeedableRng}; -pub fn seed_insecure_dummy_rng(seed: u64) { - assert!(RNG.replace(Some(SmallRng::seed_from_u64(seed))).is_none()); -} + #[cfg(not(target_thread_local))] + compile_error!(""); + + #[thread_local] + static RNG: RefCell> = RefCell::new(None); -pub fn insecure_dummy_rng(buf: &mut [u8]) -> Result<(), getrandom::Error> { - if 1_u32.swap_bytes() == 0 { - panic!() + pub(crate) fn seed_dummy_custom_getrandom(seed: u64) { + assert!(RNG.replace(Some(SmallRng::seed_from_u64(seed))).is_none()); } - RNG.borrow_mut().as_mut().unwrap().fill_bytes(buf); - Ok(()) -} -getrandom::register_custom_getrandom!(insecure_dummy_rng); + fn dummy_custom_getrandom(buf: &mut [u8]) -> Result<(), getrandom::Error> { + RNG.borrow_mut().as_mut().unwrap().fill_bytes(buf); + Ok(()) + } -// https://github.com/rust-lang/compiler-builtins/pull/563 -#[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))] -#[no_mangle] -pub extern "C" fn __bswapsi2(u: u32) -> u32 { - u.swap_bytes() + getrandom::register_custom_getrandom!(dummy_custom_getrandom); +} + +mod compiler_builtins_supplement { + // https://github.com/rust-lang/compiler-builtins/pull/563 + #[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))] + #[no_mangle] + pub extern "C" fn __bswapsi2(u: u32) -> u32 { + u.swap_bytes() + } }