Skip to content

Commit 84fa337

Browse files
committed
remove automatic snapshot stack
Signed-off-by: Jorge Prendes <[email protected]>
1 parent 33c7c3c commit 84fa337

File tree

3 files changed

+8
-48
lines changed

3 files changed

+8
-48
lines changed

src/hyperlight_host/src/mem/mgr.rs

Lines changed: 0 additions & 35 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};
@@ -73,9 +71,6 @@ pub(crate) struct SandboxMemoryManager<S> {
7371
pub(crate) load_addr: RawPtr,
7472
/// Offset for the execution entrypoint from `load_addr`
7573
pub(crate) entrypoint_offset: Offset,
76-
/// A vector of memory snapshots that can be used to save and restore the state of the memory
77-
/// This is used by the Rust Sandbox implementation (rather than the mem_snapshot field above which only exists to support current C API)
78-
snapshots: Arc<Mutex<Vec<SharedMemorySnapshot>>>,
7974
}
8075

8176
impl<S> SandboxMemoryManager<S>
@@ -95,7 +90,6 @@ where
9590
shared_mem,
9691
load_addr,
9792
entrypoint_offset,
98-
snapshots: Arc::new(Mutex::new(Vec::new())),
9993
}
10094
}
10195

@@ -277,33 +271,6 @@ where
277271
snapshot.restore_from_snapshot(&mut self.shared_mem)
278272
}
279273

280-
/// this function will create a memory snapshot and push it onto the stack of snapshots
281-
/// It should be used when you want to save the state of the memory, for example, when evolving a sandbox to a new state
282-
pub(crate) fn push_state(&mut self) -> Result<()> {
283-
let snapshot = self.snapshot()?;
284-
self.snapshots
285-
.try_lock()
286-
.map_err(|e| new_error!("Error locking at {}:{}: {}", file!(), line!(), e))?
287-
.push(snapshot);
288-
Ok(())
289-
}
290-
291-
/// this function restores a memory snapshot from the last snapshot in the list but does not pop the snapshot
292-
/// off the stack
293-
/// It should be used when you want to restore the state of the memory to a previous state but still want to
294-
/// retain that state, for example after calling a function in the guest
295-
pub(crate) fn restore_state_from_last_snapshot(&mut self) -> Result<()> {
296-
let snapshots: std::sync::MutexGuard<'_, Vec<SharedMemorySnapshot>> = self
297-
.snapshots
298-
.try_lock()
299-
.map_err(|e| new_error!("Error locking at {}:{}: {}", file!(), line!(), e))?;
300-
let last = snapshots.last();
301-
let Some(snapshot) = last else {
302-
log_then_return!(NoMemorySnapshot);
303-
};
304-
snapshot.restore_from_snapshot(&mut self.shared_mem)
305-
}
306-
307274
/// Sets `addr` to the correct offset in the memory referenced by
308275
/// `shared_mem` to indicate the address of the outb pointer and context
309276
/// for calling outb function
@@ -428,14 +395,12 @@ impl SandboxMemoryManager<ExclusiveSharedMemory> {
428395
layout: self.layout,
429396
load_addr: self.load_addr.clone(),
430397
entrypoint_offset: self.entrypoint_offset,
431-
snapshots: Arc::new(Mutex::new(Vec::new())),
432398
},
433399
SandboxMemoryManager {
434400
shared_mem: gshm,
435401
layout: self.layout,
436402
load_addr: self.load_addr.clone(),
437403
entrypoint_offset: self.entrypoint_offset,
438-
snapshots: Arc::new(Mutex::new(Vec::new())),
439404
},
440405
)
441406
}

src/hyperlight_host/src/sandbox/initialized_multi_use.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,7 @@ impl MultiUseSandbox {
114114
Output::TYPE,
115115
args.into_value(),
116116
);
117-
let ret = Output::from_value(ret?);
118-
self.mem_mgr.unwrap_mgr_mut().push_state().unwrap();
119-
ret
117+
Output::from_value(ret?)
120118
})
121119
}
122120

@@ -130,13 +128,11 @@ impl MultiUseSandbox {
130128
args: Vec<ParameterValue>,
131129
) -> Result<ReturnValue> {
132130
maybe_time_and_emit_guest_call(func_name, || {
133-
let ret = self.call_guest_function_by_name_no_reset(func_name, ret_type, args);
134-
self.mem_mgr.unwrap_mgr_mut().push_state()?;
135-
ret
131+
self.call_guest_function_by_name_no_reset(func_name, ret_type, args)
136132
})
137133
}
138134

139-
pub(crate) fn call_guest_function_by_name_no_reset(
135+
fn call_guest_function_by_name_no_reset(
140136
&mut self,
141137
function_name: &str,
142138
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)