@@ -95,6 +95,15 @@ pub struct Snapshot {
9595 /// The next action that should be performed on this snapshot
9696 next_action : NextAction ,
9797
98+ /// Guest virtual address of the guest binary's ELF entry point
99+ /// (`load_addr + e_entry - base_va`). Unlike `next_action`, which
100+ /// transitions to `Call(dispatch_addr)` once the guest has run,
101+ /// this preserves the original entry across that transition. Used
102+ /// to fill `AT_ENTRY` in guest core dumps so a debugger can
103+ /// compute the PIE load bias. 0 if unknown (e.g. an older
104+ /// on-disk snapshot that predates this field).
105+ original_entrypoint : u64 ,
106+
98107 /// The generation number assigned to this snapshot when it was
99108 /// taken — i.e. "this is the Nth snapshot taken from the sandbox's
100109 /// execution path from init to here". Propagated into the
@@ -375,13 +384,16 @@ impl Snapshot {
375384 - hyperlight_common:: layout:: SCRATCH_TOP_EXN_STACK_OFFSET
376385 + 1 ;
377386
387+ let entrypoint_gva = load_addr + entrypoint_va - base_va;
388+
378389 Ok ( Self {
379390 memory : ReadonlySharedMemory :: from_bytes ( & memory, layout. snapshot_size ( ) ) ?,
380391 layout,
381392 load_info,
382393 stack_top_gva : exn_stack_top_gva,
383394 sregs : None ,
384- next_action : NextAction :: Initialise ( load_addr + entrypoint_va - base_va) ,
395+ next_action : NextAction :: Initialise ( entrypoint_gva) ,
396+ original_entrypoint : entrypoint_gva,
385397 snapshot_generation : 0 ,
386398 host_functions : HostFunctionDetails {
387399 host_functions : None ,
@@ -408,6 +420,7 @@ impl Snapshot {
408420 stack_top_gva : u64 ,
409421 sregs : CommonSpecialRegisters ,
410422 next_action : NextAction ,
423+ original_entrypoint : u64 ,
411424 snapshot_generation : u64 ,
412425 host_functions : HostFunctionDetails ,
413426 ) -> Result < Self > {
@@ -561,6 +574,7 @@ impl Snapshot {
561574 stack_top_gva,
562575 sregs : Some ( sregs) ,
563576 next_action,
577+ original_entrypoint,
564578 snapshot_generation,
565579 host_functions,
566580 } )
@@ -607,6 +621,13 @@ impl Snapshot {
607621 self . next_action
608622 }
609623
624+ /// Guest virtual address of the guest binary's ELF entry point,
625+ /// preserved across the `Initialise` -> `Call` transition. Used
626+ /// to fill `AT_ENTRY` in guest core dumps. 0 if unknown.
627+ pub ( crate ) fn original_entrypoint ( & self ) -> u64 {
628+ self . original_entrypoint
629+ }
630+
610631 /// Validate that `provided` is a superset of the host functions
611632 /// recorded in this snapshot: every function that was registered
612633 /// at snapshot time must also be present in `provided` with a
@@ -762,6 +783,7 @@ mod tests {
762783 0 ,
763784 default_sregs ( ) ,
764785 super :: NextAction :: None ,
786+ 0 ,
765787 1 ,
766788 HostFunctionDetails :: default ( ) ,
767789 )
@@ -779,6 +801,7 @@ mod tests {
779801 0 ,
780802 default_sregs ( ) ,
781803 super :: NextAction :: None ,
804+ 0 ,
782805 2 ,
783806 HostFunctionDetails :: default ( ) ,
784807 )
0 commit comments