Skip to main content

RepInput

Struct RepInput 

Source
pub struct RepInput<T> { /* private fields */ }
Expand description

This file contains helper functions for the MSHV_ROOT_HVCALL ioctl. MSHV_ROOT_HVCALL is basically a ‘passthrough’ hypercall. The kernel makes a hypercall on behalf of the VMM without interpreting the arguments or result or changing any state in the kernel.

RepInput wraps a buffer containing the input for a “rep”[1] hypercall. Rep hypercalls have rep-eated data, i.e. a variable length array as part of the input structure e.g.:

use mshv_bindings::bindings::*;
#[repr(C, packed)]
struct hv_input_foo {
   some_field: __u64,
   variable_array_field: __IncompleteArrayField<__u64>,
}

The struct cannot be used as-is because it can’t store anything in the __IncompleteArrayField field.

RepInput abstracts a rep hypercall input by wrapping a Vec, where T is the hv_input_* struct type. The buffer backing the Vec has enough space to store both the hv_input_* struct (at index 0), and the rep data immediately following it.

Note also that the length of the variable length array field is not stored in this struct. Rather, it is passed to the hypercall in the ‘rep count’ field of the hypercall args (mshv_root_hvcall.reps). RepInput stores this count, along with the size of the entire input data.

RepInput is intended to be created with make_rep_input!() and used with make_rep_args!() below.

[1] HyperV TLFS describing the hypercall interface and rep hypercalls: https://learn.microsoft.com/en-us/virtualization/hyper-v-on-windows/tlfs/hypercall-interface

Implementations§

Source§

impl<T: Default> RepInput<T>

Source

pub fn new(vec: Vec<T>, size: usize, rep_count: usize) -> Self

Create a RepInput for a rep hypercall

§Arguments
  • vec - Vec from input_with_arr_field_as_vec(). T is hv_input_* struct
  • size - Size of the hypercall input, including the rep data
  • rep_count - number of reps
Source

pub fn as_mut_struct_ref(&mut self) -> &mut T

Source

pub fn as_struct_ptr(&self) -> *const T

Source

pub fn rep_count(&self) -> usize

Source

pub fn size(&self) -> usize

Source

pub fn input_with_arr_field_as_vec( t: T, entry_size: usize, count: usize, ) -> Vec<T>

Make Vec<T> with at least enough space for count entries of entry_size, plus one additional entry Populate the first element of the Vec with the T. The rest will hold elements of size entry_size (note the Vec cannot be used normally to modify these since size_of::() isn’t necessarily the same as entry_size)

Auto Trait Implementations§

§

impl<T> Freeze for RepInput<T>

§

impl<T> RefUnwindSafe for RepInput<T>
where T: RefUnwindSafe,

§

impl<T> Send for RepInput<T>
where T: Send,

§

impl<T> Sync for RepInput<T>
where T: Sync,

§

impl<T> Unpin for RepInput<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for RepInput<T>

§

impl<T> UnwindSafe for RepInput<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.