Skip to content

Commit

Permalink
add x86_64 and aarch64 modules
Browse files Browse the repository at this point in the history
Phase 2 of code reorganization: separate x86_64 from aarch64
functionality in modules.

Signed-off-by: Alexandra Iordache <[email protected]>
  • Loading branch information
Alexandra Iordache committed Mar 14, 2020
1 parent 16767d4 commit 8e725f4
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 19 deletions.
2 changes: 1 addition & 1 deletion coverage_config_aarch64.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"coverage_score": 70.9,
"coverage_score": 74.1,
"exclude_path": "",
"crate_features": ""
}
2 changes: 1 addition & 1 deletion coverage_config_x86_64.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"coverage_score": 76.3,
"coverage_score": 74,
"exclude_path": "",
"crate_features": ""
}
12 changes: 12 additions & 0 deletions src/loader/aarch64/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) 2019 Intel Corporation. All rights reserved.
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Copyright 2017 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE-BSD-3-Clause file.
//
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause

//! Traits and structs for loading `aarch64` kernels into guest memory.
#![cfg(target_arch = "aarch64")]
27 changes: 14 additions & 13 deletions src/loader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause

//! Traits and Structs
//! Traits and Structs for loading kernels into guest memory.
//! - [KernelLoader](trait.KernelLoader.html): load kernel image into guest memory
//! - [KernelLoaderResult](struct.KernelLoaderResult.html): the structure which loader
//! returns to VMM to assist zero page construction and boot environment setup
Expand All @@ -33,23 +33,24 @@ use vm_memory::{Address, Bytes, GuestAddress, GuestMemory, GuestUsize};
#[cfg_attr(feature = "cargo-clippy", allow(clippy::all))]
pub mod bootparam;

#[cfg(all(feature = "elf", any(target_arch = "x86", target_arch = "x86_64")))]
pub mod elf;

#[cfg(all(feature = "bzimage", any(target_arch = "x86", target_arch = "x86_64")))]
pub mod bzimage;

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
mod struct_util;

#[cfg(all(feature = "elf", any(target_arch = "x86", target_arch = "x86_64")))]
pub use elf::Elf;
#[cfg(all(feature = "elf", any(target_arch = "x86", target_arch = "x86_64")))]
pub use elf::Error as ElfError;
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
mod x86_64;

#[cfg(target_arch = "aarch64")]
mod aarch64;

#[cfg(all(feature = "bzimage", any(target_arch = "x86", target_arch = "x86_64")))]
pub use bzimage::BzImage;
pub use x86_64::bzimage::BzImage;
#[cfg(all(feature = "bzimage", any(target_arch = "x86", target_arch = "x86_64")))]
pub use bzimage::Error as BzImageError;
pub use x86_64::bzimage::Error as BzImageError;

#[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;

#[derive(Debug, PartialEq)]
/// Kernel loader errors.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::io::{Read, Seek, SeekFrom};

use vm_memory::{Address, Bytes, GuestAddress, GuestMemory, GuestUsize};

use super::{
use super::super::{
bootparam, struct_util, Error as KernelLoaderError, KernelLoader, KernelLoaderResult, Result,
};

Expand Down
File renamed without changes.
8 changes: 5 additions & 3 deletions src/loader/elf/mod.rs → src/loader/x86_64/elf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ use std::mem;

use vm_memory::{Address, Bytes, GuestAddress, GuestMemory, GuestUsize};

use super::{struct_util, Error as KernelLoaderError, KernelLoader, KernelLoaderResult, Result};
use super::super::{
struct_util, Error as KernelLoaderError, KernelLoader, KernelLoaderResult, Result,
};

#[allow(dead_code)]
#[allow(non_camel_case_types)]
Expand Down Expand Up @@ -178,7 +180,7 @@ impl KernelLoader for Elf {

if let Some(addr) = highmem_start_address {
if (ehdr.e_entry as u64) < addr.raw_value() {
Err(Error::InvalidEntryAddress)?;
return Err(Error::InvalidEntryAddress.into());
}
}

Expand Down Expand Up @@ -300,7 +302,7 @@ where
// The PVH entry point is a 32-bit address, so the descriptor field
// must be capable of storing all such addresses.
if (nhdr.n_descsz as usize) < mem::size_of::<u32>() {
Err(Error::InvalidPvhNote)?;
return Err(Error::InvalidPvhNote.into());
}

let mut pvh_addr_bytes = [0; mem::size_of::<u32>()];
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 18 additions & 0 deletions src/loader/x86_64/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) 2019 Intel Corporation. All rights reserved.
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Copyright 2017 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE-BSD-3-Clause file.
//
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause

//! Traits and structs for loading `x86_64` kernels into guest memory.
#![cfg(any(target_arch = "x86", target_arch = "x86_64"))]

#[cfg(feature = "elf")]
pub mod elf;

#[cfg(feature = "bzimage")]
pub mod bzimage;

0 comments on commit 8e725f4

Please sign in to comment.