@@ -25,7 +25,6 @@ use hyperlight_common::flatbuffer_wrappers::function_call::{
25
25
use hyperlight_common:: flatbuffer_wrappers:: function_types:: ReturnValue ;
26
26
use hyperlight_common:: flatbuffer_wrappers:: guest_error:: { ErrorCode , GuestError } ;
27
27
use hyperlight_common:: flatbuffer_wrappers:: guest_log_data:: GuestLogData ;
28
- use hyperlight_common:: peb:: HyperlightPEB ;
29
28
use serde_json:: from_str;
30
29
use tracing:: { instrument, Span } ;
31
30
@@ -236,28 +235,6 @@ impl<S> SandboxMemoryManager<S>
236
235
where
237
236
S : SharedMemory ,
238
237
{
239
- pub ( crate ) fn write_hyperlight_peb ( & mut self , hyperlight_peb : HyperlightPEB ) -> Result < ( ) > {
240
- let peb_offset = self
241
- . memory_sections
242
- . get_hyperlight_peb_section_host_address ( )
243
- . unwrap ( ) as * mut HyperlightPEB ;
244
-
245
- unsafe {
246
- peb_offset. copy_from ( & hyperlight_peb, 1 ) ;
247
- }
248
-
249
- Ok ( ( ) )
250
- }
251
-
252
- pub ( crate ) fn read_hyperlight_peb ( & self ) -> Result < HyperlightPEB > {
253
- let peb_offset = self
254
- . memory_sections
255
- . get_hyperlight_peb_section_host_address ( )
256
- . unwrap ( ) as * mut HyperlightPEB ;
257
-
258
- Ok ( unsafe { peb_offset. read ( ) } )
259
- }
260
-
261
238
/// Create a memory snapshot and push it onto the stack of snapshots.
262
239
///
263
240
/// It should be used when you want to save the state of the memory—for example, when evolving a
@@ -376,7 +353,10 @@ impl SandboxMemoryManager<HostSharedMemory> {
376
353
/// Reads a host function call from memory
377
354
#[ instrument( err( Debug ) , skip_all, parent = Span :: current( ) , level= "Trace" ) ]
378
355
pub ( crate ) fn get_host_function_call ( & mut self ) -> Result < FunctionCall > {
379
- let ( ptr, size) = self . read_hyperlight_peb ( ) ?. get_output_data_guest_region ( ) ;
356
+ let ( ptr, size) = self
357
+ . memory_sections
358
+ . read_hyperlight_peb ( ) ?
359
+ . get_output_data_guest_region ( ) ;
380
360
self . shared_mem
381
361
. try_pop_buffer_into :: < FunctionCall > ( ptr as usize , size as usize )
382
362
}
@@ -390,7 +370,10 @@ impl SandboxMemoryManager<HostSharedMemory> {
390
370
)
391
371
} ) ?;
392
372
393
- let ( ptr, size) = self . read_hyperlight_peb ( ) ?. get_input_data_guest_region ( ) ;
373
+ let ( ptr, size) = self
374
+ . memory_sections
375
+ . read_hyperlight_peb ( ) ?
376
+ . get_input_data_guest_region ( ) ;
394
377
395
378
self . shared_mem . push_buffer (
396
379
ptr as usize ,
@@ -434,23 +417,32 @@ impl SandboxMemoryManager<HostSharedMemory> {
434
417
/// Read guest log data from the `SharedMemory` contained within `self`
435
418
#[ instrument( err( Debug ) , skip_all, parent = Span :: current( ) , level= "Trace" ) ]
436
419
pub ( crate ) fn read_guest_log_data ( & mut self ) -> Result < GuestLogData > {
437
- let ( ptr, size) = self . read_hyperlight_peb ( ) ?. get_output_data_guest_region ( ) ;
420
+ let ( ptr, size) = self
421
+ . memory_sections
422
+ . read_hyperlight_peb ( ) ?
423
+ . get_output_data_guest_region ( ) ;
438
424
self . shared_mem
439
425
. try_pop_buffer_into :: < GuestLogData > ( ptr as usize , size as usize )
440
426
}
441
427
442
428
/// Get the length of the host exception
443
429
#[ instrument( err( Debug ) , skip_all, parent = Span :: current( ) , level= "Trace" ) ]
444
430
fn get_host_error_length ( & self ) -> Result < i32 > {
445
- let offset = self . read_hyperlight_peb ( ) ?. get_host_error_guest_offset ( ) as usize ;
431
+ let offset = self
432
+ . memory_sections
433
+ . read_hyperlight_peb ( ) ?
434
+ . get_host_error_guest_address ( ) as usize ;
446
435
// The host exception field is expected to contain a 32-bit length followed by the exception data.
447
436
self . shared_mem . read :: < i32 > ( offset)
448
437
}
449
438
450
439
/// Get a bool indicating if there is a host error
451
440
#[ instrument( err( Debug ) , skip_all, parent = Span :: current( ) , level= "Trace" ) ]
452
441
fn has_host_error ( & self ) -> Result < bool > {
453
- let offset = self . read_hyperlight_peb ( ) ?. get_host_error_guest_offset ( ) as usize ;
442
+ let offset = self
443
+ . memory_sections
444
+ . read_hyperlight_peb ( ) ?
445
+ . get_host_error_guest_address ( ) as usize ;
454
446
// The host exception field is expected to contain a 32-bit length followed by the exception data.
455
447
let len = self . shared_mem . read :: < i32 > ( offset) ?;
456
448
Ok ( len != 0 )
@@ -465,7 +457,10 @@ impl SandboxMemoryManager<HostSharedMemory> {
465
457
/// self.get_host_error_length()
466
458
#[ instrument( err( Debug ) , skip_all, parent = Span :: current( ) , level= "Trace" ) ]
467
459
fn get_host_error_data ( & self , exception_data_slc : & mut [ u8 ] ) -> Result < ( ) > {
468
- let offset = self . read_hyperlight_peb ( ) ?. get_host_error_guest_offset ( ) as usize ;
460
+ let offset = self
461
+ . memory_sections
462
+ . read_hyperlight_peb ( ) ?
463
+ . get_host_error_guest_address ( ) as usize ;
469
464
let len = self . get_host_error_length ( ) ?;
470
465
471
466
let exception_data_slc_len = exception_data_slc. len ( ) ;
@@ -510,9 +505,14 @@ impl SandboxMemoryManager<HostSharedMemory> {
510
505
#[ instrument( err( Debug ) , skip_all, parent = Span :: current( ) , level= "Trace" ) ]
511
506
pub ( crate ) fn get_guest_error ( & self ) -> Result < GuestError > {
512
507
// get memory buffer max size
513
- let guest_error_data_ptr =
514
- self . read_hyperlight_peb ( ) ?. get_guest_error_guest_offset ( ) as usize ;
515
- let guest_error_data_size = self . read_hyperlight_peb ( ) ?. guest_error_data_size as usize ;
508
+ let guest_error_data_ptr = self
509
+ . memory_sections
510
+ . read_hyperlight_peb ( ) ?
511
+ . get_guest_error_guest_address ( ) as usize ;
512
+ let guest_error_data_size = self
513
+ . memory_sections
514
+ . read_hyperlight_peb ( ) ?
515
+ . get_guest_error_data_size ( ) as usize ;
516
516
517
517
// get guest error from layout and shared mem
518
518
let mut guest_error_buffer = vec ! [ b'0' ; guest_error_data_size] ;
@@ -541,18 +541,29 @@ impl SandboxMemoryManager<HostSharedMemory> {
541
541
. try_into ( )
542
542
. map_err ( |_| new_error ! ( "write_outb_error: failed to convert GuestError to Vec<u8>" ) ) ?;
543
543
544
- let guest_error_data_ptr = self . read_hyperlight_peb ( ) ?. get_guest_error_guest_offset ( ) ;
545
- let guest_error_data_size = self . read_hyperlight_peb ( ) ?. guest_error_data_size ;
544
+ let guest_error_data_ptr = self
545
+ . memory_sections
546
+ . read_hyperlight_peb ( ) ?
547
+ . get_guest_error_guest_address ( ) ;
548
+ let guest_error_data_size = self
549
+ . memory_sections
550
+ . read_hyperlight_peb ( ) ?
551
+ . get_guest_error_data_size ( ) ;
546
552
547
553
if guest_error_buffer. len ( ) as u64 > guest_error_data_size {
548
554
log_then_return ! ( "The guest error message is too large to fit in the shared memory" ) ;
549
555
}
550
556
self . shared_mem
551
557
. copy_from_slice ( guest_error_buffer. as_slice ( ) , guest_error_data_ptr as usize ) ?;
552
558
553
- let host_error_data_ptr =
554
- self . read_hyperlight_peb ( ) ?. get_host_error_guest_offset ( ) as usize ;
555
- let host_error_data_size = self . read_hyperlight_peb ( ) ?. host_error_data_size as usize ;
559
+ let host_error_data_ptr = self
560
+ . memory_sections
561
+ . read_hyperlight_peb ( ) ?
562
+ . get_host_error_guest_address ( ) as usize ;
563
+ let host_error_data_size = self
564
+ . memory_sections
565
+ . read_hyperlight_peb ( ) ?
566
+ . get_host_error_data_size ( ) as usize ;
556
567
557
568
// First four bytes of host exception are length
558
569
@@ -574,8 +585,14 @@ impl SandboxMemoryManager<HostSharedMemory> {
574
585
/// Read guest panic data from the `SharedMemory` contained within `self`
575
586
#[ instrument( err( Debug ) , skip_all, parent = Span :: current( ) , level= "Trace" ) ]
576
587
pub fn read_guest_panic_context_data ( & self ) -> Result < Vec < u8 > > {
577
- let offset = self . read_hyperlight_peb ( ) ?. get_guest_panic_context_offset ( ) as usize ;
578
- let size = self . read_hyperlight_peb ( ) ?. guest_panic_context_size as usize ;
588
+ let offset = self
589
+ . memory_sections
590
+ . read_hyperlight_peb ( ) ?
591
+ . get_guest_panic_context_guest_address ( ) as usize ;
592
+ let size = self
593
+ . memory_sections
594
+ . read_hyperlight_peb ( ) ?
595
+ . get_guest_panic_context_size ( ) as usize ;
579
596
let mut vec_out = vec ! [ 0 ; size] ;
580
597
self . shared_mem
581
598
. copy_to_slice ( vec_out. as_mut_slice ( ) , offset) ?;
0 commit comments