Skip to content

Commit f8a2b80

Browse files
committed
Some printing
Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
1 parent ed7efaa commit f8a2b80

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

src/hyperlight_host/src/sandbox/initialized_multi_use.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,34 @@ impl MultiUseSandbox {
349349
// The restored snapshot is now our most current snapshot
350350
self.snapshot = Some(snapshot.clone());
351351

352+
// DEBUG: Verify snapshot memory was correctly written to shared_mem.
353+
// Compare the first 4KB of the snapshot with what's in shared_mem
354+
// to detect if restore_from_snapshot failed silently.
355+
{
356+
let snap_bytes = snapshot.memory();
357+
let check_len = 4096.min(snap_bytes.len());
358+
let mut host_bytes = vec![0u8; check_len];
359+
if self
360+
.mem_mgr
361+
.shared_mem
362+
.copy_to_slice(&mut host_bytes, 0)
363+
.is_ok()
364+
{
365+
if host_bytes[..check_len] != snap_bytes[..check_len] {
366+
let first_diff = host_bytes
367+
.iter()
368+
.zip(snap_bytes.iter())
369+
.position(|(a, b)| a != b);
370+
println!(
371+
"SNAPSHOT MISMATCH: first diff at byte {}, host={:#x} snap={:#x}",
372+
first_diff.unwrap_or(0),
373+
host_bytes[first_diff.unwrap_or(0)],
374+
snap_bytes[first_diff.unwrap_or(0)],
375+
);
376+
}
377+
}
378+
}
379+
352380
// Clear poison state when successfully restoring from snapshot.
353381
//
354382
// # Safety:
@@ -714,6 +742,27 @@ impl MultiUseSandbox {
714742

715743
self.mem_mgr.write_guest_function_call(buffer)?;
716744

745+
// DEBUG: Check if snapshot memory is still intact before dispatch.
746+
// If this fires, something corrupted host memory between restore and dispatch.
747+
{
748+
let check_len = 4096.min(self.mem_mgr.shared_mem.mem_size());
749+
let mut host_bytes = vec![0u8; check_len];
750+
if self
751+
.mem_mgr
752+
.shared_mem
753+
.copy_to_slice(&mut host_bytes, 0)
754+
.is_ok()
755+
{
756+
// Check if the first page is all zeros (which would indicate corruption)
757+
let all_zero = host_bytes.iter().all(|&b| b == 0);
758+
if all_zero {
759+
println!(
760+
"PRE-DISPATCH: first 4KB of shared_mem is ALL ZEROS — snapshot data lost"
761+
);
762+
}
763+
}
764+
}
765+
717766
let dispatch_res = self.vm.dispatch_call_from_host(
718767
&mut self.mem_mgr,
719768
&self.host_funcs,

0 commit comments

Comments
 (0)