diff --git a/.github/workflows/dep_rust.yml b/.github/workflows/dep_rust.yml index 07c9f3615..fe7d0f203 100644 --- a/.github/workflows/dep_rust.yml +++ b/.github/workflows/dep_rust.yml @@ -138,8 +138,8 @@ jobs: cargo check -p hyperlight-host --features print_debug cargo check -p hyperlight-host --features gdb - # without any driver (shouldn't compile) - just test-compilation-fail ${{ matrix.config }} + # without any features + just test-compilation-no-default-features ${{ matrix.config }} # One of the examples is flaky on Windows GH runners, so this allows us to disable it for now - name: Run Rust examples - windows diff --git a/Justfile b/Justfile index cf32292e5..77158d0c9 100644 --- a/Justfile +++ b/Justfile @@ -84,7 +84,7 @@ test-like-ci config=default-target hypervisor="kvm": cargo check -p hyperlight-host --features gdb @# without any driver (should fail to compile) - just test-compilation-fail {{config}} + just test-compilation-no-default-features {{config}} @# test the crashdump feature just test-rust-crashdump {{config}} @@ -121,10 +121,12 @@ test-seccomp target=default-target features="": cargo test --profile={{ if target == "debug" { "dev" } else { target } }} -p hyperlight-host test_violate_seccomp_filters --lib {{ if features =="" {''} else { "--features " + features } }} -- --ignored cargo test --profile={{ if target == "debug" { "dev" } else { target } }} -p hyperlight-host test_violate_seccomp_filters --no-default-features {{ if features =~"mshv3" {"--features init-paging,mshv3"} else {"--features mshv2,init-paging,kvm" } }} --lib -- --ignored -# runs tests that ensure compilation fails when it should -test-compilation-fail target=default-target: - @# the following should fail on linux because one of kvm, mshv, or mshv3 feature must be specified, which is why the exit code is inverted with an !. - {{ if os() == "linux" { "! cargo check -p hyperlight-host --no-default-features 2> /dev/null"} else { "" } }} +# tests compilation with no default features on different platforms +test-compilation-no-default-features target=default-target: + @# Linux should fail without a hypervisor feature (kvm, mshv, or mshv3) + {{ if os() == "linux" { "! cargo check -p hyperlight-host --no-default-features 2> /dev/null" } else { "" } }} + @# Windows should succeed even without default features + {{ if os() == "windows" { "cargo check -p hyperlight-host --no-default-features" } else { "" } }} # runs tests that exercise gdb debugging test-rust-gdb-debugging target=default-target features="": diff --git a/src/hyperlight_host/src/hypervisor/hyperv_windows.rs b/src/hyperlight_host/src/hypervisor/hyperv_windows.rs index cd0398854..a057c41cc 100644 --- a/src/hyperlight_host/src/hypervisor/hyperv_windows.rs +++ b/src/hyperlight_host/src/hypervisor/hyperv_windows.rs @@ -25,8 +25,11 @@ use tracing::{Span, instrument}; use windows::Win32::System::Hypervisor::{ WHV_MEMORY_ACCESS_TYPE, WHV_PARTITION_HANDLE, WHV_REGISTER_VALUE, WHV_RUN_VP_EXIT_CONTEXT, WHV_RUN_VP_EXIT_REASON, WHV_X64_SEGMENT_REGISTER, WHV_X64_SEGMENT_REGISTER_0, - WHvCancelRunVirtualProcessor, WHvX64RegisterCr0, WHvX64RegisterCr3, WHvX64RegisterCr4, - WHvX64RegisterCs, WHvX64RegisterEfer, + WHvCancelRunVirtualProcessor, WHvX64RegisterCs, +}; +#[cfg(feature = "init-paging")] +use windows::Win32::System::Hypervisor::{ + WHvX64RegisterCr0, WHvX64RegisterCr3, WHvX64RegisterCr4, WHvX64RegisterEfer, }; #[cfg(crashdump)] use {super::crashdump, std::path::Path}; @@ -399,16 +402,22 @@ impl HypervWindowsDriver { ])?; #[cfg(not(feature = "init-paging"))] - proc.set_registers(&[( - WHvX64RegisterCs, - WHV_REGISTER_VALUE { - Segment: WHV_X64_SEGMENT_REGISTER { - Base: 0, - Selector: 0, - ..Default::default() + { + proc.set_registers(&[( + WHvX64RegisterCs, + WHV_REGISTER_VALUE { + Segment: WHV_X64_SEGMENT_REGISTER { + Base: 0, + Selector: 0, + Limit: 0xFFFF, + Anonymous: WHV_X64_SEGMENT_REGISTER_0 { + Attributes: 0b1011 | (1 << 4) | (1 << 7), // Type (11: Execute/Read, accessed) | S (code segment) | P (present) + }, + ..Default::default() + }, }, - }, - )])?; + )])?; + } Ok(()) } diff --git a/src/hyperlight_host/src/sandbox/uninitialized_evolve.rs b/src/hyperlight_host/src/sandbox/uninitialized_evolve.rs index a37f747e2..6e97c4a9a 100644 --- a/src/hyperlight_host/src/sandbox/uninitialized_evolve.rs +++ b/src/hyperlight_host/src/sandbox/uninitialized_evolve.rs @@ -33,7 +33,7 @@ use crate::mem::mgr::SandboxMemoryManager; use crate::mem::ptr::{GuestPtr, RawPtr}; use crate::mem::ptr_offset::Offset; use crate::mem::shared_mem::GuestSharedMemory; -#[cfg(feature = "init-paging")] +#[cfg(any(feature = "init-paging", target_os = "windows"))] use crate::mem::shared_mem::SharedMemory; #[cfg(gdb)] use crate::sandbox::config::DebugInfo;