File tree Expand file tree Collapse file tree
src/hyperlight_guest_bin/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -86,6 +86,16 @@ pub(crate) fn internal_dispatch_function() {
8686 } ;
8787
8888 let handle = unsafe { GUEST_HANDLE } ;
89+ let canary = unsafe { crate :: GUEST_HANDLE_CANARY } ;
90+
91+ if handle. peb ( ) . is_none ( ) || canary != 0xDEAD_BEEF {
92+ panic ! (
93+ "GUEST_HANDLE is None! canary={:#x} (expected 0xDEADBEEF), peb={:#x}. \
94+ If canary is also 0, snapshot memory was not restored for this page.",
95+ canary,
96+ handle. peb( ) . map_or( 0 , |p| p as u64 ) ,
97+ ) ;
98+ }
8999
90100 let function_call = handle
91101 . try_pop_shared_input_data_into :: < FunctionCall > ( )
Original file line number Diff line number Diff line change @@ -116,6 +116,10 @@ pub(crate) static HEAP_ALLOCATOR: ProfiledLockedHeap<32> =
116116 ProfiledLockedHeap ( LockedHeap :: < 32 > :: empty ( ) ) ;
117117
118118pub static mut GUEST_HANDLE : GuestHandle = GuestHandle :: new ( ) ;
119+ /// Canary value set to 0xDEAD_BEEF during init. If this reads as 0
120+ /// after snapshot restore while GUEST_HANDLE is None, the snapshot
121+ /// memory for this region was not properly restored.
122+ pub static mut GUEST_HANDLE_CANARY : u64 = 0 ;
119123pub ( crate ) static mut REGISTERED_GUEST_FUNCTIONS : GuestFunctionRegister < GuestFunc > =
120124 GuestFunctionRegister :: new ( ) ;
121125
@@ -205,6 +209,7 @@ pub(crate) extern "C" fn generic_init(
205209) -> u64 {
206210 unsafe {
207211 GUEST_HANDLE = GuestHandle :: init ( peb_address as * mut HyperlightPEB ) ;
212+ GUEST_HANDLE_CANARY = 0xDEAD_BEEF ;
208213 #[ allow( static_mut_refs) ]
209214 let peb_ptr = GUEST_HANDLE . peb ( ) . unwrap ( ) ;
210215
You can’t perform that action at this time.
0 commit comments