@@ -20,13 +20,15 @@ use hyperlight_common::mem::{GuestMemoryRegion, HyperlightPEB, PAGE_SIZE_USIZE};
2020use  rand:: { RngCore ,  rng} ; 
2121use  tracing:: { Span ,  instrument} ; 
2222
23+ #[ cfg( feature = "init-paging" ) ]  
24+ use  super :: memory_region:: MemoryRegionType :: PageTables ; 
2325use  super :: memory_region:: MemoryRegionType :: { 
24-     Code ,  GuardPage ,  Heap ,  HostFunctionDefinitions ,  InitData ,  InputData ,  OutputData ,  PageTables , 
25-     Peb ,  Stack , 
26+     Code ,  GuardPage ,  Heap ,  HostFunctionDefinitions ,  InitData ,  InputData ,  OutputData ,  Peb ,  Stack , 
2627} ; 
2728use  super :: memory_region:: { 
2829    DEFAULT_GUEST_BLOB_MEM_FLAGS ,  MemoryRegion ,  MemoryRegionFlags ,  MemoryRegionVecBuilder , 
2930} ; 
31+ #[ cfg( feature = "init-paging" ) ]  
3032use  super :: mgr:: AMOUNT_OF_MEMORY_PER_PT ; 
3133use  super :: shared_mem:: { ExclusiveSharedMemory ,  GuestSharedMemory ,  SharedMemory } ; 
3234use  crate :: error:: HyperlightError :: { GuestOffsetIsInvalid ,  MemoryRequestTooBig } ; 
@@ -257,11 +259,13 @@ impl SandboxMemoryLayout {
257259        init_data_size :  usize , 
258260        init_data_permissions :  Option < MemoryRegionFlags > , 
259261    )  -> Result < Self >  { 
260-         let  total_page_table_size =
261-             Self :: get_total_page_table_size ( cfg,  code_size,  stack_size,  heap_size) ; 
262-         let  guest_code_offset = total_page_table_size; 
262+         #[ cfg( feature = "init-paging" ) ]  
263+         let  base = Self :: get_total_page_table_size ( cfg,  code_size,  stack_size,  heap_size) ; 
264+         #[ cfg( not( feature = "init-paging" ) ) ]  
265+         let  base = Self :: BASE_ADDRESS ; 
266+         let  guest_code_offset = base; 
263267        // The following offsets are to the fields of the PEB struct itself! 
264-         let  peb_offset = total_page_table_size  + round_up_to ( code_size,  PAGE_SIZE_USIZE ) ; 
268+         let  peb_offset = base  + round_up_to ( code_size,  PAGE_SIZE_USIZE ) ; 
265269        let  peb_security_cookie_seed_offset =
266270            peb_offset + offset_of ! ( HyperlightPEB ,  security_cookie_seed) ; 
267271        let  peb_guest_dispatch_function_ptr_offset =
@@ -325,7 +329,7 @@ impl SandboxMemoryLayout {
325329            guest_user_stack_buffer_offset, 
326330            peb_address, 
327331            guard_page_offset, 
328-             total_page_table_size, 
332+             total_page_table_size :  base , 
329333            guest_code_offset, 
330334            init_data_offset, 
331335            init_data_size, 
@@ -507,6 +511,7 @@ impl SandboxMemoryLayout {
507511    } 
508512
509513    #[ cfg( test) ]  
514+     #[ cfg( feature = "init-paging" ) ]  
510515    /// Get the page table size 
511516fn  get_page_table_size ( & self )  -> usize  { 
512517        self . total_page_table_size 
@@ -523,6 +528,7 @@ impl SandboxMemoryLayout {
523528    // then divide that by 0x200_000 (as we can map 2MB in each PT). 
524529    // This will give us the total size of the PTs required for the sandbox to which we can add the size of the PML4, PDPT and PD. 
525530    #[ instrument( skip_all,  parent = Span :: current( ) ,  level= "Trace" ) ]  
531+     #[ cfg( feature = "init-paging" ) ]  
526532    fn  get_total_page_table_size ( 
527533        cfg :  SandboxConfiguration , 
528534        code_size :  usize , 
@@ -582,19 +588,23 @@ impl SandboxMemoryLayout {
582588pub  fn  get_memory_regions ( & self ,  shared_mem :  & GuestSharedMemory )  -> Result < Vec < MemoryRegion > >  { 
583589        let  mut  builder = MemoryRegionVecBuilder :: new ( Self :: BASE_ADDRESS ,  shared_mem. base_addr ( ) ) ; 
584590
585-         // PML4, PDPT, PD 
586-         let  code_offset = builder. push_page_aligned ( 
587-             self . total_page_table_size , 
588-             MemoryRegionFlags :: READ  | MemoryRegionFlags :: WRITE , 
589-             PageTables , 
590-         ) ; 
591- 
592-         if  code_offset != self . guest_code_offset  { 
593-             return  Err ( new_error ! ( 
594-                 "Code offset does not match expected code offset expected:  {}, actual:  {}" , 
595-                 self . guest_code_offset, 
596-                 code_offset
597-             ) ) ; 
591+         cfg_if:: cfg_if! { 
592+             if  #[ cfg( feature = "init-paging" ) ]  { 
593+                 // PML4, PDPT, PD 
594+                 let  code_offset = builder. push_page_aligned( 
595+                     self . total_page_table_size, 
596+                     MemoryRegionFlags :: READ  | MemoryRegionFlags :: WRITE , 
597+                     PageTables , 
598+                 ) ; 
599+ 
600+                 if  code_offset != self . guest_code_offset { 
601+                     return  Err ( new_error!( 
602+                         "Code offset does not match expected code offset expected:  {}, actual:  {}" , 
603+                         self . guest_code_offset, 
604+                         code_offset
605+                     ) ) ; 
606+                 } 
607+             } 
598608        } 
599609
600610        // code 
0 commit comments