@@ -15,7 +15,6 @@ limitations under the License.
1515*/
1616
1717use std:: cmp:: Ordering ;
18- use std:: sync:: { Arc , Mutex } ;
1918
2019use hyperlight_common:: flatbuffer_wrappers:: function_call:: {
2120 FunctionCall , validate_guest_function_call_buffer,
@@ -34,7 +33,6 @@ use super::ptr::{GuestPtr, RawPtr};
3433use super :: ptr_offset:: Offset ;
3534use super :: shared_mem:: { ExclusiveSharedMemory , GuestSharedMemory , HostSharedMemory , SharedMemory } ;
3635use super :: shared_mem_snapshot:: SharedMemorySnapshot ;
37- use crate :: HyperlightError :: NoMemorySnapshot ;
3836use crate :: sandbox:: SandboxConfiguration ;
3937use crate :: sandbox:: uninitialized:: GuestBlob ;
4038use 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
8378impl < S > SandboxMemoryManager < S >
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 }
0 commit comments