Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 39 additions & 2 deletions src/hyperlight_common/src/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub const PAGE_SIZE: u64 = 1 << 12;
pub const PAGE_SIZE_USIZE: usize = 1 << 12;

/// A memory region in the guest address space
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq, bytemuck::Pod, bytemuck::Zeroable)]
#[repr(C)]
pub struct GuestMemoryRegion {
/// The size of the memory region
Expand Down Expand Up @@ -65,7 +65,7 @@ impl Default for FileMappingInfo {
}
}

#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq, bytemuck::Pod, bytemuck::Zeroable)]
#[repr(C)]
pub struct HyperlightPEB {
pub input_stack: GuestMemoryRegion,
Expand All @@ -80,3 +80,40 @@ pub struct HyperlightPEB {
#[cfg(feature = "nanvix-unstable")]
pub file_mappings: GuestMemoryRegion,
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn peb_round_trip() {
let peb = HyperlightPEB {
input_stack: GuestMemoryRegion {
size: 0x1111,
ptr: 0x2222,
},
output_stack: GuestMemoryRegion {
size: 0x3333,
ptr: 0x4444,
},
init_data: GuestMemoryRegion {
size: 0x5555,
ptr: 0x6666,
},
guest_heap: GuestMemoryRegion {
size: 0x7777,
ptr: 0x8888,
},
#[cfg(feature = "nanvix-unstable")]
file_mappings: GuestMemoryRegion {
size: 0x9999,
ptr: 0xaaaa,
},
};
let bytes = bytemuck::bytes_of(&peb);
let peb2 = *bytemuck::from_bytes::<HyperlightPEB>(bytes);
let peb2_bytes = bytemuck::bytes_of(&peb2);
assert_eq!(peb, peb2);
assert_eq!(bytes, peb2_bytes);
}
}
1 change: 1 addition & 0 deletions src/hyperlight_host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ flatbuffers = "25.12.19"
framehop = { version = "0.16.0", optional = true }
fallible-iterator = { version = "0.3.0", optional = true }
blake3 = "1.8.5"
bytemuck = { version = "1.24", features = ["derive"] }
page_size = "0.6.0"
termcolor = "1.2.0"
bitflags = "2.11.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1489,7 +1489,7 @@ mod tests {

let (mut hshm, gshm) = mem_mgr.build().unwrap();

let peb_address = gshm.layout.peb_address;
let peb_address = gshm.layout.peb_address();
let stack_top_gva = hyperlight_common::layout::MAX_GVA as u64
- hyperlight_common::layout::SCRATCH_TOP_EXN_STACK_OFFSET
+ 1;
Expand Down
Loading
Loading