Skip to content

Commit

Permalink
loader: reorganize imports
Browse files Browse the repository at this point in the history
Export elf and bzimage specific features as `elf::<feature>` and
`bzimage::<feature>` respectively, to further simplify loader/mod.rs.

Signed-off-by: Alexandra Iordache <[email protected]>
  • Loading branch information
Alexandra Iordache committed Mar 18, 2020
1 parent 272f3b9 commit b597cf9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
24 changes: 10 additions & 14 deletions src/loader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -99,15 +95,15 @@ impl Display for Error {
}

#[cfg(all(feature = "elf", any(target_arch = "x86", target_arch = "x86_64")))]
impl From<ElfError> for Error {
fn from(err: ElfError) -> Self {
impl From<elf::Error> 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<BzImageError> for Error {
fn from(err: BzImageError) -> Self {
impl From<bzimage::Error> for Error {
fn from(err: bzimage::Error) -> Self {
Error::Bzimage(err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/loader/x86_64/bzimage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/loader/x86_64/elf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit b597cf9

Please sign in to comment.