Skip to content

Commit

Permalink
mshv-bindings: Adapt to the latest version of zerocopy
Browse files Browse the repository at this point in the history
Few APIs of zerocopy trait are chagned and we need to adapt accordingly.

Signed-off-by: Jinank Jain <jinankjain@microsoft.com>
  • Loading branch information
jinankjain authored and Jinank Jain committed Oct 8, 2024
1 parent 5c681b7 commit a907e27
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
8 changes: 4 additions & 4 deletions mshv-bindings/src/hvdef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#![allow(dead_code)]
use crate::HV_HYP_PAGE_SIZE;
use num_enum::TryFromPrimitive;
use zerocopy::{AsBytes, FromBytes, FromZeroes};
use zerocopy::{IntoBytes, FromBytes};

pub const HV_PAGE_SIZE: usize = HV_HYP_PAGE_SIZE as usize;

Expand Down Expand Up @@ -177,7 +177,7 @@ pub enum HvError {
}

#[repr(C)]
#[derive(Copy, Clone, AsBytes, Debug, FromBytes, FromZeroes)]
#[derive(Copy, Clone, IntoBytes, Debug, FromBytes)]
pub struct HvMessageHeader {
pub typ: u32,
pub len: u8,
Expand All @@ -189,14 +189,14 @@ pub struct HvMessageHeader {
pub const MESSAGE_TYPE_TIMER_EXPIRED: u32 = 0x80000010;

#[repr(C)]
#[derive(Copy, Clone, AsBytes, Debug, FromBytes, FromZeroes)]
#[derive(Copy, Clone, IntoBytes, Debug, FromBytes)]
pub struct HvMessage {
pub header: HvMessageHeader,
pub payload: [[u8; 24]; 10],
}

#[repr(C)]
#[derive(Copy, Clone, AsBytes, Debug, FromBytes, FromZeroes)]
#[derive(Copy, Clone, IntoBytes, Debug, FromBytes)]
pub struct TimerMessagePayload {
pub timer_index: u32,
pub reserved: u32,
Expand Down
32 changes: 16 additions & 16 deletions mshv-bindings/src/x86_64/regs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ use std::convert::TryFrom;
use std::fmt;
use std::ptr;
use vmm_sys_util::errno;
use zerocopy::{AsBytes, FromBytes, FromZeroes};
use zerocopy::{IntoBytes, FromBytes};

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

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

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

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

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

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

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

#[repr(C)]
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, AsBytes, FromBytes, FromZeroes)]
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, IntoBytes, FromBytes)]
#[cfg_attr(feature = "with-serde", derive(Deserialize, Serialize))]
pub struct VcpuEvents {
pub pending_interruption: u64,
Expand All @@ -390,14 +390,14 @@ pub struct VcpuEvents {
}

#[repr(C)]
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, AsBytes, FromBytes, FromZeroes)]
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, IntoBytes, FromBytes)]
#[cfg_attr(feature = "with-serde", derive(Deserialize, Serialize))]
pub struct Xcrs {
pub xcr0: u64,
}

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

#[repr(C)]
#[derive(Copy, Clone, Debug, AsBytes, FromBytes, FromZeroes)]
#[derive(Copy, Clone, Debug, IntoBytes, FromBytes)]
/// Fixed buffer for lapic state
pub struct LapicState {
pub regs: [::std::os::raw::c_char; 1024usize],
Expand All @@ -505,7 +505,7 @@ impl Default for LapicState {
}

#[repr(C)]
#[derive(Copy, Clone, Debug, AsBytes, FromBytes, FromZeroes)]
#[derive(Copy, Clone, Debug, IntoBytes, FromBytes)]
/// Fixed buffer for xsave state
pub struct XSave {
pub buffer: [u8; 4096usize],
Expand Down Expand Up @@ -670,15 +670,15 @@ impl fmt::Display for XSave {
}

#[repr(C)]
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, AsBytes, FromBytes, FromZeroes)]
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, IntoBytes, 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, AsBytes, FromBytes, FromZeroes)]
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, IntoBytes, FromBytes)]
#[cfg_attr(feature = "with-serde", derive(Deserialize, Serialize))]
pub struct MiscRegs {
pub hypercall: u64,
Expand Down Expand Up @@ -726,7 +726,7 @@ fn get_vp_state_comp_start_offset(index: usize) -> usize {
// Local APIC, Xsave, Synthetic Message Page, Synthetic Event Flags Page
// and Synthetic Timers.
#[repr(C)]
#[derive(Copy, Clone, Debug, AsBytes, FromBytes, FromZeroes)]
#[derive(Copy, Clone, Debug, IntoBytes, FromBytes)]
/// Fixed buffer for VP state components
pub struct AllVpStateComponents {
pub buffer: [u8; VP_STATE_COMPONENTS_BUFFER_SIZE],
Expand Down

0 comments on commit a907e27

Please sign in to comment.