Skip to content

Commit a5a7651

Browse files
committed
Add hv_10_15 feature level
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
1 parent 00b9be0 commit a5a7651

4 files changed

Lines changed: 44 additions & 2 deletions

File tree

hv/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@ readme = "../README.md"
1010

1111
[dependencies]
1212
hv-sys = { path = "../hv-sys", version = "0.1.0" }
13+
14+
[features]
15+
hv_10_15 = []
16+
default = ["hv_10_15"]

hv/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ pub fn capability(cap: Capability) -> Result<u64, Error> {
6767
}
6868

6969
/// Creates an additional guest address space for the current task.
70+
#[cfg(feature = "hv_10_15")]
7071
pub fn vm_space_create() -> Result<Space, Error> {
7172
let mut space: Space = 0;
7273
call!(sys::hv_vm_space_create(&mut space))?;
@@ -77,6 +78,7 @@ pub fn vm_space_create() -> Result<Space, Error> {
7778
///
7879
/// # Arguments
7980
/// * `asid` - Address space ID
81+
#[cfg(feature = "hv_10_15")]
8082
pub fn vm_space_destroy(asid: Space) -> Result<(), Error> {
8183
call!(sys::hv_vm_space_destroy(asid))
8284
}
@@ -130,6 +132,7 @@ pub fn vm_protect(gpa: GPAddr, size: u64, flags: Memory) -> Result<(), Error> {
130132
/// * `gpa` - Page aligned address in the guest physical address space.
131133
/// * `size` - Size in bytes of the region to be mapped.
132134
/// * `flags` - READ, WRITE and EXECUTE permissions of the region.
135+
#[cfg(feature = "hv_10_15")]
133136
pub fn vm_map_space(
134137
asid: Space,
135138
uva: UVAddr,
@@ -152,6 +155,7 @@ pub fn vm_map_space(
152155
/// * `asid` - Address space ID.
153156
/// * `gpa` - Page aligned address in the guest physical address space.
154157
/// * `size` - Size in bytes of the region to be unmapped.
158+
#[cfg(feature = "hv_10_15")]
155159
pub fn vm_unmap_space(asid: Space, gpa: GPAddr, size: u64) -> Result<(), Error> {
156160
call!(sys::hv_vm_unmap_space(asid, gpa, size))
157161
}
@@ -163,6 +167,7 @@ pub fn vm_unmap_space(asid: Space, gpa: GPAddr, size: u64) -> Result<(), Error>
163167
/// * `gpa` - Page aligned address in the guest physical address space.
164168
/// * `size` - Size in bytes of the region to be modified.
165169
/// * `flags` - New READ, WRITE and EXECUTE permissions of the region.
170+
#[cfg(feature = "hv_10_15")]
166171
pub fn vm_protect_space(asid: Space, gpa: GPAddr, size: u64, flags: Memory) -> Result<(), Error> {
167172
call!(sys::hv_vm_protect_space(
168173
asid,

hv/src/vcpu.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use std::ffi::c_void;
22
use std::mem;
33

4-
use crate::{call, sys, Error};
5-
use crate::{vmx, x86};
4+
use crate::{call, sys, vmx, x86, Error, Space};
65

76
/// Represents a single virtual CPU.
87
///
@@ -18,6 +17,12 @@ impl Vcpu {
1817
Ok(Vcpu(handle))
1918
}
2019

20+
/// Associates the vCPU instance with an allocated address space.
21+
#[cfg(feature = "hv_10_15")]
22+
pub fn set_space(&self, asid: Space) -> Result<(), Error> {
23+
call!(sys::hv_vcpu_set_space(self.0, asid))
24+
}
25+
2126
/// Forces flushing of cached vCPU state.
2227
pub fn flush(&self) -> Result<(), Error> {
2328
call!(sys::hv_vcpu_flush(self.0))
@@ -34,6 +39,7 @@ impl Vcpu {
3439
}
3540

3641
/// Executes a vCPU until the given deadline.
42+
#[cfg(feature = "hv_10_15")]
3743
pub fn run_until(&self, deadline: u64) -> Result<(), Error> {
3844
call!(sys::hv_vcpu_run_until(self.0, deadline))
3945
}
@@ -130,14 +136,26 @@ impl vmx::VcpuExt for Vcpu {
130136
}
131137

132138
/// Returns the current value of a shadow VMCS field of a vCPU.
139+
#[cfg(feature = "hv_10_15")]
133140
fn read_shadow_vmcs(&self, field: u32) -> Result<u64, Error> {
134141
let mut out = 0_u64;
135142
call!(sys::hv_vmx_vcpu_read_shadow_vmcs(self.0, field, &mut out))?;
136143
Ok(out)
137144
}
138145

139146
/// Set the value of a shadow VMCS field of a vCPU.
147+
#[cfg(feature = "hv_10_15")]
140148
fn write_shadow_vmcs(&self, field: u32, value: u64) -> Result<(), Error> {
141149
call!(sys::hv_vmx_vcpu_write_shadow_vmcs(self.0, field, value))
142150
}
151+
152+
/// Set the access permissions of a shadow VMCS field of a vCPU.
153+
#[cfg(feature = "hv_10_15")]
154+
fn set_shadow_access(&self, field: u32, flags: crate::vmx::ShadowFlags) -> Result<(), Error> {
155+
call!(sys::hv_vmx_vcpu_set_shadow_access(
156+
self.0,
157+
field,
158+
flags as sys::hv_shadow_flags_t
159+
))
160+
}
143161
}

hv/src/vmx.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ pub fn read_capability(field: Capacility) -> Result<u64, Error> {
3030
Ok(out)
3131
}
3232

33+
#[cfg(feature = "hv_10_15")]
34+
#[repr(u32)]
35+
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
36+
pub enum ShadowFlags {
37+
None = sys::HV_SHADOW_VMCS_NONE,
38+
Read = sys::HV_SHADOW_VMCS_READ,
39+
Write = sys::HV_SHADOW_VMCS_WRITE,
40+
}
41+
3342
pub trait VcpuExt {
3443
/// Returns the current value of a VMCS field of a vCPU.
3544
fn read_vmcs(&self, field: u32) -> Result<u64, Error>;
@@ -38,10 +47,16 @@ pub trait VcpuExt {
3847
fn write_vmcs(&self, field: u32, value: u64) -> Result<(), Error>;
3948

4049
/// Returns the current value of a shadow VMCS field of a vCPU.
50+
#[cfg(feature = "hv_10_15")]
4151
fn read_shadow_vmcs(&self, field: u32) -> Result<u64, Error>;
4252

4353
/// Set the value of a shadow VMCS field of a vCPU.
54+
#[cfg(feature = "hv_10_15")]
4455
fn write_shadow_vmcs(&self, field: u32, value: u64) -> Result<(), Error>;
56+
57+
/// Set the access permissions of a shadow VMCS field of a vCPU.
58+
#[cfg(feature = "hv_10_15")]
59+
fn set_shadow_access(&self, field: u32, flags: ShadowFlags) -> Result<(), Error>;
4560
}
4661

4762
/// Virtual Machine Control Structure (VMCS) Field IDs.

0 commit comments

Comments
 (0)