From ade50978788f497796d8f36581560abdaeae5a5b Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Mon, 22 Feb 2021 15:43:48 +0000 Subject: [PATCH] arch: use libc::getrandom() instead of rand crate This removes the last use of rand in our tree and the removal of several dependencies. Signed-off-by: Rob Bradford --- Cargo.lock | 60 +---------------------------------- arch/Cargo.toml | 2 -- arch/src/x86_64/interrupts.rs | 15 +++++---- 3 files changed, 10 insertions(+), 67 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4cbac8615..204cb9de9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -68,7 +68,6 @@ dependencies = [ "libc", "linux-loader", "log 0.4.14", - "rand", "serde", "serde_derive", "serde_json", @@ -405,17 +404,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "getrandom" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee8025cf36f917e6a52cce185b7c7177689b838b7ec138364e50cc2277a56cf4" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "wasi", -] - [[package]] name = "gimli" version = "0.23.0" @@ -877,12 +865,6 @@ dependencies = [ "pnet_sys", ] -[[package]] -name = "ppv-lite86" -version = "0.2.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" - [[package]] name = "proc-macro2" version = "1.0.24" @@ -912,46 +894,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "rand" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e" -dependencies = [ - "libc", - "rand_chacha", - "rand_core", - "rand_hc", -] - -[[package]] -name = "rand_chacha" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8b34ba8cfb21243bd8df91854c830ff0d785fff2e82ebd4434c2644cb9ada18" -dependencies = [ - "getrandom 0.2.0", -] - -[[package]] -name = "rand_hc" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73" -dependencies = [ - "rand_core", -] - [[package]] name = "redox_syscall" version = "0.1.57" @@ -964,7 +906,7 @@ version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de0737333e7a9502c789a36d7c7fa6092a49895d4faa31ca5df163857ded2e9d" dependencies = [ - "getrandom 0.1.16", + "getrandom", "redox_syscall", "rust-argon2", ] diff --git a/arch/Cargo.toml b/arch/Cargo.toml index 75e1cc35a..b0d571f9c 100644 --- a/arch/Cargo.toml +++ b/arch/Cargo.toml @@ -26,5 +26,3 @@ vm-migration = { path = "../vm-migration" } git = "https://github.com/rust-vmm/linux-loader" features = ["elf", "bzimage"] -[dev-dependencies] -rand = "0.8.3" diff --git a/arch/src/x86_64/interrupts.rs b/arch/src/x86_64/interrupts.rs index be89787c6..73a00f3f5 100644 --- a/arch/src/x86_64/interrupts.rs +++ b/arch/src/x86_64/interrupts.rs @@ -84,10 +84,6 @@ pub fn set_lint(vcpu: &Arc) -> Result<()> { #[cfg(test)] #[cfg(feature = "kvm")] mod tests { - - extern crate rand; - use self::rand::Rng; - use super::*; const KVM_APIC_REG_SIZE: usize = 0x400; @@ -111,8 +107,15 @@ mod tests { #[test] fn test_apic_delivery_mode() { - let mut rng = rand::thread_rng(); - let mut v: Vec = (0..20).map(|_| rng.gen::()).collect(); + let mut v: Vec = Vec::new(); + v.resize(20, 0); + + unsafe { + assert_eq!( + libc::getrandom(v.as_mut_ptr() as *mut _ as *mut libc::c_void, 80, 0), + 80 + ); + } v.iter_mut() .for_each(|x| *x = set_apic_delivery_mode(*x, 2));