Skip to content

Commit 04e136b

Browse files
committed
Review updates
Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
1 parent a1565c2 commit 04e136b

File tree

5 files changed

+24
-18
lines changed

5 files changed

+24
-18
lines changed

src/hyperlight_host/src/mem/layout.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ impl SandboxMemoryLayout {
478478
self.pt_offset
479479
}
480480

481-
/// Get the offset into the snapshot region of the page tables
481+
/// Sets the size of the memory region used for page tables
482482
#[instrument(skip_all, parent = Span::current(), level= "Trace")]
483483
#[cfg(feature = "init-paging")]
484484
pub(crate) fn set_pt_size(&mut self, size: usize) {
@@ -668,8 +668,8 @@ impl SandboxMemoryLayout {
668668
if after_init_offset != expected_pt_offset {
669669
return Err(new_error!(
670670
"Page table offset does not match expected: {}, actual: {}",
671-
expected_init_data_offset,
672-
init_data_offset
671+
expected_pt_offset,
672+
after_init_offset
673673
));
674674
}
675675

src/hyperlight_host/src/mem/mgr.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl GuestPageTableBuffer {
127127
}
128128

129129
pub(crate) fn size(&self) -> usize {
130-
self.buffer.borrow().len() * PAGE_TABLE_SIZE
130+
self.buffer.borrow().len()
131131
}
132132

133133
pub(crate) fn into_bytes(self) -> Box<[u8]> {
@@ -409,8 +409,6 @@ impl SandboxMemoryManager<HostSharedMemory> {
409409
}
410410
}
411411

412-
// ...existing code...
413-
414412
#[cfg(test)]
415413
#[cfg(all(feature = "init-paging", target_arch = "x86_64"))]
416414
mod tests {

src/hyperlight_host/src/sandbox/snapshot.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,19 @@ pub struct Snapshot {
6262
/// require constant-time equality checking
6363
hash: [u8; 32],
6464

65-
/// TODO: this should not necessarily be around in the long term...
65+
/// Preinitialisation entry point for snapshots created directly from a
66+
/// guest binary.
6667
///
67-
/// When creating a snapshot directly from a guest binary, this
68-
/// tracks the address that we need to call into before actually
69-
/// using a sandbox from this snapshot in order to do
70-
/// preinitialisation. Ideally we would either not need to do this
71-
/// at all, or do it as part of the snapshot creation process and
72-
/// never need this.
68+
/// When creating a snapshot directly from a guest binary, this tracks
69+
/// the address that we need to call into before actually using a
70+
/// sandbox from this snapshot in order to perform guest-side
71+
/// preinitialisation.
72+
///
73+
/// Long-term, the intention is to run this preinitialisation eagerly as
74+
/// part of the snapshot creation process so that restored sandboxes can
75+
/// begin executing from their normal entry point without requiring this
76+
/// field. Until that refactoring happens, this remains part of the
77+
/// snapshot format and must be preserved.
7378
preinitialise: Option<u64>,
7479
}
7580

@@ -105,7 +110,8 @@ fn hash(memory: &[u8], regions: &[MemoryRegion]) -> Result<[u8; 32]> {
105110
}
106111

107112
impl Snapshot {
108-
/// Create a new snapshot that runs the guest binary identified by env
113+
/// Create a new snapshot from the guest binary identified by `env`. With the configuration
114+
/// specified in `cfg`.
109115
pub(crate) fn from_env<'a, 'b>(
110116
env: impl Into<GuestEnvironment<'a, 'b>>,
111117
cfg: SandboxConfiguration,

src/hyperlight_host/src/sandbox/uninitialized.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ pub enum GuestBinary<'a> {
8888
impl<'a> GuestBinary<'a> {
8989
/// If the guest binary is identified by a file, canonicalise the path
9090
///
91+
/// For [`GuestBinary::FilePath`], this resolves the path to its canonical
92+
/// form. For [`GuestBinary::Buffer`], this method is a no-op.
9193
/// TODO: Maybe we should make the GuestEnvironment or
9294
/// GuestBinary constructors crate-private and turn this
9395
/// into an invariant on one of those types.
@@ -161,7 +163,7 @@ impl UninitializedSandbox {
161163
// that can be changed (from the original snapshot) is the configuration defines the behaviour of
162164
// `InterruptHandler` on Linux.
163165
//
164-
// This is ok for now as this is not a public
166+
// This is ok for now as this is not a public function
165167
fn from_snapshot(
166168
snapshot: Arc<Snapshot>,
167169
cfg: Option<SandboxConfiguration>,

src/hyperlight_host/src/sandbox/uninitialized_evolve.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,11 @@ pub(crate) fn set_up_hypervisor_partition(
120120
};
121121
let entrypoint_ptr = mgr
122122
.entrypoint_offset
123-
.map(|x| {
123+
.ok_or_else(|| new_error!("Entrypoint offset is None"))
124+
.and_then(|x| {
124125
let entrypoint_total_offset = mgr.load_addr.clone() + x;
125126
GuestPtr::try_from(entrypoint_total_offset)
126-
})
127-
.ok_or(new_error!("Failed to create entrypoint pointer"))??;
127+
})?;
128128

129129
// Create gdb thread if gdb is enabled and the configuration is provided
130130
#[cfg(gdb)]

0 commit comments

Comments
 (0)