diff --git a/coverage_config_aarch64.json b/coverage_config_aarch64.json index 70ee9da9..861b91e6 100644 --- a/coverage_config_aarch64.json +++ b/coverage_config_aarch64.json @@ -1,5 +1,5 @@ { - "coverage_score": 70.9, + "coverage_score": 74.1, "exclude_path": "", "crate_features": "" } diff --git a/coverage_config_x86_64.json b/coverage_config_x86_64.json index 648083ff..d4803427 100644 --- a/coverage_config_x86_64.json +++ b/coverage_config_x86_64.json @@ -1,5 +1,5 @@ { - "coverage_score": 76.3, + "coverage_score": 74, "exclude_path": "", "crate_features": "" } diff --git a/src/loader/aarch64/mod.rs b/src/loader/aarch64/mod.rs new file mode 100644 index 00000000..e5105c03 --- /dev/null +++ b/src/loader/aarch64/mod.rs @@ -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")] diff --git a/src/loader/mod.rs b/src/loader/mod.rs index e1d22022..c0dd573b 100644 --- a/src/loader/mod.rs +++ b/src/loader/mod.rs @@ -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 @@ -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. diff --git a/src/loader/bzimage/mod.rs b/src/loader/x86_64/bzimage/mod.rs similarity index 99% rename from src/loader/bzimage/mod.rs rename to src/loader/x86_64/bzimage/mod.rs index 55c06e08..3d45e16d 100644 --- a/src/loader/bzimage/mod.rs +++ b/src/loader/x86_64/bzimage/mod.rs @@ -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, }; diff --git a/src/loader/elf/elf.rs b/src/loader/x86_64/elf/elf.rs similarity index 100% rename from src/loader/elf/elf.rs rename to src/loader/x86_64/elf/elf.rs diff --git a/src/loader/elf/mod.rs b/src/loader/x86_64/elf/mod.rs similarity index 98% rename from src/loader/elf/mod.rs rename to src/loader/x86_64/elf/mod.rs index 8c24b536..da82a268 100644 --- a/src/loader/elf/mod.rs +++ b/src/loader/x86_64/elf/mod.rs @@ -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)] @@ -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()); } } @@ -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::() { - Err(Error::InvalidPvhNote)?; + return Err(Error::InvalidPvhNote.into()); } let mut pvh_addr_bytes = [0; mem::size_of::()]; diff --git a/src/loader/elf/start_info.rs b/src/loader/x86_64/elf/start_info.rs similarity index 100% rename from src/loader/elf/start_info.rs rename to src/loader/x86_64/elf/start_info.rs diff --git a/src/loader/elf/test_badnote.bin b/src/loader/x86_64/elf/test_badnote.bin similarity index 100% rename from src/loader/elf/test_badnote.bin rename to src/loader/x86_64/elf/test_badnote.bin diff --git a/src/loader/elf/test_dummynote.bin b/src/loader/x86_64/elf/test_dummynote.bin similarity index 100% rename from src/loader/elf/test_dummynote.bin rename to src/loader/x86_64/elf/test_dummynote.bin diff --git a/src/loader/elf/test_elf.bin b/src/loader/x86_64/elf/test_elf.bin similarity index 100% rename from src/loader/elf/test_elf.bin rename to src/loader/x86_64/elf/test_elf.bin diff --git a/src/loader/elf/test_elfnote.bin b/src/loader/x86_64/elf/test_elfnote.bin similarity index 100% rename from src/loader/elf/test_elfnote.bin rename to src/loader/x86_64/elf/test_elfnote.bin diff --git a/src/loader/x86_64/mod.rs b/src/loader/x86_64/mod.rs new file mode 100644 index 00000000..1ad58b3f --- /dev/null +++ b/src/loader/x86_64/mod.rs @@ -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;