@@ -157,9 +157,9 @@ pub(crate) struct SandboxMemoryManager<S: SharedMemory> {
157157pub ( crate ) struct GuestPageTableBuffer {
158158 buffer : std:: cell:: RefCell < Vec < u8 > > ,
159159 phys_base : usize ,
160- /// Byte offset from phys_base to the active PD root.
161- /// Used on i686 to target different per-process PDs.
162- # [ cfg ( feature = "i686-guest" ) ]
160+ /// Byte offset from phys_base to the active root page table .
161+ /// For multi-root guests, each root's PD starts at a different
162+ /// offset in the buffer.
163163 root_offset : std:: cell:: Cell < usize > ,
164164}
165165
@@ -194,14 +194,7 @@ impl vmem::TableReadOps for GuestPageTableBuffer {
194194 }
195195
196196 fn root_table ( & self ) -> u64 {
197- #[ cfg( feature = "i686-guest" ) ]
198- {
199- ( self . phys_base + self . root_offset . get ( ) ) as u64
200- }
201- #[ cfg( not( feature = "i686-guest" ) ) ]
202- {
203- self . phys_base as u64
204- }
197+ ( self . phys_base + self . root_offset . get ( ) ) as u64
205198 }
206199}
207200
@@ -241,76 +234,16 @@ impl GuestPageTableBuffer {
241234 GuestPageTableBuffer {
242235 buffer : std:: cell:: RefCell :: new ( vec ! [ 0u8 ; PAGE_TABLE_SIZE ] ) ,
243236 phys_base,
244- #[ cfg( feature = "i686-guest" ) ]
245237 root_offset : std:: cell:: Cell :: new ( 0 ) ,
246238 }
247239 }
248240
249- /// Set the root offset to target a specific PD root.
250- /// Root i's PD starts at byte offset `i * PAGE_TABLE_SIZE` in the buffer.
251- #[ cfg( feature = "i686-guest" ) ]
241+ /// Set the root offset to target a specific root page table.
242+ /// Root i starts at byte offset `i * PAGE_TABLE_SIZE` in the buffer.
252243 pub ( crate ) fn set_root_offset ( & self , offset : usize ) {
253244 self . root_offset . set ( offset) ;
254245 }
255246
256- /// Copy a range of bytes within the buffer.
257- #[ cfg( feature = "i686-guest" ) ]
258- pub ( crate ) fn copy_within ( & self , src : std:: ops:: Range < usize > , dst : usize ) {
259- let mut buf = self . buffer . borrow_mut ( ) ;
260- buf. copy_within ( src, dst) ;
261- }
262-
263- /// Finalize multi-root i686 page directories after all per-root
264- /// mappings have been written into root 0 (kernel) and per-root
265- /// PDs (user).
266- ///
267- /// This performs three steps:
268- /// 1. Copy kernel PDEs (0..`user_pde_start`) from root 0 to all
269- /// other roots so every PD shares the same kernel page tables.
270- /// 2. Map the scratch region into every additional root.
271- /// 3. Set `PAGE_USER` on user-space PDEs (`user_pde_start`..scratch)
272- /// in all roots so user-mode code can access its pages.
273- ///
274- /// # Safety
275- /// Caller must ensure the scratch parameters describe a valid region.
276- #[ cfg( feature = "i686-guest" ) ]
277- pub ( crate ) unsafe fn finalize_multi_root (
278- & self ,
279- n_roots : usize ,
280- user_pde_start : usize ,
281- scratch_gpa : u64 ,
282- scratch_gva : u64 ,
283- scratch_len : u64 ,
284- ) {
285- use hyperlight_common:: vmem:: { BasicMapping , MappingKind } ;
286-
287- // Step 1: copy kernel PDEs from root 0 to all other roots.
288- let kernel_pde_bytes = user_pde_start * 4 ;
289- for i in 1 ..n_roots {
290- self . copy_within ( 0 ..kernel_pde_bytes, i * PAGE_TABLE_SIZE ) ;
291- }
292-
293- // Step 2: map scratch into all other roots.
294- for i in 1 ..n_roots {
295- self . set_root_offset ( i * PAGE_TABLE_SIZE ) ;
296- unsafe {
297- vmem:: map (
298- self ,
299- vmem:: Mapping {
300- phys_base : scratch_gpa,
301- virt_base : scratch_gva,
302- len : scratch_len,
303- kind : MappingKind :: Basic ( BasicMapping {
304- readable : true ,
305- writable : true ,
306- executable : false ,
307- } ) ,
308- user_accessible : false ,
309- } ,
310- ) ;
311- }
312- }
313- }
314247 #[ cfg( test) ]
315248 #[ allow( dead_code) ]
316249 pub ( crate ) fn size ( & self ) -> usize {
0 commit comments