Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CI and switch to stable Rust #2

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion hv-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
1 change: 1 addition & 0 deletions hv/examples/as.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
9 changes: 2 additions & 7 deletions hv/src/arm64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
11 changes: 6 additions & 5 deletions hv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,18 @@ 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;
}
}

/// Helper macro to call unsafe Hypervisor functions and map returned error codes to [Error] type.
#[macro_export]
macro_rules! call {
($f:expr) => {{
#[allow(clippy::macro_metavars_in_unsafe)]
let code = unsafe { $f };
match code {
0 => Ok(()),
Expand Down Expand Up @@ -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),
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions hv/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "1.53"
channel = "stable"
components = ["rustfmt", "clippy"]
Loading