@@ -62,7 +62,6 @@ use std::fmt::Debug;
6262use std:: mem:: { offset_of, size_of} ;
6363
6464use hyperlight_common:: mem:: { GuestMemoryRegion , HyperlightPEB , PAGE_SIZE_USIZE } ;
65- use hyperlight_common:: util:: round_up_to;
6665use tracing:: { Span , instrument} ;
6766
6867#[ cfg( feature = "init-paging" ) ]
@@ -208,7 +207,7 @@ impl SandboxMemoryLayout {
208207 ) -> Result < Self > {
209208 let guest_code_offset = 0 ;
210209 // The following offsets are to the fields of the PEB struct itself!
211- let peb_offset = round_up_to ( code_size, PAGE_SIZE_USIZE ) ;
210+ let peb_offset = code_size. next_multiple_of ( PAGE_SIZE_USIZE ) ;
212211 let peb_guest_dispatch_function_ptr_offset =
213212 peb_offset + offset_of ! ( HyperlightPEB , guest_function_dispatch_ptr) ;
214213 let peb_input_data_offset = peb_offset + offset_of ! ( HyperlightPEB , input_stack) ;
@@ -220,22 +219,17 @@ impl SandboxMemoryLayout {
220219 // which are written to PEB struct
221220 let peb_address = Self :: BASE_ADDRESS + peb_offset;
222221 // make sure input data buffer starts at 4K boundary
223- let input_data_buffer_offset = round_up_to (
224- peb_heap_data_offset + size_of :: < GuestMemoryRegion > ( ) ,
225- PAGE_SIZE_USIZE ,
226- ) ;
227- let output_data_buffer_offset = round_up_to (
228- input_data_buffer_offset + cfg. get_input_data_size ( ) ,
229- PAGE_SIZE_USIZE ,
230- ) ;
222+ let input_data_buffer_offset = ( peb_heap_data_offset + size_of :: < GuestMemoryRegion > ( ) )
223+ . next_multiple_of ( PAGE_SIZE_USIZE ) ;
224+ let output_data_buffer_offset = ( input_data_buffer_offset + cfg. get_input_data_size ( ) )
225+ . next_multiple_of ( PAGE_SIZE_USIZE ) ;
231226 // make sure heap buffer starts at 4K boundary
232- let guest_heap_buffer_offset = round_up_to (
233- output_data_buffer_offset + cfg. get_output_data_size ( ) ,
234- PAGE_SIZE_USIZE ,
235- ) ;
227+ let guest_heap_buffer_offset = ( output_data_buffer_offset + cfg. get_output_data_size ( ) )
228+ . next_multiple_of ( PAGE_SIZE_USIZE ) ;
236229 // make sure init data starts at 4K boundary
237- let init_data_offset = round_up_to ( guest_heap_buffer_offset + heap_size, PAGE_SIZE_USIZE ) ;
238- let pt_offset = round_up_to ( init_data_offset + init_data_size, PAGE_SIZE_USIZE ) ;
230+ let init_data_offset =
231+ ( guest_heap_buffer_offset + heap_size) . next_multiple_of ( PAGE_SIZE_USIZE ) ;
232+ let pt_offset = ( init_data_offset + init_data_size) . next_multiple_of ( PAGE_SIZE_USIZE ) ;
239233
240234 Ok ( Self {
241235 peb_offset,
@@ -640,38 +634,20 @@ mod tests {
640634
641635 use super :: * ;
642636
643- #[ test]
644- fn test_round_up ( ) {
645- assert_eq ! ( 0 , round_up_to( 0 , 4 ) ) ;
646- assert_eq ! ( 4 , round_up_to( 1 , 4 ) ) ;
647- assert_eq ! ( 4 , round_up_to( 2 , 4 ) ) ;
648- assert_eq ! ( 4 , round_up_to( 3 , 4 ) ) ;
649- assert_eq ! ( 4 , round_up_to( 4 , 4 ) ) ;
650- assert_eq ! ( 8 , round_up_to( 5 , 4 ) ) ;
651- assert_eq ! ( 8 , round_up_to( 6 , 4 ) ) ;
652- assert_eq ! ( 8 , round_up_to( 7 , 4 ) ) ;
653- assert_eq ! ( 8 , round_up_to( 8 , 4 ) ) ;
654- assert_eq ! ( PAGE_SIZE_USIZE , round_up_to( 44 , PAGE_SIZE_USIZE ) ) ;
655- assert_eq ! ( PAGE_SIZE_USIZE , round_up_to( 4095 , PAGE_SIZE_USIZE ) ) ;
656- assert_eq ! ( PAGE_SIZE_USIZE , round_up_to( 4096 , PAGE_SIZE_USIZE ) ) ;
657- assert_eq ! ( PAGE_SIZE_USIZE * 2 , round_up_to( 4097 , PAGE_SIZE_USIZE ) ) ;
658- assert_eq ! ( PAGE_SIZE_USIZE * 2 , round_up_to( 8191 , PAGE_SIZE_USIZE ) ) ;
659- }
660-
661637 // helper func for testing
662638 fn get_expected_memory_size ( layout : & SandboxMemoryLayout ) -> usize {
663639 let cfg = layout. sandbox_memory_config ;
664640 let mut expected_size = 0 ;
665641 // in order of layout
666642 expected_size += layout. code_size ;
667643
668- expected_size += round_up_to ( size_of :: < HyperlightPEB > ( ) , PAGE_SIZE_USIZE ) ;
644+ expected_size += size_of :: < HyperlightPEB > ( ) . next_multiple_of ( PAGE_SIZE_USIZE ) ;
669645
670- expected_size += round_up_to ( cfg. get_input_data_size ( ) , PAGE_SIZE_USIZE ) ;
646+ expected_size += cfg. get_input_data_size ( ) . next_multiple_of ( PAGE_SIZE_USIZE ) ;
671647
672- expected_size += round_up_to ( cfg. get_output_data_size ( ) , PAGE_SIZE_USIZE ) ;
648+ expected_size += cfg. get_output_data_size ( ) . next_multiple_of ( PAGE_SIZE_USIZE ) ;
673649
674- expected_size += round_up_to ( layout. heap_size , PAGE_SIZE_USIZE ) ;
650+ expected_size += layout. heap_size . next_multiple_of ( PAGE_SIZE_USIZE ) ;
675651
676652 expected_size
677653 }
0 commit comments