Skip to content
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

mshv-bindings: derive AsBytes and FromBytes for various structures #66

Merged
merged 1 commit into from
Oct 24, 2022
Merged
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
29 changes: 15 additions & 14 deletions mshv-bindings/src/regs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use std::cmp;
use std::fmt;
use std::ptr;
use vmm_sys_util::errno;
use zerocopy::{AsBytes, FromBytes};

#[repr(C)]
#[derive(Default)]
Expand Down Expand Up @@ -63,7 +64,7 @@ impl<T> ::std::clone::Clone for __IncompleteArrayField<T> {
}

#[repr(C)]
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, AsBytes, FromBytes)]
#[cfg_attr(feature = "with-serde", derive(Deserialize, Serialize))]
pub struct StandardRegisters {
pub rax: u64,
Expand All @@ -87,7 +88,7 @@ pub struct StandardRegisters {
}

#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
#[derive(Debug, Default, Copy, Clone, AsBytes, FromBytes)]
#[cfg_attr(feature = "with-serde", derive(Deserialize, Serialize))]
pub struct SegmentRegister {
/* segment register + descriptor */
Expand Down Expand Up @@ -148,7 +149,7 @@ impl From<SegmentRegister> for hv_x64_segment_register {
}

#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
#[derive(Debug, Default, Copy, Clone, FromBytes)]
#[cfg_attr(feature = "with-serde", derive(Deserialize, Serialize))]
pub struct TableRegister {
pub base: u64,
Expand All @@ -175,7 +176,7 @@ impl From<TableRegister> for hv_x64_table_register {
}

#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
#[derive(Debug, Default, Copy, Clone, FromBytes)]
#[cfg_attr(feature = "with-serde", derive(Deserialize, Serialize))]
pub struct SpecialRegisters {
pub cs: SegmentRegister,
Expand All @@ -199,7 +200,7 @@ pub struct SpecialRegisters {
}

#[repr(C)]
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, AsBytes, FromBytes)]
#[cfg_attr(feature = "with-serde", derive(Deserialize, Serialize))]
pub struct DebugRegisters {
pub dr0: u64,
Expand All @@ -211,7 +212,7 @@ pub struct DebugRegisters {
}

#[repr(C)]
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, AsBytes, FromBytes)]
#[cfg_attr(feature = "with-serde", derive(Deserialize, Serialize))]
pub struct FloatingPointUnit {
pub fpr: [[u8; 16usize]; 8usize],
Expand Down Expand Up @@ -339,7 +340,7 @@ pub fn msr_to_hv_reg_name(msr: u32) -> Result<hv_register_name, &'static str> {
}

#[repr(C)]
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, AsBytes, FromBytes)]
#[cfg_attr(feature = "with-serde", derive(Deserialize, Serialize))]
pub struct msr_entry {
pub index: u32,
Expand All @@ -366,7 +367,7 @@ pub struct msr_list {
}

#[repr(C)]
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, AsBytes, FromBytes)]
#[cfg_attr(feature = "with-serde", derive(Deserialize, Serialize))]
pub struct VcpuEvents {
pub pending_interruption: u64,
Expand All @@ -376,14 +377,14 @@ pub struct VcpuEvents {
pub pending_event1: [u8; 16usize],
}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, AsBytes, FromBytes)]
#[cfg_attr(feature = "with-serde", derive(Deserialize, Serialize))]
pub struct Xcrs {
pub xcr0: u64,
}

#[repr(C)]
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, AsBytes, FromBytes)]
pub struct hv_cpuid_entry {
pub function: __u32,
pub index: __u32,
Expand Down Expand Up @@ -473,7 +474,7 @@ impl Drop for Buffer {
}

#[repr(C)]
#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Debug, AsBytes, FromBytes)]
pub struct LapicState {
pub regs: [::std::os::raw::c_char; 1024usize],
}
Expand All @@ -489,7 +490,7 @@ impl Default for hv_register_value {
}
} */
#[repr(C)]
#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Debug, AsBytes, FromBytes)]
/// This struct normalizes the actual mhsv XSave structure
/// XSave only used in save and restore functionalities, serilization and
/// deserialization are needed. Putting all the fields into a single buffer makes
Expand Down Expand Up @@ -730,14 +731,14 @@ impl XSave {
}

#[repr(C)]
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, AsBytes, FromBytes)]
#[cfg_attr(feature = "with-serde", derive(Deserialize, Serialize))]
pub struct SuspendRegisters {
pub explicit_register: u64,
pub intercept_register: u64,
}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, AsBytes, FromBytes)]
#[cfg_attr(feature = "with-serde", derive(Deserialize, Serialize))]
pub struct MiscRegs {
pub hypercall: u64,
Expand Down