@@ -22,8 +22,8 @@ use rand::{rng, RngCore};
2222use tracing:: { instrument, Span } ;
2323
2424use super :: memory_region:: MemoryRegionType :: {
25- Code , GuardPage , GuestErrorData , Heap , HostExceptionData , HostFunctionDefinitions , InputData ,
26- OutputData , PageTables , PanicContext , Peb , Stack ,
25+ Code , GuardPage , GuestErrorData , Heap , HostExceptionData , InputData , OutputData , PageTables ,
26+ PanicContext , Peb , Stack ,
2727} ;
2828use super :: memory_region:: { MemoryRegion , MemoryRegionFlags , MemoryRegionVecBuilder } ;
2929use super :: mgr:: AMOUNT_OF_MEMORY_PER_PT ;
@@ -49,9 +49,7 @@ use crate::{log_then_return, new_error, Result};
4949// +-------------------------------------------+
5050// | Host Exception Handlers |
5151// +-------------------------------------------+
52- // | Host Function Definitions |
53- // +-------------------------------------------+
54- // | PEB Struct (0x98) |
52+ // | PEB Struct | (HyperlightPEB size)
5553// +-------------------------------------------+
5654// | Guest Code |
5755// +-------------------------------------------+
@@ -64,9 +62,6 @@ use crate::{log_then_return, new_error, Result};
6462// | PML4 |
6563// +-------------------------------------------+ 0x0_000
6664
67- ///
68- /// - `HostDefinitions` - the length of this is the `HostFunctionDefinitionSize`
69- /// field from `SandboxConfiguration`
7065///
7166/// - `HostExceptionData` - memory that contains details of any Host Exception that
7267/// occurred in outb function. it contains a 32 bit length following by a json
@@ -108,7 +103,6 @@ pub(crate) struct SandboxMemoryLayout {
108103 peb_offset : usize ,
109104 peb_security_cookie_seed_offset : usize ,
110105 peb_guest_dispatch_function_ptr_offset : usize , // set by guest in guest entrypoint
111- pub ( super ) peb_host_function_definitions_offset : usize ,
112106 pub ( crate ) peb_host_exception_offset : usize ,
113107 peb_guest_error_offset : usize ,
114108 peb_code_and_outb_pointer_offset : usize ,
@@ -121,7 +115,6 @@ pub(crate) struct SandboxMemoryLayout {
121115
122116 // The following are the actual values
123117 // that are written to the PEB struct
124- pub ( crate ) host_function_definitions_buffer_offset : usize ,
125118 pub ( crate ) host_exception_buffer_offset : usize ,
126119 pub ( super ) guest_error_buffer_offset : usize ,
127120 pub ( super ) input_data_buffer_offset : usize ,
@@ -160,10 +153,6 @@ impl Debug for SandboxMemoryLayout {
160153 "Guest Dispatch Function Pointer Offset" ,
161154 & format_args ! ( "{:#x}" , self . peb_guest_dispatch_function_ptr_offset) ,
162155 )
163- . field (
164- "Host Function Definitions Offset" ,
165- & format_args ! ( "{:#x}" , self . peb_host_function_definitions_offset) ,
166- )
167156 . field (
168157 "Host Exception Offset" ,
169158 & format_args ! ( "{:#x}" , self . peb_host_exception_offset) ,
@@ -196,10 +185,6 @@ impl Debug for SandboxMemoryLayout {
196185 "Guest Stack Offset" ,
197186 & format_args ! ( "{:#x}" , self . peb_guest_stack_data_offset) ,
198187 )
199- . field (
200- "Host Function Definitions Buffer Offset" ,
201- & format_args ! ( "{:#x}" , self . host_function_definitions_buffer_offset) ,
202- )
203188 . field (
204189 "Host Exception Buffer Offset" ,
205190 & format_args ! ( "{:#x}" , self . host_exception_buffer_offset) ,
@@ -292,8 +277,6 @@ impl SandboxMemoryLayout {
292277 peb_offset + offset_of ! ( HyperlightPEB , security_cookie_seed) ;
293278 let peb_guest_dispatch_function_ptr_offset =
294279 peb_offset + offset_of ! ( HyperlightPEB , guest_function_dispatch_ptr) ;
295- let peb_host_function_definitions_offset =
296- peb_offset + offset_of ! ( HyperlightPEB , hostFunctionDefinitions) ;
297280 let peb_host_exception_offset = peb_offset + offset_of ! ( HyperlightPEB , hostException) ;
298281 let peb_guest_error_offset = peb_offset + offset_of ! ( HyperlightPEB , guestErrorData) ;
299282 let peb_code_and_outb_pointer_offset = peb_offset + offset_of ! ( HyperlightPEB , pCode) ;
@@ -308,14 +291,9 @@ impl SandboxMemoryLayout {
308291 // The following offsets are the actual values that relate to memory layout,
309292 // which are written to PEB struct
310293 let peb_address = Self :: BASE_ADDRESS + peb_offset;
311- // make sure host function definitions buffer starts at 4K boundary
312- let host_function_definitions_buffer_offset = round_up_to (
313- peb_guest_stack_data_offset + size_of :: < GuestStackData > ( ) ,
314- PAGE_SIZE_USIZE ,
315- ) ;
316294 // make sure host exception buffer starts at 4K boundary
317295 let host_exception_buffer_offset = round_up_to (
318- host_function_definitions_buffer_offset + cfg . get_host_function_definition_size ( ) ,
296+ peb_guest_stack_data_offset + size_of :: < GuestStackData > ( ) ,
319297 PAGE_SIZE_USIZE ,
320298 ) ;
321299 let guest_error_buffer_offset = round_up_to (
@@ -351,7 +329,6 @@ impl SandboxMemoryLayout {
351329 heap_size,
352330 peb_security_cookie_seed_offset,
353331 peb_guest_dispatch_function_ptr_offset,
354- peb_host_function_definitions_offset,
355332 peb_host_exception_offset,
356333 peb_guest_error_offset,
357334 peb_code_and_outb_pointer_offset,
@@ -364,7 +341,6 @@ impl SandboxMemoryLayout {
364341 guest_error_buffer_offset,
365342 sandbox_memory_config : cfg,
366343 code_size,
367- host_function_definitions_buffer_offset,
368344 host_exception_buffer_offset,
369345 input_data_buffer_offset,
370346 output_data_buffer_offset,
@@ -410,22 +386,6 @@ impl SandboxMemoryLayout {
410386 self . peb_output_data_offset
411387 }
412388
413- /// Get the offset in guest memory to the host function definitions
414- /// size
415- #[ instrument( skip_all, parent = Span :: current( ) , level= "Trace" ) ]
416- pub ( super ) fn get_host_function_definitions_size_offset ( & self ) -> usize {
417- // The size field is the first field in the `HostFunctions` struct
418- self . peb_host_function_definitions_offset
419- }
420-
421- /// Get the offset in guest memory to the host function definitions
422- /// pointer.
423- #[ instrument( skip_all, parent = Span :: current( ) , level= "Trace" ) ]
424- fn get_host_function_definitions_pointer_offset ( & self ) -> usize {
425- // The size field is the field after the size field in the `HostFunctions` struct which is a u64
426- self . peb_host_function_definitions_offset + size_of :: < u64 > ( )
427- }
428-
429389 /// Get the offset in guest memory to the minimum guest stack address.
430390 #[ instrument( skip_all, parent = Span :: current( ) , level= "Trace" ) ]
431391 fn get_min_guest_stack_address_offset ( & self ) -> usize {
@@ -623,8 +583,6 @@ impl SandboxMemoryLayout {
623583 total_mapped_memory_size += round_up_to ( stack_size, PAGE_SIZE_USIZE ) ;
624584 total_mapped_memory_size += round_up_to ( heap_size, PAGE_SIZE_USIZE ) ;
625585 total_mapped_memory_size += round_up_to ( cfg. get_host_exception_size ( ) , PAGE_SIZE_USIZE ) ;
626- total_mapped_memory_size +=
627- round_up_to ( cfg. get_host_function_definition_size ( ) , PAGE_SIZE_USIZE ) ;
628586 total_mapped_memory_size += round_up_to ( cfg. get_guest_error_buffer_size ( ) , PAGE_SIZE_USIZE ) ;
629587 total_mapped_memory_size += round_up_to ( cfg. get_input_data_size ( ) , PAGE_SIZE_USIZE ) ;
630588 total_mapped_memory_size += round_up_to ( cfg. get_output_data_size ( ) , PAGE_SIZE_USIZE ) ;
@@ -709,31 +667,12 @@ impl SandboxMemoryLayout {
709667 }
710668
711669 // PEB
712- let host_functions_definitions_offset = builder. push_page_aligned (
670+ let host_exception_offset = builder. push_page_aligned (
713671 size_of :: < HyperlightPEB > ( ) ,
714672 MemoryRegionFlags :: READ | MemoryRegionFlags :: WRITE ,
715673 Peb ,
716674 ) ;
717675
718- let expected_host_functions_definitions_offset =
719- TryInto :: < usize > :: try_into ( self . host_function_definitions_buffer_offset ) ?;
720-
721- if host_functions_definitions_offset != expected_host_functions_definitions_offset {
722- return Err ( new_error ! (
723- "Host Function Definitions offset does not match expected Host Function Definitions offset expected: {}, actual: {}" ,
724- expected_host_functions_definitions_offset,
725- host_functions_definitions_offset
726- ) ) ;
727- }
728-
729- // host function definitions
730- let host_exception_offset = builder. push_page_aligned (
731- self . sandbox_memory_config
732- . get_host_function_definition_size ( ) ,
733- MemoryRegionFlags :: READ ,
734- HostFunctionDefinitions ,
735- ) ;
736-
737676 let expected_host_exception_offset =
738677 TryInto :: < usize > :: try_into ( self . host_exception_buffer_offset ) ?;
739678
@@ -938,16 +877,6 @@ impl SandboxMemoryLayout {
938877
939878 // Skip guest_dispatch_function_ptr_offset because it is set by the guest
940879
941- // Set up Host Function Definition
942- shared_mem. write_u64 (
943- self . get_host_function_definitions_size_offset ( ) ,
944- self . sandbox_memory_config
945- . get_host_function_definition_size ( )
946- . try_into ( ) ?,
947- ) ?;
948- let addr = get_address ! ( host_function_definitions_buffer) ;
949- shared_mem. write_u64 ( self . get_host_function_definitions_pointer_offset ( ) , addr) ?;
950-
951880 // Set up Host Exception Header
952881 // The peb only needs to include the size, not the actual buffer
953882 // since the the guest wouldn't want to read the buffer anyway
@@ -1098,8 +1027,6 @@ mod tests {
10981027
10991028 expected_size += round_up_to ( size_of :: < HyperlightPEB > ( ) , PAGE_SIZE_USIZE ) ;
11001029
1101- expected_size += round_up_to ( cfg. get_host_function_definition_size ( ) , PAGE_SIZE_USIZE ) ;
1102-
11031030 expected_size += round_up_to ( cfg. get_host_exception_size ( ) , PAGE_SIZE_USIZE ) ;
11041031
11051032 expected_size += round_up_to ( cfg. get_guest_error_buffer_size ( ) , PAGE_SIZE_USIZE ) ;
0 commit comments