Skip to content

Commit 3dc7f69

Browse files
committed
Allow unmapping existing mapped ranges in the guest
Previously, the page table manipulation interfaces exported for the use of guests did not permit unmapping an existing mapped range. This commit improves that situation, by adding an "unmapped" mapping type, which code can use to request that a remap operation make a region not-present. Signed-off-by: Lucy Menon <168595099+syntactically@users.noreply.github.com>
1 parent 0d4f86a commit 3dc7f69

File tree

5 files changed

+6
-1
lines changed

5 files changed

+6
-1
lines changed

src/hyperlight_common/src/arch/amd64/vmem.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ unsafe fn map_page<
456456
0 | // R/W - Cow page is never writable
457457
PAGE_PRESENT // P - this entry is present
458458
}
459+
MappingKind::Unmapped => 0,
459460
};
460461
unsafe {
461462
write_entry_updating(op, r.update_parent, r.entry_ptr, pte);

src/hyperlight_common/src/vmem.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ pub struct CowMapping {
196196

197197
#[derive(Debug, PartialEq, Clone, Copy)]
198198
pub enum MappingKind {
199+
Unmapped,
199200
Basic(BasicMapping),
200201
Cow(CowMapping),
201202
/* TODO: What useful things other than basic mappings actually

src/hyperlight_host/src/mem/layout.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ impl<'a> ResolvedGpa<&'a [u8], &'a [u8]> {
140140
}
141141
}
142142
#[cfg(any(gdb, feature = "mem_profile"))]
143+
#[allow(unused)] // may be unused when nanvix-unstable is also enabled
143144
pub(crate) trait ReadableSharedMemory {
144145
fn copy_to_slice(&self, slice: &mut [u8], offset: usize) -> Result<()>;
145146
}
@@ -177,7 +178,7 @@ impl<T: coherence_hack::SharedMemoryAsRefMarker> ReadableSharedMemory for T {
177178
}
178179
#[cfg(any(gdb, feature = "mem_profile"))]
179180
impl<Sn: ReadableSharedMemory, Sc: ReadableSharedMemory> ResolvedGpa<Sn, Sc> {
180-
#[cfg(feature = "gdb")]
181+
#[allow(unused)] // may be unused when nanvix-unstable is also enabled
181182
pub(crate) fn copy_to_slice(&self, slice: &mut [u8]) -> Result<()> {
182183
match &self.base {
183184
BaseGpaRegion::Snapshot(sn) => sn.copy_to_slice(slice, self.offset),

src/hyperlight_host/src/mem/mgr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ fn mapping_kind_to_flags(kind: &MappingKind) -> (MemoryRegionFlags, MemoryRegion
6868
}
6969
(flags, MemoryRegionType::Scratch)
7070
}
71+
MappingKind::Unmapped => (MemoryRegionFlags::empty(), MemoryRegionType::Snapshot),
7172
}
7273
}
7374

src/hyperlight_host/src/sandbox/snapshot.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ impl Snapshot {
471471
writable: false,
472472
executable: bm.executable,
473473
}),
474+
MappingKind::Unmapped => continue,
474475
};
475476
let new_gpa = phys_seen.entry(mapping.phys_base).or_insert_with(|| {
476477
let new_offset = snapshot_memory.len();

0 commit comments

Comments
 (0)