diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6ed5dc6..12d09fc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,7 +4,10 @@ on: [push, pull_request] jobs: checks: name: Checks - runs-on: macos-10.15 + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [macos-14, macos-15] steps: - uses: actions/checkout@v2 - run: cargo check --examples --tests --all-targets diff --git a/hv-sys/src/lib.rs b/hv-sys/src/lib.rs index 03be98f..b1cfc2e 100644 --- a/hv-sys/src/lib.rs +++ b/hv-sys/src/lib.rs @@ -3,6 +3,5 @@ #![allow(improper_ctypes)] // Comes from unit tests, don't care much #![allow(deref_nullptr)] -#![allow(unaligned_references)] include!(concat!(env!("OUT_DIR"), "/bindings.rs")); diff --git a/hv/examples/as.rs b/hv/examples/as.rs index 5f10967..5094496 100644 --- a/hv/examples/as.rs +++ b/hv/examples/as.rs @@ -72,6 +72,7 @@ fn main() -> Result<(), hv::Error> { cpu.set_reg(Reg::X1, GUEST_RESULT_ADDR as _) .expect("Failed to set X1"); + #[allow(clippy::never_loop)] loop { cpu.run().expect("Failed to run CPU"); diff --git a/hv/src/arm64/mod.rs b/hv/src/arm64/mod.rs index 9991abf..d642a4e 100644 --- a/hv/src/arm64/mod.rs +++ b/hv/src/arm64/mod.rs @@ -15,7 +15,7 @@ pub enum InterruptType { /// Events that can trigger a guest exit to the VMM. #[repr(u32)] -#[derive(Debug, Copy, Clone, Eq, PartialEq)] +#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)] pub enum ExitReason { /// Asynchronous exit requested explicitly by `hv_vcpus_exit` call. Canceled = sys::hv_exit_reason_t_HV_EXIT_REASON_CANCELED, @@ -31,15 +31,10 @@ pub enum ExitReason { /// the EOI for the guest's VTimer interrupt handler. VTimerActivated = sys::hv_exit_reason_t_HV_EXIT_REASON_VTIMER_ACTIVATED, /// Unable to determine exit reason: this should not happen under normal operation. + #[default] Unknown = sys::hv_exit_reason_t_HV_EXIT_REASON_UNKNOWN, } -impl Default for ExitReason { - fn default() -> Self { - ExitReason::Unknown - } -} - impl From<sys::hv_exit_reason_t> for ExitReason { fn from(value: sys::hv_exit_reason_t) -> Self { match value { diff --git a/hv/src/lib.rs b/hv/src/lib.rs index 642f44a..4d7fdda 100644 --- a/hv/src/lib.rs +++ b/hv/src/lib.rs @@ -26,10 +26,10 @@ pub type GPAddr = u64; bitflags::bitflags! { /// Guest physical memory region permissions. - pub struct Memory: u32 { - const READ = sys::HV_MEMORY_READ; - const WRITE = sys::HV_MEMORY_WRITE; - const EXEC = sys::HV_MEMORY_EXEC; + pub struct Memory: u64 { + const READ = 1 << 0; + const WRITE = 1 << 1; + const EXEC = 1 << 2; } } @@ -37,6 +37,7 @@ bitflags::bitflags! { #[macro_export] macro_rules! call { ($f:expr) => {{ + #[allow(clippy::macro_metavars_in_unsafe)] let code = unsafe { $f }; match code { 0 => Ok(()), @@ -70,7 +71,7 @@ impl fmt::Display for Error { Error::NoResources => write!(f, "The operation was unsuccessful because the host had no resources available to complete the request"), Error::NoDevice => write!(f, "The operation was unsuccessful because no VM or vCPU was available"), Error::Unsupported => write!(f, "The operation requested isn’t supported by the hypervisor"), - Error::Unknown(code) => write!(f, "Error code: {}", *code as i32), + Error::Unknown(code) => write!(f, "Error code: {}", *code), } } } diff --git a/hv/src/vm.rs b/hv/src/vm.rs index a64978f..b76b4ab 100644 --- a/hv/src/vm.rs +++ b/hv/src/vm.rs @@ -31,10 +31,16 @@ impl Vm { /// In order to create child objects (`Vcpu`, `Space`, etc), this object must be wrapped /// with [Arc]. /// + #[allow(clippy::not_unsafe_ptr_arg_deref)] pub fn new(options: Options) -> Result<Vm, Error> { #[cfg(target_arch = "x86_64")] let options = options.bits(); + #[cfg(not(target_arch = "x86_64"))] + if options.is_null() { + return Err(Error::BadArgument); + } + call!(sys::hv_vm_create(options))?; Ok(Vm) } diff --git a/rust-toolchain.toml b/rust-toolchain.toml index fa98443..73cb934 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "1.53" +channel = "stable" components = ["rustfmt", "clippy"]