@@ -92,6 +92,7 @@ pub(crate) struct SandboxMemoryLayout {
9292 peb_output_data_offset : usize ,
9393 peb_init_data_offset : usize ,
9494 peb_heap_data_offset : usize ,
95+ #[ cfg( feature = "nanvix-unstable" ) ]
9596 peb_file_mappings_offset : usize ,
9697
9798 guest_heap_buffer_offset : usize ,
@@ -113,57 +114,58 @@ pub(crate) struct SandboxMemoryLayout {
113114
114115impl Debug for SandboxMemoryLayout {
115116 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
116- f. debug_struct ( "SandboxMemoryLayout" )
117- . field (
118- "Total Memory Size" ,
119- & format_args ! ( "{:#x}" , self . get_memory_size( ) . unwrap_or( 0 ) ) ,
120- )
121- . field ( "Heap Size" , & format_args ! ( "{:#x}" , self . heap_size) )
122- . field (
123- "Init Data Size" ,
124- & format_args ! ( "{:#x}" , self . init_data_size) ,
125- )
126- . field ( "PEB Address" , & format_args ! ( "{:#x}" , self . peb_address) )
127- . field ( "PEB Offset" , & format_args ! ( "{:#x}" , self . peb_offset) )
128- . field ( "Code Size" , & format_args ! ( "{:#x}" , self . code_size) )
129- . field (
130- "Input Data Offset" ,
131- & format_args ! ( "{:#x}" , self . peb_input_data_offset) ,
132- )
133- . field (
134- "Output Data Offset" ,
135- & format_args ! ( "{:#x}" , self . peb_output_data_offset) ,
136- )
137- . field (
138- "Init Data Offset" ,
139- & format_args ! ( "{:#x}" , self . peb_init_data_offset) ,
140- )
141- . field (
142- "Guest Heap Offset" ,
143- & format_args ! ( "{:#x}" , self . peb_heap_data_offset) ,
144- )
145- . field (
146- "File Mappings Offset" ,
147- & format_args ! ( "{:#x}" , self . peb_file_mappings_offset) ,
148- )
149- . field (
150- "Guest Heap Buffer Offset" ,
151- & format_args ! ( "{:#x}" , self . guest_heap_buffer_offset) ,
152- )
153- . field (
154- "Init Data Offset" ,
155- & format_args ! ( "{:#x}" , self . init_data_offset) ,
156- )
157- . field ( "PT Size" , & format_args ! ( "{:#x}" , self . pt_size. unwrap_or( 0 ) ) )
158- . field (
159- "Guest Code Offset" ,
160- & format_args ! ( "{:#x}" , self . guest_code_offset) ,
161- )
162- . field (
163- "Scratch region size" ,
164- & format_args ! ( "{:#x}" , self . scratch_size) ,
165- )
166- . finish ( )
117+ let mut ff = f. debug_struct ( "SandboxMemoryLayout" ) ;
118+ ff. field (
119+ "Total Memory Size" ,
120+ & format_args ! ( "{:#x}" , self . get_memory_size( ) . unwrap_or( 0 ) ) ,
121+ )
122+ . field ( "Heap Size" , & format_args ! ( "{:#x}" , self . heap_size) )
123+ . field (
124+ "Init Data Size" ,
125+ & format_args ! ( "{:#x}" , self . init_data_size) ,
126+ )
127+ . field ( "PEB Address" , & format_args ! ( "{:#x}" , self . peb_address) )
128+ . field ( "PEB Offset" , & format_args ! ( "{:#x}" , self . peb_offset) )
129+ . field ( "Code Size" , & format_args ! ( "{:#x}" , self . code_size) )
130+ . field (
131+ "Input Data Offset" ,
132+ & format_args ! ( "{:#x}" , self . peb_input_data_offset) ,
133+ )
134+ . field (
135+ "Output Data Offset" ,
136+ & format_args ! ( "{:#x}" , self . peb_output_data_offset) ,
137+ )
138+ . field (
139+ "Init Data Offset" ,
140+ & format_args ! ( "{:#x}" , self . peb_init_data_offset) ,
141+ )
142+ . field (
143+ "Guest Heap Offset" ,
144+ & format_args ! ( "{:#x}" , self . peb_heap_data_offset) ,
145+ ) ;
146+ #[ cfg( feature = "nanvix-unstable" ) ]
147+ ff. field (
148+ "File Mappings Offset" ,
149+ & format_args ! ( "{:#x}" , self . peb_file_mappings_offset) ,
150+ ) ;
151+ ff. field (
152+ "Guest Heap Buffer Offset" ,
153+ & format_args ! ( "{:#x}" , self . guest_heap_buffer_offset) ,
154+ )
155+ . field (
156+ "Init Data Offset" ,
157+ & format_args ! ( "{:#x}" , self . init_data_offset) ,
158+ )
159+ . field ( "PT Size" , & format_args ! ( "{:#x}" , self . pt_size. unwrap_or( 0 ) ) )
160+ . field (
161+ "Guest Code Offset" ,
162+ & format_args ! ( "{:#x}" , self . guest_code_offset) ,
163+ )
164+ . field (
165+ "Scratch region size" ,
166+ & format_args ! ( "{:#x}" , self . scratch_size) ,
167+ )
168+ . finish ( )
167169 }
168170}
169171
@@ -213,6 +215,7 @@ impl SandboxMemoryLayout {
213215 let peb_output_data_offset = peb_offset + offset_of ! ( HyperlightPEB , output_stack) ;
214216 let peb_init_data_offset = peb_offset + offset_of ! ( HyperlightPEB , init_data) ;
215217 let peb_heap_data_offset = peb_offset + offset_of ! ( HyperlightPEB , guest_heap) ;
218+ #[ cfg( feature = "nanvix-unstable" ) ]
216219 let peb_file_mappings_offset = peb_offset + offset_of ! ( HyperlightPEB , file_mappings) ;
217220
218221 // The following offsets are the actual values that relate to memory layout,
@@ -227,11 +230,16 @@ impl SandboxMemoryLayout {
227230 // many file mappings the host will register, so we reserve space for
228231 // the maximum number.
229232 // The heap starts at the next page boundary after this reserved area.
233+ #[ cfg( feature = "nanvix-unstable" ) ]
230234 let file_mappings_array_end = peb_offset
231235 + size_of :: < HyperlightPEB > ( )
232236 + hyperlight_common:: mem:: MAX_FILE_MAPPINGS
233237 * size_of :: < hyperlight_common:: mem:: FileMappingInfo > ( ) ;
238+ #[ cfg( feature = "nanvix-unstable" ) ]
234239 let guest_heap_buffer_offset = file_mappings_array_end. next_multiple_of ( PAGE_SIZE_USIZE ) ;
240+ #[ cfg( not( feature = "nanvix-unstable" ) ) ]
241+ let guest_heap_buffer_offset =
242+ ( peb_offset + size_of :: < HyperlightPEB > ( ) ) . next_multiple_of ( PAGE_SIZE_USIZE ) ;
235243
236244 // make sure init data starts at 4K boundary
237245 let init_data_offset =
@@ -244,6 +252,7 @@ impl SandboxMemoryLayout {
244252 peb_output_data_offset,
245253 peb_init_data_offset,
246254 peb_heap_data_offset,
255+ #[ cfg( feature = "nanvix-unstable" ) ]
247256 peb_file_mappings_offset,
248257 sandbox_memory_config : cfg,
249258 code_size,
@@ -367,22 +376,26 @@ impl SandboxMemoryLayout {
367376
368377 /// Get the offset in guest memory to the file_mappings count field
369378 /// (the `size` field of the `GuestMemoryRegion` in the PEB).
379+ #[ cfg( feature = "nanvix-unstable" ) ]
370380 pub ( crate ) fn get_file_mappings_size_offset ( & self ) -> usize {
371381 self . peb_file_mappings_offset
372382 }
373383
374384 /// Get the offset in guest memory to the file_mappings pointer field.
385+ #[ cfg( feature = "nanvix-unstable" ) ]
375386 fn get_file_mappings_pointer_offset ( & self ) -> usize {
376387 self . get_file_mappings_size_offset ( ) + size_of :: < u64 > ( )
377388 }
378389
379390 /// Get the offset in snapshot memory where the FileMappingInfo array starts
380391 /// (immediately after the PEB struct, within the same page).
392+ #[ cfg( feature = "nanvix-unstable" ) ]
381393 pub ( crate ) fn get_file_mappings_array_offset ( & self ) -> usize {
382394 self . peb_offset + size_of :: < HyperlightPEB > ( )
383395 }
384396
385397 /// Get the guest address of the FileMappingInfo array.
398+ #[ cfg( feature = "nanvix-unstable" ) ]
386399 fn get_file_mappings_array_gva ( & self ) -> u64 {
387400 ( Self :: BASE_ADDRESS + self . get_file_mappings_array_offset ( ) ) as u64
388401 }
@@ -484,14 +497,20 @@ impl SandboxMemoryLayout {
484497 }
485498
486499 // PEB + preallocated FileMappingInfo array
487- let peb_and_array_size = size_of :: < HyperlightPEB > ( )
488- + hyperlight_common:: mem:: MAX_FILE_MAPPINGS
489- * size_of :: < hyperlight_common:: mem:: FileMappingInfo > ( ) ;
490- let heap_offset = builder. push_page_aligned (
491- peb_and_array_size,
492- MemoryRegionFlags :: READ | MemoryRegionFlags :: WRITE ,
493- Peb ,
494- ) ;
500+ #[ cfg( feature = "nanvix-unstable" ) ]
501+ let heap_offset = {
502+ let peb_and_array_size = size_of :: < HyperlightPEB > ( )
503+ + hyperlight_common:: mem:: MAX_FILE_MAPPINGS
504+ * size_of :: < hyperlight_common:: mem:: FileMappingInfo > ( ) ;
505+ builder. push_page_aligned (
506+ peb_and_array_size,
507+ MemoryRegionFlags :: READ | MemoryRegionFlags :: WRITE ,
508+ Peb ,
509+ )
510+ } ;
511+ #[ cfg( not( feature = "nanvix-unstable" ) ) ]
512+ let heap_offset =
513+ builder. push_page_aligned ( size_of :: < HyperlightPEB > ( ) , MemoryRegionFlags :: READ , Peb ) ;
495514
496515 let expected_heap_offset = TryInto :: < usize > :: try_into ( self . guest_heap_buffer_offset ) ?;
497516
@@ -634,8 +653,11 @@ impl SandboxMemoryLayout {
634653 // later by map_file_cow / evolve).
635654 // - The `ptr` field holds the guest address of the preallocated
636655 // FileMappingInfo array
637- shared_mem. write_u64 ( self . get_file_mappings_size_offset ( ) , 0 ) ?;
638- shared_mem. write_u64 (
656+ #[ cfg( feature = "nanvix-unstable" ) ]
657+ write_u64 ( mem, self . get_file_mappings_size_offset ( ) , 0 ) ?;
658+ #[ cfg( feature = "nanvix-unstable" ) ]
659+ write_u64 (
660+ mem,
639661 self . get_file_mappings_pointer_offset ( ) ,
640662 self . get_file_mappings_array_gva ( ) ,
641663 ) ?;
@@ -664,9 +686,12 @@ mod tests {
664686 expected_size += layout. code_size ;
665687
666688 // PEB + preallocated FileMappingInfo array
689+ #[ cfg( feature = "nanvix-unstable" ) ]
667690 let peb_and_array = size_of :: < HyperlightPEB > ( )
668691 + hyperlight_common:: mem:: MAX_FILE_MAPPINGS
669692 * size_of :: < hyperlight_common:: mem:: FileMappingInfo > ( ) ;
693+ #[ cfg( not( feature = "nanvix-unstable" ) ) ]
694+ let peb_and_array = size_of :: < HyperlightPEB > ( ) ;
670695 expected_size += peb_and_array. next_multiple_of ( PAGE_SIZE_USIZE ) ;
671696
672697 expected_size += layout. heap_size . next_multiple_of ( PAGE_SIZE_USIZE ) ;
0 commit comments