From 1e0b776962e4c9ac27a6f65cb7933e949e28fc33 Mon Sep 17 00:00:00 2001 From: Alexandra Iordache Date: Fri, 29 May 2020 13:02:31 +0300 Subject: [PATCH] refactor autogenerated files Signed-off-by: Alexandra Iordache --- coverage_config_x86_64.json | 5 ++-- src/configurator/x86_64/linux.rs | 2 +- src/configurator/x86_64/pvh.rs | 2 +- src/lib.rs | 5 ++++ src/loader/mod.rs | 11 +------ src/loader/x86_64/elf/mod.rs | 15 ++-------- src/loader_gen/mod.rs | 15 ++++++++++ .../x86_64}/bootparam.rs | 0 .../x86_64/elf => loader_gen/x86_64}/elf.rs | 0 src/loader_gen/x86_64/mod.rs | 29 +++++++++++++++++++ .../elf => loader_gen/x86_64}/start_info.rs | 0 11 files changed, 58 insertions(+), 26 deletions(-) create mode 100644 src/loader_gen/mod.rs rename src/{loader => loader_gen/x86_64}/bootparam.rs (100%) rename src/{loader/x86_64/elf => loader_gen/x86_64}/elf.rs (100%) create mode 100644 src/loader_gen/x86_64/mod.rs rename src/{loader/x86_64/elf => loader_gen/x86_64}/start_info.rs (100%) diff --git a/coverage_config_x86_64.json b/coverage_config_x86_64.json index 13b9301f..47fe3903 100644 --- a/coverage_config_x86_64.json +++ b/coverage_config_x86_64.json @@ -1,5 +1,6 @@ { - "coverage_score": 81, + "coverage_score": 84.8, "exclude_path": "", - "crate_features": "bzimage,elf" + "crate_features": "bzimage,elf", + "exclude_path": "loader_gen" } diff --git a/src/configurator/x86_64/linux.rs b/src/configurator/x86_64/linux.rs index a815131a..38343be7 100644 --- a/src/configurator/x86_64/linux.rs +++ b/src/configurator/x86_64/linux.rs @@ -124,7 +124,7 @@ impl BootConfigurator for LinuxBootConfigurator { #[cfg(test)] mod tests { use super::*; - use crate::loader::bootparam::boot_params; + use crate::loader_gen::bootparam::boot_params; use std::mem; use vm_memory::{Address, GuestAddress, GuestMemoryMmap}; diff --git a/src/configurator/x86_64/pvh.rs b/src/configurator/x86_64/pvh.rs index cb5c3612..4b10dd59 100644 --- a/src/configurator/x86_64/pvh.rs +++ b/src/configurator/x86_64/pvh.rs @@ -15,7 +15,7 @@ use vm_memory::{ByteValued, Bytes, GuestMemory}; use crate::configurator::{BootConfigurator, BootParams, Error as BootConfiguratorError, Result}; -use crate::loader::elf::start_info::{hvm_memmap_table_entry, hvm_modlist_entry, hvm_start_info}; +use crate::loader_gen::start_info::{hvm_memmap_table_entry, hvm_modlist_entry, hvm_start_info}; use std::error::Error as StdError; use std::fmt; diff --git a/src/lib.rs b/src/lib.rs index 3195cc75..a178c1c4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -93,4 +93,9 @@ pub mod cmdline; pub mod configurator; pub mod loader; +#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] +mod loader_gen; +#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] +pub use loader_gen::*; + extern crate vm_memory; diff --git a/src/loader/mod.rs b/src/loader/mod.rs index 120f64ad..b9bc088c 100644 --- a/src/loader/mod.rs +++ b/src/loader/mod.rs @@ -24,20 +24,11 @@ use std::ffi::CStr; use std::fmt::{self, Display}; use std::io::{Read, Seek}; -#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] use vm_memory::ByteValued; use vm_memory::{Address, Bytes, GuestAddress, GuestMemory, GuestUsize}; -#[allow(dead_code)] -#[allow(non_camel_case_types)] -#[allow(non_snake_case)] -#[allow(non_upper_case_globals)] -#[allow(missing_docs)] -#[cfg_attr(feature = "cargo-clippy", allow(clippy::all))] #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] -// Hide the autogenerated documentation for bindgen'ed sources. -#[doc(hidden)] -pub mod bootparam; +pub use crate::loader_gen::bootparam; #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] mod x86_64; diff --git a/src/loader/x86_64/elf/mod.rs b/src/loader/x86_64/elf/mod.rs index 1b319d7f..0f4b6605 100644 --- a/src/loader/x86_64/elf/mod.rs +++ b/src/loader/x86_64/elf/mod.rs @@ -18,18 +18,9 @@ use std::mem; use vm_memory::{Address, ByteValued, Bytes, GuestAddress, GuestMemory, GuestUsize}; -use super::super::{Error as KernelLoaderError, KernelLoader, KernelLoaderResult, Result}; - -#[allow(dead_code)] -#[allow(non_camel_case_types)] -#[allow(non_snake_case)] -#[allow(non_upper_case_globals)] -#[cfg_attr(feature = "cargo-clippy", allow(clippy::all))] -mod elf; - -#[allow(missing_docs)] -#[cfg_attr(feature = "cargo-clippy", allow(clippy::all))] -pub mod start_info; +use crate::loader::{Error as KernelLoaderError, KernelLoader, KernelLoaderResult, Result}; +use crate::loader_gen::elf; +pub use crate::loader_gen::start_info; unsafe impl ByteValued for elf::Elf64_Ehdr {} unsafe impl ByteValued for elf::Elf64_Nhdr {} diff --git a/src/loader_gen/mod.rs b/src/loader_gen/mod.rs new file mode 100644 index 00000000..31010c71 --- /dev/null +++ b/src/loader_gen/mod.rs @@ -0,0 +1,15 @@ +// 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 + +//! Bindgen autogenerated structs for boot parameters. + +#![cfg(any(target_arch = "x86", target_arch = "x86_64"))] + +mod x86_64; +pub use x86_64::*; diff --git a/src/loader/bootparam.rs b/src/loader_gen/x86_64/bootparam.rs similarity index 100% rename from src/loader/bootparam.rs rename to src/loader_gen/x86_64/bootparam.rs diff --git a/src/loader/x86_64/elf/elf.rs b/src/loader_gen/x86_64/elf.rs similarity index 100% rename from src/loader/x86_64/elf/elf.rs rename to src/loader_gen/x86_64/elf.rs diff --git a/src/loader_gen/x86_64/mod.rs b/src/loader_gen/x86_64/mod.rs new file mode 100644 index 00000000..c6e70e5f --- /dev/null +++ b/src/loader_gen/x86_64/mod.rs @@ -0,0 +1,29 @@ +// 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 + +//! Bindgen autogenerated structs for `x86_64` boot parameters. + +#![cfg(any(target_arch = "x86", target_arch = "x86_64"))] + +#![cfg_attr(feature = "cargo-clippy", allow(clippy::all))] +#![allow(dead_code)] +#![allow(missing_docs)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] +#![allow(non_upper_case_globals)] + +// Hide the autogenerated documentation for bindgen'ed sources. +#[doc(hidden)] +pub mod bootparam; + +#[cfg(feature = "elf")] +pub mod elf; + +#[cfg(feature = "elf")] +pub mod start_info; diff --git a/src/loader/x86_64/elf/start_info.rs b/src/loader_gen/x86_64/start_info.rs similarity index 100% rename from src/loader/x86_64/elf/start_info.rs rename to src/loader_gen/x86_64/start_info.rs