Skip to content

Commit 6ceb013

Browse files
committed
[host/driver/whp] fixed WHP support without init-paging feature
Signed-off-by: danbugs <danilochiarlone@gmail.com>
1 parent 8c55d6e commit 6ceb013

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

src/hyperlight_host/src/hypervisor/hyperv_windows.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ use tracing::{Span, instrument};
2525
use windows::Win32::System::Hypervisor::{
2626
WHV_MEMORY_ACCESS_TYPE, WHV_PARTITION_HANDLE, WHV_REGISTER_VALUE, WHV_RUN_VP_EXIT_CONTEXT,
2727
WHV_RUN_VP_EXIT_REASON, WHV_X64_SEGMENT_REGISTER, WHV_X64_SEGMENT_REGISTER_0,
28-
WHvCancelRunVirtualProcessor, WHvX64RegisterCr0, WHvX64RegisterCr3, WHvX64RegisterCr4,
29-
WHvX64RegisterCs, WHvX64RegisterEfer,
28+
WHvCancelRunVirtualProcessor, WHvX64RegisterCs,
29+
};
30+
#[cfg(feature = "init-paging")]
31+
use windows::Win32::System::Hypervisor::{
32+
WHvX64RegisterCr0, WHvX64RegisterCr3, WHvX64RegisterCr4, WHvX64RegisterEfer,
3033
};
3134
#[cfg(crashdump)]
3235
use {super::crashdump, std::path::Path};
@@ -399,16 +402,22 @@ impl HypervWindowsDriver {
399402
])?;
400403

401404
#[cfg(not(feature = "init-paging"))]
402-
proc.set_registers(&[(
403-
WHvX64RegisterCs,
404-
WHV_REGISTER_VALUE {
405-
Segment: WHV_X64_SEGMENT_REGISTER {
406-
Base: 0,
407-
Selector: 0,
408-
..Default::default()
405+
{
406+
proc.set_registers(&[(
407+
WHvX64RegisterCs,
408+
WHV_REGISTER_VALUE {
409+
Segment: WHV_X64_SEGMENT_REGISTER {
410+
Base: 0,
411+
Selector: 0,
412+
Limit: 0xFFFF,
413+
Anonymous: WHV_X64_SEGMENT_REGISTER_0 {
414+
Attributes: 0b1011 | (1 << 4) | (1 << 7), // Type (11: Execute/Read, accessed) | S (code segment) | P (present)
415+
},
416+
..Default::default()
417+
},
409418
},
410-
},
411-
)])?;
419+
)])?;
420+
}
412421

413422
Ok(())
414423
}

src/hyperlight_host/src/sandbox/uninitialized_evolve.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use crate::mem::mgr::SandboxMemoryManager;
3333
use crate::mem::ptr::{GuestPtr, RawPtr};
3434
use crate::mem::ptr_offset::Offset;
3535
use crate::mem::shared_mem::GuestSharedMemory;
36-
#[cfg(feature = "init-paging")]
36+
#[cfg(any(feature = "init-paging", target_os = "windows"))]
3737
use crate::mem::shared_mem::SharedMemory;
3838
#[cfg(gdb)]
3939
use crate::sandbox::config::DebugInfo;

0 commit comments

Comments
 (0)