Skip to content

Commit c5f8f5c

Browse files
committed
fix: add MappedFile region type, downgrade MemoryRegionType to pub(crate), fix clippy
- Add MemoryRegionType::MappedFile variant for map_file_cow regions - Downgrade MemoryRegionType from pub to pub(crate) (not part of public API) - Use MappedFile consistently on both Windows and Linux in map_file_cow - Replace disallowed debug_assert_eq! with tracing::warn! in surrogate_process - Fix Justfile merge conflict Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
1 parent dc6a698 commit c5f8f5c

3 files changed

Lines changed: 20 additions & 12 deletions

File tree

src/hyperlight_host/src/hypervisor/surrogate_process.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@ impl SurrogateProcess {
8282
) -> Result<*mut c_void> {
8383
match self.mappings.entry(host_base) {
8484
Entry::Occupied(mut oe) => {
85-
debug_assert_eq!(
86-
oe.get().mapping_type,
87-
*mapping,
88-
"Conflicting SurrogateMapping for host_base {host_base:#x}: \
89-
existing={:?}, requested={:?}",
90-
oe.get().mapping_type,
91-
mapping
92-
);
85+
if oe.get().mapping_type != *mapping {
86+
tracing::warn!(
87+
"Conflicting SurrogateMapping for host_base {host_base:#x}: \
88+
existing={:?}, requested={:?}",
89+
oe.get().mapping_type,
90+
mapping
91+
);
92+
}
9393
oe.get_mut().use_count += 1;
9494
Ok(oe.get().surrogate_base)
9595
}

src/hyperlight_host/src/mem/memory_region.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,13 @@ impl TryFrom<hv_x64_memory_intercept_message> for MemoryRegionFlags {
112112
}
113113
}
114114

115-
// only used for debugging
115+
// NOTE: In the future, all host-side knowledge about memory region types
116+
// should collapse down to Snapshot vs Scratch (see shared_mem.rs).
117+
// Until then, these variants help distinguish regions for diagnostics
118+
// and crash dumps. Not part of the public API.
116119
#[derive(Debug, PartialEq, Eq, Copy, Clone, Hash)]
117120
/// The type of memory region
118-
pub enum MemoryRegionType {
121+
pub(crate) enum MemoryRegionType {
119122
/// The region contains the guest's code
120123
Code,
121124
/// The region contains the guest's init data
@@ -128,6 +131,11 @@ pub enum MemoryRegionType {
128131
Scratch,
129132
/// The snapshot region
130133
Snapshot,
134+
/// An externally-mapped file (via [`MultiUseSandbox::map_file_cow`]).
135+
/// These regions are backed by file handles (Windows) or mmap
136+
/// (Linux) and are read-only + executable. They are cleaned up
137+
/// during restore/drop — not part of the guest's own allocator.
138+
MappedFile,
131139
}
132140

133141
/// A trait that distinguishes between different kinds of memory region representations.

src/hyperlight_host/src/sandbox/initialized_multi_use.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ impl MultiUseSandbox {
691691
host_region: host_base..host_end,
692692
guest_region: guest_base as usize..guest_base as usize + size,
693693
flags: MemoryRegionFlags::READ | MemoryRegionFlags::EXECUTE,
694-
region_type: MemoryRegionType::Code,
694+
region_type: MemoryRegionType::MappedFile,
695695
};
696696

697697
// Reset snapshot since we are mutating the sandbox state
@@ -746,7 +746,7 @@ impl MultiUseSandbox {
746746
host_region: base as usize..base.wrapping_add(size) as usize,
747747
guest_region: guest_base as usize..guest_base as usize + size,
748748
flags: MemoryRegionFlags::READ | MemoryRegionFlags::EXECUTE,
749-
region_type: MemoryRegionType::Code,
749+
region_type: MemoryRegionType::MappedFile,
750750
}) {
751751
libc::munmap(base, size);
752752
return Err(err);

0 commit comments

Comments
 (0)