From b597cf9014fe9e3c78fdcf9fdc94a4de7960817a Mon Sep 17 00:00:00 2001 From: Alexandra Iordache Date: Wed, 18 Mar 2020 20:51:40 +0200 Subject: [PATCH] loader: reorganize imports Export elf and bzimage specific features as `elf::` and `bzimage::` respectively, to further simplify loader/mod.rs. Signed-off-by: Alexandra Iordache --- src/loader/mod.rs | 24 ++++++++++-------------- src/loader/x86_64/bzimage/mod.rs | 2 +- src/loader/x86_64/elf/mod.rs | 2 +- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/loader/mod.rs b/src/loader/mod.rs index c0dd573b..103788e9 100644 --- a/src/loader/mod.rs +++ b/src/loader/mod.rs @@ -42,26 +42,22 @@ mod x86_64; #[cfg(target_arch = "aarch64")] mod aarch64; -#[cfg(all(feature = "bzimage", any(target_arch = "x86", target_arch = "x86_64")))] -pub use x86_64::bzimage::BzImage; -#[cfg(all(feature = "bzimage", any(target_arch = "x86", target_arch = "x86_64")))] -pub use x86_64::bzimage::Error as BzImageError; +#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] +pub use x86_64::*; -#[cfg(all(feature = "elf", any(target_arch = "x86", target_arch = "x86_64")))] -pub use x86_64::elf::Elf; -#[cfg(all(feature = "elf", any(target_arch = "x86", target_arch = "x86_64")))] -pub use x86_64::elf::Error as ElfError; +#[cfg(target_arch = "aarch64")] +pub use aarch64::*; #[derive(Debug, PartialEq)] /// Kernel loader errors. pub enum Error { /// Failed to load bzimage. #[cfg(all(feature = "bzimage", any(target_arch = "x86", target_arch = "x86_64")))] - Bzimage(BzImageError), + Bzimage(bzimage::Error), /// Failed to load elf image. #[cfg(all(feature = "elf", any(target_arch = "x86", target_arch = "x86_64")))] - Elf(ElfError), + Elf(elf::Error), /// Failed writing command line to guest memory. CommandLineCopy, @@ -99,15 +95,15 @@ impl Display for Error { } #[cfg(all(feature = "elf", any(target_arch = "x86", target_arch = "x86_64")))] -impl From for Error { - fn from(err: ElfError) -> Self { +impl From for Error { + fn from(err: elf::Error) -> Self { Error::Elf(err) } } #[cfg(all(feature = "bzimage", any(target_arch = "x86", target_arch = "x86_64")))] -impl From for Error { - fn from(err: BzImageError) -> Self { +impl From for Error { + fn from(err: bzimage::Error) -> Self { Error::Bzimage(err) } } diff --git a/src/loader/x86_64/bzimage/mod.rs b/src/loader/x86_64/bzimage/mod.rs index 3d45e16d..0c25783e 100644 --- a/src/loader/x86_64/bzimage/mod.rs +++ b/src/loader/x86_64/bzimage/mod.rs @@ -86,7 +86,7 @@ impl KernelLoader for BzImage { /// let gm = GuestMemoryMmap::from_ranges(&[(GuestAddress(0x0), mem_size)]).unwrap(); /// let mut kernel_image = vec![]; /// kernel_image.extend_from_slice(include_bytes!("bzimage")); - /// assert!(BzImage::load( + /// assert!(bzimage::BzImage::load( /// &gm, /// Some(kernel_addr), /// &mut Cursor::new(&kernel_image), diff --git a/src/loader/x86_64/elf/mod.rs b/src/loader/x86_64/elf/mod.rs index 33bb037d..8195e999 100644 --- a/src/loader/x86_64/elf/mod.rs +++ b/src/loader/x86_64/elf/mod.rs @@ -150,7 +150,7 @@ impl KernelLoader for Elf { /// let gm = GuestMemoryMmap::from_ranges(&[(GuestAddress(0x0), mem_size)]).unwrap(); /// let mut kernel_image = vec![]; /// kernel_image.extend_from_slice(include_bytes!("test_elf.bin")); - /// assert!(Elf::load( + /// assert!(elf::Elf::load( /// &gm, /// Some(kernel_addr), /// &mut Cursor::new(&kernel_image),