From 1b0dc1df39f365f489e2c1cf896e93a6196cfa1d Mon Sep 17 00:00:00 2001 From: Simon Davies Date: Thu, 30 Jan 2025 22:47:45 +0000 Subject: [PATCH] Updates rand crate to 0.9 Signed-off-by: Simon Davies --- Cargo.lock | 49 +++++++++++++++---- src/hyperlight_host/Cargo.toml | 2 +- .../examples/otlp_tracing/main.rs | 4 +- .../hypervisor/surrogate_process_manager.rs | 6 +-- src/hyperlight_host/src/mem/layout.rs | 6 +-- .../src/sandbox/uninitialized_evolve.rs | 4 +- 6 files changed, 50 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7e6e7ab1c..4a85d36aa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1128,7 +1128,7 @@ dependencies = [ "proc-maps", "prometheus", "proptest", - "rand", + "rand 0.9.0", "rust-embed", "seccompiler", "serde", @@ -1804,7 +1804,7 @@ dependencies = [ "glob", "opentelemetry", "percent-encoding", - "rand", + "rand 0.8.5", "serde_json", "thiserror 1.0.69", "tokio", @@ -2009,8 +2009,8 @@ dependencies = [ "bitflags 2.8.0", "lazy_static", "num-traits", - "rand", - "rand_chacha", + "rand 0.8.5", + "rand_chacha 0.3.1", "rand_xorshift", "regex-syntax 0.8.5", "rusty-fork", @@ -2069,8 +2069,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", - "rand_chacha", - "rand_core", + "rand_chacha 0.3.1", + "rand_core 0.6.4", +] + +[[package]] +name = "rand" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3779b94aeb87e8bd4e834cee3650289ee9e0d5677f976ecdb6d219e5f4f6cd94" +dependencies = [ + "rand_chacha 0.9.0", + "rand_core 0.9.0", + "zerocopy 0.8.14", ] [[package]] @@ -2080,7 +2091,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_chacha" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" +dependencies = [ + "ppv-lite86", + "rand_core 0.9.0", ] [[package]] @@ -2092,13 +2113,23 @@ dependencies = [ "getrandom 0.2.15", ] +[[package]] +name = "rand_core" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b08f3c9802962f7e1b25113931d94f43ed9725bebc59db9d0c3e9a23b67e15ff" +dependencies = [ + "getrandom 0.3.1", + "zerocopy 0.8.14", +] + [[package]] name = "rand_xorshift" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f" dependencies = [ - "rand_core", + "rand_core 0.6.4", ] [[package]] @@ -2803,7 +2834,7 @@ dependencies = [ "indexmap 1.9.3", "pin-project", "pin-project-lite", - "rand", + "rand 0.8.5", "slab", "tokio", "tokio-util", diff --git a/src/hyperlight_host/Cargo.toml b/src/hyperlight_host/Cargo.toml index 77c9aa43b..032911ddd 100644 --- a/src/hyperlight_host/Cargo.toml +++ b/src/hyperlight_host/Cargo.toml @@ -22,7 +22,7 @@ workspace = true [dependencies] goblin = { version = "0.9" } -rand = { version = "0.8.5" } +rand = { version = "0.9" } cfg-if = { version = "1.0.0" } libc = { version = "0.2.169" } paste = "1.0" diff --git a/src/hyperlight_host/examples/otlp_tracing/main.rs b/src/hyperlight_host/examples/otlp_tracing/main.rs index 702086c3b..f827f320a 100644 --- a/src/hyperlight_host/examples/otlp_tracing/main.rs +++ b/src/hyperlight_host/examples/otlp_tracing/main.rs @@ -178,8 +178,8 @@ fn run_example(wait_input: bool) -> HyperlightResult<()> { multiuse_sandbox = result.unwrap(); } let sleep_for = { - let mut rng = rand::thread_rng(); - rng.gen_range(500..3000) + let mut rng = rand::rng(); + rng.random_range(500..3000) }; thread::sleep(std::time::Duration::from_millis(sleep_for)); } diff --git a/src/hyperlight_host/src/hypervisor/surrogate_process_manager.rs b/src/hyperlight_host/src/hypervisor/surrogate_process_manager.rs index cbb81e1fb..ebfe28c06 100644 --- a/src/hyperlight_host/src/hypervisor/surrogate_process_manager.rs +++ b/src/hyperlight_host/src/hypervisor/surrogate_process_manager.rs @@ -415,7 +415,7 @@ mod tests { use std::time::{Duration, Instant}; use hyperlight_common::mem::PAGE_SIZE_USIZE; - use rand::{thread_rng, Rng}; + use rand::{rng, Rng}; use serial_test::serial; use windows::Win32::Foundation::{CloseHandle, BOOL, HANDLE, INVALID_HANDLE_VALUE}; use windows::Win32::System::Diagnostics::ToolHelp::{ @@ -439,7 +439,7 @@ mod tests { for t in 0..NUMBER_OF_SURROGATE_PROCESSES * 2 { let thread_handle = thread::spawn(move || -> Result<()> { let surrogate_process_manager_res = get_surrogate_process_manager(); - let mut rng = thread_rng(); + let mut rng = rng(); let size = PAGE_SIZE_USIZE * 3; assert!(surrogate_process_manager_res.is_ok()); let surrogate_process_manager = surrogate_process_manager_res.unwrap(); @@ -490,7 +490,7 @@ mod tests { } // in real use the process will not get returned immediately - let n: u64 = rng.gen_range(1..16); + let n: u64 = rng.random_range(1..16); thread::sleep(Duration::from_millis(n)); // dropping the surrogate process, as we do in the line // below, will return it to the surrogate process manager diff --git a/src/hyperlight_host/src/mem/layout.rs b/src/hyperlight_host/src/mem/layout.rs index 14295fb79..251032a25 100644 --- a/src/hyperlight_host/src/mem/layout.rs +++ b/src/hyperlight_host/src/mem/layout.rs @@ -13,14 +13,12 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ - use std::fmt::Debug; use std::mem::{offset_of, size_of}; use hyperlight_common::mem::{GuestStackData, HyperlightPEB, RunMode, PAGE_SIZE_USIZE}; use paste::paste; -use rand::rngs::OsRng; -use rand::RngCore; +use rand::{rng, RngCore}; use tracing::{instrument, Span}; use super::memory_region::MemoryRegionType::{ @@ -1100,7 +1098,7 @@ impl SandboxMemoryLayout { // Set up the security cookie seed let mut security_cookie_seed = [0u8; 8]; - OsRng.fill_bytes(&mut security_cookie_seed); + rng().fill_bytes(&mut security_cookie_seed); shared_mem.copy_from_slice(&security_cookie_seed, self.peb_security_cookie_seed_offset)?; // Skip guest_dispatch_function_ptr_offset because it is set by the guest diff --git a/src/hyperlight_host/src/sandbox/uninitialized_evolve.rs b/src/hyperlight_host/src/sandbox/uninitialized_evolve.rs index ee48564f2..ccbed836e 100644 --- a/src/hyperlight_host/src/sandbox/uninitialized_evolve.rs +++ b/src/hyperlight_host/src/sandbox/uninitialized_evolve.rs @@ -102,8 +102,8 @@ fn hv_init( let outb_hdl = outb_handler_wrapper(hshm.clone(), host_funcs); let mem_access_hdl = mem_access_handler_wrapper(hshm.clone()); let seed = { - let mut rng = rand::thread_rng(); - rng.gen::() + let mut rng = rand::rng(); + rng.random::() }; let peb_addr = { let peb_u64 = u64::try_from(gshm.layout.peb_address)?;