Skip to content

Commit 2a21246

Browse files
committed
Update MultiUseSandbox to use dirty page tracking in restore and devolve methods
Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
1 parent 42d9774 commit 2a21246

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/hyperlight_host/src/sandbox/initialized_multi_use.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ impl MultiUseSandbox {
193193
#[instrument(err(Debug), skip_all, parent = Span::current(), level = "Trace")]
194194
pub(crate) fn restore_state(&mut self) -> Result<()> {
195195
let mem_mgr = self.mem_mgr.unwrap_mgr_mut();
196-
mem_mgr.restore_state_from_last_snapshot()
196+
let dirty_pages = self.vm.get_and_clear_dirty_pages()?;
197+
mem_mgr.restore_state_from_last_snapshot(&dirty_pages)
197198
}
198199

199200
pub(crate) fn call_guest_function_by_name_no_reset(
@@ -275,9 +276,10 @@ impl DevolvableSandbox<MultiUseSandbox, MultiUseSandbox, Noop<MultiUseSandbox, M
275276
/// The devolve can be used to return the MultiUseSandbox to the state before the code was loaded. Thus avoiding initialisation overhead
276277
#[instrument(err(Debug), skip_all, parent = Span::current(), level = "Trace")]
277278
fn devolve(mut self, _tsn: Noop<MultiUseSandbox, MultiUseSandbox>) -> Result<MultiUseSandbox> {
279+
let dirty_pages = self.vm.get_and_clear_dirty_pages()?;
278280
self.mem_mgr
279281
.unwrap_mgr_mut()
280-
.pop_and_restore_state_from_snapshot()?;
282+
.pop_and_restore_state_from_snapshot(&dirty_pages)?;
281283
Ok(self)
282284
}
283285
}
@@ -308,7 +310,10 @@ where
308310
let mut ctx = self.new_call_context();
309311
transition_func.call(&mut ctx)?;
310312
let mut sbox = ctx.finish_no_reset();
311-
sbox.mem_mgr.unwrap_mgr_mut().push_state()?;
313+
let vm_dirty_pages = sbox.vm.get_and_clear_dirty_pages()?;
314+
sbox.mem_mgr
315+
.unwrap_mgr_mut()
316+
.push_state(Some(&vm_dirty_pages))?;
312317
Ok(sbox)
313318
}
314319
}

0 commit comments

Comments
 (0)