Skip to content

Fix Windows build with --no-default-features #712

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

Open
wants to merge 2 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
4 changes: 2 additions & 2 deletions .github/workflows/dep_rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also be checking that compilation with a hypervisor driver but without init-paging succeeds on Linux?

{{ 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="":
Expand Down
31 changes: 20 additions & 11 deletions src/hyperlight_host/src/hypervisor/hyperv_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -399,16 +402,22 @@ impl HypervWindowsDriver {
])?;

#[cfg(not(feature = "init-paging"))]
proc.set_registers(&[(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this change need to be mirrored on the Linux hypervisor drivers?

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(())
}
Expand Down
2 changes: 1 addition & 1 deletion src/hyperlight_host/src/sandbox/uninitialized_evolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading