@@ -317,40 +317,6 @@ impl Debug for SandboxMemoryLayout {
317317}
318318
319319impl SandboxMemoryLayout {
320- /// Whether `other` has the same layout configuration as `self`,
321- /// i.e. the fields that come from the guest binary and the
322- /// `SandboxConfiguration`. `snapshot_size` and `pt_size` are
323- /// excluded because they are outputs of building a snapshot blob
324- /// (the compacted data size and the size of the rebuilt
325- /// page-table tail), not configuration inputs, so they differ
326- /// between the sandbox's live layout and any snapshot taken
327- /// from it.
328- ///
329- /// TODO: separate/remove snapshot_size and pt_size from this struct.
330- pub ( crate ) fn is_compatible_with ( & self , other : & Self ) -> bool {
331- // Exhaustive destructure so adding a field to
332- // `SandboxMemoryLayout` fails to compile here, forcing the
333- // author to decide whether it participates in compatibility.
334- let Self {
335- input_data_size,
336- output_data_size,
337- heap_size,
338- code_size,
339- init_data_size,
340- init_data_permissions,
341- scratch_size,
342- snapshot_size : _,
343- pt_size : _,
344- } = self ;
345- * input_data_size == other. input_data_size
346- && * output_data_size == other. output_data_size
347- && * heap_size == other. heap_size
348- && * code_size == other. code_size
349- && * init_data_size == other. init_data_size
350- && * init_data_permissions == other. init_data_permissions
351- && * scratch_size == other. scratch_size
352- }
353-
354320 /// The maximum amount of memory a single sandbox will be allowed.
355321 ///
356322 /// Both the scratch region and the snapshot region are bounded by
@@ -788,58 +754,6 @@ mod tests {
788754 assert ! ( matches!( layout. unwrap_err( ) , MemoryRequestTooBig ( ..) ) ) ;
789755 }
790756
791- #[ test]
792- fn is_compatible_with_identical_layouts ( ) {
793- let cfg = SandboxConfiguration :: default ( ) ;
794- let a = SandboxMemoryLayout :: new ( cfg, 4096 , 0 , None ) . unwrap ( ) ;
795- let b = SandboxMemoryLayout :: new ( cfg, 4096 , 0 , None ) . unwrap ( ) ;
796- assert ! ( a. is_compatible_with( & b) ) ;
797- assert ! ( b. is_compatible_with( & a) ) ;
798- }
799-
800- #[ test]
801- fn is_compatible_with_ignores_snapshot_size_and_pt_size ( ) {
802- // `snapshot_size` and `pt_size` are outputs of building a
803- // snapshot blob, not configuration inputs, so flipping
804- // them must not break compatibility.
805- let cfg = SandboxConfiguration :: default ( ) ;
806- let a = SandboxMemoryLayout :: new ( cfg, 4096 , 0 , None ) . unwrap ( ) ;
807- let mut b = a;
808- b. snapshot_size = a. snapshot_size + PAGE_SIZE_USIZE ;
809- b. set_pt_size ( PAGE_SIZE_USIZE ) . unwrap ( ) ;
810- assert ! ( a. is_compatible_with( & b) ) ;
811- assert ! ( b. is_compatible_with( & a) ) ;
812- }
813-
814- #[ test]
815- fn is_compatible_with_rejects_each_configured_field ( ) {
816- let cfg = SandboxConfiguration :: default ( ) ;
817- let base = SandboxMemoryLayout :: new ( cfg, 4096 , 0 , None ) . unwrap ( ) ;
818-
819- // Each mutation must independently break compatibility.
820- let mutators: & [ fn ( & mut SandboxMemoryLayout ) ] = & [
821- |l| l. input_data_size += PAGE_SIZE_USIZE ,
822- |l| l. output_data_size += PAGE_SIZE_USIZE ,
823- |l| l. heap_size += PAGE_SIZE_USIZE ,
824- |l| l. code_size += PAGE_SIZE_USIZE ,
825- |l| l. init_data_size += PAGE_SIZE_USIZE ,
826- |l| l. scratch_size += PAGE_SIZE_USIZE ,
827- |l| {
828- l. init_data_permissions = Some ( MemoryRegionFlags :: READ ) ;
829- } ,
830- ] ;
831- for mutate in mutators {
832- let mut other = base;
833- mutate ( & mut other) ;
834- assert ! (
835- !base. is_compatible_with( & other) ,
836- "mutation should have broken compatibility: {:?} vs {:?}" ,
837- base,
838- other,
839- ) ;
840- }
841- }
842-
843757 /// Pinned region offsets. These methods place every region that a
844758 /// restored snapshot is interpreted against, so a change shifts
845759 /// where the loader reads captured bytes and breaks existing
0 commit comments