Skip to content

Commit 976c7d0

Browse files
committed
remove automatic snapshot stack
Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
1 parent ee62de6 commit 976c7d0

File tree

3 files changed

+8
-54
lines changed

3 files changed

+8
-54
lines changed

src/hyperlight_host/src/mem/mgr.rs

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ limitations under the License.
1515
*/
1616

1717
use std::cmp::Ordering;
18-
use std::sync::{Arc, Mutex};
1918

2019
use hyperlight_common::flatbuffer_wrappers::function_call::{
2120
FunctionCall, validate_guest_function_call_buffer,
@@ -34,7 +33,6 @@ use super::ptr::{GuestPtr, RawPtr};
3433
use super::ptr_offset::Offset;
3534
use super::shared_mem::{ExclusiveSharedMemory, GuestSharedMemory, HostSharedMemory, SharedMemory};
3635
use super::shared_mem_snapshot::SharedMemorySnapshot;
37-
use crate::HyperlightError::NoMemorySnapshot;
3836
use crate::sandbox::SandboxConfiguration;
3937
use crate::sandbox::uninitialized::GuestBlob;
4038
use crate::{Result, log_then_return, new_error};
@@ -75,9 +73,6 @@ pub(crate) struct SandboxMemoryManager<S> {
7573
pub(crate) entrypoint_offset: Offset,
7674
/// How many memory regions were mapped after sandbox creation
7775
pub(crate) mapped_rgns: u64,
78-
/// A vector of memory snapshots that can be used to save and restore the state of the memory
79-
/// This is used by the Rust Sandbox implementation (rather than the mem_snapshot field above which only exists to support current C API)
80-
snapshots: Arc<Mutex<Vec<SharedMemorySnapshot>>>,
8176
}
8277

8378
impl<S> SandboxMemoryManager<S>
@@ -98,7 +93,6 @@ where
9893
load_addr,
9994
entrypoint_offset,
10095
mapped_rgns: 0,
101-
snapshots: Arc::new(Mutex::new(Vec::new())),
10296
}
10397
}
10498

@@ -288,39 +282,6 @@ where
288282
Ok(old_rgns - self.mapped_rgns)
289283
}
290284

291-
/// this function will create a memory snapshot and push it onto the stack of snapshots
292-
/// It should be used when you want to save the state of the memory, for example, when evolving a sandbox to a new state
293-
pub(crate) fn push_state(&mut self) -> Result<()> {
294-
let snapshot = self.snapshot()?;
295-
self.snapshots
296-
.try_lock()
297-
.map_err(|e| new_error!("Error locking at {}:{}: {}", file!(), line!(), e))?
298-
.push(snapshot);
299-
Ok(())
300-
}
301-
302-
/// this function restores a memory snapshot from the last snapshot in the list but does not pop the snapshot
303-
/// off the stack
304-
/// It should be used when you want to restore the state of the memory to a previous state but still want to
305-
/// retain that state, for example after calling a function in the guest
306-
///
307-
/// Returns the number of memory regions mapped into the sandbox
308-
/// that need to be unmapped in order for the restore to be
309-
/// completed.
310-
pub(crate) fn restore_state_from_last_snapshot(&mut self) -> Result<u64> {
311-
let snapshots = self
312-
.snapshots
313-
.try_lock()
314-
.map_err(|e| new_error!("Error locking at {}:{}: {}", file!(), line!(), e))?;
315-
let last = snapshots.last();
316-
let Some(snapshot) = last else {
317-
log_then_return!(NoMemorySnapshot);
318-
};
319-
let old_rgns = self.mapped_rgns;
320-
self.mapped_rgns = snapshot.restore_from_snapshot(&mut self.shared_mem)?;
321-
Ok(old_rgns - self.mapped_rgns)
322-
}
323-
324285
/// Sets `addr` to the correct offset in the memory referenced by
325286
/// `shared_mem` to indicate the address of the outb pointer and context
326287
/// for calling outb function
@@ -446,15 +407,13 @@ impl SandboxMemoryManager<ExclusiveSharedMemory> {
446407
load_addr: self.load_addr.clone(),
447408
entrypoint_offset: self.entrypoint_offset,
448409
mapped_rgns: 0,
449-
snapshots: Arc::new(Mutex::new(Vec::new())),
450410
},
451411
SandboxMemoryManager {
452412
shared_mem: gshm,
453413
layout: self.layout,
454414
load_addr: self.load_addr.clone(),
455415
entrypoint_offset: self.entrypoint_offset,
456416
mapped_rgns: 0,
457-
snapshots: Arc::new(Mutex::new(Vec::new())),
458417
},
459418
)
460419
}

src/hyperlight_host/src/sandbox/initialized_multi_use.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,7 @@ impl MultiUseSandbox {
124124
Output::TYPE,
125125
args.into_value(),
126126
);
127-
let ret = Output::from_value(ret?);
128-
self.mem_mgr.unwrap_mgr_mut().push_state().unwrap();
129-
ret
127+
Output::from_value(ret?)
130128
})
131129
}
132130

@@ -209,13 +207,11 @@ impl MultiUseSandbox {
209207
args: Vec<ParameterValue>,
210208
) -> Result<ReturnValue> {
211209
maybe_time_and_emit_guest_call(func_name, || {
212-
let ret = self.call_guest_function_by_name_no_reset(func_name, ret_type, args);
213-
self.mem_mgr.unwrap_mgr_mut().push_state()?;
214-
ret
210+
self.call_guest_function_by_name_no_reset(func_name, ret_type, args)
215211
})
216212
}
217213

218-
pub(crate) fn call_guest_function_by_name_no_reset(
214+
fn call_guest_function_by_name_no_reset(
219215
&mut self,
220216
function_name: &str,
221217
return_type: ReturnType,

src/hyperlight_host/src/sandbox/uninitialized_evolve.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,19 +129,18 @@ where
129129
pub(super) fn evolve_impl_multi_use(u_sbox: UninitializedSandbox) -> Result<MultiUseSandbox> {
130130
evolve_impl(
131131
u_sbox,
132-
|hf, mut hshm, vm, out_hdl, mem_hdl, dispatch_ptr| {
133-
{
134-
hshm.as_mut().push_state()?;
135-
}
132+
|hf, hshm, vm, out_hdl, mem_hdl, dispatch_ptr| {
133+
#[cfg(gdb)]
134+
let dbg_mem_wrapper = dbg_mem_access_handler_wrapper(hshm.clone());
136135
Ok(MultiUseSandbox::from_uninit(
137136
hf,
138-
hshm.clone(),
137+
hshm,
139138
vm,
140139
out_hdl,
141140
mem_hdl,
142141
dispatch_ptr,
143142
#[cfg(gdb)]
144-
dbg_mem_access_handler_wrapper(hshm),
143+
dbg_mem_wrapper,
145144
))
146145
},
147146
)

0 commit comments

Comments
 (0)