Skip to content

Commit 1349263

Browse files
committed
Add another static
Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
1 parent 99d2ec2 commit 1349263

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

src/hyperlight_guest_bin/src/guest_function/call.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff 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>()

src/hyperlight_guest_bin/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ pub(crate) static HEAP_ALLOCATOR: ProfiledLockedHeap<32> =
116116
ProfiledLockedHeap(LockedHeap::<32>::empty());
117117

118118
pub 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;
119123
pub(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

0 commit comments

Comments
 (0)