@@ -1387,7 +1387,7 @@ impl Sandbox {
13871387 /// a 2.5 GB snapshot — enough to double the whole `pyhl run` wall
13881388 /// time on simple scripts.
13891389 pub fn from_snapshot_file < P : AsRef < Path > > ( path : P ) -> Result < Self > {
1390- Self :: from_snapshot_file_with ( path, & [ ] )
1390+ Self :: from_snapshot_file_full ( path, & [ ] , None )
13911391 }
13921392
13931393 /// Load a previously-persisted snapshot and register a
@@ -1402,6 +1402,26 @@ impl Sandbox {
14021402 /// fixed at setup time because it lives in the snapshot's memory
14031403 /// image.
14041404 pub fn from_snapshot_file_with < P : AsRef < Path > > ( path : P , preopens : & [ Preopen ] ) -> Result < Self > {
1405+ Self :: from_snapshot_file_full ( path, preopens, None )
1406+ }
1407+
1408+ /// Load a snapshot with an initrd file re-mapped at the standard
1409+ /// guest VA (0xC000_0000). Required when the snapshot was taken
1410+ /// from a cpiovfs-backed guest whose VFS nodes point into the
1411+ /// initrd region.
1412+ pub fn from_snapshot_file_with_initrd < P : AsRef < Path > , I : AsRef < Path > > (
1413+ path : P ,
1414+ preopens : & [ Preopen ] ,
1415+ initrd : I ,
1416+ ) -> Result < Self > {
1417+ Self :: from_snapshot_file_full ( path, preopens, Some ( initrd. as_ref ( ) . to_path_buf ( ) ) )
1418+ }
1419+
1420+ fn from_snapshot_file_full < P : AsRef < Path > > (
1421+ path : P ,
1422+ preopens : & [ Preopen ] ,
1423+ initrd : Option < std:: path:: PathBuf > ,
1424+ ) -> Result < Self > {
14051425 let loaded = Snapshot :: from_file_unchecked ( path. as_ref ( ) ) ?;
14061426 let arc = Arc :: new ( loaded) ;
14071427
@@ -1421,13 +1441,18 @@ impl Sandbox {
14211441 } ) ?;
14221442 }
14231443
1424- let inner = MultiUseSandbox :: from_snapshot ( arc. clone ( ) , host_funcs, None ) ?;
1444+ let mut inner = MultiUseSandbox :: from_snapshot ( arc. clone ( ) , host_funcs, None ) ?;
1445+
1446+ const INITRD_MAP_BASE : u64 = 0xC000_0000 ;
1447+ if let Some ( ref initrd_path) = initrd {
1448+ inner. map_file_cow ( initrd_path, INITRD_MAP_BASE , Some ( "initrd" ) ) ?;
1449+ }
14251450
14261451 Ok ( Self {
14271452 inner,
14281453 snapshot : Some ( arc) ,
1429- file_mapping_path : None ,
1430- file_mapping_base : 0 ,
1454+ file_mapping_path : initrd ,
1455+ file_mapping_base : INITRD_MAP_BASE ,
14311456 } )
14321457 }
14331458}
0 commit comments