Skip to content

Commit

Permalink
Updates to make clippy happy
Browse files Browse the repository at this point in the history
Since clippy runs with --all-features and the mshv2 and mshv3 features are mutually exclusive these changes ensure that clippy is able to run and we can still enforce mutually exclusivity

Signed-off-by: Simon Davies <[email protected]>
  • Loading branch information
simongdavies committed Nov 12, 2024
1 parent 60f14bf commit 9008214
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 24 deletions.
13 changes: 9 additions & 4 deletions src/hyperlight_host/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ use anyhow::Result;
use built::write_built_file;

fn main() -> Result<()> {
// mshv2 and mshv3 features are mutually exclusive.
#[cfg(all(feature = "mshv2", feature = "mshv3"))]
panic!("mshv2 and mshv3 features are mutually exclusive");

// re-run the build if this script is changed (or deleted!),
// even if the rust code is completely unchanged.
println!("cargo:rerun-if-changed=build.rs");
Expand Down Expand Up @@ -98,9 +94,18 @@ fn main() -> Result<()> {
// inprocess feature is aliased with debug_assertions to make it only available in debug-builds.
// You should never use #[cfg(feature = "inprocess")] in the codebase. Use #[cfg(inprocess)] instead.
inprocess: { all(feature = "inprocess", debug_assertions) },
// the following is a bit of a hack to stop clippy failing wehn run with -all features as it enables both mshv2 and mshv3 at the same time causing errors
mshv2: { all(feature = "mshv2", target_os = "linux", not(clippy)) },
mshv3: { all(feature = "mshv3", target_os = "linux") },
}

write_built_file()?;

// mshv2 and mshv3 features are mutually exclusive
#[cfg(all(feature = "mshv2", feature = "mshv3", not(clippy)))]
Err(anyhow::anyhow!(
"mshv2 and mshv3 features are mutually exclusive"
))?;

Ok(())
}
4 changes: 2 additions & 2 deletions src/hyperlight_host/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

#[cfg(feature = "mshv2")]
#[cfg(mshv2)]
extern crate mshv_ioctls2 as mshv_ioctls;

#[cfg(feature = "mshv3")]
#[cfg(mshv3)]
extern crate mshv_ioctls3 as mshv_ioctls;

use std::array::TryFromSliceError;
Expand Down
20 changes: 10 additions & 10 deletions src/hyperlight_host/src/hypervisor/hyperv_linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,28 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

#[cfg(feature = "mshv2")]
#[cfg(mshv2)]
extern crate mshv_bindings2 as mshv_bindings;
#[cfg(feature = "mshv2")]
#[cfg(mshv2)]
extern crate mshv_ioctls2 as mshv_ioctls;

#[cfg(feature = "mshv3")]
#[cfg(mshv3)]
extern crate mshv_bindings3 as mshv_bindings;
#[cfg(feature = "mshv3")]
#[cfg(mshv3)]
extern crate mshv_ioctls3 as mshv_ioctls;

use std::fmt::{Debug, Formatter};

use log::error;
#[cfg(feature = "mshv2")]
#[cfg(mshv2)]
use mshv_bindings::hv_message;
use mshv_bindings::{
hv_message_type, hv_message_type_HVMSG_GPA_INTERCEPT, hv_message_type_HVMSG_UNMAPPED_GPA,
hv_message_type_HVMSG_X64_HALT, hv_message_type_HVMSG_X64_IO_PORT_INTERCEPT, hv_register_assoc,
hv_register_name_HV_X64_REGISTER_RIP, hv_register_value, mshv_user_mem_region,
FloatingPointUnit, SegmentRegister, SpecialRegisters, StandardRegisters,
};
#[cfg(feature = "mshv3")]
#[cfg(mshv3)]
use mshv_bindings::{
hv_partition_property_code_HV_PARTITION_PROPERTY_SYNTHETIC_PROC_FEATURES,
hv_partition_synthetic_processor_features,
Expand Down Expand Up @@ -105,9 +105,9 @@ impl HypervLinuxDriver {
}
let mshv = Mshv::new()?;
let pr = Default::default();
#[cfg(feature = "mshv2")]
#[cfg(mshv2)]
let vm_fd = mshv.create_vm_with_config(&pr)?;
#[cfg(feature = "mshv3")]
#[cfg(mshv3)]
let vm_fd = {
let vm_fd = mshv.create_vm_with_args(&pr)?;
let features: hv_partition_synthetic_processor_features = Default::default();
Expand Down Expand Up @@ -311,12 +311,12 @@ impl Hypervisor for HypervLinuxDriver {
const UNMAPPED_GPA_MESSAGE: hv_message_type = hv_message_type_HVMSG_UNMAPPED_GPA;
const INVALID_GPA_ACCESS_MESSAGE: hv_message_type = hv_message_type_HVMSG_GPA_INTERCEPT;

#[cfg(feature = "mshv2")]
#[cfg(mshv2)]
let run_result = {
let hv_message: hv_message = Default::default();
&self.vcpu_fd.run(hv_message)
};
#[cfg(feature = "mshv3")]
#[cfg(mshv3)]
let run_result = &self.vcpu_fd.run();

let result = match run_result {
Expand Down
16 changes: 8 additions & 8 deletions src/hyperlight_host/src/mem/memory_region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

#[cfg(feature = "mshv2")]
#[cfg(mshv2)]
extern crate mshv_bindings2 as mshv_bindings;
#[cfg(feature = "mshv2")]
#[cfg(mshv2)]
extern crate mshv_ioctls2 as mshv_ioctls;

#[cfg(feature = "mshv3")]
#[cfg(mshv3)]
extern crate mshv_bindings3 as mshv_bindings;
#[cfg(feature = "mshv3")]
#[cfg(mshv3)]
extern crate mshv_ioctls3 as mshv_ioctls;

use std::ops::Range;
Expand All @@ -32,11 +32,11 @@ use hyperlight_common::mem::PAGE_SHIFT;
use hyperlight_common::mem::PAGE_SIZE_USIZE;
#[cfg(mshv)]
use mshv_bindings::{hv_x64_memory_intercept_message, mshv_user_mem_region};
#[cfg(feature = "mshv2")]
#[cfg(mshv2)]
use mshv_bindings::{
HV_MAP_GPA_EXECUTABLE, HV_MAP_GPA_PERMISSIONS_NONE, HV_MAP_GPA_READABLE, HV_MAP_GPA_WRITABLE,
};
#[cfg(feature = "mshv3")]
#[cfg(mshv3)]
use mshv_bindings::{
MSHV_SET_MEM_BIT_EXECUTABLE, MSHV_SET_MEM_BIT_UNMAP, MSHV_SET_MEM_BIT_WRITABLE,
};
Expand Down Expand Up @@ -242,7 +242,7 @@ impl From<MemoryRegion> for mshv_user_mem_region {
let guest_pfn = region.guest_region.start as u64 >> PAGE_SHIFT;
let userspace_addr = region.host_region.start as u64;

#[cfg(feature = "mshv2")]
#[cfg(mshv2)]
{
let flags = region.flags.iter().fold(0, |acc, flag| {
let flag_value = match flag {
Expand All @@ -261,7 +261,7 @@ impl From<MemoryRegion> for mshv_user_mem_region {
flags,
}
}
#[cfg(feature = "mshv3")]
#[cfg(mshv3)]
{
let flags: u8 = region.flags.iter().fold(0, |acc, flag| {
let flag_value = match flag {
Expand Down

0 comments on commit 9008214

Please sign in to comment.