Skip to content

Commit

Permalink
Update zerocopy to latest released version (#4)
Browse files Browse the repository at this point in the history
Signed-off-by: Muminul Islam <[email protected]>
  • Loading branch information
Muminul Islam Russell authored Oct 15, 2023
1 parent b1e8149 commit c1b0201
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 53 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ range_map_vec = "0.1.0"
static_assertions = "1.1"
thiserror = "1.0"
tracing = "0.1"
zerocopy = "0.6"
zerocopy = { version = "0.7.1", features = ["alloc","derive"] }
11 changes: 6 additions & 5 deletions igvm/src/hv_defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use core::fmt::Debug;
use open_enum::open_enum;
use zerocopy::AsBytes;
use zerocopy::FromBytes;
use zerocopy::FromZeroes;

#[open_enum]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
Expand Down Expand Up @@ -178,7 +179,7 @@ impl From<Vtl> for u8 {

/// An aligned u128 value.
#[repr(C, align(16))]
#[derive(Copy, Clone, PartialEq, Eq, AsBytes, FromBytes)]
#[derive(Copy, Clone, PartialEq, Eq, AsBytes, FromBytes, FromZeroes)]
pub struct AlignedU128([u8; 16]);

impl AlignedU128 {
Expand Down Expand Up @@ -235,7 +236,7 @@ impl From<AlignedU128> for u128 {

/// A `HV_REGISTER_VALUE` that represents virtual processor registers.
#[repr(C)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, AsBytes, FromBytes)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, AsBytes, FromBytes, FromZeroes)]
pub struct HvRegisterValue(pub AlignedU128);

impl HvRegisterValue {
Expand Down Expand Up @@ -299,7 +300,7 @@ impl From<u128> for HvRegisterValue {
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, AsBytes, FromBytes)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, AsBytes, FromBytes, FromZeroes)]
pub struct HvX64TableRegister {
pub pad: [u16; 3],
pub limit: u16,
Expand All @@ -319,7 +320,7 @@ impl From<HvRegisterValue> for HvX64TableRegister {
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, AsBytes, FromBytes)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, AsBytes, FromBytes, FromZeroes)]
pub struct HvX64SegmentRegister {
pub base: u64,
pub limit: u32,
Expand Down Expand Up @@ -348,7 +349,7 @@ macro_rules! registers {
$(,)?
}) => {
#[open_enum]
#[derive(AsBytes, FromBytes, Debug, Clone, Copy, PartialEq, Eq)]
#[derive(AsBytes, FromBytes, FromZeroes, Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u32)]
pub enum $name {
$($variant = $value,)*
Expand Down
11 changes: 6 additions & 5 deletions igvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use std::mem::size_of_val;
use thiserror::Error;
use zerocopy::AsBytes;
use zerocopy::FromBytes;
use zerocopy::FromZeroes;

pub mod hv_defs;
pub mod page_table;
Expand Down Expand Up @@ -3671,7 +3672,7 @@ mod tests {
};
let expected_header = IGVM_VHS_PAGE_DATA {
gpa,
..FromBytes::new_zeroed()
..FromZeroes::new_zeroed()
};
test_variable_header(
IgvmRevision::V1,
Expand All @@ -3695,7 +3696,7 @@ mod tests {
let expected_header = IGVM_VHS_PAGE_DATA {
gpa,
file_offset: file_data_offset,
..FromBytes::new_zeroed()
..FromZeroes::new_zeroed()
};
data.resize(PAGE_SIZE_4K as usize, 0);
let expected_file_data = Some(data);
Expand All @@ -3721,7 +3722,7 @@ mod tests {
let expected_header = IGVM_VHS_PAGE_DATA {
gpa,
file_offset: file_data_offset,
..FromBytes::new_zeroed()
..FromZeroes::new_zeroed()
};
let expected_file_data = Some(data);
test_variable_header(
Expand Down Expand Up @@ -3957,7 +3958,7 @@ mod tests {
number_of_bytes,
compatibility_mask,
flags,
..FromBytes::new_zeroed()
..FromZeroes::new_zeroed()
};

let header = IgvmDirectiveHeader::RequiredMemory {
Expand Down Expand Up @@ -3985,7 +3986,7 @@ mod tests {
number_of_bytes,
compatibility_mask,
flags,
..FromBytes::new_zeroed()
..FromZeroes::new_zeroed()
};

let header = IgvmDirectiveHeader::RequiredMemory {
Expand Down
6 changes: 4 additions & 2 deletions igvm/src/page_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::collections::BTreeMap;
use thiserror::Error;
use zerocopy::AsBytes;
use zerocopy::FromBytes;
use zerocopy::FromZeroes;

const X64_CR4_LA57: u64 = 0x0000000000001000; // 5-level paging enabled

Expand All @@ -32,7 +33,7 @@ pub const X64_LARGE_PAGE_SIZE: u64 = 0x200000;
/// Number of bytes in a 1GB page for X64.
pub const X64_1GB_PAGE_SIZE: u64 = 0x40000000;

#[derive(Copy, Clone, PartialEq, Eq, AsBytes, FromBytes)]
#[derive(Copy, Clone, PartialEq, Eq, AsBytes, FromBytes, FromZeroes)]
#[repr(transparent)]
pub struct PageTableEntry {
entry: u64,
Expand Down Expand Up @@ -122,7 +123,7 @@ impl PageTableEntry {
}

#[repr(C)]
#[derive(Debug, Clone, PartialEq, Eq, AsBytes, FromBytes)]
#[derive(Debug, Clone, PartialEq, Eq, AsBytes, FromBytes, FromZeroes)]
pub struct PageTable {
entries: [PageTableEntry; PAGE_TABLE_ENTRY_COUNT],
}
Expand Down Expand Up @@ -556,6 +557,7 @@ mod tests {
use crate::hv_defs::Vtl;
use range_map_vec::RangeMap;
use zerocopy::FromBytes;
use zerocopy::FromZeroes;

#[derive(Debug, Clone)]
struct PteInfo {
Expand Down
13 changes: 7 additions & 6 deletions igvm/src/snp_defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use zerocopy::AsBytes;
use zerocopy::FromBytes;
use zerocopy::FromZeroes;

/// Virtual Event Injection
/// Defined by the following union in C:
Expand All @@ -24,12 +25,12 @@ use zerocopy::FromBytes;
/// } SEV_EVENT_INJECT_INFO, *PSEV_EVENT_INJECT_INFO;
/// ```
#[repr(transparent)]
#[derive(Debug, Clone, Copy, AsBytes, FromBytes, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, AsBytes, FromBytes, FromZeroes, PartialEq, Eq)]
pub struct SevEventInjectInfo(pub u64);

/// A X64 selector register.
#[repr(C)]
#[derive(Debug, Clone, Copy, AsBytes, FromBytes, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, AsBytes, FromBytes, FromZeroes, PartialEq, Eq)]
pub struct SevSelector {
pub selector: u16,
pub attrib: u16,
Expand All @@ -39,7 +40,7 @@ pub struct SevSelector {

/// A X64 XMM register.
#[repr(C)]
#[derive(Debug, Clone, Copy, AsBytes, FromBytes, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, AsBytes, FromBytes, FromZeroes, PartialEq, Eq)]
pub struct SevXmmRegister {
low: u64,
high: u64,
Expand All @@ -66,7 +67,7 @@ pub struct SevXmmRegister {
/// };
///```
#[bitfield_struct::bitfield(u64)]
#[derive(AsBytes, FromBytes, PartialEq, Eq)]
#[derive(AsBytes, FromBytes, FromZeroes, PartialEq, Eq)]
pub struct SevFeatures {
pub snp: bool,
pub vtom: bool,
Expand Down Expand Up @@ -104,12 +105,12 @@ pub struct SevFeatures {
/// };
///```
#[repr(transparent)]
#[derive(Debug, Clone, Copy, AsBytes, FromBytes, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, AsBytes, FromBytes, FromZeroes, PartialEq, Eq)]
pub struct SevVirtualInterruptControl(pub u64);

/// SEV VMSA structure representing CPU state
#[repr(C)]
#[derive(Debug, Clone, Copy, AsBytes, FromBytes, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, AsBytes, FromBytes, FromZeroes, PartialEq, Eq)]
pub struct SevVmsa {
// Selector Info
pub es: SevSelector,
Expand Down
Loading

0 comments on commit c1b0201

Please sign in to comment.